Changeset 0afa35a
- Timestamp:
- 01/08/23 20:04:25 (23 months ago)
- Branches:
- main
- Children:
- 4a93293
- Parents:
- 16f38d4
- Location:
- FullyStocked/src/main
- Files:
-
- 10 added
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
FullyStocked/src/main/java/com/bazi/fullystocked/Models/Answers.java
r16f38d4 r0afa35a 8 8 import javax.validation.constraints.NotEmpty; 9 9 import javax.validation.constraints.NotNull; 10 import java.io.Serializable; 10 11 import java.time.LocalDateTime; 11 12 … … 22 23 private String answertext; 23 24 24 public Answers(Questions question, String answertext) {25 public Answers(Questions question, Integer answerCount, String answertext) { 25 26 this.datecreated = LocalDateTime.now(); 26 27 this.answertext = answertext; 27 answerId.setQuestion(question); 28 this.answerId=new AnswerId(); 29 this.answerId.setAnswerid(answerCount); 30 this.answerId.setQuestion(question); 28 31 } 29 32 } -
FullyStocked/src/main/java/com/bazi/fullystocked/Models/Enumerations/ArticleStatus.java
r16f38d4 r0afa35a 2 2 3 3 public enum ArticleStatus { 4 ORDERED, DELIVERED, PROCESSED 4 ORDERED("Ordered"), DELIVERED("Delivered"), PROCESSED("Processed"); 5 private String name; 6 7 ArticleStatus(String s) { 8 this.name=s; 9 } 10 public String getName() { 11 return this.name; 12 } 13 public String toString() { 14 return name; 15 } 5 16 } -
FullyStocked/src/main/java/com/bazi/fullystocked/Models/Enumerations/OrderPriority.java
r16f38d4 r0afa35a 2 2 3 3 public enum OrderPriority { 4 LOW, MEDIUM, HIGH; 4 LOW("Low"), MEDIUM("Medium"), HIGH("High"); 5 private String name; 6 7 OrderPriority(String s) { 8 this.name=s; 9 } 10 public String getName() { 11 return this.name; 12 } 13 public String toString() { 14 return name; 15 } 5 16 } -
FullyStocked/src/main/java/com/bazi/fullystocked/Repositories/AnswersRepository.java
r16f38d4 r0afa35a 11 11 public interface AnswersRepository extends JpaRepository<Answers, AnswerId> { 12 12 List<Answers> findAnswersByAnswerId_Question(Questions q); 13 int countAnswersByAnswerId_Question(Questions q); 13 14 } -
FullyStocked/src/main/java/com/bazi/fullystocked/Services/Implementations/AnswerServiceImpl.java
r16f38d4 r0afa35a 35 35 throw new InvalidArgumentsException(); 36 36 } 37 return Optional.of(answersRepository.save(new Answers(question, text)));37 return Optional.of(answersRepository.save(new Answers(question, answersRepository.countAnswersByAnswerId_Question(question) +1, text))); 38 38 } 39 39 } -
FullyStocked/src/main/java/com/bazi/fullystocked/Services/Implementations/QuestionServiceImpl.java
r16f38d4 r0afa35a 1 1 package com.bazi.fullystocked.Services.Implementations; 2 2 3 import com.bazi.fullystocked.Models.Exceptions.ArticleAlreadyInQuestionException; 3 4 import com.bazi.fullystocked.Models.Exceptions.InvalidArgumentsException; 4 5 import com.bazi.fullystocked.Models.Managers; … … 39 40 throw new InvalidArgumentsException(); 40 41 } 41 return Optional.of( new Questions(text, worker, manager));42 return Optional.of(questionsRepository.save(new Questions(text, worker, manager))); 42 43 } 43 44 … … 47 48 Questions question=questionsRepository.findById(questionid).orElseThrow(InvalidArgumentsException::new); 48 49 StoredArticles article=storedArticlesRepository.findById(sarticleid).orElseThrow(InvalidArgumentsException::new); 49 question.getStoredarticlesList().add(article); 50 if(article.getQuestionsList().stream().anyMatch(questions -> questions.getQuestionid().equals(questionid))) 51 { 52 throw new ArticleAlreadyInQuestionException(); 53 } 54 article.getQuestionsList().add(question); 55 storedArticlesRepository.save(article); 50 56 questionsRepository.save(question); 51 57 return Optional.of(question); -
FullyStocked/src/main/java/com/bazi/fullystocked/Web/Controller/WorkerController.java
r16f38d4 r0afa35a 2 2 3 3 import com.bazi.fullystocked.Models.Enumerations.ArticleStatus; 4 import com.bazi.fullystocked.Models.Questions; 4 5 import com.bazi.fullystocked.Models.SqlViews.ArticlesReport; 5 6 import com.bazi.fullystocked.Models.Workers; 6 import com.bazi.fullystocked.Services.ArticlesService; 7 import com.bazi.fullystocked.Services.OrderedArticlesService; 8 import com.bazi.fullystocked.Services.StoredArticlesService; 7 import com.bazi.fullystocked.Services.*; 9 8 import org.springframework.stereotype.Controller; 10 9 import org.springframework.ui.Model; … … 20 19 private final ArticlesService articlesService; 21 20 private final OrderedArticlesService orderedArticlesService; 21 private final QuestionsService questionsService; 22 private final ManagersService managersService; 22 23 23 public WorkerController(StoredArticlesService storedArticlesService, ArticlesService articlesService, OrderedArticlesService orderedArticlesService ) {24 public WorkerController(StoredArticlesService storedArticlesService, ArticlesService articlesService, OrderedArticlesService orderedArticlesService, QuestionsService questionsService, ManagersService managersService) { 24 25 this.storedArticlesService = storedArticlesService; 25 26 this.articlesService = articlesService; 26 27 this.orderedArticlesService = orderedArticlesService; 28 this.questionsService = questionsService; 29 this.managersService = managersService; 27 30 } 28 31 … … 84 87 } 85 88 89 @PostMapping("/articles/askAQuestion") 90 public String askAQuestionForASingleArticle(@RequestParam Integer articleId, Model model) 91 { 92 model.addAttribute("articleId", articleId); 93 model.addAttribute("managers", managersService.findAll()); 94 return "AskAQuestionSingle"; 95 } 96 @PostMapping("/articles/askAQuestion/send") 97 public String sendQuestionSingle(@RequestParam Integer articleId, @RequestParam Integer managerId, @RequestParam String text, HttpServletRequest request) 98 { 99 try 100 { 101 Workers u= (Workers) request.getSession().getAttribute("user"); 102 if(storedArticlesService.findById(articleId).isEmpty()) 103 { 104 return "redirect:/worker/articles"; 105 } 106 if(!storedArticlesService.findById(articleId).get().getLocationid().equals(u.getLocation().getLocationid())) 107 { 108 return "redirect:/login"; 109 } 110 Questions q=questionsService.create(text, u.getUserid(), managerId).orElseThrow(); 111 questionsService.addArticle(q.getQuestionid(), articleId); 112 return "redirect:/worker"; 113 } 114 catch (Exception e) 115 { 116 return "redirect:/worker?error="+e.getMessage(); 117 } 118 } 119 86 120 } -
FullyStocked/src/main/resources/templates/detailsArticle.html
r16f38d4 r0afa35a 68 68 <div class="project-info-box mt-0 mb-0"> 69 69 <p class="mb-0"> 70 <form action="/worker/articles/askAQuestion" th:method="POST"> 71 <input type="hidden" name="articleId" th:value="${article.getSarticleid()}"> 72 <button class="btn btn-primary" >Креаирај прашање</button> 73 </form> 74 75 </p> 76 </div> 77 78 <div class="project-info-box mt-3 mb-0"> 79 <p class="mb-0"> 70 80 <a class="btn btn-danger" href="/worker/articles" role="button">« Назад</a> 71 81
Note:
See TracChangeset
for help on using the changeset viewer.