diff --git a/src/main/java/com/nexters/moyeomoyeo/team_building/controller/UserSurveyController.java b/src/main/java/com/nexters/moyeomoyeo/team_building/controller/UserSurveyController.java index 368dba1..fe5cf62 100644 --- a/src/main/java/com/nexters/moyeomoyeo/team_building/controller/UserSurveyController.java +++ b/src/main/java/com/nexters/moyeomoyeo/team_building/controller/UserSurveyController.java @@ -15,12 +15,7 @@ import jakarta.validation.Valid; import lombok.RequiredArgsConstructor; import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; @RestController @Tag(name = "유저 설문", description = "유저 설문 페이지 관련 api 입니다.") @@ -39,7 +34,7 @@ public class UserSurveyController { @Content(mediaType = "application/json", schema = @Schema(implementation = ExceptionResponse.class))}) @PostMapping("/{teamBuildingUuid}/users") public ResponseEntity createUser(@PathVariable(value = "teamBuildingUuid") String teamBuildingUuid, - @RequestBody @Valid UserRequest userRequest) { + @RequestBody @Valid UserRequest userRequest) { return ResponseEntity.ok() .header("X-Accel-Buffering", "no") .body(userService.createUser(teamBuildingUuid, userRequest)); @@ -47,8 +42,8 @@ public ResponseEntity createUser(@PathVariable(value = "teamBuildingUu @Operation(summary = "팀 빌딩 팀 데이터 조회", description = "팀 빌딩, 팀 정보가 조회됩니다. (유저 선택 정보 제외) ") @GetMapping("/{teamBuildingUuid}/teams") - public ResponseEntity findTeamBuildingAndTeams( + public ResponseEntity findTeamBuildingExcludingUser( @PathVariable(value = "teamBuildingUuid") String teamBuildingUuid) { - return ResponseEntity.ok(teamBuildingCoreService.findTeamBuilding(teamBuildingUuid)); + return ResponseEntity.ok(teamBuildingCoreService.findTeamBuildingExcludingUser(teamBuildingUuid)); } } diff --git a/src/main/java/com/nexters/moyeomoyeo/team_building/service/TeamBuildingCoreService.java b/src/main/java/com/nexters/moyeomoyeo/team_building/service/TeamBuildingCoreService.java index ef4d2a5..92e7585 100644 --- a/src/main/java/com/nexters/moyeomoyeo/team_building/service/TeamBuildingCoreService.java +++ b/src/main/java/com/nexters/moyeomoyeo/team_building/service/TeamBuildingCoreService.java @@ -1,27 +1,24 @@ package com.nexters.moyeomoyeo.team_building.service; -import static com.nexters.moyeomoyeo.team_building.controller.dto.response.TeamBuildingResponse.TeamBuildingInfo.makeTeamBuildingInfo; -import static com.nexters.moyeomoyeo.team_building.controller.dto.response.TeamInfo.isSelectDone; - import com.nexters.moyeomoyeo.common.constant.ExceptionInfo; import com.nexters.moyeomoyeo.notification.service.NotificationService; import com.nexters.moyeomoyeo.team_building.controller.dto.request.UserPickRequest; -import com.nexters.moyeomoyeo.team_building.controller.dto.response.PickUserResponse; -import com.nexters.moyeomoyeo.team_building.controller.dto.response.TeamBuildingResponse; -import com.nexters.moyeomoyeo.team_building.controller.dto.response.TeamInfo; -import com.nexters.moyeomoyeo.team_building.controller.dto.response.UserInfo; -import com.nexters.moyeomoyeo.team_building.controller.dto.response.UserPickResponse; +import com.nexters.moyeomoyeo.team_building.controller.dto.response.*; import com.nexters.moyeomoyeo.team_building.domain.constant.RoundStatus; import com.nexters.moyeomoyeo.team_building.domain.entity.Team; import com.nexters.moyeomoyeo.team_building.domain.entity.TeamBuilding; import com.nexters.moyeomoyeo.team_building.domain.entity.User; import com.nexters.moyeomoyeo.team_building.domain.repository.TeamBuildingRepository; -import java.util.List; -import java.util.Objects; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import java.util.List; +import java.util.Objects; + +import static com.nexters.moyeomoyeo.team_building.controller.dto.response.TeamBuildingResponse.TeamBuildingInfo.makeTeamBuildingInfo; +import static com.nexters.moyeomoyeo.team_building.controller.dto.response.TeamInfo.isSelectDone; + @Service @RequiredArgsConstructor public class TeamBuildingCoreService { @@ -78,6 +75,28 @@ private static List makeUserInfo(List targetTeam) { return targetTeam.stream().map(UserInfo::makeUserInfo).toList(); } + private static void addUserAndMoveTeamRound(Team targetTeam, List pickedUsers) { + for (final User user : pickedUsers) { + user.addTeam(targetTeam); + user.updateSelectedRound(targetTeam.getRoundStatus()); + } + targetTeam.nextRound(); + } + + private static void validateRequest(RoundStatus teamBuildingRoundStatus, Team targetTeam, List pickedUsers) { + if (!RoundStatus.isPickUserPossible(teamBuildingRoundStatus)) { + throw ExceptionInfo.BAD_REQUEST_FOR_USER_PICK.exception(); + } + + if (isSelectDone(teamBuildingRoundStatus, targetTeam.getRoundStatus())) { + throw ExceptionInfo.DUPLICATED_PICK_REQUEST.exception(); + } + + if (!isChosenTeam(targetTeam, pickedUsers)) { + throw ExceptionInfo.BAD_REQUEST_FOR_USER_PICK.exception(); + } + } + @Transactional(readOnly = true) public TeamBuildingResponse findTeamBuilding(String teamBuildingUuid) { final TeamBuilding teamBuilding = findByUuid(teamBuildingUuid); @@ -90,6 +109,22 @@ public TeamBuildingResponse findTeamBuilding(String teamBuildingUuid) { .build(); } + /** + * 설문 팀 조회시 user choice 는 다른 유저에게 숨겨져야함 + * + * @param teamBuildingUuid teambuilding uuid + * @return userInfo 가 제외된 팀빌딩 정보 + */ + @Transactional(readOnly = true) + public TeamBuildingResponse findTeamBuildingExcludingUser(String teamBuildingUuid) { + final TeamBuilding teamBuilding = findByUuid(teamBuildingUuid); + + return TeamBuildingResponse.builder() + .teamBuildingInfo(makeTeamBuildingInfo(teamBuilding)) + .teamInfoList(teamBuilding.getTeams().stream().map(TeamInfo::makeTeamInfo).toList()) + .build(); + } + @Transactional public UserPickResponse pickUsers(String teamBuildingUuid, String teamUuid, UserPickRequest userPickRequest) { final TeamBuilding teamBuilding = findByUuid(teamBuildingUuid); @@ -122,28 +157,6 @@ private void broadcastPickedUsers(String teamBuildingUuid, String teamUuid, Stri notificationService.broadcast(teamBuildingUuid, "pick-user", userResponse); } - private static void addUserAndMoveTeamRound(Team targetTeam, List pickedUsers) { - for (final User user : pickedUsers) { - user.addTeam(targetTeam); - user.updateSelectedRound(targetTeam.getRoundStatus()); - } - targetTeam.nextRound(); - } - - private static void validateRequest(RoundStatus teamBuildingRoundStatus, Team targetTeam, List pickedUsers) { - if (!RoundStatus.isPickUserPossible(teamBuildingRoundStatus)) { - throw ExceptionInfo.BAD_REQUEST_FOR_USER_PICK.exception(); - } - - if (isSelectDone(teamBuildingRoundStatus, targetTeam.getRoundStatus())) { - throw ExceptionInfo.DUPLICATED_PICK_REQUEST.exception(); - } - - if (!isChosenTeam(targetTeam, pickedUsers)) { - throw ExceptionInfo.BAD_REQUEST_FOR_USER_PICK.exception(); - } - } - private TeamBuilding findByUuid(String teamBuildingUuid) { return teamBuildingRepository.findByUuid(teamBuildingUuid) .orElseThrow(ExceptionInfo.INVALID_TEAM_BUILDING_UUID::exception);