Skip to content

Commit

Permalink
Merge pull request #137 from swm-nodriversomabus/BUS-202-MVP1-API-test
Browse files Browse the repository at this point in the history
fix(BE): 매칭 신청 시 신청자 등록 오류 BUS-202-MVP1-API-test
  • Loading branch information
Lemonade255 authored Oct 19, 2023
2 parents c90648f + 6efeca0 commit 39831cb
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<FindMatchingDto> getByUserIdIsAndStateEquals(ApplicationStateEnum state);
List<FindUserDto> getByMatchingIdIsAndStateEquals(Long matchingId, ApplicationStateEnum state);
MatchingApplicationDto updateMatchingApplication(MatchingApplicationDto matchingApplicationDto);
SaveMatchingApplicationDto updateMatchingApplication(SaveMatchingApplicationDto matchingApplicationDto);
}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
}
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -103,7 +110,7 @@ public List<FindUserDto> 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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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)
Expand All @@ -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);
}

Expand Down
4 changes: 2 additions & 2 deletions src/test/java/com/example/api/user/UserServiceTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

Expand Down

0 comments on commit 39831cb

Please sign in to comment.