Skip to content

Commit

Permalink
Merge pull request #26 from Team-Shaka/feat/22
Browse files Browse the repository at this point in the history
Feat/22 초대장 관련 API 요청/응답 구현
  • Loading branch information
HyoBN authored May 8, 2024
2 parents fba6dc9 + a636392 commit a4cb32c
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,18 @@ public InvitationResponseDTO.getInvitations toGetInvitations(List<InvitationResp
.invitations(invitationDtos)
.build();
}

public InvitationResponseDTO.myInvitationInfo toMyInvitationInfo(User user){
return InvitationResponseDTO.myInvitationInfo.builder()
.availableInvitation(user.getInvitationCount())
.activeRate(user.getActiveRate())
.build();
}

public InvitationResponseDTO.invitationAccept toInvitationResult(Long treeHouseId){
return InvitationResponseDTO.invitationAccept.builder()
.treehouseId(treeHouseId)
.build();
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,7 @@
import treehouse.server.global.entity.Invitation.Invitation;
import treehouse.server.global.entity.User.User;
import treehouse.server.global.entity.member.Member;
import treehouse.server.global.entity.redis.RefreshToken;
import treehouse.server.global.entity.treeHouse.TreeHouse;
import treehouse.server.global.exception.GlobalErrorCode;
import treehouse.server.global.exception.ThrowClass.AuthException;
import treehouse.server.global.exception.ThrowClass.GeneralException;
import treehouse.server.global.redis.service.RedisService;
import treehouse.server.global.security.jwt.dto.TokenDTO;
import treehouse.server.global.security.provider.TokenProvider;

import java.util.List;
import java.util.stream.Collectors;
Expand All @@ -39,10 +32,7 @@ public class InvitationService {
@Transactional
public InvitationResponseDTO.getInvitations getInvitations(User user) {

log.error("User name : ", user.getName());
log.error("User id : ", user.getId());
List<Invitation> invitations = invitationQueryAdapter.findAllByPhone(user.getPhone());
log.error("size : ", invitations.size());

List<InvitationResponseDTO.getInvitation> invitationDtos = invitations.stream()
.map(invitation -> {
Expand All @@ -57,4 +47,18 @@ public InvitationResponseDTO.getInvitations getInvitations(User user) {
.collect(Collectors.toList());
return invitationMapper.toGetInvitations(invitationDtos);
}

public InvitationResponseDTO.myInvitationInfo getMyInvitationInfo(User user){
return invitationMapper.toMyInvitationInfo(user);
}

@Transactional
public InvitationResponseDTO.invitationAccept decisionInvitation(User user, InvitationRequestDTO.invitationAcceptDecision request){
// 해당 User 에게 온 초대장인지 검증하는 로직 추가
Long treehouseId = 0L;
if (request.isAcceptDecision()==true) {
treehouseId = 1L; // treehouse 관련 로직 개발 후, invitation.getTreeHouse.getId() 등으로 바꾸기
}
return invitationMapper.toInvitationResult(treehouseId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
@RequiredArgsConstructor
@Slf4j
@Validated
@Tag(name = "😎 Invitation API", description = "초대장 관련 API 입니다. 초대장 조회, 전송 등의 API가 포함됩니다.")
@Tag(name = "📨 Invitation API", description = "초대장 관련 API 입니다. 초대장 조회, 전송 등의 API가 포함됩니다.")
@RequestMapping("/users")
public class InvitationApi {

Expand All @@ -32,5 +32,18 @@ public CommonResponse<InvitationResponseDTO.getInvitations> getInvitations(
return CommonResponse.onSuccess(invitationService.getInvitations(user));
}

@GetMapping("/availableInvitation")
@Operation(summary = "소유한 초대장 개수 및 게이지 조회", description = "소유한 초대장 개수 및 게이지를 조회합니다.")
public CommonResponse<InvitationResponseDTO.myInvitationInfo> getAvailableInvitation(@AuthMember @Parameter(hidden = true) User user){

return CommonResponse.onSuccess(invitationService.getMyInvitationInfo(user));
}

@PostMapping("/invitations/accept")
@Operation(summary = "초대장을 수락할지 거절할지 결정", description = "초대장을 수락할지 거절할지 결정하는 API 입니다.")
public CommonResponse<InvitationResponseDTO.invitationAccept> acceptInvitation(
@AuthMember @Parameter(hidden = true) User user, @RequestBody InvitationRequestDTO.invitationAcceptDecision request) {
return CommonResponse.onSuccess(invitationService.decisionInvitation(user, request));
}

}
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
package treehouse.server.api.invitation.presentation.dto;

import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.util.List;
import lombok.*;


public class InvitationRequestDTO {

@Getter
@NoArgsConstructor
public static class invitationAcceptDecision{
private Long invitationId;
private boolean acceptDecision;

}


}
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,21 @@ public static class getInvitations {
List<InvitationResponseDTO.getInvitation> invitations;
}

@Builder
@Getter
@NoArgsConstructor
@AllArgsConstructor
public static class myInvitationInfo{
private Integer availableInvitation;
private Integer activeRate;
}

@Builder
@Getter
@NoArgsConstructor
@AllArgsConstructor
public static class invitationAccept {
private Long treehouseId;

}
}
3 changes: 2 additions & 1 deletion src/main/java/treehouse/server/global/entity/User/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,11 @@ public class User extends BaseDateTimeEntity {

// 활동량 및 초대장 개수 트리별로 적용되는 것 맞는지 확인하기
@Builder.Default
private Double activeRate = 0.0; //활동량
private Integer activeRate = 0; //활동량
@Builder.Default
private Integer invitationCount = 3; //남아있는 초대장의 개수


// 탈퇴일자 필요한지 확인하기
// 특정 트리의 탈퇴한 멤버를 Member Table 에 그대로 쌓을건지?
// db의 Member Table에 userId 필드 값은 그대로 두는지 or -1 등으로 갱신하는지
Expand Down

0 comments on commit a4cb32c

Please sign in to comment.