mirror of https://github.com/halo-dev/halo
Fix update post bug
parent
7935ccd728
commit
95f23f84ea
|
@ -48,6 +48,15 @@ public interface PostRepository extends BaseRepository<Post, Integer>, JpaSpecif
|
||||||
*/
|
*/
|
||||||
long countByUrl(@NonNull String url);
|
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
|
* Get post by url
|
||||||
*
|
*
|
||||||
|
|
|
@ -189,7 +189,12 @@ public class PostServiceImpl extends AbstractCrudService<Post, Integer> implemen
|
||||||
Assert.notNull(postOperation, "Post operation must not be null");
|
Assert.notNull(postOperation, "Post operation must not be null");
|
||||||
|
|
||||||
// Check url
|
// 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) {
|
if (count > 0) {
|
||||||
throw new AlreadyExistsException("The post url has been exist already").setErrorData(post.getUrl());
|
throw new AlreadyExistsException("The post url has been exist already").setErrorData(post.getUrl());
|
||||||
|
|
Loading…
Reference in New Issue