From c1dd00a71df763f0cabd4fdc5e5509fd334409b9 Mon Sep 17 00:00:00 2001 From: Lemonade255 Date: Fri, 10 Nov 2023 13:21:03 +0900 Subject: [PATCH 1/5] =?UTF-8?q?feat(BE):=20=EC=88=99=EC=86=8C=20=EB=A7=A4?= =?UTF-8?q?=EC=B9=AD=20=EC=83=9D=EC=84=B1=20BUS-212-accommodation-API=20#4?= =?UTF-8?q?2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/common/type/ErrorCodeEnum.java | 1 + .../adapter/in/rest/MatchingController.java | 17 +++++++++-- ...ngEntity.java => AccommodationEntity.java} | 7 +++-- .../AccommodationPersistenceAdapter.java | 23 +++++++++++++++ ...MatchingApplicationPersistenceAdapter.java | 2 +- .../persistence/MatchingMapperInterface.java | 6 +++- .../port/in/AccommodationUsecase.java | 7 +++++ .../port/out/AccommodationPort.java | 7 +++++ .../api/matching/domain/Accommodation.java | 15 ++++++++++ ...MatchingDto.java => AccommodationDto.java} | 5 +++- .../repository/AccommodationRepository.java | 7 +++++ .../service/AccommodationService.java | 28 +++++++++++++++++++ 12 files changed, 117 insertions(+), 8 deletions(-) rename src/main/java/com/example/api/matching/adapter/out/persistence/{AccommodationMatchingEntity.java => AccommodationEntity.java} (73%) create mode 100644 src/main/java/com/example/api/matching/adapter/out/persistence/AccommodationPersistenceAdapter.java create mode 100644 src/main/java/com/example/api/matching/application/port/in/AccommodationUsecase.java create mode 100644 src/main/java/com/example/api/matching/application/port/out/AccommodationPort.java create mode 100644 src/main/java/com/example/api/matching/domain/Accommodation.java rename src/main/java/com/example/api/matching/dto/{AccommodationMatchingDto.java => AccommodationDto.java} (77%) create mode 100644 src/main/java/com/example/api/matching/repository/AccommodationRepository.java create mode 100644 src/main/java/com/example/api/matching/service/AccommodationService.java diff --git a/src/main/java/com/example/api/common/type/ErrorCodeEnum.java b/src/main/java/com/example/api/common/type/ErrorCodeEnum.java index 6dbf3e3..4c51689 100644 --- a/src/main/java/com/example/api/common/type/ErrorCodeEnum.java +++ b/src/main/java/com/example/api/common/type/ErrorCodeEnum.java @@ -19,6 +19,7 @@ public enum ErrorCodeEnum { MATCHING_NOT_FOUND(HttpStatus.BAD_REQUEST, "매칭 정보가 없습니다"), PREFERENCE_NOT_FOUND(HttpStatus.BAD_REQUEST, "선호도 정보가 없습니다"), APPLICATION_NOT_FOUND(HttpStatus.BAD_REQUEST, "신청 정보가 없습니다"), + ACCOMMODATION_NOT_FOUND(HttpStatus.BAD_REQUEST, "숙소 정보가 없습니다"), FILE_NOT_FOUND(HttpStatus.BAD_REQUEST, "파일이 없습니다"), INVALID_DATATYPE(HttpStatus.BAD_REQUEST, "유효하지 않은 데이터입니다"), // 401 Unauthorized diff --git a/src/main/java/com/example/api/matching/adapter/in/rest/MatchingController.java b/src/main/java/com/example/api/matching/adapter/in/rest/MatchingController.java index 808d1f3..b708104 100644 --- a/src/main/java/com/example/api/matching/adapter/in/rest/MatchingController.java +++ b/src/main/java/com/example/api/matching/adapter/in/rest/MatchingController.java @@ -10,6 +10,7 @@ import com.example.api.matching.application.port.in.*; import com.example.api.matching.domain.MatchingApplication; import com.example.api.matching.dto.*; +import com.example.api.matching.type.MatchingTypeEnum; import com.example.api.member.application.port.in.AddMemberChatRoomUsecase; import com.example.api.user.application.port.in.FindUserUsecase; import com.example.api.user.dto.FindUserInfoDto; @@ -26,9 +27,9 @@ import java.util.List; @RestController +@Slf4j @RequiredArgsConstructor @EnableWebMvc -@Slf4j @Tag(name = "Matching", description = "Matching API") public class MatchingController { private final FindUserUsecase findUserUsecase; @@ -36,6 +37,7 @@ public class MatchingController { private final FindMatchingUsecase findMatchingUsecase; private final DeleteMatchingUsecase deleteMatchingUsecase; private final MatchingApplicationUsecase matchingApplicationUsecase; + private final AccommodationUsecase accommodationUsecase; private final LikeUsecase likeUsecase; private final CreateChatRoomUsecase createChatRoomUsecase; private final AddMemberChatRoomUsecase addMemberChatRoomUsecase; @@ -47,13 +49,13 @@ public class MatchingController { */ @Operation(summary = "Create matching", description = "새로운 매칭을 생성한다.") @PostMapping("/matching") - public FindMatchingDto createMatching(@Valid @RequestBody SaveMatchingDto saveMatchingDto) { + public FindMatchingDto createMatching(@Valid @RequestBody SaveMatchingDto saveMatchingDto, @Valid @RequestBody AccommodationDto accommodationDto) { SecurityUser securityUser = AuthenticationUtils.getCurrentUserAuthentication(); if (securityUser == null) { log.error("MatchingController::createMatching: Login is needed"); throw new CustomException(ErrorCodeEnum.LOGIN_IS_NOT_DONE); } - FindMatchingDto findMatchingDto = saveMatchingUsecase.createMatching(securityUser.getUserId(), saveMatchingDto); + FindMatchingDto findMatchingDto = saveMatchingUsecase.createMatching(securityUser.getUserId(), saveMatchingDto); SaveMatchingApplicationDto saveMatchingApplicationDto = SaveMatchingApplicationDto.builder() .userId(securityUser.getUserId()) @@ -62,6 +64,15 @@ public FindMatchingDto createMatching(@Valid @RequestBody SaveMatchingDto saveMa .isActive(true) .build(); matchingApplicationUsecase.createMatchingApplicationData(securityUser.getUserId(), saveMatchingApplicationDto); + + if (saveMatchingDto.getType().equals(MatchingTypeEnum.Accommodation)) { + if (accommodationDto == null) { + log.error("MatchingController::createMatching: Accommodation data not found"); + throw new CustomException(ErrorCodeEnum.ACCOMMODATION_NOT_FOUND); + } + accommodationUsecase.createAccommodation(findMatchingDto.getMatchingId(), accommodationDto); + } + return findMatchingDto; } diff --git a/src/main/java/com/example/api/matching/adapter/out/persistence/AccommodationMatchingEntity.java b/src/main/java/com/example/api/matching/adapter/out/persistence/AccommodationEntity.java similarity index 73% rename from src/main/java/com/example/api/matching/adapter/out/persistence/AccommodationMatchingEntity.java rename to src/main/java/com/example/api/matching/adapter/out/persistence/AccommodationEntity.java index a140178..fffd4ea 100644 --- a/src/main/java/com/example/api/matching/adapter/out/persistence/AccommodationMatchingEntity.java +++ b/src/main/java/com/example/api/matching/adapter/out/persistence/AccommodationEntity.java @@ -9,14 +9,17 @@ @ToString @NoArgsConstructor @AllArgsConstructor -@Table(name="accommodationMatching") -public class AccommodationMatchingEntity { +@Table(name="accommodation") +public class AccommodationEntity { @Id private Long matchingId; @Column private Integer price; + @Column + private Integer pricePerOne; + @Column(length = 3000) private String room; } \ No newline at end of file diff --git a/src/main/java/com/example/api/matching/adapter/out/persistence/AccommodationPersistenceAdapter.java b/src/main/java/com/example/api/matching/adapter/out/persistence/AccommodationPersistenceAdapter.java new file mode 100644 index 0000000..4af15b4 --- /dev/null +++ b/src/main/java/com/example/api/matching/adapter/out/persistence/AccommodationPersistenceAdapter.java @@ -0,0 +1,23 @@ +package com.example.api.matching.adapter.out.persistence; + +import com.example.api.matching.application.port.out.AccommodationPort; +import com.example.api.matching.domain.Accommodation; +import com.example.api.matching.repository.AccommodationRepository; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.stereotype.Repository; + +@Repository +@Slf4j +@RequiredArgsConstructor +@ComponentScan +public class AccommodationPersistenceAdapter implements AccommodationPort { + private final MatchingMapperInterface matchingMapper; + private final AccommodationRepository accommodationRepository; + + @Override + public void createAccommodation(Accommodation accommodation) { + accommodationRepository.save(matchingMapper.toEntity(accommodation)); + } +} \ No newline at end of file diff --git a/src/main/java/com/example/api/matching/adapter/out/persistence/MatchingApplicationPersistenceAdapter.java b/src/main/java/com/example/api/matching/adapter/out/persistence/MatchingApplicationPersistenceAdapter.java index 54676d1..81b4dc0 100644 --- a/src/main/java/com/example/api/matching/adapter/out/persistence/MatchingApplicationPersistenceAdapter.java +++ b/src/main/java/com/example/api/matching/adapter/out/persistence/MatchingApplicationPersistenceAdapter.java @@ -14,8 +14,8 @@ import java.util.UUID; @Repository -@RequiredArgsConstructor @Slf4j +@RequiredArgsConstructor @ComponentScan public class MatchingApplicationPersistenceAdapter implements MatchingApplicationPort { private final MatchingMapperInterface matchingMapper; diff --git a/src/main/java/com/example/api/matching/adapter/out/persistence/MatchingMapperInterface.java b/src/main/java/com/example/api/matching/adapter/out/persistence/MatchingMapperInterface.java index 094bace..3ae6699 100644 --- a/src/main/java/com/example/api/matching/adapter/out/persistence/MatchingMapperInterface.java +++ b/src/main/java/com/example/api/matching/adapter/out/persistence/MatchingMapperInterface.java @@ -1,5 +1,6 @@ package com.example.api.matching.adapter.out.persistence; +import com.example.api.matching.domain.Accommodation; import com.example.api.matching.domain.Matching; import com.example.api.matching.domain.MatchingApplication; import com.example.api.matching.dto.*; @@ -13,14 +14,17 @@ public interface MatchingMapperInterface { Matching toDomain(SaveMatchingDto matchingDto); MatchingApplication toDomain(SaveMatchingApplicationDto matchingApplicationDto); + Accommodation toDomain(AccommodationDto accommodationDto); MatchingEntity toEntity(Matching matching); MatchingApplicationEntity toEntity(MatchingApplication matchingApplication); + AccommodationEntity toEntity(Accommodation accommodation); LikeEntity toEntity(LikeDto likeDto); Matching toDomain(MatchingEntity matchingEntity); MatchingApplication toDomain(MatchingApplicationEntity matchingApplicationEntity); + Accommodation toDomain(AccommodationEntity accommodationEntity); FindMatchingDto toDto(Matching matching); FindMatchingApplicationDto toDto(MatchingApplication matchingApplication); FindMatchingDto toDto(MatchingEntity matchingEntity); - AccommodationMatchingDto toDto(AccommodationMatchingEntity accommodationMatchingEntity); + AccommodationDto toDto(Accommodation accommodation); LikeDto toDto(LikeEntity likeEntity); } \ No newline at end of file diff --git a/src/main/java/com/example/api/matching/application/port/in/AccommodationUsecase.java b/src/main/java/com/example/api/matching/application/port/in/AccommodationUsecase.java new file mode 100644 index 0000000..470e7e1 --- /dev/null +++ b/src/main/java/com/example/api/matching/application/port/in/AccommodationUsecase.java @@ -0,0 +1,7 @@ +package com.example.api.matching.application.port.in; + +import com.example.api.matching.dto.AccommodationDto; + +public interface AccommodationUsecase { + void createAccommodation(Long matchingId, AccommodationDto accommodationDto); +} \ No newline at end of file diff --git a/src/main/java/com/example/api/matching/application/port/out/AccommodationPort.java b/src/main/java/com/example/api/matching/application/port/out/AccommodationPort.java new file mode 100644 index 0000000..e8a04c0 --- /dev/null +++ b/src/main/java/com/example/api/matching/application/port/out/AccommodationPort.java @@ -0,0 +1,7 @@ +package com.example.api.matching.application.port.out; + +import com.example.api.matching.domain.Accommodation; + +public interface AccommodationPort { + void createAccommodation(Accommodation accommodation); +} \ No newline at end of file diff --git a/src/main/java/com/example/api/matching/domain/Accommodation.java b/src/main/java/com/example/api/matching/domain/Accommodation.java new file mode 100644 index 0000000..a0fbbd6 --- /dev/null +++ b/src/main/java/com/example/api/matching/domain/Accommodation.java @@ -0,0 +1,15 @@ +package com.example.api.matching.domain; + +import lombok.*; + +@Getter +@Setter +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class Accommodation { + private Long matchingId; + private Integer price; + private Integer pricePerOne; + private String room; +} \ No newline at end of file diff --git a/src/main/java/com/example/api/matching/dto/AccommodationMatchingDto.java b/src/main/java/com/example/api/matching/dto/AccommodationDto.java similarity index 77% rename from src/main/java/com/example/api/matching/dto/AccommodationMatchingDto.java rename to src/main/java/com/example/api/matching/dto/AccommodationDto.java index d40e79f..5885184 100644 --- a/src/main/java/com/example/api/matching/dto/AccommodationMatchingDto.java +++ b/src/main/java/com/example/api/matching/dto/AccommodationDto.java @@ -9,11 +9,14 @@ @ToString @NoArgsConstructor @AllArgsConstructor -public class AccommodationMatchingDto { +public class AccommodationDto { private Long matchingId; @Min(0) private Integer price; + @Min(0) + private Integer pricePerOne; + private String room; } \ No newline at end of file diff --git a/src/main/java/com/example/api/matching/repository/AccommodationRepository.java b/src/main/java/com/example/api/matching/repository/AccommodationRepository.java new file mode 100644 index 0000000..e07e248 --- /dev/null +++ b/src/main/java/com/example/api/matching/repository/AccommodationRepository.java @@ -0,0 +1,7 @@ +package com.example.api.matching.repository; + +import com.example.api.matching.adapter.out.persistence.AccommodationEntity; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface AccommodationRepository extends JpaRepository { +} \ No newline at end of file diff --git a/src/main/java/com/example/api/matching/service/AccommodationService.java b/src/main/java/com/example/api/matching/service/AccommodationService.java new file mode 100644 index 0000000..ebe2eb1 --- /dev/null +++ b/src/main/java/com/example/api/matching/service/AccommodationService.java @@ -0,0 +1,28 @@ +package com.example.api.matching.service; + +import com.example.api.matching.adapter.out.persistence.MatchingMapperInterface; +import com.example.api.matching.application.port.in.AccommodationUsecase; +import com.example.api.matching.application.port.out.AccommodationPort; +import com.example.api.matching.domain.Accommodation; +import com.example.api.matching.dto.AccommodationDto; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +@Service +@Slf4j +@RequiredArgsConstructor +@Transactional(readOnly = true) +public class AccommodationService implements AccommodationUsecase { + private final MatchingMapperInterface matchingMapper; + private final AccommodationPort accommodationPort; + + @Override + @Transactional + public void createAccommodation(Long matchingId, AccommodationDto accommodationDto) { + Accommodation accommodation = matchingMapper.toDomain(accommodationDto); + accommodation.setMatchingId(matchingId); + accommodationPort.createAccommodation(accommodation); + } +} \ No newline at end of file From 04875a4ad1f7921e572c3d4d237aa9c5678750b1 Mon Sep 17 00:00:00 2001 From: Lemonade255 Date: Mon, 13 Nov 2023 13:10:12 +0900 Subject: [PATCH 2/5] =?UTF-8?q?feat(BE):=20=EC=88=99=EC=86=8C=20=EB=A7=A4?= =?UTF-8?q?=EC=B9=AD=20=EB=8D=B0=EC=9D=B4=ED=84=B0=20=EC=84=A4=EC=A0=95=20?= =?UTF-8?q?BUS-212-accommodation-API?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../persistence/MatchingMapperInterface.java | 2 + .../domain/AccommodationMatching.java | 34 +++++++++ .../dto/AccommodationMatchingDto.java | 75 +++++++++++++++++++ .../api/matching/dto/FindMatchingDto.java | 3 +- .../api/matching/dto/SaveMatchingDto.java | 2 +- 5 files changed, 114 insertions(+), 2 deletions(-) create mode 100644 src/main/java/com/example/api/matching/domain/AccommodationMatching.java create mode 100644 src/main/java/com/example/api/matching/dto/AccommodationMatchingDto.java diff --git a/src/main/java/com/example/api/matching/adapter/out/persistence/MatchingMapperInterface.java b/src/main/java/com/example/api/matching/adapter/out/persistence/MatchingMapperInterface.java index 3ae6699..0f3f08f 100644 --- a/src/main/java/com/example/api/matching/adapter/out/persistence/MatchingMapperInterface.java +++ b/src/main/java/com/example/api/matching/adapter/out/persistence/MatchingMapperInterface.java @@ -1,6 +1,7 @@ package com.example.api.matching.adapter.out.persistence; import com.example.api.matching.domain.Accommodation; +import com.example.api.matching.domain.AccommodationMatching; import com.example.api.matching.domain.Matching; import com.example.api.matching.domain.MatchingApplication; import com.example.api.matching.dto.*; @@ -26,5 +27,6 @@ public interface MatchingMapperInterface { FindMatchingApplicationDto toDto(MatchingApplication matchingApplication); FindMatchingDto toDto(MatchingEntity matchingEntity); AccommodationDto toDto(Accommodation accommodation); + AccommodationMatchingDto toDto(AccommodationMatching accommodationMatching); LikeDto toDto(LikeEntity likeEntity); } \ No newline at end of file diff --git a/src/main/java/com/example/api/matching/domain/AccommodationMatching.java b/src/main/java/com/example/api/matching/domain/AccommodationMatching.java new file mode 100644 index 0000000..877ea80 --- /dev/null +++ b/src/main/java/com/example/api/matching/domain/AccommodationMatching.java @@ -0,0 +1,34 @@ +package com.example.api.matching.domain; + +import com.example.api.matching.type.MatchingTypeEnum; +import lombok.*; + +import java.time.LocalDateTime; +import java.util.UUID; + +@Getter +@Setter +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class AccommodationMatching { + private Long matchingId; + private UUID writerId; + private MatchingTypeEnum type; + private String title; + private String place; + private String content; + private LocalDateTime startDate; + private LocalDateTime endDate; + private Integer currentMember; + private Integer maxMember; + private Integer minusAge; + private Integer plusAge; + private Integer price; + private Integer pricePerOne; + private String room; + private Integer readCount; + private LocalDateTime createdAt; + private LocalDateTime updatedAt; + private Boolean isActive; +} \ No newline at end of file diff --git a/src/main/java/com/example/api/matching/dto/AccommodationMatchingDto.java b/src/main/java/com/example/api/matching/dto/AccommodationMatchingDto.java new file mode 100644 index 0000000..dd1bcd3 --- /dev/null +++ b/src/main/java/com/example/api/matching/dto/AccommodationMatchingDto.java @@ -0,0 +1,75 @@ +package com.example.api.matching.dto; + +import com.example.api.matching.type.MatchingTypeEnum; +import jakarta.validation.constraints.Min; +import jakarta.validation.constraints.NotBlank; +import jakarta.validation.constraints.NotNull; +import lombok.*; + +import java.time.LocalDateTime; +import java.util.UUID; +@Getter +@Setter +@Builder +@ToString +@NoArgsConstructor +@AllArgsConstructor +public class AccommodationMatchingDto { + private Long matchingId; + + @NotNull + private UUID writerId; + + @NotNull + private MatchingTypeEnum type; + + @NotBlank + private String title; + + @NotBlank + private String place; + + @NotBlank + private String content; + + @NotNull + private LocalDateTime startDate; + + @NotNull + private LocalDateTime endDate; + + @NotNull + @Min(1) + private Integer currentMember; + + @NotNull + @Min(2) + private Integer maxMember; + + @NotNull + @Min(0) + private Integer minusAge; + + @NotNull + @Min(0) + private Integer plusAge; + + @Min(0) + private Integer price; + + @Min(0) + private Integer pricePerOne; + + private String room; + + @NotNull + @Min(0) + private Integer readCount; + + private LocalDateTime createdAt; + + private LocalDateTime updatedAt; + + @NotNull + private Boolean isActive; +} \ No newline at end of file diff --git a/src/main/java/com/example/api/matching/dto/FindMatchingDto.java b/src/main/java/com/example/api/matching/dto/FindMatchingDto.java index b5b0bf5..9a0d5ed 100644 --- a/src/main/java/com/example/api/matching/dto/FindMatchingDto.java +++ b/src/main/java/com/example/api/matching/dto/FindMatchingDto.java @@ -16,6 +16,7 @@ @NoArgsConstructor @AllArgsConstructor public class FindMatchingDto { + @NotNull private Long matchingId; @NotNull @@ -44,7 +45,7 @@ public class FindMatchingDto { private Integer currentMember; @NotNull - @Min(1) + @Min(2) private Integer maxMember; @NotNull diff --git a/src/main/java/com/example/api/matching/dto/SaveMatchingDto.java b/src/main/java/com/example/api/matching/dto/SaveMatchingDto.java index dd577be..38e5509 100644 --- a/src/main/java/com/example/api/matching/dto/SaveMatchingDto.java +++ b/src/main/java/com/example/api/matching/dto/SaveMatchingDto.java @@ -34,7 +34,7 @@ public class SaveMatchingDto { private LocalDateTime endDate; @NotNull - @Min(value = 1, message = "MaxMember must be at least 1") + @Min(value = 2, message = "MaxMember must be at least 2") private Integer maxMember; @NotNull From e0131e1570cfb897fcc6225ba4731f343ce47578 Mon Sep 17 00:00:00 2001 From: Lemonade255 Date: Tue, 14 Nov 2023 22:14:26 +0900 Subject: [PATCH 3/5] =?UTF-8?q?feat(BE):=20=EC=88=99=EC=86=8C=20=EC=A1=B0?= =?UTF-8?q?=ED=9A=8C/=EC=88=98=EC=A0=95/=EC=82=AD=EC=A0=9C=20BUS-212-accom?= =?UTF-8?q?modation-API=20#42=20#43=20#44?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../adapter/in/rest/MatchingController.java | 56 ++++++++++++++----- .../AccommodationPersistenceAdapter.java | 24 +++++++- .../persistence/MatchingMapperInterface.java | 1 + .../port/in/AccommodationUsecase.java | 3 + .../port/out/AccommodationPort.java | 3 + .../dto/AccommodationMatchingDto.java | 1 + .../repository/AccommodationRepository.java | 3 + .../service/AccommodationService.java | 27 ++++++++- .../api/matching/service/MatchingService.java | 5 +- 9 files changed, 107 insertions(+), 16 deletions(-) diff --git a/src/main/java/com/example/api/matching/adapter/in/rest/MatchingController.java b/src/main/java/com/example/api/matching/adapter/in/rest/MatchingController.java index b708104..1e45e3d 100644 --- a/src/main/java/com/example/api/matching/adapter/in/rest/MatchingController.java +++ b/src/main/java/com/example/api/matching/adapter/in/rest/MatchingController.java @@ -1,17 +1,15 @@ package com.example.api.matching.adapter.in.rest; import com.example.api.auth.domain.SecurityUser; -import com.example.api.chatroom.application.port.in.CreateChatRoomUsecase; -import com.example.api.chatroom.domain.ChatRoom; import com.example.api.common.exception.CustomException; import com.example.api.common.type.ApplicationStateEnum; import com.example.api.common.type.ErrorCodeEnum; import com.example.api.common.utils.AuthenticationUtils; +import com.example.api.matching.adapter.out.persistence.MatchingMapperInterface; import com.example.api.matching.application.port.in.*; import com.example.api.matching.domain.MatchingApplication; import com.example.api.matching.dto.*; import com.example.api.matching.type.MatchingTypeEnum; -import com.example.api.member.application.port.in.AddMemberChatRoomUsecase; import com.example.api.user.application.port.in.FindUserUsecase; import com.example.api.user.dto.FindUserInfoDto; import com.example.api.user.dto.UserAuthorityCheckDto; @@ -27,9 +25,9 @@ import java.util.List; @RestController -@Slf4j @RequiredArgsConstructor @EnableWebMvc +@Slf4j @Tag(name = "Matching", description = "Matching API") public class MatchingController { private final FindUserUsecase findUserUsecase; @@ -39,8 +37,7 @@ public class MatchingController { private final MatchingApplicationUsecase matchingApplicationUsecase; private final AccommodationUsecase accommodationUsecase; private final LikeUsecase likeUsecase; - private final CreateChatRoomUsecase createChatRoomUsecase; - private final AddMemberChatRoomUsecase addMemberChatRoomUsecase; + private final MatchingMapperInterface matchingMapper; /** * 새 매칭 생성 @@ -79,11 +76,10 @@ public FindMatchingDto createMatching(@Valid @RequestBody SaveMatchingDto saveMa /** * 새 매칭 신청 생성 * @param matchingApplicationDto (데이터) - * @return chatroom */ @Operation(summary = "Create matching application", description = "새로운 매칭 신청을 생성한다.") @PostMapping("/matching/application") - public ChatRoom createMatchingApplication(@Valid @RequestBody SaveMatchingApplicationDto matchingApplicationDto) { + public void createMatchingApplication(@Valid @RequestBody SaveMatchingApplicationDto matchingApplicationDto) { SecurityUser securityUser = AuthenticationUtils.getCurrentUserAuthentication(); if (securityUser == null) { log.error("MatchingController::createMatchingApplication: Login is needed"); @@ -100,8 +96,8 @@ public ChatRoom createMatchingApplication(@Valid @RequestBody SaveMatchingApplic } MatchingApplication matchingApplication = matchingApplicationUsecase.createMatchingApplicationData(securityUser.getUserId(), matchingApplicationDto); - ChatRoom chatRoom = createChatRoomUsecase.createMatchingChatRoom(matchingApplication); - return addMemberChatRoomUsecase.setupMatchingChatRoom(matchingApplication, chatRoom); + //ChatRoom chatRoom = createChatRoomUsecase.createMatchingChatRoom(matchingApplication); + //return addMemberChatRoomUsecase.setupMatchingChatRoom(matchingApplication, chatRoom); } /** @@ -120,19 +116,26 @@ public List getAll() { } /** - * ID가 matchingId인 매칭 조회 + * ID가 matchingId인 매칭 조회 (유형 범용) * @param matchingId (데이터) * @return matching data */ @Operation(summary = "Get matching", description = "ID가 matchingId인 매칭을 조회한다.") @GetMapping("/matching/{matchingId}") - public FindMatchingDto getMatchingById(@PathVariable Long matchingId) { + public AccommodationMatchingDto getMatchingById(@PathVariable Long matchingId) { SecurityUser securityUser = AuthenticationUtils.getCurrentUserAuthentication(); if (securityUser == null) { log.error("MatchingController::getMatchingById: Login is needed"); throw new CustomException(ErrorCodeEnum.LOGIN_IS_NOT_DONE); } - return findMatchingUsecase.getMatchingById(matchingId); + AccommodationMatchingDto matchingDto = matchingMapper.toDto(findMatchingUsecase.getMatchingById(matchingId)); + if (matchingDto.getType().equals(MatchingTypeEnum.Accommodation)) { + AccommodationDto accommodationDto = accommodationUsecase.getAccommodation(matchingId); + matchingDto.setPrice(accommodationDto.getPrice()); + matchingDto.setPricePerOne(accommodationDto.getPrice() / Math.max(matchingDto.getCurrentMember(), 1)); + matchingDto.setRoom(accommodationDto.getRoom()); + } + return matchingDto; } /** @@ -215,6 +218,17 @@ public FindMatchingDto updateMatching(@PathVariable Long matchingId, @RequestBod } return saveMatchingUsecase.updateMatching(matchingId, matchingDto); } + + @Operation(summary = "Update accommodation", description = "숙소 정보를 수정한다.") + @PutMapping("/matching/{matchingId}/accommodation") + public void updateAccommodation(@PathVariable Long matchingId, @RequestBody AccommodationDto accommodationDto) { + SecurityUser securityUser = AuthenticationUtils.getCurrentUserAuthentication(); + if (securityUser == null) { + log.error("MatchingController::updateAccommodation: Login is needed"); + throw new CustomException(ErrorCodeEnum.LOGIN_IS_NOT_DONE); + } + accommodationUsecase.updateAccommodation(matchingId, accommodationDto); + } /** * 매칭의 좋아요 토글 @@ -288,4 +302,20 @@ public void deleteMatching(@PathVariable Long matchingId) { } deleteMatchingUsecase.deleteMatching(matchingId); } + + @Operation(summary = "Reset accommodation", description = "숙소 정보를 초기화한다.") + @DeleteMapping("/matching/{matchingId}/accommodation") + public void deleteAccommodation(@PathVariable Long matchingId) { + SecurityUser securityUser = AuthenticationUtils.getCurrentUserAuthentication(); + if (securityUser == null) { + log.error("MatchingController::deleteAccommodation: Login is needed"); + throw new CustomException(ErrorCodeEnum.LOGIN_IS_NOT_DONE); + } + FindMatchingDto matchingDto = findMatchingUsecase.getMatchingById(matchingId); + if (matchingDto == null) { + log.error("MatchingController::deleteMatching: No such matching"); + throw new CustomException(ErrorCodeEnum.MATCHING_NOT_FOUND); + } + accommodationUsecase.deleteAccommodation(matchingId); + } } \ No newline at end of file diff --git a/src/main/java/com/example/api/matching/adapter/out/persistence/AccommodationPersistenceAdapter.java b/src/main/java/com/example/api/matching/adapter/out/persistence/AccommodationPersistenceAdapter.java index 4af15b4..a2046a3 100644 --- a/src/main/java/com/example/api/matching/adapter/out/persistence/AccommodationPersistenceAdapter.java +++ b/src/main/java/com/example/api/matching/adapter/out/persistence/AccommodationPersistenceAdapter.java @@ -9,8 +9,8 @@ import org.springframework.stereotype.Repository; @Repository -@Slf4j @RequiredArgsConstructor +@Slf4j @ComponentScan public class AccommodationPersistenceAdapter implements AccommodationPort { private final MatchingMapperInterface matchingMapper; @@ -20,4 +20,26 @@ public class AccommodationPersistenceAdapter implements AccommodationPort { public void createAccommodation(Accommodation accommodation) { accommodationRepository.save(matchingMapper.toEntity(accommodation)); } + + @Override + public Accommodation getAccommodation(Long matchingId) { + return matchingMapper.toDomain(accommodationRepository.getByMatchingId(matchingId). + orElse(AccommodationEntity.builder() + .matchingId(matchingId) + .price(0) + .pricePerOne(0) + .room("") + .build() + )); + } + + @Override + public void updateAccommodation(Accommodation accommodation) { + accommodationRepository.save(matchingMapper.toEntity(accommodation)); + } + + @Override + public void deleteAccommodation(Accommodation accommodation) { + accommodationRepository.save(matchingMapper.toEntity(accommodation)); + } } \ No newline at end of file diff --git a/src/main/java/com/example/api/matching/adapter/out/persistence/MatchingMapperInterface.java b/src/main/java/com/example/api/matching/adapter/out/persistence/MatchingMapperInterface.java index 0f3f08f..ef0aa2b 100644 --- a/src/main/java/com/example/api/matching/adapter/out/persistence/MatchingMapperInterface.java +++ b/src/main/java/com/example/api/matching/adapter/out/persistence/MatchingMapperInterface.java @@ -28,5 +28,6 @@ public interface MatchingMapperInterface { FindMatchingDto toDto(MatchingEntity matchingEntity); AccommodationDto toDto(Accommodation accommodation); AccommodationMatchingDto toDto(AccommodationMatching accommodationMatching); + AccommodationMatchingDto toDto(FindMatchingDto matchingDto); LikeDto toDto(LikeEntity likeEntity); } \ No newline at end of file diff --git a/src/main/java/com/example/api/matching/application/port/in/AccommodationUsecase.java b/src/main/java/com/example/api/matching/application/port/in/AccommodationUsecase.java index 470e7e1..f4aba37 100644 --- a/src/main/java/com/example/api/matching/application/port/in/AccommodationUsecase.java +++ b/src/main/java/com/example/api/matching/application/port/in/AccommodationUsecase.java @@ -4,4 +4,7 @@ public interface AccommodationUsecase { void createAccommodation(Long matchingId, AccommodationDto accommodationDto); + AccommodationDto getAccommodation(Long matchingId); + void updateAccommodation(Long matchingId, AccommodationDto accommodationDto); + void deleteAccommodation(Long matchingId); } \ No newline at end of file diff --git a/src/main/java/com/example/api/matching/application/port/out/AccommodationPort.java b/src/main/java/com/example/api/matching/application/port/out/AccommodationPort.java index e8a04c0..8647e89 100644 --- a/src/main/java/com/example/api/matching/application/port/out/AccommodationPort.java +++ b/src/main/java/com/example/api/matching/application/port/out/AccommodationPort.java @@ -4,4 +4,7 @@ public interface AccommodationPort { void createAccommodation(Accommodation accommodation); + Accommodation getAccommodation(Long matchingId); + void updateAccommodation(Accommodation accommodation); + void deleteAccommodation(Accommodation accommodation); } \ No newline at end of file diff --git a/src/main/java/com/example/api/matching/dto/AccommodationMatchingDto.java b/src/main/java/com/example/api/matching/dto/AccommodationMatchingDto.java index dd1bcd3..6590a05 100644 --- a/src/main/java/com/example/api/matching/dto/AccommodationMatchingDto.java +++ b/src/main/java/com/example/api/matching/dto/AccommodationMatchingDto.java @@ -8,6 +8,7 @@ import java.time.LocalDateTime; import java.util.UUID; + @Getter @Setter @Builder diff --git a/src/main/java/com/example/api/matching/repository/AccommodationRepository.java b/src/main/java/com/example/api/matching/repository/AccommodationRepository.java index e07e248..35ca2c4 100644 --- a/src/main/java/com/example/api/matching/repository/AccommodationRepository.java +++ b/src/main/java/com/example/api/matching/repository/AccommodationRepository.java @@ -3,5 +3,8 @@ import com.example.api.matching.adapter.out.persistence.AccommodationEntity; import org.springframework.data.jpa.repository.JpaRepository; +import java.util.Optional; + public interface AccommodationRepository extends JpaRepository { + Optional getByMatchingId(Long matchingId); } \ No newline at end of file diff --git a/src/main/java/com/example/api/matching/service/AccommodationService.java b/src/main/java/com/example/api/matching/service/AccommodationService.java index ebe2eb1..c1664cd 100644 --- a/src/main/java/com/example/api/matching/service/AccommodationService.java +++ b/src/main/java/com/example/api/matching/service/AccommodationService.java @@ -11,8 +11,8 @@ import org.springframework.transaction.annotation.Transactional; @Service -@Slf4j @RequiredArgsConstructor +@Slf4j @Transactional(readOnly = true) public class AccommodationService implements AccommodationUsecase { private final MatchingMapperInterface matchingMapper; @@ -25,4 +25,29 @@ public void createAccommodation(Long matchingId, AccommodationDto accommodationD accommodation.setMatchingId(matchingId); accommodationPort.createAccommodation(accommodation); } + + @Override + public AccommodationDto getAccommodation(Long matchingId) { + return matchingMapper.toDto(accommodationPort.getAccommodation(matchingId)); + } + + @Override + @Transactional + public void updateAccommodation(Long matchingId, AccommodationDto accommodationDto) { + Accommodation accommodation = matchingMapper.toDomain(accommodationDto); + accommodation.setMatchingId(matchingId); + accommodationPort.updateAccommodation(accommodation); + } + + @Override + @Transactional + public void deleteAccommodation(Long matchingId) { + Accommodation accommodation = Accommodation.builder() + .matchingId(matchingId) + .price(0) + .pricePerOne(0) + .room("") + .build(); + accommodationPort.deleteAccommodation(accommodation); + } } \ No newline at end of file diff --git a/src/main/java/com/example/api/matching/service/MatchingService.java b/src/main/java/com/example/api/matching/service/MatchingService.java index 9bd29ec..676940e 100644 --- a/src/main/java/com/example/api/matching/service/MatchingService.java +++ b/src/main/java/com/example/api/matching/service/MatchingService.java @@ -24,8 +24,8 @@ import java.util.*; @Service -@Slf4j @RequiredArgsConstructor +@Slf4j @Transactional(readOnly = true) public class MatchingService implements SaveMatchingUsecase, FindMatchingUsecase, DeleteMatchingUsecase, LikeUsecase { private final PreferenceService preferenceService; @@ -100,6 +100,9 @@ public List getRecommendedMatchingList(UUID userId) { FindMatchingDto findMatchingDto = this.getMatchingById(matchingData.getFirst()); if (findMatchingDto != null) { sortedMatchingList.add(findMatchingDto); + if (sortedMatchingList.size() == 10) { + break; + } } } } catch (Exception e) { From 02f40b4cfbdffbd93e4ee2ebcf0ce7bc020e9297 Mon Sep 17 00:00:00 2001 From: Lemonade255 Date: Wed, 15 Nov 2023 18:06:01 +0900 Subject: [PATCH 4/5] =?UTF-8?q?feat(BE):=20=EC=88=99=EC=86=8C=20=EB=A7=A4?= =?UTF-8?q?=EC=B9=AD=20=EB=AA=A9=EB=A1=9D=20=EC=A1=B0=ED=9A=8C/=EC=88=99?= =?UTF-8?q?=EC=86=8C=20=EC=B6=94=EC=B2=9C=20BUS-212-accommodation-API=20#4?= =?UTF-8?q?1=20#53?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../adapter/in/rest/MatchingController.java | 26 +++++++++++ .../AccommodationPersistenceAdapter.java | 17 ++++++- .../persistence/MatchingMapperInterface.java | 1 + .../port/in/AccommodationUsecase.java | 6 +++ .../port/out/AccommodationPort.java | 6 +++ .../repository/AccommodationRepository.java | 2 + .../repository/MatchingRepository.java | 2 + .../service/AccommodationService.java | 46 ++++++++++++++++++- .../api/matching/service/MatchingService.java | 2 +- 9 files changed, 105 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/example/api/matching/adapter/in/rest/MatchingController.java b/src/main/java/com/example/api/matching/adapter/in/rest/MatchingController.java index 1e45e3d..fdeae27 100644 --- a/src/main/java/com/example/api/matching/adapter/in/rest/MatchingController.java +++ b/src/main/java/com/example/api/matching/adapter/in/rest/MatchingController.java @@ -114,6 +114,21 @@ public List getAll() { } return findMatchingUsecase.getAll(); } + + /** + * 숙소 매칭 목록 조회 + * @return accommodation matching list + */ + @Operation(summary = "Get all accommodation matching", description = "모든 숙소 매칭 목록을 조회한다.") + @GetMapping("/accommodationmatching") + public List getAccommodationMatchingList() { + SecurityUser securityUser = AuthenticationUtils.getCurrentUserAuthentication(); + if (securityUser == null) { + log.error("MatchingController::getAccommodationMatchingList: Login is needed"); + throw new CustomException(ErrorCodeEnum.LOGIN_IS_NOT_DONE); + } + return accommodationUsecase.getAccommodationMatchingList(); + } /** * ID가 matchingId인 매칭 조회 (유형 범용) @@ -201,6 +216,17 @@ public int getLikeCount(@PathVariable Long matchingId) { } return likeUsecase.getLikeCount(matchingId); } + + @Operation(summary = "Get recommended accommodation list", description = "추천 숙소 리스트를 반환한다.") + @GetMapping("/accommodation/recommended") + public List getRecommendedAccommodationList() { + SecurityUser securityUser = AuthenticationUtils.getCurrentUserAuthentication(); + if (securityUser == null) { + log.error("MatchingController::getRecommendedAccommodationList: Login is needed"); + throw new CustomException(ErrorCodeEnum.LOGIN_IS_NOT_DONE); + } + return accommodationUsecase.getRecommendedAccommodationList(securityUser.getUserId()); + } /** * ID가 matchingId인 매칭 정보 수정 diff --git a/src/main/java/com/example/api/matching/adapter/out/persistence/AccommodationPersistenceAdapter.java b/src/main/java/com/example/api/matching/adapter/out/persistence/AccommodationPersistenceAdapter.java index a2046a3..d81c881 100644 --- a/src/main/java/com/example/api/matching/adapter/out/persistence/AccommodationPersistenceAdapter.java +++ b/src/main/java/com/example/api/matching/adapter/out/persistence/AccommodationPersistenceAdapter.java @@ -3,24 +3,39 @@ import com.example.api.matching.application.port.out.AccommodationPort; import com.example.api.matching.domain.Accommodation; import com.example.api.matching.repository.AccommodationRepository; +import com.example.api.matching.repository.MatchingRepository; +import com.example.api.matching.type.MatchingTypeEnum; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.context.annotation.ComponentScan; import org.springframework.stereotype.Repository; +import java.util.List; + @Repository @RequiredArgsConstructor @Slf4j @ComponentScan public class AccommodationPersistenceAdapter implements AccommodationPort { - private final MatchingMapperInterface matchingMapper; + private final MatchingRepository matchingRepository; private final AccommodationRepository accommodationRepository; + private final MatchingMapperInterface matchingMapper; @Override public void createAccommodation(Accommodation accommodation) { accommodationRepository.save(matchingMapper.toEntity(accommodation)); } + @Override + public List getAccommodationMatchingList() { + return matchingRepository.getByType(MatchingTypeEnum.Accommodation); + } + + @Override + public List getAccommodationList() { + return accommodationRepository.getAllBy(); + } + @Override public Accommodation getAccommodation(Long matchingId) { return matchingMapper.toDomain(accommodationRepository.getByMatchingId(matchingId). diff --git a/src/main/java/com/example/api/matching/adapter/out/persistence/MatchingMapperInterface.java b/src/main/java/com/example/api/matching/adapter/out/persistence/MatchingMapperInterface.java index ef0aa2b..1151aea 100644 --- a/src/main/java/com/example/api/matching/adapter/out/persistence/MatchingMapperInterface.java +++ b/src/main/java/com/example/api/matching/adapter/out/persistence/MatchingMapperInterface.java @@ -21,6 +21,7 @@ public interface MatchingMapperInterface { AccommodationEntity toEntity(Accommodation accommodation); LikeEntity toEntity(LikeDto likeDto); Matching toDomain(MatchingEntity matchingEntity); + AccommodationMatching toAccommodationDomain(MatchingEntity matchingEntity); MatchingApplication toDomain(MatchingApplicationEntity matchingApplicationEntity); Accommodation toDomain(AccommodationEntity accommodationEntity); FindMatchingDto toDto(Matching matching); diff --git a/src/main/java/com/example/api/matching/application/port/in/AccommodationUsecase.java b/src/main/java/com/example/api/matching/application/port/in/AccommodationUsecase.java index f4aba37..f73bfb7 100644 --- a/src/main/java/com/example/api/matching/application/port/in/AccommodationUsecase.java +++ b/src/main/java/com/example/api/matching/application/port/in/AccommodationUsecase.java @@ -1,10 +1,16 @@ package com.example.api.matching.application.port.in; import com.example.api.matching.dto.AccommodationDto; +import com.example.api.matching.dto.AccommodationMatchingDto; + +import java.util.List; +import java.util.UUID; public interface AccommodationUsecase { void createAccommodation(Long matchingId, AccommodationDto accommodationDto); + List getAccommodationMatchingList(); AccommodationDto getAccommodation(Long matchingId); + List getRecommendedAccommodationList(UUID userId); void updateAccommodation(Long matchingId, AccommodationDto accommodationDto); void deleteAccommodation(Long matchingId); } \ No newline at end of file diff --git a/src/main/java/com/example/api/matching/application/port/out/AccommodationPort.java b/src/main/java/com/example/api/matching/application/port/out/AccommodationPort.java index 8647e89..cb68b61 100644 --- a/src/main/java/com/example/api/matching/application/port/out/AccommodationPort.java +++ b/src/main/java/com/example/api/matching/application/port/out/AccommodationPort.java @@ -1,9 +1,15 @@ package com.example.api.matching.application.port.out; +import com.example.api.matching.adapter.out.persistence.AccommodationEntity; +import com.example.api.matching.adapter.out.persistence.MatchingEntity; import com.example.api.matching.domain.Accommodation; +import java.util.List; + public interface AccommodationPort { void createAccommodation(Accommodation accommodation); + List getAccommodationMatchingList(); + List getAccommodationList(); Accommodation getAccommodation(Long matchingId); void updateAccommodation(Accommodation accommodation); void deleteAccommodation(Accommodation accommodation); diff --git a/src/main/java/com/example/api/matching/repository/AccommodationRepository.java b/src/main/java/com/example/api/matching/repository/AccommodationRepository.java index 35ca2c4..c9157dd 100644 --- a/src/main/java/com/example/api/matching/repository/AccommodationRepository.java +++ b/src/main/java/com/example/api/matching/repository/AccommodationRepository.java @@ -3,8 +3,10 @@ import com.example.api.matching.adapter.out.persistence.AccommodationEntity; import org.springframework.data.jpa.repository.JpaRepository; +import java.util.List; import java.util.Optional; public interface AccommodationRepository extends JpaRepository { + List getAllBy(); Optional getByMatchingId(Long matchingId); } \ No newline at end of file diff --git a/src/main/java/com/example/api/matching/repository/MatchingRepository.java b/src/main/java/com/example/api/matching/repository/MatchingRepository.java index b6197e6..291e55c 100644 --- a/src/main/java/com/example/api/matching/repository/MatchingRepository.java +++ b/src/main/java/com/example/api/matching/repository/MatchingRepository.java @@ -1,6 +1,7 @@ package com.example.api.matching.repository; import com.example.api.matching.adapter.out.persistence.MatchingEntity; +import com.example.api.matching.type.MatchingTypeEnum; import org.springframework.data.jpa.repository.JpaRepository; import java.util.List; @@ -11,6 +12,7 @@ public interface MatchingRepository extends JpaRepository List getAllBy(); Optional getByMatchingId(Long matchingId); List getByWriterId(UUID userId); + List getByType(MatchingTypeEnum type); List getByIsActive(Boolean isActive); void deleteAllBy(); void deleteByMatchingId(Long matchingId); diff --git a/src/main/java/com/example/api/matching/service/AccommodationService.java b/src/main/java/com/example/api/matching/service/AccommodationService.java index c1664cd..a380956 100644 --- a/src/main/java/com/example/api/matching/service/AccommodationService.java +++ b/src/main/java/com/example/api/matching/service/AccommodationService.java @@ -1,22 +1,31 @@ package com.example.api.matching.service; +import com.example.api.common.type.Pair; +import com.example.api.matching.adapter.out.persistence.AccommodationEntity; +import com.example.api.matching.adapter.out.persistence.MatchingEntity; import com.example.api.matching.adapter.out.persistence.MatchingMapperInterface; import com.example.api.matching.application.port.in.AccommodationUsecase; import com.example.api.matching.application.port.out.AccommodationPort; +import com.example.api.matching.application.port.out.FindMatchingPort; import com.example.api.matching.domain.Accommodation; +import com.example.api.matching.domain.AccommodationMatching; import com.example.api.matching.dto.AccommodationDto; +import com.example.api.matching.dto.AccommodationMatchingDto; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import java.util.*; + @Service @RequiredArgsConstructor @Slf4j @Transactional(readOnly = true) public class AccommodationService implements AccommodationUsecase { - private final MatchingMapperInterface matchingMapper; + private final FindMatchingPort findMatchingPort; private final AccommodationPort accommodationPort; + private final MatchingMapperInterface matchingMapper; @Override @Transactional @@ -26,11 +35,46 @@ public void createAccommodation(Long matchingId, AccommodationDto accommodationD accommodationPort.createAccommodation(accommodation); } + @Override + public List getAccommodationMatchingList() { + List matchingList = accommodationPort.getAccommodationMatchingList(); + List accommodationMatchingList = new ArrayList<>(); + for (MatchingEntity matchingEntity: matchingList) { + AccommodationMatching accommodationMatching = matchingMapper.toAccommodationDomain(matchingEntity); + Accommodation accommodation = accommodationPort.getAccommodation(matchingEntity.getMatchingId()); + accommodationMatching.setPrice(accommodation.getPrice()); + accommodationMatching.setPricePerOne(accommodation.getPrice() / accommodationMatching.getCurrentMember()); + accommodationMatching.setRoom(accommodation.getRoom()); + accommodationMatchingList.add(matchingMapper.toDto(accommodationMatching)); + } + return accommodationMatchingList; + } + @Override public AccommodationDto getAccommodation(Long matchingId) { return matchingMapper.toDto(accommodationPort.getAccommodation(matchingId)); } + @Override + public List getRecommendedAccommodationList(UUID userId) { + List accommodationList = accommodationPort.getAccommodationList(); + List> accommodationPriceList = new ArrayList<>(); + for (AccommodationEntity accommodationData: accommodationList) { + Optional matchingEntity = findMatchingPort.getByMatchingId(accommodationData.getMatchingId()); + matchingEntity.ifPresent(entity -> accommodationPriceList.add(new Pair<>(accommodationData.getMatchingId(), accommodationData.getPrice() / entity.getMaxMember()))); + } + accommodationPriceList.sort(Comparator.comparing(Pair::getSecond)); + + List sortedAccommodationList = new ArrayList<>(); + for (Pair accommodationData: accommodationPriceList) { + sortedAccommodationList.add(this.getAccommodation(accommodationData.getFirst())); + if (sortedAccommodationList.size() == 10) { + break; + } + } + return sortedAccommodationList; + } + @Override @Transactional public void updateAccommodation(Long matchingId, AccommodationDto accommodationDto) { diff --git a/src/main/java/com/example/api/matching/service/MatchingService.java b/src/main/java/com/example/api/matching/service/MatchingService.java index 676940e..ddf1822 100644 --- a/src/main/java/com/example/api/matching/service/MatchingService.java +++ b/src/main/java/com/example/api/matching/service/MatchingService.java @@ -29,12 +29,12 @@ @Transactional(readOnly = true) public class MatchingService implements SaveMatchingUsecase, FindMatchingUsecase, DeleteMatchingUsecase, LikeUsecase { private final PreferenceService preferenceService; - private final MatchingMapperInterface matchingMapper; private final SaveMatchingPort saveMatchingPort; private final FindMatchingPort findMatchingPort; private final DeleteMatchingPort deleteMatchingPort; private final MatchingApplicationPort matchingApplicationPort; private final LikePort likePort; + private final MatchingMapperInterface matchingMapper; @Override @Transactional From 9f392d953db4398043979d7d7c3f6bc6edf615b0 Mon Sep 17 00:00:00 2001 From: Lemonade255 Date: Wed, 15 Nov 2023 19:03:58 +0900 Subject: [PATCH 5/5] =?UTF-8?q?feat(BE):=20=EC=8B=9D=EC=82=AC=20=EB=A7=A4?= =?UTF-8?q?=EC=B9=AD=20=EB=A6=AC=EC=8A=A4=ED=8A=B8=20=EC=A1=B0=ED=9A=8C=20?= =?UTF-8?q?BUS-212-accommodation-API?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../matching/adapter/in/rest/MatchingController.java | 11 +++++++++++ .../out/persistence/MatchingPersistenceAdapter.java | 6 ++++++ .../application/port/in/FindMatchingUsecase.java | 1 + .../application/port/out/FindMatchingPort.java | 1 + .../example/api/matching/service/MatchingService.java | 5 +++++ 5 files changed, 24 insertions(+) diff --git a/src/main/java/com/example/api/matching/adapter/in/rest/MatchingController.java b/src/main/java/com/example/api/matching/adapter/in/rest/MatchingController.java index fdeae27..3d6140a 100644 --- a/src/main/java/com/example/api/matching/adapter/in/rest/MatchingController.java +++ b/src/main/java/com/example/api/matching/adapter/in/rest/MatchingController.java @@ -114,6 +114,17 @@ public List getAll() { } return findMatchingUsecase.getAll(); } + + @Operation(summary = "Get all dining matching", description = "모든 식사 매칭 목록을 조회한다.") + @GetMapping("/diningmatching") + public List getDiningMatchingList() { + SecurityUser securityUser = AuthenticationUtils.getCurrentUserAuthentication(); + if (securityUser == null) { + log.error("MatchingController::getDiningMatchingList: Login is needed"); + throw new CustomException(ErrorCodeEnum.LOGIN_IS_NOT_DONE); + } + return findMatchingUsecase.getDiningMatchingList(); + } /** * 숙소 매칭 목록 조회 diff --git a/src/main/java/com/example/api/matching/adapter/out/persistence/MatchingPersistenceAdapter.java b/src/main/java/com/example/api/matching/adapter/out/persistence/MatchingPersistenceAdapter.java index 97046d5..f7dbef6 100644 --- a/src/main/java/com/example/api/matching/adapter/out/persistence/MatchingPersistenceAdapter.java +++ b/src/main/java/com/example/api/matching/adapter/out/persistence/MatchingPersistenceAdapter.java @@ -4,6 +4,7 @@ import com.example.api.matching.domain.Matching; import com.example.api.matching.repository.LikeRepository; import com.example.api.matching.repository.MatchingRepository; +import com.example.api.matching.type.MatchingTypeEnum; import lombok.RequiredArgsConstructor; import org.springframework.context.annotation.ComponentScan; import org.springframework.stereotype.Repository; @@ -31,6 +32,11 @@ public List getAllBy() { return matchingRepository.getAllBy(); } + @Override + public List getDiningMatchingList() { + return matchingRepository.getByType(MatchingTypeEnum.Dining); + } + @Override public Optional getByMatchingId(Long matchingId) { return matchingRepository.getByMatchingId(matchingId); diff --git a/src/main/java/com/example/api/matching/application/port/in/FindMatchingUsecase.java b/src/main/java/com/example/api/matching/application/port/in/FindMatchingUsecase.java index e71239b..a129721 100644 --- a/src/main/java/com/example/api/matching/application/port/in/FindMatchingUsecase.java +++ b/src/main/java/com/example/api/matching/application/port/in/FindMatchingUsecase.java @@ -7,6 +7,7 @@ public interface FindMatchingUsecase { List getAll(); + List getDiningMatchingList(); FindMatchingDto getMatchingById(Long matchingId); List getMatchingByWriterId(UUID userId); List getMatchingByIsActive(Boolean isActive); diff --git a/src/main/java/com/example/api/matching/application/port/out/FindMatchingPort.java b/src/main/java/com/example/api/matching/application/port/out/FindMatchingPort.java index 6ef0e7b..19d8122 100644 --- a/src/main/java/com/example/api/matching/application/port/out/FindMatchingPort.java +++ b/src/main/java/com/example/api/matching/application/port/out/FindMatchingPort.java @@ -8,6 +8,7 @@ public interface FindMatchingPort { List getAllBy(); + List getDiningMatchingList(); Optional getByMatchingId(Long matchingId); List getByWriterId(UUID userId); List getByIsActive(Boolean isActive); diff --git a/src/main/java/com/example/api/matching/service/MatchingService.java b/src/main/java/com/example/api/matching/service/MatchingService.java index ddf1822..ec6aab2 100644 --- a/src/main/java/com/example/api/matching/service/MatchingService.java +++ b/src/main/java/com/example/api/matching/service/MatchingService.java @@ -62,6 +62,11 @@ public List setCurrentMember(List matchingEntit public List getAll() { return this.setCurrentMember(findMatchingPort.getAllBy()); } + + @Override + public List getDiningMatchingList() { + return this.setCurrentMember(findMatchingPort.getDiningMatchingList()); + } @Override public FindMatchingDto getMatchingById(Long matchingId) {