From dd674c43b6f20d4ddca8bbb26bbca3c64f869dbc Mon Sep 17 00:00:00 2001 From: BOMIN LYU Date: Thu, 3 Oct 2024 22:42:15 +0900 Subject: [PATCH 01/10] =?UTF-8?q?feat:=20Mapstruct=20=EC=82=AC=EC=9A=A9?= =?UTF-8?q?=EC=9D=84=20=EC=9C=84=ED=95=9C=20=EC=9D=98=EC=A1=B4=EC=84=B1=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle | 3 +++ 1 file changed, 3 insertions(+) diff --git a/build.gradle b/build.gradle index 8a1403ac..3608e286 100644 --- a/build.gradle +++ b/build.gradle @@ -40,6 +40,9 @@ dependencies { implementation 'org.springframework.boot:spring-boot-starter-web' implementation "io.jsonwebtoken:jjwt-api:${jjwt_version}" implementation "org.springdoc:springdoc-openapi-starter-webmvc-ui:${swagger_version}" + implementation 'org.mapstruct:mapstruct:1.6.2' + + annotationProcessor 'org.mapstruct:mapstruct-processor:1.6.2' testImplementation 'org.springframework.boot:spring-boot-starter-test' // testImplementation 'org.springframework.security:spring-security-test' From f8eb5046c70bf56200892235474caeef315b4608 Mon Sep 17 00:00:00 2001 From: BOMIN LYU Date: Thu, 3 Oct 2024 22:43:48 +0900 Subject: [PATCH 02/10] =?UTF-8?q?feat:=20Controller=20=EA=B3=84=EC=B8=B5?= =?UTF-8?q?=20DTO=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../spot/dto/controllerdto/SpotCreationRequest.java | 12 ++++++++++++ .../spot/dto/controllerdto/SpotCreationResponse.java | 10 ++++++++++ .../spot/dto/controllerdto/SpotDetailResponse.java | 10 ++++++++++ .../spot/dto/controllerdto/SpotModifyRequest.java | 4 ++++ .../spot/dto/controllerdto/SpotViewedResponse.java | 6 ++++++ 5 files changed, 42 insertions(+) create mode 100644 src/main/java/com/ordertogether/team14_be/spot/dto/controllerdto/SpotCreationRequest.java create mode 100644 src/main/java/com/ordertogether/team14_be/spot/dto/controllerdto/SpotCreationResponse.java create mode 100644 src/main/java/com/ordertogether/team14_be/spot/dto/controllerdto/SpotDetailResponse.java create mode 100644 src/main/java/com/ordertogether/team14_be/spot/dto/controllerdto/SpotModifyRequest.java create mode 100644 src/main/java/com/ordertogether/team14_be/spot/dto/controllerdto/SpotViewedResponse.java diff --git a/src/main/java/com/ordertogether/team14_be/spot/dto/controllerdto/SpotCreationRequest.java b/src/main/java/com/ordertogether/team14_be/spot/dto/controllerdto/SpotCreationRequest.java new file mode 100644 index 00000000..0401380b --- /dev/null +++ b/src/main/java/com/ordertogether/team14_be/spot/dto/controllerdto/SpotCreationRequest.java @@ -0,0 +1,12 @@ +package com.ordertogether.team14_be.spot.dto.controllerdto; + +import java.math.BigDecimal; + +public record SpotCreationRequest( + Long id, + BigDecimal lat, + BigDecimal lng, + String storeName, + Integer minimumOrderAmount, + String togetherOrderLink, + String pickUpLocation) {} diff --git a/src/main/java/com/ordertogether/team14_be/spot/dto/controllerdto/SpotCreationResponse.java b/src/main/java/com/ordertogether/team14_be/spot/dto/controllerdto/SpotCreationResponse.java new file mode 100644 index 00000000..8695c545 --- /dev/null +++ b/src/main/java/com/ordertogether/team14_be/spot/dto/controllerdto/SpotCreationResponse.java @@ -0,0 +1,10 @@ +package com.ordertogether.team14_be.spot.dto.controllerdto; + +import com.ordertogether.team14_be.spot.enums.Category; + +public record SpotCreationResponse( + Long id, + Category category, + String storeName, + Integer minimumOrderAmount, + String pickUpLocation) {} diff --git a/src/main/java/com/ordertogether/team14_be/spot/dto/controllerdto/SpotDetailResponse.java b/src/main/java/com/ordertogether/team14_be/spot/dto/controllerdto/SpotDetailResponse.java new file mode 100644 index 00000000..e0dce369 --- /dev/null +++ b/src/main/java/com/ordertogether/team14_be/spot/dto/controllerdto/SpotDetailResponse.java @@ -0,0 +1,10 @@ +package com.ordertogether.team14_be.spot.dto.controllerdto; + +import com.ordertogether.team14_be.spot.enums.Category; + +public record SpotDetailResponse( + Category category, + String storeName, + Integer minimumOrderAmount, + String pickUpLocation, + String deliveryStatus) {} diff --git a/src/main/java/com/ordertogether/team14_be/spot/dto/controllerdto/SpotModifyRequest.java b/src/main/java/com/ordertogether/team14_be/spot/dto/controllerdto/SpotModifyRequest.java new file mode 100644 index 00000000..3d46ab2f --- /dev/null +++ b/src/main/java/com/ordertogether/team14_be/spot/dto/controllerdto/SpotModifyRequest.java @@ -0,0 +1,4 @@ +package com.ordertogether.team14_be.spot.dto.controllerdto; + +public record SpotModifyRequest( + Long id, String storeName, Integer minimumOrderAmount, String pickUpLocation) {} diff --git a/src/main/java/com/ordertogether/team14_be/spot/dto/controllerdto/SpotViewedResponse.java b/src/main/java/com/ordertogether/team14_be/spot/dto/controllerdto/SpotViewedResponse.java new file mode 100644 index 00000000..f51ac0cb --- /dev/null +++ b/src/main/java/com/ordertogether/team14_be/spot/dto/controllerdto/SpotViewedResponse.java @@ -0,0 +1,6 @@ +package com.ordertogether.team14_be.spot.dto.controllerdto; + +import com.ordertogether.team14_be.spot.enums.Category; + +public record SpotViewedResponse( + Category category, String storeName, Integer minimumOrderAmount, String pickUpLocation) {} From e3e11b8f76a7e5459ec556784ab787e89588e342 Mon Sep 17 00:00:00 2001 From: BOMIN LYU Date: Thu, 3 Oct 2024 22:45:08 +0900 Subject: [PATCH 03/10] =?UTF-8?q?feat:=20Mapstruct=EB=A5=BC=20=EC=9D=B4?= =?UTF-8?q?=EC=9A=A9=ED=95=B4=20SpotMapper=20=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../team14_be/spot/mapper/SpotMapper.java | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 src/main/java/com/ordertogether/team14_be/spot/mapper/SpotMapper.java diff --git a/src/main/java/com/ordertogether/team14_be/spot/mapper/SpotMapper.java b/src/main/java/com/ordertogether/team14_be/spot/mapper/SpotMapper.java new file mode 100644 index 00000000..566a36cc --- /dev/null +++ b/src/main/java/com/ordertogether/team14_be/spot/mapper/SpotMapper.java @@ -0,0 +1,33 @@ +package com.ordertogether.team14_be.spot.mapper; + +import com.ordertogether.team14_be.spot.dto.controllerdto.SpotCreationRequest; +import com.ordertogether.team14_be.spot.dto.controllerdto.SpotCreationResponse; +import com.ordertogether.team14_be.spot.dto.controllerdto.SpotDetailResponse; +import com.ordertogether.team14_be.spot.dto.controllerdto.SpotViewedResponse; +import com.ordertogether.team14_be.spot.dto.servicedto.SpotDto; +import com.ordertogether.team14_be.spot.entity.Spot; +import org.mapstruct.Mapper; +import org.mapstruct.MappingTarget; +import org.mapstruct.ReportingPolicy; +import org.mapstruct.factory.Mappers; + +@Mapper( + componentModel = "spring", + unmappedTargetPolicy = ReportingPolicy.IGNORE) // Spring Bean으로 등록 +public interface SpotMapper { + SpotMapper INSTANCE = Mappers.getMapper(SpotMapper.class); // 객체 생성해서 INSTANCE에 할당 + + SpotDto toDto(Spot spot); + + SpotDto toSpotDto(SpotCreationRequest spotCreationRequest); + + Spot toEntity(SpotDto spotDto); + + Spot toEntity(SpotDto spotDto, @MappingTarget Spot spot); // 생성 또는 수정할 때 사용 + + SpotCreationResponse toSpotCreationResponse(SpotDto spotDto); + + SpotDetailResponse toSpotDetailResponse(SpotDto spotDto); + + SpotViewedResponse toSpotViewedResponse(SpotDto spotDto); +} From 43d5f46277b3c30e664dad1d9e0fd41982f3b65c Mon Sep 17 00:00:00 2001 From: BOMIN LYU Date: Thu, 3 Oct 2024 22:45:33 +0900 Subject: [PATCH 04/10] =?UTF-8?q?refactor:=20=EC=9D=B4=EB=A6=84=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 --- .../{SpotRepository.java => SimpleSpotRepository.java} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename src/main/java/com/ordertogether/team14_be/spot/repository/{SpotRepository.java => SimpleSpotRepository.java} (85%) diff --git a/src/main/java/com/ordertogether/team14_be/spot/repository/SpotRepository.java b/src/main/java/com/ordertogether/team14_be/spot/repository/SimpleSpotRepository.java similarity index 85% rename from src/main/java/com/ordertogether/team14_be/spot/repository/SpotRepository.java rename to src/main/java/com/ordertogether/team14_be/spot/repository/SimpleSpotRepository.java index 706897b5..37052ef3 100644 --- a/src/main/java/com/ordertogether/team14_be/spot/repository/SpotRepository.java +++ b/src/main/java/com/ordertogether/team14_be/spot/repository/SimpleSpotRepository.java @@ -8,7 +8,7 @@ import org.springframework.stereotype.Repository; @Repository -public interface SpotRepository extends JpaRepository { +public interface SimpleSpotRepository extends JpaRepository { List findByLatAndLngAndIsDeletedFalse(BigDecimal lat, BigDecimal lng); Optional findByIdAndIsDeletedFalse(Long id); From 970565341b0cbf9f94215f612487f614efc2dc41 Mon Sep 17 00:00:00 2001 From: BOMIN LYU Date: Thu, 3 Oct 2024 22:50:18 +0900 Subject: [PATCH 05/10] =?UTF-8?q?feat:=20SimpleSpotRepository=EB=A5=BC=20?= =?UTF-8?q?=EA=B0=80=EC=A7=80=EB=8A=94=20Repository=20=EA=B3=84=EC=B8=B5?= =?UTF-8?q?=20=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../spot/repository/SpotRepository.java | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 src/main/java/com/ordertogether/team14_be/spot/repository/SpotRepository.java diff --git a/src/main/java/com/ordertogether/team14_be/spot/repository/SpotRepository.java b/src/main/java/com/ordertogether/team14_be/spot/repository/SpotRepository.java new file mode 100644 index 00000000..853fea4e --- /dev/null +++ b/src/main/java/com/ordertogether/team14_be/spot/repository/SpotRepository.java @@ -0,0 +1,42 @@ +package com.ordertogether.team14_be.spot.repository; + +import com.ordertogether.team14_be.spot.dto.servicedto.SpotDto; +import com.ordertogether.team14_be.spot.entity.Spot; +import com.ordertogether.team14_be.spot.mapper.SpotMapper; +import jakarta.persistence.EntityNotFoundException; +import java.math.BigDecimal; +import java.util.List; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Repository; + +@Repository +@RequiredArgsConstructor +public class SpotRepository { + + private final SimpleSpotRepository simpleSpotRepository; + + public SpotDto save(Spot spot) { + return SpotMapper.INSTANCE.toDto(simpleSpotRepository.save(spot)); + } + + public SpotDto findByIdAndIsDeletedFalse(Long id) { + return SpotMapper.INSTANCE.toDto( + simpleSpotRepository + .findByIdAndIsDeletedFalse(id) + .orElseThrow(() -> new EntityNotFoundException(id + "에 해당하는 Spot을 찾을 수 없습니다."))); + } + + public List findByLatAndLngAndIsDeletedFalse(BigDecimal lat, BigDecimal lng) { + return simpleSpotRepository.findByLatAndLngAndIsDeletedFalse(lat, lng).stream() + .map(SpotMapper.INSTANCE::toDto) + .toList(); + } + + public void delete(Long id) { + Spot spot = + simpleSpotRepository + .findByIdAndIsDeletedFalse(id) + .orElseThrow(() -> new EntityNotFoundException(id + "에 해당하는 Spot을 찾을 수 없습니다.")); + spot.delete(); + } +} From a64232f2001228317bf64a6958a90305b4e8cb05 Mon Sep 17 00:00:00 2001 From: BOMIN LYU Date: Thu, 3 Oct 2024 22:51:33 +0900 Subject: [PATCH 06/10] =?UTF-8?q?refactor:=20Controller=20=EA=B3=84?= =?UTF-8?q?=EC=B8=B5=EC=9D=98=20Dto=EB=A5=BC=20=EB=B0=98=ED=99=98=ED=95=98?= =?UTF-8?q?=EB=8F=84=EB=A1=9D=20=EC=88=98=EC=A0=95,=20Service=20=EA=B3=84?= =?UTF-8?q?=EC=B8=B5=EC=9D=98=20Dto=EB=A5=BC=20=EC=9D=B8=EC=9E=90=EB=A1=9C?= =?UTF-8?q?=20=EB=84=98=EA=B8=B0=EB=8F=84=EB=A1=9D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../spot/controller/SpotController.java | 33 +++++++++++-------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/src/main/java/com/ordertogether/team14_be/spot/controller/SpotController.java b/src/main/java/com/ordertogether/team14_be/spot/controller/SpotController.java index c8a9cc98..491b13b0 100644 --- a/src/main/java/com/ordertogether/team14_be/spot/controller/SpotController.java +++ b/src/main/java/com/ordertogether/team14_be/spot/controller/SpotController.java @@ -1,46 +1,53 @@ package com.ordertogether.team14_be.spot.controller; -import com.ordertogether.team14_be.spot.dto.SpotDto; +import com.ordertogether.team14_be.spot.dto.controllerdto.SpotCreationRequest; +import com.ordertogether.team14_be.spot.dto.controllerdto.SpotCreationResponse; +import com.ordertogether.team14_be.spot.dto.controllerdto.SpotDetailResponse; +import com.ordertogether.team14_be.spot.dto.controllerdto.SpotViewedResponse; +import com.ordertogether.team14_be.spot.mapper.SpotMapper; import com.ordertogether.team14_be.spot.service.SpotService; import java.math.BigDecimal; import java.util.List; -import org.springframework.beans.factory.annotation.Autowired; +import lombok.RequiredArgsConstructor; +import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; @RestController +@RequiredArgsConstructor public class SpotController { private final SpotService spotService; - @Autowired - public SpotController(SpotService spotService) { - this.spotService = spotService; - } - // Spot 전체 조회하기 @GetMapping("/api/v1/spot/{lat}/{lng}") - public ResponseEntity> getSpot( + public ResponseEntity> getSpot( @PathVariable BigDecimal lat, @PathVariable BigDecimal lng) { return ResponseEntity.ok(spotService.getSpot(lat, lng)); } // Spot 생성하기 @PostMapping("/api/v1/spot") - public ResponseEntity createSpot(@RequestBody SpotDto spotDto) { - return ResponseEntity.ok(spotService.createSpot(spotDto)); + public ResponseEntity createSpot( + @RequestBody SpotCreationRequest spotCreationRequest) { + return new ResponseEntity<>( + spotService.createSpot(SpotMapper.INSTANCE.toSpotDto(spotCreationRequest)), + HttpStatus.CREATED); } // Spot 상세 조회하기 @GetMapping("/api/v1/spot/{id}") - public ResponseEntity getSpot(@PathVariable Long id) { + public ResponseEntity getSpotDetail(@PathVariable Long id) { return ResponseEntity.ok(spotService.getSpot(id)); } // Spot 수정하기 @PutMapping("/api/v1/spot") - public ResponseEntity updateSpot(@RequestBody SpotDto spotDto) { - return ResponseEntity.ok(spotService.updateSpot(spotDto)); + public ResponseEntity updateSpot( + @RequestBody SpotCreationRequest spotCreationRequest) { + return ResponseEntity.ok( + SpotMapper.INSTANCE.toSpotCreationResponse( + spotService.updateSpot(SpotMapper.INSTANCE.toSpotDto(spotCreationRequest)))); } // Spot 삭제하기 From d1c5770755586d8c7c20ac49344c68c2aeb66e79 Mon Sep 17 00:00:00 2001 From: BOMIN LYU Date: Thu, 3 Oct 2024 22:52:26 +0900 Subject: [PATCH 07/10] =?UTF-8?q?refactor:=20servicedto=20=ED=8C=A8?= =?UTF-8?q?=ED=82=A4=EC=A7=80=EB=A1=9C=20=EC=9D=B4=EB=8F=99,=20accessLevel?= =?UTF-8?q?=20=EC=A1=B0=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../spot/dto/{ => servicedto}/SpotDto.java | 26 +++---------------- 1 file changed, 3 insertions(+), 23 deletions(-) rename src/main/java/com/ordertogether/team14_be/spot/dto/{ => servicedto}/SpotDto.java (51%) diff --git a/src/main/java/com/ordertogether/team14_be/spot/dto/SpotDto.java b/src/main/java/com/ordertogether/team14_be/spot/dto/servicedto/SpotDto.java similarity index 51% rename from src/main/java/com/ordertogether/team14_be/spot/dto/SpotDto.java rename to src/main/java/com/ordertogether/team14_be/spot/dto/servicedto/SpotDto.java index 4a988d84..d33bba55 100644 --- a/src/main/java/com/ordertogether/team14_be/spot/dto/SpotDto.java +++ b/src/main/java/com/ordertogether/team14_be/spot/dto/servicedto/SpotDto.java @@ -1,6 +1,5 @@ -package com.ordertogether.team14_be.spot.dto; +package com.ordertogether.team14_be.spot.dto.servicedto; -import com.ordertogether.team14_be.spot.entity.Spot; import com.ordertogether.team14_be.spot.enums.Category; import jakarta.persistence.Column; import java.math.BigDecimal; @@ -8,8 +7,8 @@ import lombok.*; @Builder -@NoArgsConstructor(access = AccessLevel.PRIVATE) -@AllArgsConstructor(access = AccessLevel.PROTECTED) +@NoArgsConstructor +@AllArgsConstructor @Getter public class SpotDto { private Long id; @@ -31,23 +30,4 @@ public class SpotDto { private LocalDateTime modifiedAt; private Long createdBy; private Long modifiedBy; - - public Spot toEntity() { - return Spot.builder() - .id(id) - .lat(lat) - .lng(lng) - .category(category) - .storeName(storeName) - .minimumOrderAmount(minimumOrderAmount) - .togetherOrderLink(togetherOrderLink) - .pickUpLocation(pickUpLocation) - .deliveryStatus(deliveryStatus) - .isDeleted(isDeleted) - .createdAt(createdAt) - .modifiedAt(modifiedAt) - .createdBy(createdBy) - .modifiedBy(modifiedBy) - .build(); - } } From 36f437851e74efe6e1b685f69d738bd0b79214fd Mon Sep 17 00:00:00 2001 From: BOMIN LYU Date: Thu, 3 Oct 2024 22:53:40 +0900 Subject: [PATCH 08/10] =?UTF-8?q?refactor:=20=EB=A7=A4=ED=95=91=20?= =?UTF-8?q?=EB=B0=A9=EC=8B=9D=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../team14_be/spot/service/SpotService.java | 70 ++++++------------- 1 file changed, 23 insertions(+), 47 deletions(-) diff --git a/src/main/java/com/ordertogether/team14_be/spot/service/SpotService.java b/src/main/java/com/ordertogether/team14_be/spot/service/SpotService.java index a16a6dc4..375efb85 100644 --- a/src/main/java/com/ordertogether/team14_be/spot/service/SpotService.java +++ b/src/main/java/com/ordertogether/team14_be/spot/service/SpotService.java @@ -1,79 +1,55 @@ package com.ordertogether.team14_be.spot.service; -import com.ordertogether.team14_be.spot.dto.SpotDto; +import com.ordertogether.team14_be.spot.dto.controllerdto.SpotCreationResponse; +import com.ordertogether.team14_be.spot.dto.controllerdto.SpotDetailResponse; +import com.ordertogether.team14_be.spot.dto.controllerdto.SpotViewedResponse; +import com.ordertogether.team14_be.spot.dto.servicedto.SpotDto; import com.ordertogether.team14_be.spot.entity.Spot; +import com.ordertogether.team14_be.spot.mapper.SpotMapper; import com.ordertogether.team14_be.spot.repository.SpotRepository; -import jakarta.persistence.EntityNotFoundException; import jakarta.transaction.Transactional; import java.math.BigDecimal; import java.util.List; -import java.util.Optional; -import java.util.stream.Collectors; -import org.springframework.beans.factory.annotation.Autowired; +import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; @Service +@RequiredArgsConstructor public class SpotService { private final SpotRepository spotRepository; - @Autowired - public SpotService(SpotRepository spotRepository) { - this.spotRepository = spotRepository; - } - // Spot 전체 조회하기 - public List getSpot(BigDecimal lat, BigDecimal lng) { + public List getSpot(BigDecimal lat, BigDecimal lng) { return spotRepository.findByLatAndLngAndIsDeletedFalse(lat, lng).stream() - .map(this::toDto) - .collect(Collectors.toList()); + .map(SpotMapper.INSTANCE::toSpotViewedResponse) + .toList(); } @Transactional - public SpotDto createSpot(SpotDto spotDto) { - Spot spot = spotDto.toEntity(); - return toDto(spotRepository.save(spot)); + public SpotCreationResponse createSpot(SpotDto spotDto) { + Spot spot = SpotMapper.INSTANCE.toEntity(spotDto, new Spot()); + return SpotMapper.INSTANCE.toSpotCreationResponse(spotRepository.save(spot)); } // Spot 상세 조회하기 - public SpotDto getSpot(Long id) { - Spot spot = - spotRepository - .findById(id) - .orElseThrow(() -> new EntityNotFoundException("Spot을 찾을 수 없습니다.")); - return toDto(spot); + public SpotDetailResponse getSpot(Long id) { + SpotDto spotDto = spotRepository.findByIdAndIsDeletedFalse(id); + return SpotMapper.INSTANCE.toSpotDetailResponse(spotDto); } @Transactional public SpotDto updateSpot(SpotDto spotDto) { - Spot spot = spotRepository.save(spotDto.toEntity()); - return toDto(spot); + Spot spot = + SpotMapper.INSTANCE.toEntity( + spotDto, + SpotMapper.INSTANCE.toEntity( + spotRepository.findByIdAndIsDeletedFalse(spotDto.getId()))); + return SpotMapper.INSTANCE.toDto(spot); } @Transactional public void deleteSpot(Long id) { - Optional spotToDelete = spotRepository.findByIdAndIsDeletedFalse(id); - spotToDelete.ifPresent(Spot::delete); - } - - // Service Layer에서 toDto만들어서 매핑시키기 - public SpotDto toDto(Spot spotInStream) { - Spot spot = - spotRepository - .findById(spotInStream.getId()) - .orElseThrow(() -> new EntityNotFoundException("Spot을 찾을 수 없습니다.")); - - return SpotDto.builder() - .id(spot.getId()) - .lat(spot.getLat()) - .lng(spot.getLng()) - .category(spot.getCategory()) - .storeName(spot.getStoreName()) - .minimumOrderAmount(spot.getMinimumOrderAmount()) - .togetherOrderLink(spot.getTogetherOrderLink()) - .pickUpLocation(spot.getPickUpLocation()) - .deliveryStatus(spot.getDeliveryStatus()) - .isDeleted(spot.getIsDeleted()) - .build(); + spotRepository.delete(id); } } From 4f9d598c9f111e3e12b9ba82238cae31870c0e0a Mon Sep 17 00:00:00 2001 From: BOMIN LYU Date: Thu, 3 Oct 2024 22:57:40 +0900 Subject: [PATCH 09/10] =?UTF-8?q?feat:=20Member=EC=9D=98=20PK=EB=A5=BC=20?= =?UTF-8?q?=EC=B0=B8=EC=A1=B0=ED=95=98=EB=8F=84=EB=A1=9D=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 --- .../java/com/ordertogether/team14_be/spot/entity/Spot.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/main/java/com/ordertogether/team14_be/spot/entity/Spot.java b/src/main/java/com/ordertogether/team14_be/spot/entity/Spot.java index a658376c..20373b01 100644 --- a/src/main/java/com/ordertogether/team14_be/spot/entity/Spot.java +++ b/src/main/java/com/ordertogether/team14_be/spot/entity/Spot.java @@ -1,6 +1,7 @@ package com.ordertogether.team14_be.spot.entity; import com.ordertogether.team14_be.common.persistence.entity.BaseEntity; +import com.ordertogether.team14_be.member.persistence.entity.Member; import com.ordertogether.team14_be.spot.enums.Category; import jakarta.persistence.*; import java.math.BigDecimal; @@ -21,6 +22,10 @@ public class Spot extends BaseEntity { @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; + @ManyToOne + @JoinColumn(name = "master_id") // PK 참조해서 master_id 속성 추가 + private Member member; + @Column(precision = 10, scale = 8) private BigDecimal lat; From 54ee14537b59530e06d90377b33091a12fea1bbc Mon Sep 17 00:00:00 2001 From: BOMIN LYU Date: Fri, 4 Oct 2024 19:36:03 +0900 Subject: [PATCH 10/10] =?UTF-8?q?refactor:=20=EC=A1=B0=ED=9A=8C=20?= =?UTF-8?q?=EB=A9=94=EC=84=9C=EB=93=9C=20readOnly=EB=A1=9C=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/ordertogether/team14_be/spot/service/SpotService.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/ordertogether/team14_be/spot/service/SpotService.java b/src/main/java/com/ordertogether/team14_be/spot/service/SpotService.java index 375efb85..b7ee8dfd 100644 --- a/src/main/java/com/ordertogether/team14_be/spot/service/SpotService.java +++ b/src/main/java/com/ordertogether/team14_be/spot/service/SpotService.java @@ -7,11 +7,11 @@ import com.ordertogether.team14_be.spot.entity.Spot; import com.ordertogether.team14_be.spot.mapper.SpotMapper; import com.ordertogether.team14_be.spot.repository.SpotRepository; -import jakarta.transaction.Transactional; import java.math.BigDecimal; import java.util.List; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; @Service @RequiredArgsConstructor @@ -20,6 +20,7 @@ public class SpotService { private final SpotRepository spotRepository; // Spot 전체 조회하기 + @Transactional(readOnly = true) public List getSpot(BigDecimal lat, BigDecimal lng) { return spotRepository.findByLatAndLngAndIsDeletedFalse(lat, lng).stream() .map(SpotMapper.INSTANCE::toSpotViewedResponse) @@ -33,6 +34,7 @@ public SpotCreationResponse createSpot(SpotDto spotDto) { } // Spot 상세 조회하기 + @Transactional(readOnly = true) public SpotDetailResponse getSpot(Long id) { SpotDto spotDto = spotRepository.findByIdAndIsDeletedFalse(id); return SpotMapper.INSTANCE.toSpotDetailResponse(spotDto);