Skip to content

Commit

Permalink
Feat: 완성된 팀 정보 조회 (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
kduoh99 committed Nov 1, 2024
1 parent 75e2c39 commit 28daed2
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public RspTemplate<Void> completeProfile(
@Valid @RequestBody ProfileReqDto reqDto) {

memberService.completeProfile(TEMP_MEMBER_ID, reqDto);
return new RspTemplate<>(HttpStatus.OK, "프로필 완성 성공");
return new RspTemplate<>(HttpStatus.CREATED, "프로필 완성 성공");
}

@GetMapping("/profile")
Expand Down
20 changes: 19 additions & 1 deletion src/main/java/com/hackathon/momento/team/api/TeamController.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@

import com.hackathon.momento.global.template.RspTemplate;
import com.hackathon.momento.team.api.dto.request.TeamBuildingReqDto;
import com.hackathon.momento.team.api.dto.response.TeamInfoResDto;
import com.hackathon.momento.team.application.TeamService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
Expand Down Expand Up @@ -39,7 +42,7 @@ public RspTemplate<Void> saveTeamBuilding(
@Valid @RequestBody TeamBuildingReqDto reqDto) {

teamService.saveTeamBuilding(TEMP_MEMBER_ID, reqDto);
return new RspTemplate<>(HttpStatus.OK, "팀 빌딩 정보 저장 성공");
return new RspTemplate<>(HttpStatus.CREATED, "팀 빌딩 정보 저장 성공");
}

@PostMapping("/execute-building")
Expand All @@ -57,4 +60,19 @@ public RspTemplate<Void> executeTeamBuilding() {
teamService.executeTeamBuilding();
return new RspTemplate<>(HttpStatus.OK, "AI 팀 빌딩 요청 성공");
}

@GetMapping("/completed-profile")
@Operation(
summary = "완성된 팀 정보 조회",
description = "사용자의 완성된 팀 정보를 조회합니다.",
responses = {
@ApiResponse(responseCode = "200", description = "팀 정보 조회 성공"),
@ApiResponse(responseCode = "400", description = "잘못된 요청"),
@ApiResponse(responseCode = "500", description = "서버 오류")
}
)
public RspTemplate<List<TeamInfoResDto>> getTeamInfoProfile() {
List<TeamInfoResDto> teamProfile = teamService.getTeamInfoProfile(TEMP_MEMBER_ID);
return new RspTemplate<>(HttpStatus.OK, "팀 정보 조회 성공", teamProfile);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.hackathon.momento.team.api.dto.response;

import com.hackathon.momento.team.domain.TeamBuilding;
import lombok.Builder;

@Builder
public record MemberInfoResDto(
String name,
String email,
String position
) {
public static MemberInfoResDto from(TeamBuilding teamBuilding) {
return MemberInfoResDto.builder()
.name(teamBuilding.getMember().getName())
.email(teamBuilding.getMember().getEmail())
.position(teamBuilding.getMyPosition())
.build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.hackathon.momento.team.api.dto.response;

import com.hackathon.momento.team.domain.TeamInfo;
import java.util.List;
import java.util.stream.Collectors;
import lombok.Builder;

@Builder
public record TeamInfoResDto(
String teamName,
List<MemberInfoResDto> members
) {
public static TeamInfoResDto from(TeamInfo teamInfo) {
return TeamInfoResDto.builder()
.teamName(teamInfo.getTeamName())
.members(teamInfo.getTeamBuildings().stream()
.map(MemberInfoResDto::from)
.collect(Collectors.toList()))
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.hackathon.momento.team.api.dto.request.GPTReqDto;
import com.hackathon.momento.team.api.dto.request.TeamBuildingReqDto;
import com.hackathon.momento.team.api.dto.response.GPTResDto;
import com.hackathon.momento.team.api.dto.response.TeamInfoResDto;
import com.hackathon.momento.team.domain.Status;
import com.hackathon.momento.team.domain.TeamBuilding;
import com.hackathon.momento.team.domain.TeamInfo;
Expand All @@ -15,6 +16,7 @@
import com.hackathon.momento.team.exception.TeamBuildingConflictException;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
Expand Down Expand Up @@ -141,4 +143,17 @@ private List<TeamInfo> parseResToTeamInfo(String resContent, List<TeamBuilding>

return teamInfos;
}

public List<TeamInfoResDto> getTeamInfoProfile(Long memberId) {
Member member = memberRepository.findById(memberId)
.orElseThrow(MemberNotFoundException::new);

List<TeamBuilding> completedTeams = teamBuildingRepository.findByMemberAndStatus(member,
Status.COMPLETED);

return completedTeams.stream()
.map(TeamBuilding::getTeamInfo)
.map(TeamInfoResDto::from)
.collect(Collectors.toList());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,6 @@ public interface TeamBuildingRepository extends JpaRepository<TeamBuilding, Long
boolean existsByMemberAndStatus(Member member, Status status);

List<TeamBuilding> findByStatus(Status status);

List<TeamBuilding> findByMemberAndStatus(Member member, Status status);
}

0 comments on commit 28daed2

Please sign in to comment.