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 345e96c..01eb918 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 @@ -5,7 +5,7 @@ import com.example.api.matching.application.port.in.*; import com.example.api.matching.dto.FindMatchingDto; import com.example.api.matching.dto.LikeDto; -import com.example.api.matching.dto.MatchingApplicationDto; +import com.example.api.matching.dto.SaveMatchingApplicationDto; import com.example.api.matching.dto.SaveMatchingDto; import com.example.api.user.dto.FindUserDto; import io.swagger.v3.oas.annotations.Operation; @@ -46,7 +46,7 @@ public FindMatchingDto createMatching(@RequestBody SaveMatchingDto matchingDto) */ @Operation(summary = "Create matching application", description = "새로운 매칭 신청을 생성한다.") @PostMapping("/matching/application") - public ChatRoom createMatchingApplication(@RequestBody MatchingApplicationDto matchingApplicationDto) { + public ChatRoom createMatchingApplication(@RequestBody SaveMatchingApplicationDto matchingApplicationDto) { return matchingApplicationUsecase.createMatchingApplication(matchingApplicationDto); } 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 0791fa9..62c5503 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 @@ -3,7 +3,7 @@ import com.example.api.matching.domain.Matching; import com.example.api.matching.domain.MatchingApplication; import com.example.api.matching.dto.LikeDto; -import com.example.api.matching.dto.MatchingApplicationDto; +import com.example.api.matching.dto.SaveMatchingApplicationDto; import com.example.api.matching.dto.FindMatchingDto; import com.example.api.matching.dto.SaveMatchingDto; import org.mapstruct.InjectionStrategy; @@ -15,14 +15,14 @@ unmappedTargetPolicy = ReportingPolicy.IGNORE) public interface MatchingMapperInterface { Matching toDomain(SaveMatchingDto matchingDto); - MatchingApplication toDomain(MatchingApplicationDto matchingApplicationDto); + MatchingApplication toDomain(SaveMatchingApplicationDto matchingApplicationDto); MatchingEntity toEntity(Matching matching); MatchingApplicationEntity toEntity(MatchingApplication matchingApplication); LikeEntity toEntity(LikeDto likeDto); Matching toDomain(MatchingEntity matchingEntity); MatchingApplication toDomain(MatchingApplicationEntity matchingApplicationEntity); FindMatchingDto toDto(Matching matching); - MatchingApplicationDto toDto(MatchingApplication matchingApplication); + SaveMatchingApplicationDto toDto(MatchingApplication matchingApplication); FindMatchingDto toDto(MatchingEntity matchingEntity); LikeDto toDto(LikeEntity likeEntity); } \ No newline at end of file diff --git a/src/main/java/com/example/api/matching/application/port/in/MatchingApplicationUsecase.java b/src/main/java/com/example/api/matching/application/port/in/MatchingApplicationUsecase.java index 291a4c7..7b5368c 100644 --- a/src/main/java/com/example/api/matching/application/port/in/MatchingApplicationUsecase.java +++ b/src/main/java/com/example/api/matching/application/port/in/MatchingApplicationUsecase.java @@ -2,15 +2,15 @@ import com.example.api.chatroom.domain.ChatRoom; import com.example.api.common.type.ApplicationStateEnum; -import com.example.api.matching.dto.MatchingApplicationDto; +import com.example.api.matching.dto.SaveMatchingApplicationDto; import com.example.api.matching.dto.FindMatchingDto; import com.example.api.user.dto.FindUserDto; import java.util.List; public interface MatchingApplicationUsecase { - ChatRoom createMatchingApplication(MatchingApplicationDto matchingApplicationDto); + ChatRoom createMatchingApplication(SaveMatchingApplicationDto matchingApplicationDto); List getByUserIdIsAndStateEquals(ApplicationStateEnum state); List getByMatchingIdIsAndStateEquals(Long matchingId, ApplicationStateEnum state); - MatchingApplicationDto updateMatchingApplication(MatchingApplicationDto matchingApplicationDto); + SaveMatchingApplicationDto updateMatchingApplication(SaveMatchingApplicationDto matchingApplicationDto); } \ No newline at end of file diff --git a/src/main/java/com/example/api/matching/dto/MatchingApplicationDto.java b/src/main/java/com/example/api/matching/dto/FindMatchingApplicationDto.java similarity index 90% rename from src/main/java/com/example/api/matching/dto/MatchingApplicationDto.java rename to src/main/java/com/example/api/matching/dto/FindMatchingApplicationDto.java index 268a68c..05faa08 100644 --- a/src/main/java/com/example/api/matching/dto/MatchingApplicationDto.java +++ b/src/main/java/com/example/api/matching/dto/FindMatchingApplicationDto.java @@ -1,6 +1,5 @@ package com.example.api.matching.dto; - import com.example.api.common.type.ApplicationStateEnum; import jakarta.validation.constraints.Min; import jakarta.validation.constraints.NotNull; @@ -15,21 +14,21 @@ @ToString @NoArgsConstructor @AllArgsConstructor -public class MatchingApplicationDto { +public class FindMatchingApplicationDto { @NotNull private UUID userId; - + @NotNull @Min(1) private Long matchingId; - + @NotNull private ApplicationStateEnum state; - + 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/SaveMatchingApplicationDto.java b/src/main/java/com/example/api/matching/dto/SaveMatchingApplicationDto.java new file mode 100644 index 0000000..ee74044 --- /dev/null +++ b/src/main/java/com/example/api/matching/dto/SaveMatchingApplicationDto.java @@ -0,0 +1,24 @@ +package com.example.api.matching.dto; + +import com.example.api.common.type.ApplicationStateEnum; +import jakarta.validation.constraints.Min; +import jakarta.validation.constraints.NotNull; +import lombok.*; + +@Getter +@Setter +@Builder +@ToString +@NoArgsConstructor +@AllArgsConstructor +public class SaveMatchingApplicationDto { + @NotNull + @Min(1) + private Long matchingId; + + @NotNull + private ApplicationStateEnum state; + + @NotNull + private Boolean isActive; +} \ No newline at end of file diff --git a/src/main/java/com/example/api/matching/service/MatchingApplicationService.java b/src/main/java/com/example/api/matching/service/MatchingApplicationService.java index 8850ec2..2d71c18 100644 --- a/src/main/java/com/example/api/matching/service/MatchingApplicationService.java +++ b/src/main/java/com/example/api/matching/service/MatchingApplicationService.java @@ -17,7 +17,7 @@ import com.example.api.matching.application.port.out.MatchingApplicationPort; import com.example.api.matching.domain.MatchingApplication; import com.example.api.matching.dto.FindMatchingDto; -import com.example.api.matching.dto.MatchingApplicationDto; +import com.example.api.matching.dto.SaveMatchingApplicationDto; import com.example.api.member.dto.AddMemberDto; import com.example.api.member.service.MemberService; import com.example.api.user.adapter.out.persistence.UserMapperInterface; @@ -49,8 +49,15 @@ public class MatchingApplicationService implements MatchingApplicationUsecase { @Override @Transactional - public ChatRoom createMatchingApplication(MatchingApplicationDto matchingApplicationDto) { - MatchingApplication matchingApplication = matchingApplicationPort.createMatchingApplication(matchingMapper.toDomain(matchingApplicationDto)); + public ChatRoom createMatchingApplication(SaveMatchingApplicationDto matchingApplicationDto) { + SecurityUser securityUser = AuthenticationUtils.getCurrentUserAuthentication(); + if (securityUser == null) { + log.error("MatchingApplicationService::createMatchingApplication: Authentication is needed."); + return ChatRoom.builder().build(); + } + MatchingApplication matchingApplication = matchingMapper.toDomain(matchingApplicationDto); + matchingApplication.setUserId(securityUser.getUserId()); + matchingApplication = matchingApplicationPort.createMatchingApplication(matchingApplication); CreateChatRoomDto createChatRoomDto = CreateChatRoomDto.builder() .masterId(matchingApplication.getUserId()) @@ -103,7 +110,7 @@ public List getByMatchingIdIsAndStateEquals(Long matchingId, Applic @Override @Transactional - public MatchingApplicationDto updateMatchingApplication(MatchingApplicationDto matchingApplicationDto) { + public SaveMatchingApplicationDto updateMatchingApplication(SaveMatchingApplicationDto matchingApplicationDto) { MatchingApplication matchingApplication = matchingApplicationPort.updateMatchingApplication(matchingMapper.toDomain(matchingApplicationDto)); return matchingMapper.toDto(matchingApplication); } diff --git a/src/test/java/com/example/api/matching/MatchingApplicationServiceTests.java b/src/test/java/com/example/api/matching/MatchingApplicationServiceTests.java index d519efa..025e448 100644 --- a/src/test/java/com/example/api/matching/MatchingApplicationServiceTests.java +++ b/src/test/java/com/example/api/matching/MatchingApplicationServiceTests.java @@ -3,7 +3,7 @@ import com.example.api.common.type.ApplicationStateEnum; import com.example.api.matching.adapter.out.persistence.MatchingMapperInterface; import com.example.api.matching.application.port.out.MatchingApplicationPort; -import com.example.api.matching.dto.MatchingApplicationDto; +import com.example.api.matching.dto.SaveMatchingApplicationDto; import com.example.api.matching.service.MatchingApplicationService; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -24,13 +24,12 @@ public class MatchingApplicationServiceTests { private MatchingMapperInterface matchingMapper = mock(MatchingMapperInterface.class); @Mock private MatchingApplicationPort matchingApplicationPort; - private MatchingApplicationDto matchingApplication; + private SaveMatchingApplicationDto matchingApplication; private final String userUUID = "09a46fb0-2ae0-4a35-8aad-0a9e4311a1a3"; @BeforeEach void beforeEach() { - matchingApplication = MatchingApplicationDto.builder() - .userId(UUID.fromString(userUUID)) + matchingApplication = SaveMatchingApplicationDto.builder() .matchingId(2L) .state(ApplicationStateEnum.Pending) .isActive(true) @@ -45,7 +44,7 @@ void createMatchingApplicationTest() { @Test void getByUserIdIsAndStateEqualsTest() { - matchingApplicationService.getByUserIdIsAndStateEquals(userUUID, ApplicationStateEnum.Pending); + matchingApplicationService.getByUserIdIsAndStateEquals(ApplicationStateEnum.Pending); verify(matchingApplicationPort, times(1)).getByUserIdIsAndStateEquals(UUID.fromString(userUUID), ApplicationStateEnum.Pending); } diff --git a/src/test/java/com/example/api/user/UserServiceTests.java b/src/test/java/com/example/api/user/UserServiceTests.java index e577af9..13787e5 100644 --- a/src/test/java/com/example/api/user/UserServiceTests.java +++ b/src/test/java/com/example/api/user/UserServiceTests.java @@ -114,13 +114,13 @@ void getUserByIdTest() { @Test void updateUserTest() { user1.setMannerScore(77); - userService.updateUser(userUUID, newUser); + userService.updateUser(newUser); verify(saveUserPort, times(1)).updateUser(UUID.fromString(userUUID), userMapper.toDomain(newUser)); } @Test void deleteUserTest() { - userService.deleteUser(userUUID); + userService.deleteUser(); verify(deleteUserPort, times(1)).deleteByUserId(UUID.fromString(userUUID)); }