From db19446929fd164a66521f4517cfac0f7e47aaea Mon Sep 17 00:00:00 2001 From: xhaktmchl Date: Fri, 7 Oct 2022 12:12:59 +0900 Subject: [PATCH] =?UTF-8?q?#9=20feat:=20Board=EC=83=9D=EC=84=B1=20?= =?UTF-8?q?=EC=A4=91=20City=EC=A1=B0=ED=9A=8C=20=EB=B0=8F=20=EA=B2=80?= =?UTF-8?q?=EC=A6=9D=20=EC=BD=94=EB=93=9C=20=EC=B6=94=EA=B0=80/=20feat:=20?= =?UTF-8?q?City=EB=A6=AC=ED=8C=8C=EC=A7=80=ED=86=A0=EB=A6=AC=20=EB=B0=8F?= =?UTF-8?q?=20CityException=20=EA=B8=B0=EB=B3=B8=20=EA=B5=AC=EC=A1=B0=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/board/dto/response/BoardRes.java | 2 +- .../com/yogit/server/board/entity/Board.java | 4 ++-- .../server/board/service/BoardServiceImpl.java | 7 ++++++- .../user/exception/city/CityException.java | 11 +++++++++++ .../user/exception/city/CityExceptionList.java | 17 +++++++++++++++++ .../exception/city/NotFoundCityException.java | 8 ++++++++ .../server/user/repository/CityRepository.java | 7 +++++++ 7 files changed, 52 insertions(+), 4 deletions(-) create mode 100644 server/src/main/java/com/yogit/server/user/exception/city/CityException.java create mode 100644 server/src/main/java/com/yogit/server/user/exception/city/CityExceptionList.java create mode 100644 server/src/main/java/com/yogit/server/user/exception/city/NotFoundCityException.java create mode 100644 server/src/main/java/com/yogit/server/user/repository/CityRepository.java diff --git a/server/src/main/java/com/yogit/server/board/dto/response/BoardRes.java b/server/src/main/java/com/yogit/server/board/dto/response/BoardRes.java index f68e663..a35411d 100644 --- a/server/src/main/java/com/yogit/server/board/dto/response/BoardRes.java +++ b/server/src/main/java/com/yogit/server/board/dto/response/BoardRes.java @@ -74,7 +74,7 @@ public class BoardRes { public static BoardRes toDto(Board board){ return BoardRes.builder() .boardId(board.getId()) - //.cityId(board.getCity().getId()) + .cityId(board.getCity().getId()) .hostId(board.getHost().getId()) .title(board.getTitle()) .address(board.getAddress()) diff --git a/server/src/main/java/com/yogit/server/board/entity/Board.java b/server/src/main/java/com/yogit/server/board/entity/Board.java index 029765a..51cc9c9 100644 --- a/server/src/main/java/com/yogit/server/board/entity/Board.java +++ b/server/src/main/java/com/yogit/server/board/entity/Board.java @@ -89,9 +89,9 @@ public Board(Long id, City city, User host, String title, String address, float } // 개발 중 임시 생성자 - public Board(CreateBoardReq dto, User host){ + public Board(CreateBoardReq dto, User host, City city){ // this.id = id; -// this.city = city; + this.city = city; this.host = host; this.title = dto.getTitle(); this.address = dto.getAddress(); diff --git a/server/src/main/java/com/yogit/server/board/service/BoardServiceImpl.java b/server/src/main/java/com/yogit/server/board/service/BoardServiceImpl.java index f5b314f..f1a2454 100644 --- a/server/src/main/java/com/yogit/server/board/service/BoardServiceImpl.java +++ b/server/src/main/java/com/yogit/server/board/service/BoardServiceImpl.java @@ -8,6 +8,8 @@ import com.yogit.server.user.entity.City; import com.yogit.server.user.entity.User; import com.yogit.server.user.exception.NotFoundUserException; +import com.yogit.server.user.exception.city.NotFoundCityException; +import com.yogit.server.user.repository.CityRepository; import com.yogit.server.user.repository.UserRepository; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; @@ -20,6 +22,7 @@ public class BoardServiceImpl implements BoardService{ private final BoardRepository boardRepository; private final UserRepository userRepository; + private final CityRepository cityRepository; @Transactional(readOnly = false) @Override @@ -29,12 +32,14 @@ public ApplicationResponse createBoard(CreateBoardReq dto){ User host = userRepository.findById(dto.getHostId()) .orElseThrow(() -> new NotFoundUserException()); // city조회 + City city = cityRepository.findById(dto.getCityId()) + .orElseThrow(() -> new NotFoundCityException()); // boardUsers 조회q // boardImages 조회 // boardCategories 조회 // board 생성 - Board board = new Board(dto, host); + Board board = new Board(dto, host, city); // currentMember 디폴트=0 board.changeBoardCurrentMember(0); diff --git a/server/src/main/java/com/yogit/server/user/exception/city/CityException.java b/server/src/main/java/com/yogit/server/user/exception/city/CityException.java new file mode 100644 index 0000000..5336f72 --- /dev/null +++ b/server/src/main/java/com/yogit/server/user/exception/city/CityException.java @@ -0,0 +1,11 @@ +package com.yogit.server.user.exception.city; + +import com.yogit.server.global.exception.ApplicationException; +import org.springframework.http.HttpStatus; + +public class CityException extends ApplicationException { + + protected CityException(String errorCode, HttpStatus httpStatus, String message) { + super(errorCode, httpStatus, message); + } +} diff --git a/server/src/main/java/com/yogit/server/user/exception/city/CityExceptionList.java b/server/src/main/java/com/yogit/server/user/exception/city/CityExceptionList.java new file mode 100644 index 0000000..4d99357 --- /dev/null +++ b/server/src/main/java/com/yogit/server/user/exception/city/CityExceptionList.java @@ -0,0 +1,17 @@ +package com.yogit.server.user.exception.city; + +import lombok.Getter; +import lombok.RequiredArgsConstructor; +import org.springframework.http.HttpStatus; + +@Getter +@RequiredArgsConstructor +public enum CityExceptionList { + + // 에러 목록 + NOT_FOUND_CITY("C0001", HttpStatus.NOT_FOUND, "존재하지 않는 City아이디입니다."); + + private final String CODE; + private final HttpStatus HTTPSTATUS; + private final String MESSAGE; +} diff --git a/server/src/main/java/com/yogit/server/user/exception/city/NotFoundCityException.java b/server/src/main/java/com/yogit/server/user/exception/city/NotFoundCityException.java new file mode 100644 index 0000000..57e9b53 --- /dev/null +++ b/server/src/main/java/com/yogit/server/user/exception/city/NotFoundCityException.java @@ -0,0 +1,8 @@ +package com.yogit.server.user.exception.city; + + +public class NotFoundCityException extends CityException{ + public NotFoundCityException(){ + super(CityExceptionList.NOT_FOUND_CITY.getCODE(), CityExceptionList.NOT_FOUND_CITY.getHTTPSTATUS(), CityExceptionList.NOT_FOUND_CITY.getMESSAGE()); + } +} diff --git a/server/src/main/java/com/yogit/server/user/repository/CityRepository.java b/server/src/main/java/com/yogit/server/user/repository/CityRepository.java new file mode 100644 index 0000000..dd3ebde --- /dev/null +++ b/server/src/main/java/com/yogit/server/user/repository/CityRepository.java @@ -0,0 +1,7 @@ +package com.yogit.server.user.repository; + +import com.yogit.server.user.entity.City; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface CityRepository extends JpaRepository { +}