Prevent duplicate Articles from ArticleOffer
This commit is contained in:
		@ -120,11 +120,17 @@ public class InternArticleController {
 | 
			
		||||
	@PostMapping("/addArticle/{id}")
 | 
			
		||||
	public RedirectView addArticle(@PathVariable(required = true) String id) {
 | 
			
		||||
		// article is not already listed, create new one
 | 
			
		||||
		int offeredArticleID = Integer.parseInt(id);
 | 
			
		||||
		long offeredArticleID = Long.parseLong(id);
 | 
			
		||||
 | 
			
		||||
		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
 | 
			
		||||
		tmpArticle.description = "";
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user