Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(admin) : 팀빌딩 시작 기능 추가 (#57) #58

Merged
merged 1 commit into from
Jul 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
plugins {
id 'java'
id 'org.springframework.boot' version '3.0.6'
id 'io.spring.dependency-management' version '1.1.0'
id 'org.springframework.boot' version '3.2.6'
id 'io.spring.dependency-management' version '1.1.5'
}

group = 'com.nexters'
Expand All @@ -25,6 +25,7 @@ dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-validation'
implementation 'io.hypersistence:hypersistence-utils-hibernate-63:3.7.7'
compileOnly 'org.projectlombok:lombok'
runtimeOnly 'com.h2database:h2'
runtimeOnly 'com.mysql:mysql-connector-j'
Expand All @@ -33,11 +34,11 @@ dependencies {
// Micrometer 의존성 추가
implementation 'io.micrometer:micrometer-core:1.10.8'
implementation 'io.micrometer:micrometer-registry-prometheus:1.10.8'
testImplementation 'io.micrometer:micrometer-observation:1.10.8'

implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.0.2'

testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'io.micrometer:micrometer-observation:1.10.8'

implementation 'com.google.code.findbugs:jsr305:3.0.2'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ public enum ExceptionInfo {
INVALID_TEAM_BUILDING_UUID("팀빌딩을 찾을 수 없습니다.", HttpStatus.BAD_REQUEST),
INVALID_TEAM_UUID("팀을 찾을 수 없습니다.", HttpStatus.BAD_REQUEST),
INVALID_USER_UUID("유저를 찾을 수 없습니다.", HttpStatus.BAD_REQUEST),
BAD_REQUEST_FOR_USER_PICK("해당 유저를 선택할 수 없습니다.", HttpStatus.BAD_REQUEST),
BAD_REQUEST_FOR_USER_PICK("유효하지 않은 유저 선택 요청입니다.", HttpStatus.BAD_REQUEST),
ALREADY_JOINED_USER("다른 팀에 배정되어 있는 유저입니다.", HttpStatus.BAD_REQUEST),
COMPLETED_TEAM_BUILDING("이미 종료된 팀빌딩입니다.", HttpStatus.BAD_REQUEST),
INVALID_START_REQUEST("시작 라운드에서만 팀빌딩을 시작할 수 있습니다.", HttpStatus.BAD_REQUEST),
INVALID_ADJUST_REQUEST("조정 라운드에서만 조정 가능합니다.", HttpStatus.BAD_REQUEST),
INVALID_FINISH_REQUEST("조정 라운드에서만 팀빌딩을 종료할 수 있습니다.", HttpStatus.BAD_REQUEST),
INVALID_DELETE_REQUEST("1라운드에서만 회원을 삭제할 수 있습니다.", HttpStatus.BAD_REQUEST),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public SseEmitter subscribe(String teamBuildingUuid) {
return emitter;
}

public void broadCast(String teamBuildingUuid, String name, Object data) {
public void broadcast(String teamBuildingUuid, String name, Object data) {
for (final SseEmitter emitter : handler.getEmitters(teamBuildingUuid)) {
sendNotification(emitter, name, data);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
public class TeamBuildingAdminController {

private final TeamBuildingAdminService adminService;
private final UserService userService;

@Operation(summary = "팀 빌딩 생성 요청", description = "팀빌딩 방과 팀 리스트를 생성됩니다. ")
@ApiResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(implementation = TeamBuildingResponse.class)))
Expand Down Expand Up @@ -78,4 +77,16 @@ public ResponseEntity<Void> finishTeamBuilding(@PathVariable(value = "teamBuildi
.header("X-Accel-Buffering", "no")
.build();
}

@Operation(summary = "팀 빌딩 시작하기", description = """
운영진이 START 단계에서 팀빌딩을 시작합니다. \s
event : start-team-building, data : RoundStatus(FIRST_ROUND) \s
""")
@PutMapping("/{teamBuildingUuid}/start")
public ResponseEntity<Void> startTeamBuilding(@PathVariable(value = "teamBuildingUuid") String teamBuildingUuid) {
adminService.startTeamBuilding(teamBuildingUuid);
return ResponseEntity.ok()
.header("X-Accel-Buffering", "no")
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import com.nexters.moyeomoyeo.team_building.controller.dto.request.UserRequest;
import com.nexters.moyeomoyeo.team_building.controller.dto.response.TeamBuildingResponse;
import com.nexters.moyeomoyeo.team_building.controller.dto.response.UserInfo;
import com.nexters.moyeomoyeo.team_building.service.TeamBuildingService;
import com.nexters.moyeomoyeo.team_building.service.TeamBuildingCoreService;
import com.nexters.moyeomoyeo.team_building.service.UserService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Content;
Expand All @@ -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 @@ -29,7 +24,7 @@
public class UserSurveyController {

private final UserService userService;
private final TeamBuildingService teamBuildingService;
private final TeamBuildingCoreService teamBuildingCoreService;

@Operation(summary = "회원 생성 요청", description = """
회원이 생성됩니다. \s
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(teamBuildingService.findTeamBuildingAndTeams(teamBuildingUuid));
return ResponseEntity.ok(teamBuildingCoreService.findTeamBuildingExcludingUser(teamBuildingUuid));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import com.nexters.moyeomoyeo.team_building.domain.constant.Position;
import com.nexters.moyeomoyeo.team_building.domain.constant.RoundStatus;
import com.nexters.moyeomoyeo.team_building.domain.entity.User;
import com.nexters.moyeomoyeo.team_building.domain.entity.UserChoice;
import io.swagger.v3.oas.annotations.media.Schema;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Objects;
import lombok.AccessLevel;
Expand Down Expand Up @@ -33,23 +33,21 @@ public class UserInfo {
private String profileLink;
@Schema(description = "선택받은 라운드")
private RoundStatus selectedRound;
private LocalDateTime createdDate;


public static UserInfo makeUserInfo(User user) {
final List<String> choices = user.getChoices().stream()
.map(UserChoice::getTeamUuid)
.toList();

final String joinedTeamUuid = Objects.isNull(user.getTeam()) ? null : user.getTeam().getUuid();

return UserInfo.builder()
.uuid(user.getUuid())
.userName(user.getName())
.position(user.getPosition())
.choices(choices)
.choices(user.getChoices())
.joinedTeamUuid(joinedTeamUuid)
.profileLink(user.getProfileLink())
.selectedRound(user.getSelectedRound())
.createdDate(user.getCreatedDate())
.build();
}
}
Original file line number Diff line number Diff line change
@@ -1,24 +1,30 @@
package com.nexters.moyeomoyeo.team_building.domain.constant;

import java.util.List;
import lombok.Getter;

public enum RoundStatus {
COMPLETE(6, null),
ADJUSTED_ROUND(5, COMPLETE),
FORTH_ROUND(4, ADJUSTED_ROUND),
THIRD_ROUND(3, FORTH_ROUND),
FOURTH_ROUND(4, ADJUSTED_ROUND),
THIRD_ROUND(3, FOURTH_ROUND),
SECOND_ROUND(2, THIRD_ROUND),
FIRST_ROUND(1, SECOND_ROUND),
START(0, FIRST_ROUND)
;

@Getter
final private int weight;
private final int order;

@Getter
final private RoundStatus nextStatus;
private final RoundStatus nextStatus;

RoundStatus(int weight, RoundStatus nextStatus) {
this.weight = weight;
RoundStatus(int order, RoundStatus nextStatus) {
this.order = order;
this.nextStatus = nextStatus;
}

public static boolean isPickUserPossible(RoundStatus roundStatus) {
return List.of(FIRST_ROUND, SECOND_ROUND, THIRD_ROUND, FOURTH_ROUND).contains(roundStatus);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public class Team extends BaseEntity {
@Enumerated(EnumType.STRING)
@Column(name = "round_status")
@Builder.Default
private RoundStatus roundStatus = RoundStatus.FIRST_ROUND;
private RoundStatus roundStatus = RoundStatus.START;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "team_building_id")
Expand All @@ -57,16 +57,6 @@ public class Team extends BaseEntity {
@Builder.Default
private List<User> users = new ArrayList<>();

protected Team(String name, String pmName, Position pmPosition, RoundStatus roundStatus,
TeamBuilding teamBuilding) {
this.name = name;
this.pmName = pmName;
this.pmPosition = pmPosition;
this.uuid = UuidGenerator.createUuid();
this.roundStatus = roundStatus;
this.teamBuilding = teamBuilding;
}

public void nextRound() {
if (this.roundStatus == RoundStatus.COMPLETE) {
throw ExceptionInfo.COMPLETED_TEAM_BUILDING.exception();
Expand All @@ -77,6 +67,5 @@ public void nextRound() {

public void addTeamBuilding(TeamBuilding teamBuilding) {
this.teamBuilding = teamBuilding;
this.teamBuilding.getTeams().add(this);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@


import static com.nexters.moyeomoyeo.team_building.domain.constant.RoundStatus.FIRST_ROUND;
import static com.nexters.moyeomoyeo.team_building.domain.constant.RoundStatus.START;

import com.nexters.moyeomoyeo.common.constant.ExceptionInfo;
import com.nexters.moyeomoyeo.common.entity.BaseEntity;
Expand Down Expand Up @@ -43,7 +44,7 @@ public class TeamBuilding extends BaseEntity {
@Enumerated(EnumType.STRING)
@Column(name = "round_status")
@Builder.Default
private RoundStatus roundStatus = FIRST_ROUND;
private RoundStatus roundStatus = START;

@OneToMany(mappedBy = "teamBuilding", cascade = CascadeType.ALL)
@Builder.Default
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.nexters.moyeomoyeo.common.util.UuidGenerator;
import com.nexters.moyeomoyeo.team_building.domain.constant.Position;
import com.nexters.moyeomoyeo.team_building.domain.constant.RoundStatus;
import io.hypersistence.utils.hibernate.type.json.JsonType;
import io.micrometer.common.lang.Nullable;
import jakarta.persistence.CascadeType;
import jakarta.persistence.Column;
Expand All @@ -26,6 +27,7 @@
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;
import org.hibernate.annotations.Type;

@Entity
@Getter
Expand All @@ -50,10 +52,10 @@ public class User extends BaseEntity {

private String profileLink;

@OneToMany(mappedBy = "user", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
@OrderBy("choice_order asc")
@Type(JsonType.class)
@Column(columnDefinition = "TEXT")
@Builder.Default
private List<UserChoice> choices = new ArrayList<>();
private List<String> choices = new ArrayList<>();

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "team_id")
Expand All @@ -73,8 +75,12 @@ public void addTeam(Team team) {
}


public UserChoice findChoice(int weight) {
return this.choices.get(weight - 1);
/**
* @param order 순서
* @return 순서에 해당하는 teamUuid
*/
public String findChoice(int order) {
return this.choices.get(order - 1);
}


Expand Down

This file was deleted.

Loading
Loading