Prevent duplicate Articles from ArticleOffer
This commit is contained in:
parent
2989b54593
commit
ffe9af0633
|
@ -120,11 +120,17 @@ public class InternArticleController {
|
||||||
@PostMapping("/addArticle/{id}")
|
@PostMapping("/addArticle/{id}")
|
||||||
public RedirectView addArticle(@PathVariable(required = true) String id) {
|
public RedirectView addArticle(@PathVariable(required = true) String id) {
|
||||||
// article is not already listed, create new one
|
// article is not already listed, create new one
|
||||||
int offeredArticleID = Integer.parseInt(id);
|
long offeredArticleID = Long.parseLong(id);
|
||||||
|
|
||||||
Article tmpArticle = new Article();
|
Article tmpArticle = new Article();
|
||||||
|
|
||||||
ArticleOffer offeredArticle = offersRepository.findOfferedArticleById(offeredArticleID);
|
ArticleOffer offeredArticle = offersRepository.findById(offeredArticleID).get();
|
||||||
|
|
||||||
|
// Check for duplicates
|
||||||
|
Optional<Article> related = articleRepository.findArticleByArticleOffer(offeredArticle);
|
||||||
|
if (related.isPresent()) {
|
||||||
|
return new RedirectView("../" + related.get().id);
|
||||||
|
}
|
||||||
|
|
||||||
// set default values
|
// set default values
|
||||||
tmpArticle.description = "";
|
tmpArticle.description = "";
|
||||||
|
|
Reference in New Issue