Skip to content

Commit

Permalink
fix(team-building) : 유저 선택 정보 숨김
Browse files Browse the repository at this point in the history
  • Loading branch information
parkdaye committed Jul 4, 2024
1 parent 030eae8 commit f87d2d9
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 입니다.")
Expand All @@ -39,16 +34,16 @@ public class UserSurveyController {
@Content(mediaType = "application/json", schema = @Schema(implementation = ExceptionResponse.class))})
@PostMapping("/{teamBuildingUuid}/users")
public ResponseEntity<UserInfo> 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));
}

@Operation(summary = "팀 빌딩 팀 데이터 조회", description = "팀 빌딩, 팀 정보가 조회됩니다. (유저 선택 정보 제외) ")
@GetMapping("/{teamBuildingUuid}/teams")
public ResponseEntity<TeamBuildingResponse> findTeamBuildingAndTeams(
public ResponseEntity<TeamBuildingResponse> findTeamBuildingExcludingUser(
@PathVariable(value = "teamBuildingUuid") String teamBuildingUuid) {
return ResponseEntity.ok(teamBuildingCoreService.findTeamBuilding(teamBuildingUuid));
return ResponseEntity.ok(teamBuildingCoreService.findTeamBuildingExcludingUser(teamBuildingUuid));
}
}
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -78,6 +75,28 @@ private static List<UserInfo> makeUserInfo(List<User> targetTeam) {
return targetTeam.stream().map(UserInfo::makeUserInfo).toList();
}

private static void addUserAndMoveTeamRound(Team targetTeam, List<User> pickedUsers) {
for (final User user : pickedUsers) {
user.addTeam(targetTeam);
user.updateSelectedRound(targetTeam.getRoundStatus());
}
targetTeam.nextRound();
}

private static void validateRequest(RoundStatus teamBuildingRoundStatus, Team targetTeam, List<User> 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);
Expand All @@ -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);
Expand Down Expand Up @@ -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<User> pickedUsers) {
for (final User user : pickedUsers) {
user.addTeam(targetTeam);
user.updateSelectedRound(targetTeam.getRoundStatus());
}
targetTeam.nextRound();
}

private static void validateRequest(RoundStatus teamBuildingRoundStatus, Team targetTeam, List<User> 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);
Expand Down

0 comments on commit f87d2d9

Please sign in to comment.