Fix update post bug

pull/137/head
johnniang 2019-03-21 23:59:56 +08:00
parent 7935ccd728
commit 95f23f84ea
2 changed files with 15 additions and 1 deletions

View File

@ -48,6 +48,15 @@ public interface PostRepository extends BaseRepository<Post, Integer>, JpaSpecif
*/
long countByUrl(@NonNull String url);
/**
* Count by not url and post id not in.
*
* @param id post id must not be null
* @param url post url must not be null
* @return the count
*/
long countByIdNotAndUrl(@NonNull Integer id, @NonNull String url);
/**
* Get post by url
*

View File

@ -189,7 +189,12 @@ public class PostServiceImpl extends AbstractCrudService<Post, Integer> implemen
Assert.notNull(postOperation, "Post operation must not be null");
// Check url
long count = postRepository.countByUrl(post.getUrl());
long count;
if (post.getId() != null) {
count = postRepository.countByIdNotAndUrl(post.getId(), post.getUrl());
} else {
count = postRepository.countByUrl(post.getUrl());
}
if (count > 0) {
throw new AlreadyExistsException("The post url has been exist already").setErrorData(post.getUrl());