Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @Entity
- @Getter
- @Setter
- @Table(name = "users")
- public class User {
- @Id
- @GeneratedValue(generator = "increment")
- @GenericGenerator(name= "increment", strategy= "increment")
- @Column(name = "id", unique = true, nullable = false)
- private long id;
- @Column(name = "login", length = 30, nullable = false)
- private String login;
- @Column(name = "password", length = 30, nullable = false)
- private String password;
- @Column(name = "name", length = 150, nullable = false)
- private String name;
- @Column(name = "count_true_answers", nullable = false)
- private long countTrueAnswers;
- @Column(name = "count_questions", nullable = false)
- private long countQuestions;
- @ManyToOne(fetch = FetchType.EAGER)
- @JoinColumn(name = "id_group", nullable = false)
- private Group group;
- @Transient
- private List<Question> questionsUser;
- @Transient
- private Queue<Log> logsUser = new LinkedList<>();
- public User(){
- }
- @Builder
- public User(String login, String password, String name, long countTrueAnswers, long countQuestions, Group group) {
- this.login = login;
- this.password = password;
- this.name = name;
- this.countTrueAnswers = countTrueAnswers;
- this.countQuestions = countQuestions;
- this.group = group;
- }
- public void addLog(Log log){
- logsUser.add(log);
- }
- public void removeQuestion(String title){
- for (Question question : questionsUser) {
- if(question.getTitle().equals(title)){
- questionsUser.remove(question);
- return;
- }
- }
- }
- }
- @Component
- public class OlympiadImpl implements Olympiad {
- @Autowired
- private QuestionsService questionsService;
- @Autowired
- private UsersService usersService;
- private User currentUser;
- public void startOlympiad(String login, String password){
- currentUser = usersService.getUserByLoginAndPassword(login, password);
- currentUser.setQuestionsUser(questionsService.getQuestions());
- }
- public String getStatisticUser() {
- return String.valueOf(currentUser.getCountTrueAnswers() + "/" + currentUser.getCountQuestions());
- }
- public List<Question> getQuestions() {
- return currentUser.getQuestionsUser();
- }
- public Question getQuestion(String title){
- for (Question question : currentUser.getQuestionsUser()) {
- if(question.getTitle().equals(title)){
- return question;
- }
- }
- return currentUser.getQuestionsUser().get(0);
- }
- public Queue<Log> getLogsOfRunningTest(){
- return currentUser.getLogsUser();
- }
- public ResultChecking checkTask(String nameQuestion, String
- // Проверка задания
- }
- private void delQuestion(String title){
- currentUser.removeQuestion(title);
- }
- }
Add Comment
Please, Sign In to add comment