Skip to content

Commit

Permalink
Merge pull request #154 from swm-nodriversomabus/BUS-202-MVP1-API-test
Browse files Browse the repository at this point in the history
feat(BE): 매칭 신청 수락/거절 컨트롤러 연결 BUS-202-MVP1-API-test #71
  • Loading branch information
Lemonade255 authored Oct 25, 2023
2 parents a3da8af + 6fd0ac3 commit 0e1613a
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 10 deletions.
3 changes: 1 addition & 2 deletions src/main/java/com/example/api/chatroom/domain/ChatRoom.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.example.api.chatroom.domain;

import com.example.api.chatroom.type.ChatRoomEnum;
import com.example.api.member.domain.Member;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
Expand All @@ -22,7 +21,7 @@ public class ChatRoom {
private List<UUID> memberIds;

@Builder
public ChatRoom(UUID chatroomId, ChatRoomEnum type, String chatroomName, Boolean isActive, UUID masterId, List<UUID> memberIds){
public ChatRoom(UUID chatroomId, ChatRoomEnum type, String chatroomName, Boolean isActive, UUID masterId, List<UUID> memberIds) {
this.chatroomId = chatroomId;
this.type = type;
this.masterId = masterId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
public enum ApplicationStateEnum {
Pending("대기", 0),
Declined("거절", 1),
Approved("수락", 2);
Approved("수락", 2),
Owner("작성자", 3);

private final String applicationState;
private final Integer stateCode;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.example.api.chatroom.domain.ChatRoom;
import com.example.api.common.type.ApplicationStateEnum;
import com.example.api.matching.adapter.out.persistence.MatchingApplicationPK;
import com.example.api.matching.application.port.in.*;
import com.example.api.matching.domain.MatchingApplication;
import com.example.api.matching.dto.*;
Expand Down Expand Up @@ -123,21 +124,42 @@ public int getLikeCount(@PathVariable Long matchingId) {
* @return MatchingDto
*/
@Operation(summary = "Update matching", description = "매칭 정보를 수정한다.")
@PatchMapping("/matching/{matchingId}")
@PutMapping("/matching/{matchingId}")
public FindMatchingDto updateMatching(@PathVariable Long matchingId, @RequestBody SaveMatchingDto matchingDto) {
return saveMatchingUsecase.updateMatching(matchingId, matchingDto);
}

/**
* 매칭의 좋아요 토글
* @param likeDto (Data)
* @param likeDto (데이터)
*/
@Operation(summary = "Toggle like state", description = "사용자가 매칭에 좋아요를 누른 상태를 변경한다.")
@PatchMapping("/matching/like")
@PutMapping("/matching/like")
public void toggleLike(@RequestBody LikeDto likeDto) {
likeUsecase.toggleLike(likeDto);
}

/**
* 매칭 신청 수락/거절
* @param matchingApplicationDto (데이터)
*/
@Operation(summary = "Process matching application", description = "매칭 신청을 처리한다.")
@PutMapping("/matching/application")
public void processMatchingApplication(SaveMatchingApplicationDto matchingApplicationDto) {
MatchingApplicationPK matchingApplicationPK = MatchingApplicationPK.builder()
.userId(matchingApplicationDto.getUserId())
.matchingId(matchingApplicationDto.getMatchingId())
.build();


if (matchingApplicationDto.getState() == ApplicationStateEnum.Approved) {
matchingApplicationUsecase.approveMatchingApplication(matchingApplicationDto);
}
if (matchingApplicationDto.getState() == ApplicationStateEnum.Declined) {
matchingApplicationUsecase.declineMatchingApplication(matchingApplicationDto);
}
}

/**
* 전체 매칭 삭제 (비상시 외 사용 금지)
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package com.example.api.matching.adapter.out.persistence;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.RequiredArgsConstructor;

import java.io.Serializable;
import java.util.UUID;

@Data
@Builder
@AllArgsConstructor
@RequiredArgsConstructor
public class MatchingApplicationPK implements Serializable {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.example.api.chatroom.domain.ChatRoom;
import com.example.api.common.type.ApplicationStateEnum;
import com.example.api.matching.adapter.out.persistence.MatchingApplicationPK;
import com.example.api.matching.domain.MatchingApplication;
import com.example.api.matching.dto.FindMatchingApplicationDto;
import com.example.api.matching.dto.SaveMatchingApplicationDto;
Expand All @@ -17,5 +18,6 @@ public interface MatchingApplicationUsecase {
List<FindMatchingDto> getByUserIdIsAndStateEquals(ApplicationStateEnum state);
List<FindUserDto> getByMatchingIdIsAndStateEquals(Long matchingId, ApplicationStateEnum state);
String getUserStatus(Long matchingId);
FindMatchingApplicationDto updateMatchingApplication(SaveMatchingApplicationDto matchingApplicationDto);
void approveMatchingApplication(SaveMatchingApplicationDto matchingApplicationPK);
void declineMatchingApplication(SaveMatchingApplicationDto matchingApplicationPK);
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,17 @@
import jakarta.validation.constraints.NotNull;
import lombok.*;

import java.util.UUID;

@Getter
@Setter
@Builder
@ToString
@NoArgsConstructor
@AllArgsConstructor
public class SaveMatchingApplicationDto {
private UUID userId;

@NotNull
@Min(1)
private Long matchingId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,15 +148,19 @@ public String getUserStatus(Long matchingId) {
}
}

@Override
@Transactional
public FindMatchingApplicationDto updateMatchingApplication(SaveMatchingApplicationDto matchingApplicationDto) {
MatchingApplication matchingApplication = matchingApplicationPort.updateMatchingApplication(matchingMapper.toDomain(matchingApplicationDto));
return matchingMapper.toDto(matchingApplication);
}

@Override
@Transactional
public void acceptMatchingApplication(MatchingApplicationPK matchingApplicationPK) {
public void approveMatchingApplication(SaveMatchingApplicationDto matchingApplicationDto) {
MatchingApplicationPK matchingApplicationPK = MatchingApplicationPK.builder()
.userId(matchingApplicationDto.getUserId())
.matchingId(matchingApplicationDto.getMatchingId())
.build();
MatchingApplicationEntity matchingApplicationEntity = matchingApplicationPort.getByMatchingApplicationPK(matchingApplicationPK)
.orElseThrow(NoSuchElementException::new);
MatchingApplication matchingApplication = matchingMapper.toDomain(matchingApplicationEntity);
Expand All @@ -169,8 +173,13 @@ public void acceptMatchingApplication(MatchingApplicationPK matchingApplicationP
fcmService.sendNotification(fcmDto);
}

@Override
@Transactional
public void declineMatchingApplication(MatchingApplicationPK matchingApplicationPK) {
public void declineMatchingApplication(SaveMatchingApplicationDto matchingApplicationDto) {
MatchingApplicationPK matchingApplicationPK = MatchingApplicationPK.builder()
.userId(matchingApplicationDto.getUserId())
.matchingId(matchingApplicationDto.getMatchingId())
.build();
MatchingApplicationEntity matchingApplicationEntity = matchingApplicationPort.getByMatchingApplicationPK(matchingApplicationPK)
.orElseThrow(NoSuchElementException::new);
MatchingApplication matchingApplication = matchingMapper.toDomain(matchingApplicationEntity);
Expand Down

0 comments on commit 0e1613a

Please sign in to comment.