Guest User

Untitled

a guest
Mar 18th, 2018
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.86 KB | None | 0 0
  1. @Entity
  2. @Getter
  3. @Setter
  4. @Table(name = "users")
  5. public class User {
  6.  
  7. @Id
  8. @GeneratedValue(generator = "increment")
  9. @GenericGenerator(name= "increment", strategy= "increment")
  10. @Column(name = "id", unique = true, nullable = false)
  11. private long id;
  12.  
  13. @Column(name = "login", length = 30, nullable = false)
  14. private String login;
  15.  
  16. @Column(name = "password", length = 30, nullable = false)
  17. private String password;
  18.  
  19. @Column(name = "name", length = 150, nullable = false)
  20. private String name;
  21.  
  22. @Column(name = "count_true_answers", nullable = false)
  23. private long countTrueAnswers;
  24.  
  25. @Column(name = "count_questions", nullable = false)
  26. private long countQuestions;
  27.  
  28. @ManyToOne(fetch = FetchType.EAGER)
  29. @JoinColumn(name = "id_group", nullable = false)
  30. private Group group;
  31.  
  32. @Transient
  33. private List<Question> questionsUser;
  34.  
  35. @Transient
  36. private Queue<Log> logsUser = new LinkedList<>();
  37.  
  38. public User(){
  39.  
  40. }
  41.  
  42. @Builder
  43. public User(String login, String password, String name, long countTrueAnswers, long countQuestions, Group group) {
  44. this.login = login;
  45. this.password = password;
  46. this.name = name;
  47. this.countTrueAnswers = countTrueAnswers;
  48. this.countQuestions = countQuestions;
  49. this.group = group;
  50. }
  51.  
  52. public void addLog(Log log){
  53. logsUser.add(log);
  54. }
  55.  
  56. public void removeQuestion(String title){
  57. for (Question question : questionsUser) {
  58. if(question.getTitle().equals(title)){
  59. questionsUser.remove(question);
  60. return;
  61. }
  62. }
  63. }
  64.  
  65. }
  66.  
  67. @Component
  68. public class OlympiadImpl implements Olympiad {
  69.  
  70. @Autowired
  71. private QuestionsService questionsService;
  72. @Autowired
  73. private UsersService usersService;
  74.  
  75. private User currentUser;
  76.  
  77. public void startOlympiad(String login, String password){
  78. currentUser = usersService.getUserByLoginAndPassword(login, password);
  79. currentUser.setQuestionsUser(questionsService.getQuestions());
  80. }
  81.  
  82. public String getStatisticUser() {
  83. return String.valueOf(currentUser.getCountTrueAnswers() + "/" + currentUser.getCountQuestions());
  84. }
  85.  
  86. public List<Question> getQuestions() {
  87. return currentUser.getQuestionsUser();
  88. }
  89.  
  90. public Question getQuestion(String title){
  91. for (Question question : currentUser.getQuestionsUser()) {
  92. if(question.getTitle().equals(title)){
  93. return question;
  94. }
  95. }
  96. return currentUser.getQuestionsUser().get(0);
  97. }
  98.  
  99. public Queue<Log> getLogsOfRunningTest(){
  100. return currentUser.getLogsUser();
  101. }
  102.  
  103. public ResultChecking checkTask(String nameQuestion, String
  104. // Проверка задания
  105. }
  106.  
  107.  
  108. private void delQuestion(String title){
  109. currentUser.removeQuestion(title);
  110. }
  111.  
  112. }
Add Comment
Please, Sign In to add comment