diff --git a/src/main/java/com/umc/DongnaeFriend/domain/account/sharing/dto/SharingDto.java b/src/main/java/com/umc/DongnaeFriend/domain/account/sharing/dto/SharingDto.java index 7825ef8..01bb153 100644 --- a/src/main/java/com/umc/DongnaeFriend/domain/account/sharing/dto/SharingDto.java +++ b/src/main/java/com/umc/DongnaeFriend/domain/account/sharing/dto/SharingDto.java @@ -10,7 +10,9 @@ import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; +import org.springframework.lang.Nullable; +import javax.validation.constraints.NotNull; import java.util.List; public class SharingDto { @@ -20,12 +22,17 @@ public class SharingDto { @AllArgsConstructor @NoArgsConstructor public static class Request { + + @NotNull(message = "카테고리는 필수입니다.") private int category; + @NotNull(message = "제목은 필수입니다.") private String title; + @NotNull(message = "내용은 필수입니다.") private String content; + private List images; public SharingBoard toEntity(User user) { diff --git a/src/main/java/com/umc/DongnaeFriend/domain/account/sharing/service/AccountBookSharingServiceImpl.java b/src/main/java/com/umc/DongnaeFriend/domain/account/sharing/service/AccountBookSharingServiceImpl.java index e741567..87338b3 100644 --- a/src/main/java/com/umc/DongnaeFriend/domain/account/sharing/service/AccountBookSharingServiceImpl.java +++ b/src/main/java/com/umc/DongnaeFriend/domain/account/sharing/service/AccountBookSharingServiceImpl.java @@ -59,7 +59,6 @@ public List searchByKeyword(String keyword, int categor if (sharingBoards.isEmpty()) { throw new CustomException(ErrorCode.NO_CONTENT_FOUND); } - log.info("board found" + sharingBoards.get(0).getId()); return getListResponses(sharingBoards); } @@ -118,7 +117,7 @@ public SharingDto.Response getBoard(long board_id) { @Override public void updateBoard(long board_id, SharingDto.Request req) { SharingBoard board = sharingBoardRepository.findById(board_id).orElseThrow( - () -> new CustomException(ErrorCode.INVALID_VALUE)); + () -> new CustomException(ErrorCode.NO_CONTENT_FOUND)); board.updateBoard(req); sharingBoardRepository.save(board); @@ -132,6 +131,15 @@ public void updateBoard(long board_id, SharingDto.Request req) { */ @Override public void deleteBoard(long board_id) { + Optional sharingBoard = sharingBoardRepository.findById(board_id); + if (sharingBoard.isEmpty()) { + throw new CustomException(ErrorCode.NO_CONTENT_FOUND); + } + + if (!Objects.equals(sharingBoard.get().getUser().getId(), user.getId())) { + throw new CustomException(ErrorCode.INVALID_AUTH_TOKEN); + } + sharingBoardRepository.deleteById(board_id); } diff --git a/src/main/java/com/umc/DongnaeFriend/domain/dongnae/dto/DongnaeBoardDto.java b/src/main/java/com/umc/DongnaeFriend/domain/dongnae/dto/DongnaeBoardDto.java index 6489bcf..59ff18d 100644 --- a/src/main/java/com/umc/DongnaeFriend/domain/dongnae/dto/DongnaeBoardDto.java +++ b/src/main/java/com/umc/DongnaeFriend/domain/dongnae/dto/DongnaeBoardDto.java @@ -11,6 +11,8 @@ import com.umc.DongnaeFriend.domain.user.entity.User; import lombok.*; +import javax.validation.Valid; +import javax.validation.constraints.NotNull; import java.util.List; import java.util.stream.Collectors; @@ -21,12 +23,19 @@ public class DongnaeBoardDto { @AllArgsConstructor @NoArgsConstructor public static class Request { + @NotNull(message = "카테고리는 필수입니다.") private int category; + + @NotNull(message = "제목은 필수입니다.") private String title; + @NotNull(message = "내응은 필수입니다.") private String content; private List images; + + @NotNull(message = "장소는 필수입니다.") private String place; + @NotNull(message = "자세한 장소는 필수입니다.") private String placeLocation; diff --git a/src/main/java/com/umc/DongnaeFriend/domain/dongnae/service/DongnaeBoardServiceImpl.java b/src/main/java/com/umc/DongnaeFriend/domain/dongnae/service/DongnaeBoardServiceImpl.java index a0554b0..97d4ef9 100644 --- a/src/main/java/com/umc/DongnaeFriend/domain/dongnae/service/DongnaeBoardServiceImpl.java +++ b/src/main/java/com/umc/DongnaeFriend/domain/dongnae/service/DongnaeBoardServiceImpl.java @@ -12,6 +12,8 @@ import com.umc.DongnaeFriend.domain.type.YesNo; import com.umc.DongnaeFriend.domain.user.entity.User; import com.umc.DongnaeFriend.domain.user.repository.UserRepository; +import com.umc.DongnaeFriend.global.exception.CustomException; +import com.umc.DongnaeFriend.global.exception.ErrorCode; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Pageable; @@ -80,11 +82,15 @@ public List searchByKeyword(String keyword, int ca List dongnaeBoardList = dongnaeBoardRepository.findByKeyword(keyword, categoryName, pageable); + if (dongnaeBoardList.isEmpty()) { + throw new CustomException(ErrorCode.NO_CONTENT_FOUND); + } + return getListResponses(dongnaeBoardList); } /* - * [동네정보] 게시글 목록 조회 + * [동네정보] 게시글 목록 조회 DLETED * @param sort */ @Override @@ -106,12 +112,6 @@ public List searchAll(int sort) { @Override public void createBoard(DongnaeBoardDto.Request req) { //TODO : User Mapping UserRepository 필요. - - Dongnae dongnae = Dongnae.builder().id(1L).gu("서울구").dong("서울동").city("서울시").townName("무슨마을").build(); - User user = User.builder().id(1L).age(Age.AGE10).email("email").dongnae(dongnae).gender(Gender.FEMALE).infoCert(YesNo.NO).townCert(YesNo.NO).townCertCnt(10).id(1L).kakaoId(90L).nickname("nickname").refreshToken("refreshToken").build(); - - dongnaeRepository.save(dongnae); - userRepository.save(user); dongnaeBoardRepository.save(req.toEntity(user, dongnae)); } @@ -126,7 +126,7 @@ public DongnaeBoardDto.Response getBoard(long board_id) { //TODO : User 식별자 필요. Optional board = dongnaeBoardRepository.findById(board_id); if (board.isEmpty()) { - throw new RuntimeException(); + throw new CustomException(ErrorCode.NO_CONTENT_FOUND); } //Get Images @@ -165,17 +165,17 @@ public DongnaeBoardDto.Response getBoard(long board_id) { * [동네정보] 게시글 수정 */ @Override - public void updateBoard(long board_id, DongnaeBoardDto.Request request) throws AuthenticationException { + public void updateBoard(long board_id, DongnaeBoardDto.Request request) { Optional board = dongnaeBoardRepository.findById(board_id); if (board.isPresent()) { //User Validaiton if (!Objects.equals(board.get().getUser().getId(), user.getId())) { - throw new AuthenticationException(); + throw new CustomException(ErrorCode.INVALID_AUTH_TOKEN); } board.get().updateBoard(request); dongnaeBoardRepository.save(board.get()); } else { - throw new EntityNotFoundException(); + throw new CustomException(ErrorCode.INVALID_VALUE); } } @@ -183,10 +183,10 @@ public void updateBoard(long board_id, DongnaeBoardDto.Request request) throws A public void deleteBoard(long board_id) throws AuthenticationException { Optional board = dongnaeBoardRepository.findById(board_id); - if (board.isEmpty()) throw new EntityNotFoundException(); + if (board.isEmpty()) throw new CustomException(ErrorCode.NO_CONTENT_FOUND); //User Validation if (!Objects.equals(board.get().getUser().getId(), user.getId())) { - throw new AuthenticationException(); + throw new CustomException(ErrorCode.INVALID_AUTH_TOKEN); } else { dongnaeBoardRepository.deleteById(board_id); }