From 533d5169b2e374648e587eb613c7dd06ae7780b1 Mon Sep 17 00:00:00 2001 From: Dustbox Date: Thu, 15 Feb 2024 17:07:07 +0900 Subject: [PATCH 01/14] [Feat] add Road Domain Files --- .../ttubeog/domain/road/dto/request/CreateRoadRequestDto.java | 4 ++++ .../com/ttubeog/domain/road/dto/response/RoadResponseDto.java | 4 ++++ 2 files changed, 8 insertions(+) create mode 100644 src/main/java/com/ttubeog/domain/road/dto/request/CreateRoadRequestDto.java create mode 100644 src/main/java/com/ttubeog/domain/road/dto/response/RoadResponseDto.java diff --git a/src/main/java/com/ttubeog/domain/road/dto/request/CreateRoadRequestDto.java b/src/main/java/com/ttubeog/domain/road/dto/request/CreateRoadRequestDto.java new file mode 100644 index 00000000..04d23fa4 --- /dev/null +++ b/src/main/java/com/ttubeog/domain/road/dto/request/CreateRoadRequestDto.java @@ -0,0 +1,4 @@ +package com.ttubeog.domain.road.dto.request; + +public class CreateRoadRequestDto { +} diff --git a/src/main/java/com/ttubeog/domain/road/dto/response/RoadResponseDto.java b/src/main/java/com/ttubeog/domain/road/dto/response/RoadResponseDto.java new file mode 100644 index 00000000..907f2d6c --- /dev/null +++ b/src/main/java/com/ttubeog/domain/road/dto/response/RoadResponseDto.java @@ -0,0 +1,4 @@ +package com.ttubeog.domain.road.dto.response; + +public class RoadResponseDto { +} From 7834d73a85b451916b0e472cdb4de73dff0b569f Mon Sep 17 00:00:00 2001 From: Dustbox Date: Thu, 15 Feb 2024 17:48:28 +0900 Subject: [PATCH 02/14] [Feat] implement Road Entity --- .../com/ttubeog/domain/road/domain/Road.java | 29 ++++++++++++++++--- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/ttubeog/domain/road/domain/Road.java b/src/main/java/com/ttubeog/domain/road/domain/Road.java index efc2bdcd..b289220d 100644 --- a/src/main/java/com/ttubeog/domain/road/domain/Road.java +++ b/src/main/java/com/ttubeog/domain/road/domain/Road.java @@ -1,10 +1,10 @@ package com.ttubeog.domain.road.domain; import com.ttubeog.domain.common.BaseEntity; -import jakarta.persistence.Entity; -import jakarta.persistence.GeneratedValue; -import jakarta.persistence.GenerationType; -import jakarta.persistence.Id; +import com.ttubeog.domain.member.domain.Member; +import com.ttubeog.domain.spot.domain.Spot; +import com.ttubeog.domain.store.domain.Store; +import jakarta.persistence.*; @Entity public class Road extends BaseEntity { @@ -12,4 +12,25 @@ public class Road extends BaseEntity { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "spot_id") + private Spot spot; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "store_id") + private Store store; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "member_id", nullable = false) + private Member member; + + @Column(name = "name", nullable = false) + private String name; + + @Column(name = "road_file", nullable = false) + private String roadFile; + + @Column(name = "time", nullable = false) + private String time; } From deff1d9b3f41845afd523ec7162036cb359c5c66 Mon Sep 17 00:00:00 2001 From: Dustbox Date: Fri, 16 Feb 2024 02:43:52 +0900 Subject: [PATCH 03/14] =?UTF-8?q?[Refac]=20=ED=8F=89=EC=A0=90=20Update=20?= =?UTF-8?q?=EC=98=A4=EB=A5=98=20=EC=88=98=EC=A0=95=20=EB=B0=8F=20GuestBook?= =?UTF-8?q?=20Controller=20=EB=B6=84=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../application/GuestBookService.java | 26 +++-- .../domain/guestbook/domain/GuestBook.java | 7 +- .../repository/GuestBookRepository.java | 7 ++ .../dto/response/GuestBookResponseDto.java | 6 +- .../presentation/GuestBookController.java | 102 +++++++++++++++++- .../spot/presentation/SpotController.java | 69 ------------ 6 files changed, 126 insertions(+), 91 deletions(-) diff --git a/src/main/java/com/ttubeog/domain/guestbook/application/GuestBookService.java b/src/main/java/com/ttubeog/domain/guestbook/application/GuestBookService.java index d886357b..563e348a 100644 --- a/src/main/java/com/ttubeog/domain/guestbook/application/GuestBookService.java +++ b/src/main/java/com/ttubeog/domain/guestbook/application/GuestBookService.java @@ -28,14 +28,18 @@ import com.ttubeog.global.payload.Message; import feign.Response; import io.swagger.v3.oas.annotations.tags.Tag; +import jakarta.persistence.criteria.CriteriaBuilder; import jakarta.servlet.http.HttpServletRequest; import lombok.NonNull; import lombok.RequiredArgsConstructor; import org.apache.ibatis.jdbc.Null; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageRequest; import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import java.awt.print.Pageable; import java.util.List; @RequiredArgsConstructor @@ -130,6 +134,7 @@ public ResponseEntity createGuestBook(HttpServletRequest request, CreateGuest guestBookRepository.save(guestBook); + CreateImageRequestDto createImageRequestDto = CreateImageRequestDto.builder() .image(createGuestBookRequestDto.getImage()) .imageType(ImageType.GUESTBOOK) @@ -137,6 +142,7 @@ public ResponseEntity createGuestBook(HttpServletRequest request, CreateGuest .build(); imageService.createImage(createImageRequestDto); + if (createGuestBookRequestDto.getGuestBookType().equals(GuestBookType.SPOT)) { spot = spotRepository.findById(createGuestBookRequestDto.getSpotId()).orElseThrow(InvalidSpotIdException::new); @@ -146,7 +152,7 @@ public ResponseEntity createGuestBook(HttpServletRequest request, CreateGuest float updateStarValue; - updateStarValue = ((originStars * guestBookNum) + createGuestBookRequestDto.getStar()) / (guestBookNum + 1); + updateStarValue = ((originStars + (float)createGuestBookRequestDto.getStar()) / (float)(guestBookNum + 1)); spot.updateStars(updateStarValue); @@ -160,7 +166,7 @@ public ResponseEntity createGuestBook(HttpServletRequest request, CreateGuest float updateStarValue; - updateStarValue = ((originStars * guestBookNum) + createGuestBookRequestDto.getStar()) / (guestBookNum + 1); + updateStarValue = ((originStars + (float)createGuestBookRequestDto.getStar()) / (float)(guestBookNum + 1)); store.updateStars(updateStarValue); @@ -184,17 +190,17 @@ public ResponseEntity findByGuestBookId(HttpServletRequest request, Long gues return getResponseEntity(guestBook); } - // Spot ID 로 GuestBook 을 조회하는 Method 입니다. 현재 따로 사용하지 않습니다. - public ResponseEntity findGuestBookBySpotId(HttpServletRequest request, Long spotId) { + // Spot ID 로 GuestBook 을 조회하는 Method 입니다. + public ResponseEntity findGuestBookBySpotId(HttpServletRequest request, Long spotId, Integer pageNum) { Long memberId = jwtTokenProvider.getMemberId(request); memberRepository.findById(memberId).orElseThrow(InvalidMemberException::new); - List guestBookList = guestBookRepository.findAllBySpot_Id(spotId); + Page guestBookPage = guestBookRepository.findAllBySpot_Id(spotId, PageRequest.of(pageNum, 10)); List guestBookResponseDtoList = null; - for (GuestBook guestBook : guestBookList) { + for (GuestBook guestBook : guestBookPage) { GuestBookResponseDto guestBookResponseDto = GuestBookResponseDto.builder() .id(guestBook.getId()) .content(guestBook.getContent()) @@ -214,17 +220,17 @@ public ResponseEntity findGuestBookBySpotId(HttpServletRequest request, Long return ResponseEntity.ok(apiResponse); } - // Store ID 로 GuestBook 을 조회하는 Method 입니다. 현재 따로 사용하지 않습니다. - public ResponseEntity findGuestBookByStoreId(HttpServletRequest request, Long storeId) { + // Store ID 로 GuestBook 을 조회하는 Method 입니다. + public ResponseEntity findGuestBookByStoreId(HttpServletRequest request, Long storeId, Integer pageNum) { Long memberId = jwtTokenProvider.getMemberId(request); memberRepository.findById(memberId).orElseThrow(InvalidMemberException::new); - List guestBookList = guestBookRepository.findAllByStore_Id(storeId); + Page guestBookPage = guestBookRepository.findAllByStore_Id(storeId, PageRequest.of(pageNum, 10)); List guestBookResponseDtoList = null; - for (GuestBook guestBook : guestBookList) { + for (GuestBook guestBook : guestBookPage) { GuestBookResponseDto guestBookResponseDto = GuestBookResponseDto.builder() .id(guestBook.getId()) .content(guestBook.getContent()) diff --git a/src/main/java/com/ttubeog/domain/guestbook/domain/GuestBook.java b/src/main/java/com/ttubeog/domain/guestbook/domain/GuestBook.java index 4f2bad81..fd435ca2 100644 --- a/src/main/java/com/ttubeog/domain/guestbook/domain/GuestBook.java +++ b/src/main/java/com/ttubeog/domain/guestbook/domain/GuestBook.java @@ -43,10 +43,7 @@ public class GuestBook extends BaseEntity { private Float star; - @OneToOne(mappedBy = "guestBook", cascade = CascadeType.ALL) - private Image image; - - public GuestBook(Long id, Member member, GuestBookType guestBookType, Spot spot, Store store, String content, Float star, Image image) { + public GuestBook(Long id, Member member, GuestBookType guestBookType, Spot spot, Store store, String content, Float star) { this.id = id; this.member = member; this.guestBookType = guestBookType; @@ -54,12 +51,10 @@ public GuestBook(Long id, Member member, GuestBookType guestBookType, Spot spot, this.store = store; this.content = content; this.star = star; - this.image = image; } public void updateGuestBook(String content, Float star, Image image) { this.content = content; this.star = star; - this.image = image; } } diff --git a/src/main/java/com/ttubeog/domain/guestbook/domain/repository/GuestBookRepository.java b/src/main/java/com/ttubeog/domain/guestbook/domain/repository/GuestBookRepository.java index 3bb0a2f5..15d769da 100644 --- a/src/main/java/com/ttubeog/domain/guestbook/domain/repository/GuestBookRepository.java +++ b/src/main/java/com/ttubeog/domain/guestbook/domain/repository/GuestBookRepository.java @@ -1,11 +1,14 @@ package com.ttubeog.domain.guestbook.domain.repository; import com.ttubeog.domain.guestbook.domain.GuestBook; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageRequest; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; +import java.awt.print.Pageable; import java.util.List; @Repository @@ -13,6 +16,8 @@ public interface GuestBookRepository extends JpaRepository { List findAllBySpot_Id(Long spotId); + Page findAllBySpot_Id(Long spotId, PageRequest pageRequest); + Long countAllBySpot_Id(Long spotId); @Query("SELECT SUM(g.star) FROM GuestBook g WHERE g.spot.id = :spotId") @@ -20,6 +25,8 @@ public interface GuestBookRepository extends JpaRepository { List findAllByStore_Id(Long storeId); + Page findAllByStore_Id(Long storeId, PageRequest pageRequest); + Long countAllByStore_Id(Long storeId); @Query("SELECT SUM(g.star) FROM GuestBook g WHERE g.store.id = :storeId") diff --git a/src/main/java/com/ttubeog/domain/guestbook/dto/response/GuestBookResponseDto.java b/src/main/java/com/ttubeog/domain/guestbook/dto/response/GuestBookResponseDto.java index 6f8e4495..1643090a 100644 --- a/src/main/java/com/ttubeog/domain/guestbook/dto/response/GuestBookResponseDto.java +++ b/src/main/java/com/ttubeog/domain/guestbook/dto/response/GuestBookResponseDto.java @@ -24,10 +24,7 @@ public class GuestBookResponseDto { private Float star; - private String image; - - - public GuestBookResponseDto(Long id, Long memberId, GuestBookType guestBookType, Long spotId, Long storeId, String content, Float star, String image) { + public GuestBookResponseDto(Long id, Long memberId, GuestBookType guestBookType, Long spotId, Long storeId, String content, Float star) { this.id = id; this.memberId = memberId; this.guestBookType = guestBookType; @@ -35,6 +32,5 @@ public GuestBookResponseDto(Long id, Long memberId, GuestBookType guestBookType, this.storeId = storeId; this.content = content; this.star = star; - this.image = image; } } diff --git a/src/main/java/com/ttubeog/domain/guestbook/presentation/GuestBookController.java b/src/main/java/com/ttubeog/domain/guestbook/presentation/GuestBookController.java index 4b317aa3..30307c64 100644 --- a/src/main/java/com/ttubeog/domain/guestbook/presentation/GuestBookController.java +++ b/src/main/java/com/ttubeog/domain/guestbook/presentation/GuestBookController.java @@ -1,8 +1,108 @@ package com.ttubeog.domain.guestbook.presentation; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.ttubeog.domain.guestbook.application.GuestBookService; +import com.ttubeog.domain.guestbook.dto.request.CreateGuestBookRequestDto; +import com.ttubeog.domain.guestbook.dto.response.GuestBookResponseDto; +import com.ttubeog.domain.member.exception.InvalidMemberException; +import com.ttubeog.domain.spot.dto.request.CreateSpotRequestDto; +import com.ttubeog.domain.spot.dto.response.SpotResponseDto; +import com.ttubeog.domain.spot.exception.AlreadyExistsSpotException; +import com.ttubeog.domain.spot.exception.InvalidDongAreaException; +import com.ttubeog.domain.spot.exception.InvalidImageListSizeException; +import com.ttubeog.global.config.security.token.CurrentUser; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.media.ArraySchema; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.oas.annotations.responses.ApiResponse; import io.swagger.v3.oas.annotations.tags.Tag; -import org.springframework.web.bind.annotation.RestController; +import jakarta.persistence.Table; +import jakarta.servlet.http.HttpServletRequest; +import lombok.RequiredArgsConstructor; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; +@Tag(name = "GuestBook", description = "GuestBook API(방명록 API)") +@RequiredArgsConstructor @RestController +@RequestMapping("api/v1/guestbook") public class GuestBookController { + + private final GuestBookService guestBookService; + + /** + * 방명록 생성 API + * @param request 유저 검증 + * @param createGuestBookRequestDto 방명록 생성 DTO + * @return ResponseEntity -> GuestBookResponseDto + * @throws JsonProcessingException json processing 에러 + */ + @Operation(summary = "산책 스팟 생성", + description = "산책 스팟을 생성합니다.", + responses = {@ApiResponse( + responseCode = "200", + description = "OK", + content = { + @Content( + mediaType = "application/json", + array = @ArraySchema(schema = @Schema(implementation = GuestBookResponseDto.class)) + ) + } + ), + @ApiResponse( + responseCode = "500 - InvalidMemberException", + description = "멤버가 올바르지 않습니다.", + content = { + @Content( + mediaType = "application/json", + array = @ArraySchema(schema = @Schema(implementation = InvalidMemberException.class)) + ) + } + ) + } + ) + @PostMapping + @ResponseStatus(value = HttpStatus.CREATED) + public ResponseEntity createGuestBook( + @CurrentUser HttpServletRequest request, + @RequestBody CreateGuestBookRequestDto createGuestBookRequestDto + ) throws JsonProcessingException { + return guestBookService.createGuestBook(request, createGuestBookRequestDto); + } + + + + @GetMapping("/{spotId}&{pageNum}") + @ResponseStatus(value = HttpStatus.OK) + public ResponseEntity findGuestBookBySpotId( + @CurrentUser HttpServletRequest request, + @RequestParam(name = "spotId") Long spotId, + @RequestParam(name = "pageNum") Integer pageNum + ) throws JsonProcessingException { + return guestBookService.findGuestBookBySpotId(request, spotId, pageNum); + } + + + @GetMapping("/{storeId}&{pageNum}") + @ResponseStatus(value = HttpStatus.OK) + public ResponseEntity findGuestBookByStoreId( + @CurrentUser HttpServletRequest request, + @RequestParam(name = "storeId") Long storeId, + @RequestParam(name = "pageNum") Integer pageNum + ) throws JsonProcessingException { + return guestBookService.findGuestBookByStoreId(request, storeId, pageNum); + } + + + @DeleteMapping("/{guestBookId}") + @ResponseStatus(value = HttpStatus.OK) + public ResponseEntity deleteGuestBook( + @CurrentUser HttpServletRequest request, + @RequestParam(name = "guestBookId") Long guestBookId + ) throws JsonProcessingException { + return guestBookService.deleteGuestBook(request, guestBookId); + } + } diff --git a/src/main/java/com/ttubeog/domain/spot/presentation/SpotController.java b/src/main/java/com/ttubeog/domain/spot/presentation/SpotController.java index 2360d64b..c9a3befe 100644 --- a/src/main/java/com/ttubeog/domain/spot/presentation/SpotController.java +++ b/src/main/java/com/ttubeog/domain/spot/presentation/SpotController.java @@ -320,75 +320,6 @@ public ResponseEntity deleteSpot( } - /** - * 산책 스팟 방명록 작성 API - * @param request 유저 검증 - * @param createGuestBookRequestDto 방명록 작성 DTO - * @return ResponseEntity -> GuestBookResponseDto - * @throws JsonProcessingException JSON Processing 에러 - */ - @Operation(summary = "산책 스팟 방명록 작성", - description = "산책 스팟을 방명록을 작성합니다.\n" + - "GuestBook(방명록) 기능 미구현.", - responses = {@ApiResponse( - responseCode = "200", - description = "OK", - content = { - @Content( - mediaType = "application/json", - array = @ArraySchema(schema = @Schema(implementation = GuestBookService.class)) - ) - } - ), - @ApiResponse( - responseCode = "500 - InvalidMemberException", - description = "멤버가 올바르지 않습니다.", - content = { - @Content( - mediaType = "application/json", - array = @ArraySchema(schema = @Schema(implementation = InvalidMemberException.class)) - ) - } - ), - @ApiResponse( - responseCode = "500 - AlreadyExistsSpotException", - description = "이미 존재하는 산책 장소명입니다.", - content = { - @Content( - mediaType = "application/json", - array = @ArraySchema(schema = @Schema(implementation = AlreadyExistsSpotException.class)) - ) - } - ), - @ApiResponse( - responseCode = "500 - InvalidDongAreaException", - description = "유효하지 않은 지역 정보입니다.", - content = { - @Content( - mediaType = "application/json", - array = @ArraySchema(schema = @Schema(implementation = InvalidDongAreaException.class)) - ) - } - ), - @ApiResponse( - responseCode = "500 - InvalidImageListSizeException", - description = "유효하지 않은 이미지 개수입니다.", - content = { - @Content( - mediaType = "application/json", - array = @ArraySchema(schema = @Schema(implementation = InvalidImageListSizeException.class)) - ) - } - ) - } - ) - @PostMapping("/{spotId}/guestbook") - public ResponseEntity createGuestBook( - @CurrentUser HttpServletRequest request, - @RequestBody CreateGuestBookRequestDto createGuestBookRequestDto - ) throws JsonProcessingException { - return guestBookService.createGuestBook(request, createGuestBookRequestDto); - } /** * 산책 스팟 좋아요 누르기 API From bcbb5d16e39ed60eeff8b96ab9544b944daa086c Mon Sep 17 00:00:00 2001 From: Dustbox Date: Fri, 16 Feb 2024 02:46:50 +0900 Subject: [PATCH 04/14] =?UTF-8?q?[Chore]=20=EB=AF=B8=EC=82=AC=EC=9A=A9=20i?= =?UTF-8?q?mport=EB=AC=B8=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/guestbook/application/GuestBookService.java | 5 ----- .../guestbook/domain/repository/GuestBookRepository.java | 1 - .../domain/guestbook/presentation/GuestBookController.java | 6 ------ .../ttubeog/domain/spot/presentation/SpotController.java | 2 -- 4 files changed, 14 deletions(-) diff --git a/src/main/java/com/ttubeog/domain/guestbook/application/GuestBookService.java b/src/main/java/com/ttubeog/domain/guestbook/application/GuestBookService.java index 563e348a..6c7d3d84 100644 --- a/src/main/java/com/ttubeog/domain/guestbook/application/GuestBookService.java +++ b/src/main/java/com/ttubeog/domain/guestbook/application/GuestBookService.java @@ -26,20 +26,15 @@ import com.ttubeog.domain.store.exception.InvalidStoreIdException; import com.ttubeog.global.payload.ApiResponse; import com.ttubeog.global.payload.Message; -import feign.Response; -import io.swagger.v3.oas.annotations.tags.Tag; -import jakarta.persistence.criteria.CriteriaBuilder; import jakarta.servlet.http.HttpServletRequest; import lombok.NonNull; import lombok.RequiredArgsConstructor; -import org.apache.ibatis.jdbc.Null; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageRequest; import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import java.awt.print.Pageable; import java.util.List; @RequiredArgsConstructor diff --git a/src/main/java/com/ttubeog/domain/guestbook/domain/repository/GuestBookRepository.java b/src/main/java/com/ttubeog/domain/guestbook/domain/repository/GuestBookRepository.java index 15d769da..0aac0e2d 100644 --- a/src/main/java/com/ttubeog/domain/guestbook/domain/repository/GuestBookRepository.java +++ b/src/main/java/com/ttubeog/domain/guestbook/domain/repository/GuestBookRepository.java @@ -8,7 +8,6 @@ import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; -import java.awt.print.Pageable; import java.util.List; @Repository diff --git a/src/main/java/com/ttubeog/domain/guestbook/presentation/GuestBookController.java b/src/main/java/com/ttubeog/domain/guestbook/presentation/GuestBookController.java index 30307c64..ede1b7b4 100644 --- a/src/main/java/com/ttubeog/domain/guestbook/presentation/GuestBookController.java +++ b/src/main/java/com/ttubeog/domain/guestbook/presentation/GuestBookController.java @@ -5,11 +5,6 @@ import com.ttubeog.domain.guestbook.dto.request.CreateGuestBookRequestDto; import com.ttubeog.domain.guestbook.dto.response.GuestBookResponseDto; import com.ttubeog.domain.member.exception.InvalidMemberException; -import com.ttubeog.domain.spot.dto.request.CreateSpotRequestDto; -import com.ttubeog.domain.spot.dto.response.SpotResponseDto; -import com.ttubeog.domain.spot.exception.AlreadyExistsSpotException; -import com.ttubeog.domain.spot.exception.InvalidDongAreaException; -import com.ttubeog.domain.spot.exception.InvalidImageListSizeException; import com.ttubeog.global.config.security.token.CurrentUser; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.media.ArraySchema; @@ -17,7 +12,6 @@ import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.responses.ApiResponse; import io.swagger.v3.oas.annotations.tags.Tag; -import jakarta.persistence.Table; import jakarta.servlet.http.HttpServletRequest; import lombok.RequiredArgsConstructor; import org.springframework.http.HttpStatus; diff --git a/src/main/java/com/ttubeog/domain/spot/presentation/SpotController.java b/src/main/java/com/ttubeog/domain/spot/presentation/SpotController.java index c9a3befe..9f95a2e0 100644 --- a/src/main/java/com/ttubeog/domain/spot/presentation/SpotController.java +++ b/src/main/java/com/ttubeog/domain/spot/presentation/SpotController.java @@ -2,7 +2,6 @@ import com.fasterxml.jackson.core.JsonProcessingException; import com.ttubeog.domain.guestbook.application.GuestBookService; -import com.ttubeog.domain.guestbook.dto.request.CreateGuestBookRequestDto; import com.ttubeog.domain.member.exception.InvalidMemberException; import com.ttubeog.domain.spot.application.SpotService; import com.ttubeog.domain.spot.dto.request.CreateSpotRequestDto; @@ -31,7 +30,6 @@ public class SpotController { private final SpotService spotService; - private final GuestBookService guestBookService; /** From 0accc88ccf7ab7aabb4ce48db3cae30f18a43c33 Mon Sep 17 00:00:00 2001 From: Dustbox Date: Fri, 16 Feb 2024 04:22:19 +0900 Subject: [PATCH 05/14] =?UTF-8?q?[Feat]=20RoadController=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/road/application/RoadService.java | 22 +++++++ .../com/ttubeog/domain/road/domain/Road.java | 23 +++++++- .../dto/request/CreateRoadRequestDto.java | 20 +++++++ .../road/dto/response/RoadResponseDto.java | 24 ++++++++ .../road/presentation/RoadController.java | 58 ++++++++++++++++++- .../roadcoordinate/domain/RoadCoordinate.java | 38 ++++++++++++ .../repository/RoedCoordinateRepository.java | 9 +++ 7 files changed, 191 insertions(+), 3 deletions(-) create mode 100644 src/main/java/com/ttubeog/domain/roadcoordinate/domain/RoadCoordinate.java create mode 100644 src/main/java/com/ttubeog/domain/roadcoordinate/domain/repository/RoedCoordinateRepository.java diff --git a/src/main/java/com/ttubeog/domain/road/application/RoadService.java b/src/main/java/com/ttubeog/domain/road/application/RoadService.java index 9b8d51b1..693c0980 100644 --- a/src/main/java/com/ttubeog/domain/road/application/RoadService.java +++ b/src/main/java/com/ttubeog/domain/road/application/RoadService.java @@ -1,6 +1,9 @@ package com.ttubeog.domain.road.application; +import com.ttubeog.domain.road.dto.request.CreateRoadRequestDto; +import jakarta.servlet.http.HttpServletRequest; import lombok.RequiredArgsConstructor; +import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -8,4 +11,23 @@ @Service @Transactional(readOnly = true) public class RoadService { + public ResponseEntity createGuestBook(HttpServletRequest request, CreateRoadRequestDto createRoadRequestDto) { + + return null; + } + + public ResponseEntity findRoadBySpotId(HttpServletRequest request, Long spotId, Long pageNum) { + + return null; + } + + public ResponseEntity findRoadByStoreId(HttpServletRequest request, Long storeId, Long pageNum) { + + return null; + } + + public ResponseEntity deleteRoad(HttpServletRequest request, Long roadId) { + + return null; + } } diff --git a/src/main/java/com/ttubeog/domain/road/domain/Road.java b/src/main/java/com/ttubeog/domain/road/domain/Road.java index b289220d..28410805 100644 --- a/src/main/java/com/ttubeog/domain/road/domain/Road.java +++ b/src/main/java/com/ttubeog/domain/road/domain/Road.java @@ -2,11 +2,20 @@ import com.ttubeog.domain.common.BaseEntity; import com.ttubeog.domain.member.domain.Member; +import com.ttubeog.domain.roadcoordinate.domain.RoadCoordinate; import com.ttubeog.domain.spot.domain.Spot; import com.ttubeog.domain.store.domain.Store; import jakarta.persistence.*; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +import java.util.List; @Entity +@Getter +@Builder +@NoArgsConstructor public class Road extends BaseEntity { @Id @@ -28,9 +37,19 @@ public class Road extends BaseEntity { @Column(name = "name", nullable = false) private String name; - @Column(name = "road_file", nullable = false) - private String roadFile; + @OneToMany(mappedBy = "road", cascade = CascadeType.ALL) + private List roadCoordinateList; @Column(name = "time", nullable = false) private String time; + + public Road(Long id, Spot spot, Store store, Member member, String name, List roadCoordinateList, String time) { + this.id = id; + this.spot = spot; + this.store = store; + this.member = member; + this.name = name; + this.roadCoordinateList = roadCoordinateList; + this.time = time; + } } diff --git a/src/main/java/com/ttubeog/domain/road/dto/request/CreateRoadRequestDto.java b/src/main/java/com/ttubeog/domain/road/dto/request/CreateRoadRequestDto.java index 04d23fa4..419c744c 100644 --- a/src/main/java/com/ttubeog/domain/road/dto/request/CreateRoadRequestDto.java +++ b/src/main/java/com/ttubeog/domain/road/dto/request/CreateRoadRequestDto.java @@ -1,4 +1,24 @@ package com.ttubeog.domain.road.dto.request; +import lombok.Data; +import lombok.Getter; + +import java.util.List; + +@Data +@Getter public class CreateRoadRequestDto { + + private Long spotId; + + private Long storeId; + + private Long memberId; + + private String name; + + private List> roadCoordinateList; + + private String time; + } diff --git a/src/main/java/com/ttubeog/domain/road/dto/response/RoadResponseDto.java b/src/main/java/com/ttubeog/domain/road/dto/response/RoadResponseDto.java index 907f2d6c..d1822cce 100644 --- a/src/main/java/com/ttubeog/domain/road/dto/response/RoadResponseDto.java +++ b/src/main/java/com/ttubeog/domain/road/dto/response/RoadResponseDto.java @@ -1,4 +1,28 @@ package com.ttubeog.domain.road.dto.response; +import lombok.Builder; +import lombok.Data; +import lombok.Getter; + +import java.util.List; + +@Data +@Getter +@Builder public class RoadResponseDto { + + private Long id; + + private Long spotId; + + private Long storeId; + + private Long memberId; + + private String name; + + private List> roadCoordinateList; + + private String time; + } diff --git a/src/main/java/com/ttubeog/domain/road/presentation/RoadController.java b/src/main/java/com/ttubeog/domain/road/presentation/RoadController.java index 50380913..8d930b25 100644 --- a/src/main/java/com/ttubeog/domain/road/presentation/RoadController.java +++ b/src/main/java/com/ttubeog/domain/road/presentation/RoadController.java @@ -1,7 +1,63 @@ package com.ttubeog.domain.road.presentation; -import org.springframework.web.bind.annotation.RestController; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.ttubeog.domain.guestbook.dto.request.CreateGuestBookRequestDto; +import com.ttubeog.domain.road.application.RoadService; +import com.ttubeog.domain.road.domain.repository.RoadRepository; +import com.ttubeog.domain.road.dto.request.CreateRoadRequestDto; +import com.ttubeog.global.config.security.token.CurrentUser; +import io.swagger.v3.core.util.Json; +import io.swagger.v3.oas.annotations.tags.Tag; +import jakarta.servlet.http.HttpServletRequest; +import lombok.RequiredArgsConstructor; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.security.access.annotation.Secured; +import org.springframework.web.bind.annotation.*; +@Tag(name = "Road", description = "Road API(산책로 API)") +@RequiredArgsConstructor @RestController +@RequestMapping("api/v1/road") public class RoadController { + + private final RoadService roadService; + + @PostMapping + @ResponseStatus(value = HttpStatus.CREATED) + public ResponseEntity createRoad( + @CurrentUser HttpServletRequest request, + @RequestBody CreateRoadRequestDto createRoadRequestDto + ) throws JsonProcessingException { + return roadService.createGuestBook(request, createRoadRequestDto); + } + + @GetMapping("/{spotId}&{pageNum}") + @ResponseStatus(value = HttpStatus.OK) + public ResponseEntity findRoadBySpotId( + @CurrentUser HttpServletRequest request, + @RequestParam(name = "spotId") Long spotId, + @RequestParam(name = "pageNum") Long pageNum + ) throws JsonProcessingException { + return roadService.findRoadBySpotId(request, spotId, pageNum); + } + + @GetMapping("/{storeId}&{pageNum}") + @ResponseStatus(value = HttpStatus.OK) + public ResponseEntity findRoadByStoreId( + @CurrentUser HttpServletRequest request, + @RequestParam(name = "storeId") Long storeId, + @RequestParam(name = "pageNum") Long pageNum + ) throws JsonProcessingException { + return roadService.findRoadByStoreId(request, storeId, pageNum); + } + + @DeleteMapping("/{roadId}") + @ResponseStatus(value = HttpStatus.OK) + public ResponseEntity deleteRoad( + @CurrentUser HttpServletRequest request, + @RequestParam(name = "roadId") Long roadId + ) throws JsonProcessingException { + return roadService.deleteRoad(request, roadId); + } } diff --git a/src/main/java/com/ttubeog/domain/roadcoordinate/domain/RoadCoordinate.java b/src/main/java/com/ttubeog/domain/roadcoordinate/domain/RoadCoordinate.java new file mode 100644 index 00000000..037c2201 --- /dev/null +++ b/src/main/java/com/ttubeog/domain/roadcoordinate/domain/RoadCoordinate.java @@ -0,0 +1,38 @@ +package com.ttubeog.domain.roadcoordinate.domain; + +import com.ttubeog.domain.common.BaseEntity; +import com.ttubeog.domain.road.domain.Road; +import io.swagger.v3.oas.annotations.tags.Tag; +import jakarta.persistence.*; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Tag(name = "road_coordinate") +@Entity +@Getter +@Builder +@NoArgsConstructor +public class RoadCoordinate extends BaseEntity { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + @ManyToOne + @JoinColumn(name = "road_id") + private Road road; + + @Column(name = "latitude") + private Double latitude; + + @Column(name = "longitude") + private Double longitude; + + public RoadCoordinate(Long id, Road road, Double latitude, Double longitude) { + this.id = id; + this.road = road; + this.latitude = latitude; + this.longitude = longitude; + } +} diff --git a/src/main/java/com/ttubeog/domain/roadcoordinate/domain/repository/RoedCoordinateRepository.java b/src/main/java/com/ttubeog/domain/roadcoordinate/domain/repository/RoedCoordinateRepository.java new file mode 100644 index 00000000..40524218 --- /dev/null +++ b/src/main/java/com/ttubeog/domain/roadcoordinate/domain/repository/RoedCoordinateRepository.java @@ -0,0 +1,9 @@ +package com.ttubeog.domain.roadcoordinate.domain.repository; + +import com.ttubeog.domain.roadcoordinate.domain.RoadCoordinate; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +@Repository +public interface RoedCoordinateRepository extends JpaRepository { +} From 5e2bac9dc930a02f26b6e5b20ca5e220f7c2a42e Mon Sep 17 00:00:00 2001 From: Dustbox Date: Fri, 16 Feb 2024 04:23:01 +0900 Subject: [PATCH 06/14] =?UTF-8?q?[Chore]=20unuse=20import=20=EC=82=AD?= =?UTF-8?q?=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/ttubeog/domain/road/presentation/RoadController.java | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/main/java/com/ttubeog/domain/road/presentation/RoadController.java b/src/main/java/com/ttubeog/domain/road/presentation/RoadController.java index 8d930b25..982819f8 100644 --- a/src/main/java/com/ttubeog/domain/road/presentation/RoadController.java +++ b/src/main/java/com/ttubeog/domain/road/presentation/RoadController.java @@ -1,18 +1,14 @@ package com.ttubeog.domain.road.presentation; import com.fasterxml.jackson.core.JsonProcessingException; -import com.ttubeog.domain.guestbook.dto.request.CreateGuestBookRequestDto; import com.ttubeog.domain.road.application.RoadService; -import com.ttubeog.domain.road.domain.repository.RoadRepository; import com.ttubeog.domain.road.dto.request.CreateRoadRequestDto; import com.ttubeog.global.config.security.token.CurrentUser; -import io.swagger.v3.core.util.Json; import io.swagger.v3.oas.annotations.tags.Tag; import jakarta.servlet.http.HttpServletRequest; import lombok.RequiredArgsConstructor; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; -import org.springframework.security.access.annotation.Secured; import org.springframework.web.bind.annotation.*; @Tag(name = "Road", description = "Road API(산책로 API)") From 3b65ec5dd5fe6cde67d885bd3484cdf015a2d918 Mon Sep 17 00:00:00 2001 From: Dustbox Date: Fri, 16 Feb 2024 04:44:44 +0900 Subject: [PATCH 07/14] =?UTF-8?q?[Feat]=20createGuestBook=20service=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 --- .../domain/road/application/RoadService.java | 61 +++++++++++++++++++ .../com/ttubeog/domain/road/domain/Road.java | 6 +- .../ttubeog/domain/road/domain/RoadType.java | 7 +++ .../domain/repository/RoadRepository.java | 5 ++ .../dto/request/CreateRoadRequestDto.java | 3 + .../road/dto/response/RoadResponseDto.java | 3 + .../exception/DuplicateRoadNameException.java | 12 ++++ .../exception/InvalidRoadTypeException.java | 12 ++++ .../roadcoordinate/domain/RoadCoordinate.java | 4 ++ 9 files changed, 112 insertions(+), 1 deletion(-) create mode 100644 src/main/java/com/ttubeog/domain/road/domain/RoadType.java create mode 100644 src/main/java/com/ttubeog/domain/road/exception/DuplicateRoadNameException.java create mode 100644 src/main/java/com/ttubeog/domain/road/exception/InvalidRoadTypeException.java diff --git a/src/main/java/com/ttubeog/domain/road/application/RoadService.java b/src/main/java/com/ttubeog/domain/road/application/RoadService.java index 693c0980..93871e74 100644 --- a/src/main/java/com/ttubeog/domain/road/application/RoadService.java +++ b/src/main/java/com/ttubeog/domain/road/application/RoadService.java @@ -1,18 +1,79 @@ package com.ttubeog.domain.road.application; +import com.ttubeog.domain.auth.security.JwtTokenProvider; +import com.ttubeog.domain.member.domain.Member; +import com.ttubeog.domain.member.domain.repository.MemberRepository; +import com.ttubeog.domain.member.exception.InvalidMemberException; +import com.ttubeog.domain.road.domain.Road; +import com.ttubeog.domain.road.domain.RoadType; +import com.ttubeog.domain.road.domain.repository.RoadRepository; import com.ttubeog.domain.road.dto.request.CreateRoadRequestDto; +import com.ttubeog.domain.road.exception.DuplicateRoadNameException; +import com.ttubeog.domain.road.exception.InvalidRoadTypeException; +import com.ttubeog.domain.road.presentation.RoadController; +import com.ttubeog.domain.roadcoordinate.domain.RoadCoordinate; +import com.ttubeog.domain.spot.domain.Spot; +import com.ttubeog.domain.spot.domain.repository.SpotRepository; +import com.ttubeog.domain.spot.exception.InvalidSpotIdException; +import com.ttubeog.domain.store.domain.Store; +import com.ttubeog.domain.store.domain.repository.StoreRepository; import jakarta.servlet.http.HttpServletRequest; import lombok.RequiredArgsConstructor; import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import java.util.ArrayList; +import java.util.List; + @RequiredArgsConstructor @Service @Transactional(readOnly = true) public class RoadService { + + private final RoadRepository roadRepository; + private final SpotRepository spotRepository; + private final StoreRepository storeRepository; + private final MemberRepository memberRepository; + + private final JwtTokenProvider jwtTokenProvider; + public ResponseEntity createGuestBook(HttpServletRequest request, CreateRoadRequestDto createRoadRequestDto) { + Long memberId = jwtTokenProvider.getMemberId(request); + + Member member = memberRepository.findById(memberId).orElseThrow(InvalidMemberException::new); + + Road road; + Spot spot; + Store store; + + List roadCoordinateList = new ArrayList<>(); + List> roadCoordinateDoubleList = createRoadRequestDto.getRoadCoordinateList(); + for (List roadCoordinateDouble : roadCoordinateDoubleList) { + RoadCoordinate roadCoordinate = RoadCoordinate.builder() + .latitude(roadCoordinateDouble.get(0)) + .longitude(roadCoordinateDouble.get(1)) + .build(); + roadCoordinateList.add(roadCoordinate); + } + + if (createRoadRequestDto.getRoadType().equals(RoadType.SPOT)) { + + spot = spotRepository.findById(createRoadRequestDto.getSpotId()).orElseThrow(InvalidSpotIdException::new); + + roadRepository.findBySpotAndName(spot, createRoadRequestDto.getName()).orElseThrow(DuplicateRoadNameException::new); + + road = Road.builder().build(); + + } else if (createRoadRequestDto.getRoadType().equals(RoadType.STORE)) { + + } else { + throw new InvalidRoadTypeException(); + } + + + return null; } diff --git a/src/main/java/com/ttubeog/domain/road/domain/Road.java b/src/main/java/com/ttubeog/domain/road/domain/Road.java index 28410805..00d88bd7 100644 --- a/src/main/java/com/ttubeog/domain/road/domain/Road.java +++ b/src/main/java/com/ttubeog/domain/road/domain/Road.java @@ -22,6 +22,9 @@ public class Road extends BaseEntity { @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; + @Column(name = "road_type", nullable = false) + private RoadType roadType; + @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "spot_id") private Spot spot; @@ -43,8 +46,9 @@ public class Road extends BaseEntity { @Column(name = "time", nullable = false) private String time; - public Road(Long id, Spot spot, Store store, Member member, String name, List roadCoordinateList, String time) { + public Road(Long id, RoadType roadType, Spot spot, Store store, Member member, String name, List roadCoordinateList, String time) { this.id = id; + this.roadType = roadType; this.spot = spot; this.store = store; this.member = member; diff --git a/src/main/java/com/ttubeog/domain/road/domain/RoadType.java b/src/main/java/com/ttubeog/domain/road/domain/RoadType.java new file mode 100644 index 00000000..84e89108 --- /dev/null +++ b/src/main/java/com/ttubeog/domain/road/domain/RoadType.java @@ -0,0 +1,7 @@ +package com.ttubeog.domain.road.domain; + +public enum RoadType { + + SPOT, + STORE; +} diff --git a/src/main/java/com/ttubeog/domain/road/domain/repository/RoadRepository.java b/src/main/java/com/ttubeog/domain/road/domain/repository/RoadRepository.java index 75ea6f08..adc18707 100644 --- a/src/main/java/com/ttubeog/domain/road/domain/repository/RoadRepository.java +++ b/src/main/java/com/ttubeog/domain/road/domain/repository/RoadRepository.java @@ -1,9 +1,14 @@ package com.ttubeog.domain.road.domain.repository; import com.ttubeog.domain.road.domain.Road; +import com.ttubeog.domain.spot.domain.Spot; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; +import java.util.Optional; + @Repository public interface RoadRepository extends JpaRepository { + + Optional findBySpotAndName(Spot spot, String name); } diff --git a/src/main/java/com/ttubeog/domain/road/dto/request/CreateRoadRequestDto.java b/src/main/java/com/ttubeog/domain/road/dto/request/CreateRoadRequestDto.java index 419c744c..7e271c67 100644 --- a/src/main/java/com/ttubeog/domain/road/dto/request/CreateRoadRequestDto.java +++ b/src/main/java/com/ttubeog/domain/road/dto/request/CreateRoadRequestDto.java @@ -1,5 +1,6 @@ package com.ttubeog.domain.road.dto.request; +import com.ttubeog.domain.road.domain.RoadType; import lombok.Data; import lombok.Getter; @@ -9,6 +10,8 @@ @Getter public class CreateRoadRequestDto { + private RoadType roadType; + private Long spotId; private Long storeId; diff --git a/src/main/java/com/ttubeog/domain/road/dto/response/RoadResponseDto.java b/src/main/java/com/ttubeog/domain/road/dto/response/RoadResponseDto.java index d1822cce..7e79b22a 100644 --- a/src/main/java/com/ttubeog/domain/road/dto/response/RoadResponseDto.java +++ b/src/main/java/com/ttubeog/domain/road/dto/response/RoadResponseDto.java @@ -1,5 +1,6 @@ package com.ttubeog.domain.road.dto.response; +import com.ttubeog.domain.road.domain.RoadType; import lombok.Builder; import lombok.Data; import lombok.Getter; @@ -13,6 +14,8 @@ public class RoadResponseDto { private Long id; + private RoadType roadType; + private Long spotId; private Long storeId; diff --git a/src/main/java/com/ttubeog/domain/road/exception/DuplicateRoadNameException.java b/src/main/java/com/ttubeog/domain/road/exception/DuplicateRoadNameException.java new file mode 100644 index 00000000..bdd27bb2 --- /dev/null +++ b/src/main/java/com/ttubeog/domain/road/exception/DuplicateRoadNameException.java @@ -0,0 +1,12 @@ +package com.ttubeog.domain.road.exception; + +public class DuplicateRoadNameException extends RuntimeException { + + public DuplicateRoadNameException() { + super("중복된 산책로 이름입니다."); + } + + public DuplicateRoadNameException(String message) { + super(message); + } +} diff --git a/src/main/java/com/ttubeog/domain/road/exception/InvalidRoadTypeException.java b/src/main/java/com/ttubeog/domain/road/exception/InvalidRoadTypeException.java new file mode 100644 index 00000000..c22430fb --- /dev/null +++ b/src/main/java/com/ttubeog/domain/road/exception/InvalidRoadTypeException.java @@ -0,0 +1,12 @@ +package com.ttubeog.domain.road.exception; + +public class InvalidRoadTypeException extends RuntimeException { + + public InvalidRoadTypeException() { + super("유효하지 않은 산책로 타입입니다."); + } + + public InvalidRoadTypeException(String message) { + super(message); + } +} diff --git a/src/main/java/com/ttubeog/domain/roadcoordinate/domain/RoadCoordinate.java b/src/main/java/com/ttubeog/domain/roadcoordinate/domain/RoadCoordinate.java index 037c2201..4402e4cb 100644 --- a/src/main/java/com/ttubeog/domain/roadcoordinate/domain/RoadCoordinate.java +++ b/src/main/java/com/ttubeog/domain/roadcoordinate/domain/RoadCoordinate.java @@ -35,4 +35,8 @@ public RoadCoordinate(Long id, Road road, Double latitude, Double longitude) { this.latitude = latitude; this.longitude = longitude; } + + public void updateRoad(Road road) { + this.road = road; + } } From 8937ffe1dffd7d49c3bb84e2a8d8b4917b96821c Mon Sep 17 00:00:00 2001 From: Dustbox Date: Fri, 16 Feb 2024 14:45:02 +0900 Subject: [PATCH 08/14] =?UTF-8?q?[Feat]=20road=20domain=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../application/GuestBookService.java | 6 +- .../domain/road/application/RoadService.java | 181 +++++++++++++++++- .../com/ttubeog/domain/road/domain/Road.java | 5 +- .../domain/repository/RoadRepository.java | 10 + .../dto/request/CreateRoadRequestDto.java | 4 - .../road/dto/response/RoadResponseDto.java | 8 +- .../exception/InvalidRoadIdException.java | 14 ++ .../road/presentation/RoadController.java | 7 +- ...ory.java => RoadCoordinateRepository.java} | 2 +- 9 files changed, 211 insertions(+), 26 deletions(-) create mode 100644 src/main/java/com/ttubeog/domain/road/exception/InvalidRoadIdException.java rename src/main/java/com/ttubeog/domain/roadcoordinate/domain/repository/{RoedCoordinateRepository.java => RoadCoordinateRepository.java} (81%) diff --git a/src/main/java/com/ttubeog/domain/guestbook/application/GuestBookService.java b/src/main/java/com/ttubeog/domain/guestbook/application/GuestBookService.java index 6c7d3d84..f25a4fcf 100644 --- a/src/main/java/com/ttubeog/domain/guestbook/application/GuestBookService.java +++ b/src/main/java/com/ttubeog/domain/guestbook/application/GuestBookService.java @@ -280,10 +280,14 @@ public ResponseEntity updateGuestBook(HttpServletRequest request, Long guestB public ResponseEntity deleteGuestBook(HttpServletRequest request, Long guestBookId) { Long memberId = jwtTokenProvider.getMemberId(request); - memberRepository.findById(memberId).orElseThrow(InvalidMemberException::new); + Member member = memberRepository.findById(memberId).orElseThrow(InvalidMemberException::new); GuestBook guestBook = guestBookRepository.findById(guestBookId).orElseThrow(InvalidGuestBookIdException::new); + if (!guestBook.getMember().equals(member)) { + throw new InvalidMemberException(); + } + guestBookRepository.delete(guestBook); imageService.deleteImage(imageRepository.findByGuestBookId(guestBookId).orElseThrow(InvalidImageException::new).getId()); diff --git a/src/main/java/com/ttubeog/domain/road/application/RoadService.java b/src/main/java/com/ttubeog/domain/road/application/RoadService.java index 93871e74..49a5ea05 100644 --- a/src/main/java/com/ttubeog/domain/road/application/RoadService.java +++ b/src/main/java/com/ttubeog/domain/road/application/RoadService.java @@ -8,17 +8,24 @@ import com.ttubeog.domain.road.domain.RoadType; import com.ttubeog.domain.road.domain.repository.RoadRepository; import com.ttubeog.domain.road.dto.request.CreateRoadRequestDto; +import com.ttubeog.domain.road.dto.response.RoadResponseDto; import com.ttubeog.domain.road.exception.DuplicateRoadNameException; +import com.ttubeog.domain.road.exception.InvalidRoadIdException; import com.ttubeog.domain.road.exception.InvalidRoadTypeException; -import com.ttubeog.domain.road.presentation.RoadController; import com.ttubeog.domain.roadcoordinate.domain.RoadCoordinate; +import com.ttubeog.domain.roadcoordinate.domain.repository.RoadCoordinateRepository; import com.ttubeog.domain.spot.domain.Spot; import com.ttubeog.domain.spot.domain.repository.SpotRepository; import com.ttubeog.domain.spot.exception.InvalidSpotIdException; import com.ttubeog.domain.store.domain.Store; import com.ttubeog.domain.store.domain.repository.StoreRepository; +import com.ttubeog.domain.store.exception.InvalidStoreIdException; +import com.ttubeog.global.payload.ApiResponse; +import com.ttubeog.global.payload.Message; import jakarta.servlet.http.HttpServletRequest; import lombok.RequiredArgsConstructor; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageRequest; import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -32,13 +39,15 @@ public class RoadService { private final RoadRepository roadRepository; + private final RoadCoordinateRepository roadCoordinateRepository; private final SpotRepository spotRepository; private final StoreRepository storeRepository; private final MemberRepository memberRepository; private final JwtTokenProvider jwtTokenProvider; - public ResponseEntity createGuestBook(HttpServletRequest request, CreateRoadRequestDto createRoadRequestDto) { + @Transactional + public ResponseEntity createRoad(HttpServletRequest request, CreateRoadRequestDto createRoadRequestDto) { Long memberId = jwtTokenProvider.getMemberId(request); @@ -62,33 +71,185 @@ public ResponseEntity createGuestBook(HttpServletRequest request, CreateRoadR spot = spotRepository.findById(createRoadRequestDto.getSpotId()).orElseThrow(InvalidSpotIdException::new); - roadRepository.findBySpotAndName(spot, createRoadRequestDto.getName()).orElseThrow(DuplicateRoadNameException::new); + if (roadRepository.findBySpotAndName(spot, createRoadRequestDto.getName()).isPresent()) { + throw new DuplicateRoadNameException(); + } - road = Road.builder().build(); + road = Road.builder() + .roadType(RoadType.SPOT) + .spot(spot) + .member(member) + .name(createRoadRequestDto.getName()) + .roadCoordinateList(roadCoordinateList) + .build(); } else if (createRoadRequestDto.getRoadType().equals(RoadType.STORE)) { + store = storeRepository.findById(createRoadRequestDto.getStoreId()).orElseThrow(InvalidStoreIdException::new); + + if (roadRepository.findByStoreAndName(store, createRoadRequestDto.getName()).isPresent()) { + throw new DuplicateRoadNameException(); + } + + road = Road.builder() + .roadType(RoadType.STORE) + .store(store) + .member(member) + .name(createRoadRequestDto.getName()) + .roadCoordinateList(roadCoordinateList) + .build(); } else { throw new InvalidRoadTypeException(); } + for (RoadCoordinate roadCoordinate : roadCoordinateList) { + roadCoordinate.updateRoad(road); + } + + roadRepository.save(road); + + roadCoordinateRepository.saveAll(roadCoordinateList); + + List> roadCoordinateDoubleListResponse = new ArrayList<>(); + for (RoadCoordinate roadCoordinate : road.getRoadCoordinateList()) { + List roadCoordinateDoubleResponse = new ArrayList<>(); + roadCoordinateDoubleResponse.add(roadCoordinate.getLatitude()); + roadCoordinateDoubleResponse.add(roadCoordinate.getLongitude()); + roadCoordinateDoubleListResponse.add(roadCoordinateDoubleResponse); + } + + RoadResponseDto roadResponseDto; + + if (road.getRoadType().equals(RoadType.SPOT)) { + roadResponseDto = RoadResponseDto.builder() + .id(road.getId()) + .roadType(RoadType.SPOT) + .spotId(road.getSpot().getId()) + .memberId(road.getMember().getId()) + .name(road.getName()) + .roadCoordinateDoubleList(roadCoordinateDoubleListResponse) + .build(); + } else if (road.getRoadType().equals(RoadType.STORE)) { + roadResponseDto = RoadResponseDto.builder() + .id(road.getId()) + .roadType(RoadType.STORE) + .storeId(road.getStore().getId()) + .memberId(road.getMember().getId()) + .name(road.getName()) + .roadCoordinateDoubleList(roadCoordinateDoubleListResponse) + .build(); + } else { + throw new InvalidRoadTypeException(); + } + ApiResponse apiResponse = ApiResponse.builder() + .check(true) + .information(roadResponseDto) + .build(); - return null; + return ResponseEntity.ok(apiResponse); } - public ResponseEntity findRoadBySpotId(HttpServletRequest request, Long spotId, Long pageNum) { + public ResponseEntity findRoadBySpotId(HttpServletRequest request, Long spotId, Integer pageNum) { - return null; + Long memberId = jwtTokenProvider.getMemberId(request); + + Member member = memberRepository.findById(memberId).orElseThrow(InvalidMemberException::new); + + Page roadPage = roadRepository.findAllBySpot_Id(spotId, PageRequest.of(pageNum, 1)); + + List roadResponseDtoList = new ArrayList<>(); + + for (Road road : roadPage) { + List> roadCoordinateDoubleList = new ArrayList<>(); + for (RoadCoordinate roadCoordinate : road.getRoadCoordinateList()) { + List roadCoordinateDouble = new ArrayList<>(); + roadCoordinateDouble.add(roadCoordinate.getLatitude()); + roadCoordinateDouble.add(roadCoordinate.getLongitude()); + roadCoordinateDoubleList.add(roadCoordinateDouble); + } + + RoadResponseDto roadResponseDto = RoadResponseDto.builder() + .id(road.getId()) + .roadType(road.getRoadType()) + .spotId(road.getSpot().getId()) + .memberId(road.getMember().getId()) + .name(road.getName()) + .roadCoordinateDoubleList(roadCoordinateDoubleList) + .build(); + roadResponseDtoList.add(roadResponseDto); + } + + ApiResponse apiResponse = ApiResponse.builder() + .check(true) + .information(roadResponseDtoList) + .build(); + + return ResponseEntity.ok(apiResponse); } - public ResponseEntity findRoadByStoreId(HttpServletRequest request, Long storeId, Long pageNum) { + public ResponseEntity findRoadByStoreId(HttpServletRequest request, Long storeId, Integer pageNum) { + + Long memberId = jwtTokenProvider.getMemberId(request); + + Member member = memberRepository.findById(memberId).orElseThrow(InvalidMemberException::new); - return null; + Page roadPage = roadRepository.findAllByStore_Id(storeId, PageRequest.of(pageNum, 1)); + + List roadResponseDtoList = new ArrayList<>(); + + for (Road road : roadPage) { + List> roadCoordinateDoubleList = new ArrayList<>(); + for (RoadCoordinate roadCoordinate : road.getRoadCoordinateList()) { + List roadCoordinateDouble = new ArrayList<>(); + roadCoordinateDouble.add(roadCoordinate.getLatitude()); + roadCoordinateDouble.add(roadCoordinate.getLongitude()); + roadCoordinateDoubleList.add(roadCoordinateDouble); + } + + RoadResponseDto roadResponseDto = RoadResponseDto.builder() + .id(road.getId()) + .roadType(road.getRoadType()) + .storeId(road.getStore().getId()) + .memberId(road.getMember().getId()) + .name(road.getName()) + .roadCoordinateDoubleList(roadCoordinateDoubleList) + .build(); + roadResponseDtoList.add(roadResponseDto); + } + + ApiResponse apiResponse = ApiResponse.builder() + .check(true) + .information(roadResponseDtoList) + .build(); + + return ResponseEntity.ok(apiResponse); } + @Transactional public ResponseEntity deleteRoad(HttpServletRequest request, Long roadId) { - return null; + Long memberId = jwtTokenProvider.getMemberId(request); + + Member member = memberRepository.findById(memberId).orElseThrow(InvalidMemberException::new); + + Road road = roadRepository.findById(roadId).orElseThrow(InvalidRoadIdException::new); + + if (!road.getMember().equals(member)) { + throw new InvalidMemberException(); + } + + List roadCoordinateList = road.getRoadCoordinateList(); + + roadRepository.delete(road); + + roadCoordinateRepository.deleteAll(roadCoordinateList); + + ApiResponse apiResponse = ApiResponse.builder() + .check(true) + .information(Message.builder().message("산책로를 삭제했습니다.").build()) + .build(); + + return ResponseEntity.ok(apiResponse); } } diff --git a/src/main/java/com/ttubeog/domain/road/domain/Road.java b/src/main/java/com/ttubeog/domain/road/domain/Road.java index 00d88bd7..3c2c3e16 100644 --- a/src/main/java/com/ttubeog/domain/road/domain/Road.java +++ b/src/main/java/com/ttubeog/domain/road/domain/Road.java @@ -43,10 +43,8 @@ public class Road extends BaseEntity { @OneToMany(mappedBy = "road", cascade = CascadeType.ALL) private List roadCoordinateList; - @Column(name = "time", nullable = false) - private String time; - public Road(Long id, RoadType roadType, Spot spot, Store store, Member member, String name, List roadCoordinateList, String time) { + public Road(Long id, RoadType roadType, Spot spot, Store store, Member member, String name, List roadCoordinateList) { this.id = id; this.roadType = roadType; this.spot = spot; @@ -54,6 +52,5 @@ public Road(Long id, RoadType roadType, Spot spot, Store store, Member member, S this.member = member; this.name = name; this.roadCoordinateList = roadCoordinateList; - this.time = time; } } diff --git a/src/main/java/com/ttubeog/domain/road/domain/repository/RoadRepository.java b/src/main/java/com/ttubeog/domain/road/domain/repository/RoadRepository.java index adc18707..125bc905 100644 --- a/src/main/java/com/ttubeog/domain/road/domain/repository/RoadRepository.java +++ b/src/main/java/com/ttubeog/domain/road/domain/repository/RoadRepository.java @@ -2,6 +2,9 @@ import com.ttubeog.domain.road.domain.Road; import com.ttubeog.domain.spot.domain.Spot; +import com.ttubeog.domain.store.domain.Store; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageRequest; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; @@ -11,4 +14,11 @@ public interface RoadRepository extends JpaRepository { Optional findBySpotAndName(Spot spot, String name); + + Optional findByStoreAndName(Store store, String name); + + Page findAllBySpot_Id(Long spotId, PageRequest pageRequest); + + Page findAllByStore_Id(Long storeId, PageRequest pageRequest); + } diff --git a/src/main/java/com/ttubeog/domain/road/dto/request/CreateRoadRequestDto.java b/src/main/java/com/ttubeog/domain/road/dto/request/CreateRoadRequestDto.java index 7e271c67..5ddcdbf7 100644 --- a/src/main/java/com/ttubeog/domain/road/dto/request/CreateRoadRequestDto.java +++ b/src/main/java/com/ttubeog/domain/road/dto/request/CreateRoadRequestDto.java @@ -16,12 +16,8 @@ public class CreateRoadRequestDto { private Long storeId; - private Long memberId; - private String name; private List> roadCoordinateList; - private String time; - } diff --git a/src/main/java/com/ttubeog/domain/road/dto/response/RoadResponseDto.java b/src/main/java/com/ttubeog/domain/road/dto/response/RoadResponseDto.java index 7e79b22a..70733b3c 100644 --- a/src/main/java/com/ttubeog/domain/road/dto/response/RoadResponseDto.java +++ b/src/main/java/com/ttubeog/domain/road/dto/response/RoadResponseDto.java @@ -1,6 +1,10 @@ package com.ttubeog.domain.road.dto.response; +import com.ttubeog.domain.member.domain.Member; import com.ttubeog.domain.road.domain.RoadType; +import com.ttubeog.domain.roadcoordinate.domain.RoadCoordinate; +import com.ttubeog.domain.spot.domain.Spot; +import com.ttubeog.domain.store.domain.Store; import lombok.Builder; import lombok.Data; import lombok.Getter; @@ -24,8 +28,6 @@ public class RoadResponseDto { private String name; - private List> roadCoordinateList; - - private String time; + private List> roadCoordinateDoubleList; } diff --git a/src/main/java/com/ttubeog/domain/road/exception/InvalidRoadIdException.java b/src/main/java/com/ttubeog/domain/road/exception/InvalidRoadIdException.java new file mode 100644 index 00000000..9b361374 --- /dev/null +++ b/src/main/java/com/ttubeog/domain/road/exception/InvalidRoadIdException.java @@ -0,0 +1,14 @@ +package com.ttubeog.domain.road.exception; + +import com.ttubeog.domain.member.exception.InvalidMemberException; + +public class InvalidRoadIdException extends RuntimeException { + + public InvalidRoadIdException() { + super("올바르지 않은 산책로 Id 입니다."); + } + + public InvalidRoadIdException(String message) { + super(message); + } +} diff --git a/src/main/java/com/ttubeog/domain/road/presentation/RoadController.java b/src/main/java/com/ttubeog/domain/road/presentation/RoadController.java index 982819f8..37a5cac6 100644 --- a/src/main/java/com/ttubeog/domain/road/presentation/RoadController.java +++ b/src/main/java/com/ttubeog/domain/road/presentation/RoadController.java @@ -5,6 +5,7 @@ import com.ttubeog.domain.road.dto.request.CreateRoadRequestDto; import com.ttubeog.global.config.security.token.CurrentUser; import io.swagger.v3.oas.annotations.tags.Tag; +import jakarta.persistence.criteria.CriteriaBuilder; import jakarta.servlet.http.HttpServletRequest; import lombok.RequiredArgsConstructor; import org.springframework.http.HttpStatus; @@ -25,7 +26,7 @@ public ResponseEntity createRoad( @CurrentUser HttpServletRequest request, @RequestBody CreateRoadRequestDto createRoadRequestDto ) throws JsonProcessingException { - return roadService.createGuestBook(request, createRoadRequestDto); + return roadService.createRoad(request, createRoadRequestDto); } @GetMapping("/{spotId}&{pageNum}") @@ -33,7 +34,7 @@ public ResponseEntity createRoad( public ResponseEntity findRoadBySpotId( @CurrentUser HttpServletRequest request, @RequestParam(name = "spotId") Long spotId, - @RequestParam(name = "pageNum") Long pageNum + @RequestParam(name = "pageNum") Integer pageNum ) throws JsonProcessingException { return roadService.findRoadBySpotId(request, spotId, pageNum); } @@ -43,7 +44,7 @@ public ResponseEntity findRoadBySpotId( public ResponseEntity findRoadByStoreId( @CurrentUser HttpServletRequest request, @RequestParam(name = "storeId") Long storeId, - @RequestParam(name = "pageNum") Long pageNum + @RequestParam(name = "pageNum") Integer pageNum ) throws JsonProcessingException { return roadService.findRoadByStoreId(request, storeId, pageNum); } diff --git a/src/main/java/com/ttubeog/domain/roadcoordinate/domain/repository/RoedCoordinateRepository.java b/src/main/java/com/ttubeog/domain/roadcoordinate/domain/repository/RoadCoordinateRepository.java similarity index 81% rename from src/main/java/com/ttubeog/domain/roadcoordinate/domain/repository/RoedCoordinateRepository.java rename to src/main/java/com/ttubeog/domain/roadcoordinate/domain/repository/RoadCoordinateRepository.java index 40524218..c9ade995 100644 --- a/src/main/java/com/ttubeog/domain/roadcoordinate/domain/repository/RoedCoordinateRepository.java +++ b/src/main/java/com/ttubeog/domain/roadcoordinate/domain/repository/RoadCoordinateRepository.java @@ -5,5 +5,5 @@ import org.springframework.stereotype.Repository; @Repository -public interface RoedCoordinateRepository extends JpaRepository { +public interface RoadCoordinateRepository extends JpaRepository { } From 1c884af9a6bbb6df0e7e40de3514b3cc4e52d79d Mon Sep 17 00:00:00 2001 From: Dustbox Date: Fri, 16 Feb 2024 14:56:37 +0900 Subject: [PATCH 09/14] =?UTF-8?q?[Chore]=20Swagger=20Annotation=20?= =?UTF-8?q?=EB=AC=B8=EC=84=9C=ED=99=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../presentation/GuestBookController.java | 100 ++++++++++++- .../road/presentation/RoadController.java | 137 +++++++++++++++++- 2 files changed, 233 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/ttubeog/domain/guestbook/presentation/GuestBookController.java b/src/main/java/com/ttubeog/domain/guestbook/presentation/GuestBookController.java index ede1b7b4..85c588fb 100644 --- a/src/main/java/com/ttubeog/domain/guestbook/presentation/GuestBookController.java +++ b/src/main/java/com/ttubeog/domain/guestbook/presentation/GuestBookController.java @@ -33,8 +33,8 @@ public class GuestBookController { * @return ResponseEntity -> GuestBookResponseDto * @throws JsonProcessingException json processing 에러 */ - @Operation(summary = "산책 스팟 생성", - description = "산책 스팟을 생성합니다.", + @Operation(summary = "방명록 생성 / createGuestBook", + description = "방명록 생성 API 입니다.", responses = {@ApiResponse( responseCode = "200", description = "OK", @@ -67,7 +67,38 @@ public ResponseEntity createGuestBook( } - + /** + * 산책 스팟에 속한 모든 방명록 페이징 조회 API + * @param request + * @param spotId + * @param pageNum + * @return + * @throws JsonProcessingException + */ + @Operation(summary = "산책 스팟 소속 방명록 조회 API / findGuestBookBySpotId", + description = "산책 스팟에 속한 방명록을 페이징하여 조회하는 API 입니다.", + responses = {@ApiResponse( + responseCode = "200", + description = "OK", + content = { + @Content( + mediaType = "application/json", + array = @ArraySchema(schema = @Schema(implementation = GuestBookResponseDto.class)) + ) + } + ), + @ApiResponse( + responseCode = "500 - InvalidMemberException", + description = "멤버가 올바르지 않습니다.", + content = { + @Content( + mediaType = "application/json", + array = @ArraySchema(schema = @Schema(implementation = InvalidMemberException.class)) + ) + } + ) + } + ) @GetMapping("/{spotId}&{pageNum}") @ResponseStatus(value = HttpStatus.OK) public ResponseEntity findGuestBookBySpotId( @@ -79,6 +110,38 @@ public ResponseEntity findGuestBookBySpotId( } + /** + * 매장에 속한 모든 방명록 페이징 조회 API + * @param request + * @param storeId + * @param pageNum + * @return + * @throws JsonProcessingException + */ + @Operation(summary = "매장 소속 방명록 조회 API / findGuestBookByStoreId", + description = "매장에 속한 방명록을 페이징하여 조회하는 API 입니다.", + responses = {@ApiResponse( + responseCode = "200", + description = "OK", + content = { + @Content( + mediaType = "application/json", + array = @ArraySchema(schema = @Schema(implementation = GuestBookResponseDto.class)) + ) + } + ), + @ApiResponse( + responseCode = "500 - InvalidMemberException", + description = "멤버가 올바르지 않습니다.", + content = { + @Content( + mediaType = "application/json", + array = @ArraySchema(schema = @Schema(implementation = InvalidMemberException.class)) + ) + } + ) + } + ) @GetMapping("/{storeId}&{pageNum}") @ResponseStatus(value = HttpStatus.OK) public ResponseEntity findGuestBookByStoreId( @@ -90,6 +153,37 @@ public ResponseEntity findGuestBookByStoreId( } + /** + * 방명록 삭제 API + * @param request + * @param guestBookId + * @return + * @throws JsonProcessingException + */ + @Operation(summary = "방명록 삭제 API / deleteGuestBook", + description = " 방명록을 삭제하는 API 입니다.", + responses = {@ApiResponse( + responseCode = "200", + description = "OK", + content = { + @Content( + mediaType = "application/json", + array = @ArraySchema(schema = @Schema(implementation = ResponseEntity.class)) + ) + } + ), + @ApiResponse( + responseCode = "500 - InvalidMemberException", + description = "멤버가 올바르지 않습니다.", + content = { + @Content( + mediaType = "application/json", + array = @ArraySchema(schema = @Schema(implementation = InvalidMemberException.class)) + ) + } + ) + } + ) @DeleteMapping("/{guestBookId}") @ResponseStatus(value = HttpStatus.OK) public ResponseEntity deleteGuestBook( diff --git a/src/main/java/com/ttubeog/domain/road/presentation/RoadController.java b/src/main/java/com/ttubeog/domain/road/presentation/RoadController.java index 37a5cac6..dd78b489 100644 --- a/src/main/java/com/ttubeog/domain/road/presentation/RoadController.java +++ b/src/main/java/com/ttubeog/domain/road/presentation/RoadController.java @@ -1,11 +1,18 @@ package com.ttubeog.domain.road.presentation; import com.fasterxml.jackson.core.JsonProcessingException; +import com.ttubeog.domain.member.exception.InvalidMemberException; import com.ttubeog.domain.road.application.RoadService; +import com.ttubeog.domain.road.domain.repository.RoadRepository; import com.ttubeog.domain.road.dto.request.CreateRoadRequestDto; +import com.ttubeog.domain.road.dto.response.RoadResponseDto; import com.ttubeog.global.config.security.token.CurrentUser; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.media.ArraySchema; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.oas.annotations.responses.ApiResponse; import io.swagger.v3.oas.annotations.tags.Tag; -import jakarta.persistence.criteria.CriteriaBuilder; import jakarta.servlet.http.HttpServletRequest; import lombok.RequiredArgsConstructor; import org.springframework.http.HttpStatus; @@ -20,6 +27,37 @@ public class RoadController { private final RoadService roadService; + /** + * 산책로 생성 API + * @param request + * @param createRoadRequestDto + * @return + * @throws JsonProcessingException + */ + @Operation(summary = "산책로 생성 API / createRoad", + description = "산책로를 생성하는 API 입니다.", + responses = {@ApiResponse( + responseCode = "200", + description = "OK", + content = { + @Content( + mediaType = "application/json", + array = @ArraySchema(schema = @Schema(implementation = RoadResponseDto.class)) + ) + } + ), + @ApiResponse( + responseCode = "500 - InvalidMemberException", + description = "멤버가 올바르지 않습니다.", + content = { + @Content( + mediaType = "application/json", + array = @ArraySchema(schema = @Schema(implementation = InvalidMemberException.class)) + ) + } + ) + } + ) @PostMapping @ResponseStatus(value = HttpStatus.CREATED) public ResponseEntity createRoad( @@ -29,6 +67,38 @@ public ResponseEntity createRoad( return roadService.createRoad(request, createRoadRequestDto); } + /** + * 산책 스팟에 속한 산책로 페이징 조회 API + * @param request + * @param spotId + * @param pageNum + * @return + * @throws JsonProcessingException + */ + @Operation(summary = "산책 스팟 소속 산책로 페이징 조회 API", + description = "산책 스팟에 속한 산책로를 페이징하여 조회하는 API 입니다.", + responses = {@ApiResponse( + responseCode = "200", + description = "OK", + content = { + @Content( + mediaType = "application/json", + array = @ArraySchema(schema = @Schema(implementation = RoadRepository.class)) + ) + } + ), + @ApiResponse( + responseCode = "500 - InvalidMemberException", + description = "멤버가 올바르지 않습니다.", + content = { + @Content( + mediaType = "application/json", + array = @ArraySchema(schema = @Schema(implementation = InvalidMemberException.class)) + ) + } + ) + } + ) @GetMapping("/{spotId}&{pageNum}") @ResponseStatus(value = HttpStatus.OK) public ResponseEntity findRoadBySpotId( @@ -39,6 +109,39 @@ public ResponseEntity findRoadBySpotId( return roadService.findRoadBySpotId(request, spotId, pageNum); } + + /** + * 매장 소속 산책로 페이징 조회 API + * @param request + * @param storeId + * @param pageNum + * @return + * @throws JsonProcessingException + */ + @Operation(summary = "매장 소속 산책로 페이징 조회 API", + description = "매장에 속한 산책로를 페이징하여 조회하는 API 입니다.", + responses = {@ApiResponse( + responseCode = "200", + description = "OK", + content = { + @Content( + mediaType = "application/json", + array = @ArraySchema(schema = @Schema(implementation = RoadRepository.class)) + ) + } + ), + @ApiResponse( + responseCode = "500 - InvalidMemberException", + description = "멤버가 올바르지 않습니다.", + content = { + @Content( + mediaType = "application/json", + array = @ArraySchema(schema = @Schema(implementation = InvalidMemberException.class)) + ) + } + ) + } + ) @GetMapping("/{storeId}&{pageNum}") @ResponseStatus(value = HttpStatus.OK) public ResponseEntity findRoadByStoreId( @@ -49,6 +152,38 @@ public ResponseEntity findRoadByStoreId( return roadService.findRoadByStoreId(request, storeId, pageNum); } + + /** + * 산책로 삭제 API + * @param request + * @param roadId + * @return + * @throws JsonProcessingException + */ + @Operation(summary = "산책로 삭제 API", + description = "산책로를 삭제하는 API 입니다.", + responses = {@ApiResponse( + responseCode = "200", + description = "OK", + content = { + @Content( + mediaType = "application/json", + array = @ArraySchema(schema = @Schema(implementation = ResponseEntity.class)) + ) + } + ), + @ApiResponse( + responseCode = "500 - InvalidMemberException", + description = "멤버가 올바르지 않습니다.", + content = { + @Content( + mediaType = "application/json", + array = @ArraySchema(schema = @Schema(implementation = InvalidMemberException.class)) + ) + } + ) + } + ) @DeleteMapping("/{roadId}") @ResponseStatus(value = HttpStatus.OK) public ResponseEntity deleteRoad( From bf27cdd2c52a0ca3283f7234f305fe86a3676ab4 Mon Sep 17 00:00:00 2001 From: Dustbox Date: Fri, 16 Feb 2024 15:10:33 +0900 Subject: [PATCH 10/14] =?UTF-8?q?[Chore]=20=EB=AF=B8=EC=82=AC=EC=9A=A9=20?= =?UTF-8?q?=EB=94=94=EB=A0=89=ED=86=A0=EB=A6=AC=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../application/RoadCoordinateService.java | 4 ---- .../dto/request/CreateRoadCoordinateRequestDto.java | 9 --------- .../dto/response/RoadResponseCoordinateDto.java | 8 -------- 3 files changed, 21 deletions(-) delete mode 100644 src/main/java/com/ttubeog/domain/roadcoordinate/application/RoadCoordinateService.java delete mode 100644 src/main/java/com/ttubeog/domain/roadcoordinate/dto/request/CreateRoadCoordinateRequestDto.java delete mode 100644 src/main/java/com/ttubeog/domain/roadcoordinate/dto/response/RoadResponseCoordinateDto.java diff --git a/src/main/java/com/ttubeog/domain/roadcoordinate/application/RoadCoordinateService.java b/src/main/java/com/ttubeog/domain/roadcoordinate/application/RoadCoordinateService.java deleted file mode 100644 index 0619b8cb..00000000 --- a/src/main/java/com/ttubeog/domain/roadcoordinate/application/RoadCoordinateService.java +++ /dev/null @@ -1,4 +0,0 @@ -package com.ttubeog.domain.roadcoordinate.application; - -public class RoadCoordinateService { -} diff --git a/src/main/java/com/ttubeog/domain/roadcoordinate/dto/request/CreateRoadCoordinateRequestDto.java b/src/main/java/com/ttubeog/domain/roadcoordinate/dto/request/CreateRoadCoordinateRequestDto.java deleted file mode 100644 index aefc3378..00000000 --- a/src/main/java/com/ttubeog/domain/roadcoordinate/dto/request/CreateRoadCoordinateRequestDto.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.ttubeog.domain.roadcoordinate.dto.request; - -import lombok.Data; - -@Data -public class CreateRoadCoordinateRequestDto { - - -} diff --git a/src/main/java/com/ttubeog/domain/roadcoordinate/dto/response/RoadResponseCoordinateDto.java b/src/main/java/com/ttubeog/domain/roadcoordinate/dto/response/RoadResponseCoordinateDto.java deleted file mode 100644 index 04a99e42..00000000 --- a/src/main/java/com/ttubeog/domain/roadcoordinate/dto/response/RoadResponseCoordinateDto.java +++ /dev/null @@ -1,8 +0,0 @@ -package com.ttubeog.domain.roadcoordinate.dto.response; - - -import lombok.Data; - -@Data -public class RoadResponseCoordinateDto { -} From e5872149f8ee1d30898c60e6d56d3209afa790c1 Mon Sep 17 00:00:00 2001 From: Dustbox Date: Fri, 16 Feb 2024 15:16:48 +0900 Subject: [PATCH 11/14] =?UTF-8?q?[Feat]=20Road,=20RoadCoordinate=20Entity?= =?UTF-8?q?=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/ttubeog/domain/road/domain/Road.java | 3 ++- .../domain/roadcoordinate/domain/RoadCoordinate.java | 9 +++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/ttubeog/domain/road/domain/Road.java b/src/main/java/com/ttubeog/domain/road/domain/Road.java index 3c2c3e16..b693d7b0 100644 --- a/src/main/java/com/ttubeog/domain/road/domain/Road.java +++ b/src/main/java/com/ttubeog/domain/road/domain/Road.java @@ -6,6 +6,7 @@ import com.ttubeog.domain.spot.domain.Spot; import com.ttubeog.domain.store.domain.Store; import jakarta.persistence.*; +import lombok.AccessLevel; import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; @@ -15,7 +16,7 @@ @Entity @Getter @Builder -@NoArgsConstructor +@NoArgsConstructor(access = AccessLevel.PROTECTED) public class Road extends BaseEntity { @Id diff --git a/src/main/java/com/ttubeog/domain/roadcoordinate/domain/RoadCoordinate.java b/src/main/java/com/ttubeog/domain/roadcoordinate/domain/RoadCoordinate.java index 4402e4cb..d1d20bf4 100644 --- a/src/main/java/com/ttubeog/domain/roadcoordinate/domain/RoadCoordinate.java +++ b/src/main/java/com/ttubeog/domain/roadcoordinate/domain/RoadCoordinate.java @@ -4,6 +4,7 @@ import com.ttubeog.domain.road.domain.Road; import io.swagger.v3.oas.annotations.tags.Tag; import jakarta.persistence.*; +import lombok.AccessLevel; import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; @@ -12,21 +13,21 @@ @Entity @Getter @Builder -@NoArgsConstructor +@NoArgsConstructor(access = AccessLevel.PROTECTED) public class RoadCoordinate extends BaseEntity { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; - @ManyToOne + @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "road_id") private Road road; - @Column(name = "latitude") + @Column(name = "latitude", nullable = false) private Double latitude; - @Column(name = "longitude") + @Column(name = "longitude", nullable = false) private Double longitude; public RoadCoordinate(Long id, Road road, Double latitude, Double longitude) { From 921b967d6398fcafb7dd223b307543c9490aff87 Mon Sep 17 00:00:00 2001 From: Dustbox Date: Fri, 16 Feb 2024 15:20:17 +0900 Subject: [PATCH 12/14] =?UTF-8?q?[Chore]=20Swagger=20Annotation=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ttubeog/domain/road/presentation/RoadController.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/ttubeog/domain/road/presentation/RoadController.java b/src/main/java/com/ttubeog/domain/road/presentation/RoadController.java index dd78b489..7dba249a 100644 --- a/src/main/java/com/ttubeog/domain/road/presentation/RoadController.java +++ b/src/main/java/com/ttubeog/domain/road/presentation/RoadController.java @@ -75,7 +75,7 @@ public ResponseEntity createRoad( * @return * @throws JsonProcessingException */ - @Operation(summary = "산책 스팟 소속 산책로 페이징 조회 API", + @Operation(summary = "산책 스팟 소속 산책로 페이징 조회 API / findRoadBySpotId", description = "산책 스팟에 속한 산책로를 페이징하여 조회하는 API 입니다.", responses = {@ApiResponse( responseCode = "200", @@ -118,7 +118,7 @@ public ResponseEntity findRoadBySpotId( * @return * @throws JsonProcessingException */ - @Operation(summary = "매장 소속 산책로 페이징 조회 API", + @Operation(summary = "매장 소속 산책로 페이징 조회 API / findRoadByStoreId", description = "매장에 속한 산책로를 페이징하여 조회하는 API 입니다.", responses = {@ApiResponse( responseCode = "200", @@ -160,7 +160,7 @@ public ResponseEntity findRoadByStoreId( * @return * @throws JsonProcessingException */ - @Operation(summary = "산책로 삭제 API", + @Operation(summary = "산책로 삭제 API / deleteRoadgi", description = "산책로를 삭제하는 API 입니다.", responses = {@ApiResponse( responseCode = "200", From 438ac56256a751fe4d4913862c1bef64fb570336 Mon Sep 17 00:00:00 2001 From: Dustbox Date: Fri, 16 Feb 2024 15:40:29 +0900 Subject: [PATCH 13/14] =?UTF-8?q?[Refac]=20GuestBook=20Service/Repository?= =?UTF-8?q?=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../guestbook/application/GuestBookService.java | 12 ++++++++---- .../domain/repository/GuestBookRepository.java | 12 +++++++----- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/ttubeog/domain/guestbook/application/GuestBookService.java b/src/main/java/com/ttubeog/domain/guestbook/application/GuestBookService.java index f25a4fcf..5f485e4c 100644 --- a/src/main/java/com/ttubeog/domain/guestbook/application/GuestBookService.java +++ b/src/main/java/com/ttubeog/domain/guestbook/application/GuestBookService.java @@ -143,7 +143,7 @@ public ResponseEntity createGuestBook(HttpServletRequest request, CreateGuest Float originStars = guestBookRepository.sumStarBySpotId(spot.getId()); - Long guestBookNum = guestBookRepository.countAllBySpot_Id(spot.getId()); + Long guestBookNum = guestBookRepository.countAllBySpot(spot); float updateStarValue; @@ -157,7 +157,7 @@ public ResponseEntity createGuestBook(HttpServletRequest request, CreateGuest Float originStars = guestBookRepository.sumStarByStoreId(store.getId()); - Long guestBookNum = guestBookRepository.countAllByStore_Id(store.getId()); + Long guestBookNum = guestBookRepository.countAllByStore(store); float updateStarValue; @@ -191,7 +191,9 @@ public ResponseEntity findGuestBookBySpotId(HttpServletRequest request, Long memberRepository.findById(memberId).orElseThrow(InvalidMemberException::new); - Page guestBookPage = guestBookRepository.findAllBySpot_Id(spotId, PageRequest.of(pageNum, 10)); + Spot spot = spotRepository.findById(spotId).orElseThrow(InvalidSpotIdException::new); + + Page guestBookPage = guestBookRepository.findAllBySpot(spot, PageRequest.of(pageNum, 10)); List guestBookResponseDtoList = null; @@ -221,7 +223,9 @@ public ResponseEntity findGuestBookByStoreId(HttpServletRequest request, Long memberRepository.findById(memberId).orElseThrow(InvalidMemberException::new); - Page guestBookPage = guestBookRepository.findAllByStore_Id(storeId, PageRequest.of(pageNum, 10)); + Store store = storeRepository.findById(storeId).orElseThrow(InvalidStoreIdException::new); + + Page guestBookPage = guestBookRepository.findAllByStore(store, PageRequest.of(pageNum, 10)); List guestBookResponseDtoList = null; diff --git a/src/main/java/com/ttubeog/domain/guestbook/domain/repository/GuestBookRepository.java b/src/main/java/com/ttubeog/domain/guestbook/domain/repository/GuestBookRepository.java index 0aac0e2d..44da0734 100644 --- a/src/main/java/com/ttubeog/domain/guestbook/domain/repository/GuestBookRepository.java +++ b/src/main/java/com/ttubeog/domain/guestbook/domain/repository/GuestBookRepository.java @@ -1,6 +1,8 @@ package com.ttubeog.domain.guestbook.domain.repository; import com.ttubeog.domain.guestbook.domain.GuestBook; +import com.ttubeog.domain.spot.domain.Spot; +import com.ttubeog.domain.store.domain.Store; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageRequest; import org.springframework.data.jpa.repository.JpaRepository; @@ -13,20 +15,20 @@ @Repository public interface GuestBookRepository extends JpaRepository { - List findAllBySpot_Id(Long spotId); + List findAllBySpot(Store store); - Page findAllBySpot_Id(Long spotId, PageRequest pageRequest); + Page findAllBySpot(Spot spot, PageRequest pageRequest); - Long countAllBySpot_Id(Long spotId); + Long countAllBySpot(Spot spot); @Query("SELECT SUM(g.star) FROM GuestBook g WHERE g.spot.id = :spotId") Float sumStarBySpotId(@Param("spotId") Long spotId); List findAllByStore_Id(Long storeId); - Page findAllByStore_Id(Long storeId, PageRequest pageRequest); + Page findAllByStore(Store store, PageRequest pageRequest); - Long countAllByStore_Id(Long storeId); + Long countAllByStore(Store store); @Query("SELECT SUM(g.star) FROM GuestBook g WHERE g.store.id = :storeId") Float sumStarByStoreId(@Param("storeId") Long storeId); From bc02ccee9fed1e68dd7cf48e181b1aaa67ce5916 Mon Sep 17 00:00:00 2001 From: Dustbox Date: Fri, 16 Feb 2024 16:14:01 +0900 Subject: [PATCH 14/14] =?UTF-8?q?[Feat]=20RoadRepository=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../guestbook/domain/repository/GuestBookRepository.java | 4 ++-- .../java/com/ttubeog/domain/spot/application/SpotService.java | 2 +- .../com/ttubeog/domain/store/application/StoreService.java | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/ttubeog/domain/guestbook/domain/repository/GuestBookRepository.java b/src/main/java/com/ttubeog/domain/guestbook/domain/repository/GuestBookRepository.java index 44da0734..b21d56d3 100644 --- a/src/main/java/com/ttubeog/domain/guestbook/domain/repository/GuestBookRepository.java +++ b/src/main/java/com/ttubeog/domain/guestbook/domain/repository/GuestBookRepository.java @@ -15,7 +15,7 @@ @Repository public interface GuestBookRepository extends JpaRepository { - List findAllBySpot(Store store); + List findAllBySpot(Spot spot); Page findAllBySpot(Spot spot, PageRequest pageRequest); @@ -24,7 +24,7 @@ public interface GuestBookRepository extends JpaRepository { @Query("SELECT SUM(g.star) FROM GuestBook g WHERE g.spot.id = :spotId") Float sumStarBySpotId(@Param("spotId") Long spotId); - List findAllByStore_Id(Long storeId); + List findAllByStore(Store store); Page findAllByStore(Store store, PageRequest pageRequest); diff --git a/src/main/java/com/ttubeog/domain/spot/application/SpotService.java b/src/main/java/com/ttubeog/domain/spot/application/SpotService.java index 151f5b6e..1d654fcc 100644 --- a/src/main/java/com/ttubeog/domain/spot/application/SpotService.java +++ b/src/main/java/com/ttubeog/domain/spot/application/SpotService.java @@ -212,7 +212,7 @@ public ResponseEntity deleteSpot(HttpServletRequest request, Long spotId) { List imageList = imageRepository.findBySpotId(spot.getId()); imageRepository.deleteAll(imageList); - List guestBookList = guestBookRepository.findAllBySpot_Id(spotId); + List guestBookList = guestBookRepository.findAllBySpot(spot); guestBookRepository.deleteAll(guestBookList); ApiResponse apiResponse = ApiResponse.builder() diff --git a/src/main/java/com/ttubeog/domain/store/application/StoreService.java b/src/main/java/com/ttubeog/domain/store/application/StoreService.java index 06310cad..4a919c01 100644 --- a/src/main/java/com/ttubeog/domain/store/application/StoreService.java +++ b/src/main/java/com/ttubeog/domain/store/application/StoreService.java @@ -210,7 +210,7 @@ public ResponseEntity deleteStore(HttpServletRequest request, Long storeId) { benefitRepository.deleteAll(benefits); // 해당 매장과 연관된 방명록 삭제 - List guestBooks = guestBookRepository.findAllByStore_Id(storeId); + List guestBooks = guestBookRepository.findAllByStore(store); guestBookRepository.deleteAll(guestBooks); // 해당 매장과 연관된 좋아요 삭제 @@ -245,7 +245,7 @@ public ResponseEntity getStoreDetails(HttpServletRequest request, Long storeI .stream() .map(Benefit::getType) .collect(Collectors.toList()); - Integer guestbookCount = guestBookRepository.countAllByStore_Id(storeId).intValue(); + Integer guestbookCount = guestBookRepository.countAllByStore(store).intValue(); Integer likesCount = likesRepository.countByStoreId(storeId); //Boolean isFavorited = likesRepository.existsByMemberIdAndStoreId(memberId, storeId);