Skip to content

Commit

Permalink
Merge pull request #32 from Nexters/dev
Browse files Browse the repository at this point in the history
Dev -> Main 2023.08.13 03.24...
  • Loading branch information
parkdaye authored Aug 12, 2023
2 parents b38ef66 + 5628cfc commit f67a879
Show file tree
Hide file tree
Showing 16 changed files with 142 additions and 62 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
import java.util.Base64;
import java.util.Base64.Encoder;
import java.util.UUID;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;

@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class UuidGenerator {

private static final Encoder BASE64_URL_ENCODER = Base64.getUrlEncoder().withoutPadding();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.nexters.moyeomoyeo.notification.handler;

import com.nexters.moyeomoyeo.common.constant.ExceptionInfo;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand All @@ -21,7 +21,7 @@ public List<SseEmitter> getEmitters(String teamBuildingUuid) {
final List<SseEmitter> emitterList = emitterMap.get(teamBuildingUuid);

if (Objects.isNull(emitterList)) {
throw ExceptionInfo.INVALID_TEAM_BUILDING_UUID.exception();
return Collections.emptyList();
}

return emitterList;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
Expand All @@ -33,23 +34,25 @@ public class TeamBuildingAdminController {

@Operation(summary = "팀 빌딩 생성 요청", description = "팀빌딩 방과 팀 리스트를 생성됩니다. ")
@ApiResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(implementation = TeamBuildingResponse.class)))
@ApiResponse(responseCode = "400", description = "BAD REQUEST", content = {
@Content(mediaType = "application/json", schema = @Schema(implementation = ExceptionResponse.class))})
@ApiResponse(responseCode = "400", description = "BAD REQUEST", content = {@Content(mediaType = "application/json", schema = @Schema(implementation = ExceptionResponse.class))})
@PostMapping
public ResponseEntity<TeamBuildingResponse> createTeamBuilding(
@RequestBody @Valid TeamBuildingRequest teamBuildingRequest) {
public ResponseEntity<TeamBuildingResponse> createTeamBuilding(@RequestBody @Valid TeamBuildingRequest teamBuildingRequest) {
return ResponseEntity.ok(teamBuildingService.createTeamBuilding(teamBuildingRequest));
}

@Operation(summary = "조정 단계 팀원 수정 (단일 유저) ", description = "운영진이 조정단계에서 조정할 때 사용합니다. ")
@PostMapping("/{teamBuildingUuid}/users/{userUuid}")
public ResponseEntity<UserInfo> adjustUser(
@PathVariable(value = "teamBuildingUuid") String teamBuildingUuid,
@PathVariable(value = "userUuid") String userUuid,
@RequestBody @Valid UserAdjustRequest userAdjustRequest) {
public ResponseEntity<UserInfo> adjustUser(@PathVariable(value = "teamBuildingUuid") String teamBuildingUuid, @PathVariable(value = "userUuid") String userUuid, @RequestBody @Valid UserAdjustRequest userAdjustRequest) {
return ResponseEntity.ok(userService.adjustUser(teamBuildingUuid, userUuid, userAdjustRequest.getTeamUuid()));
}

@Operation(summary = "팀원 삭제 (단일 유저) ", description = "운영진이 팀원 조정할 때 사용합니다. ")
@DeleteMapping("/{teamBuildingUuid}/users/{userUuid}")
public ResponseEntity<Void> deleteUser(@PathVariable(value = "teamBuildingUuid") String teamBuildingUuid, @PathVariable(value = "userUuid") String userUuid) {
userService.deleteUser(teamBuildingUuid, userUuid);
return ResponseEntity.ok().build();
}

@Operation(summary = "팀 빌딩 마치기", description = "운영진이 조정 단계에서 팀빌딩을 마칩니다.")
@PutMapping("/{teamBuildingUuid}/finish")
public ResponseEntity<Void> finishTeamBuilding(@PathVariable(value = "teamBuildingUuid") String teamBuildingUuid) {
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,12 @@

import lombok.*;

/**
* serialize/deserialize 할 때 jsonValue 사용해서 enum mapping 되도록 설정
*/
@Getter
@RequiredArgsConstructor
public enum Position implements Constant {
DESIGNER("designer"),
BACK_END("backend"),
FRONT_END("frontend"),
IOS("ios"),
ANDROID("android");

private final String value;
public enum Position {
DESIGNER,
BACK_END,
FRONT_END,
IOS,
ANDROID
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package com.nexters.moyeomoyeo.team_building.domain.repository;

import com.nexters.moyeomoyeo.team_building.domain.entity.User;

import java.util.Optional;

public interface UserRepository {

User save(User user);

void delete(User user);

Optional<User> findByUuid(String uuid);
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package com.nexters.moyeomoyeo.team_building.infra;

import com.nexters.moyeomoyeo.team_building.domain.entity.User;
import java.util.Optional;
import org.springframework.data.jpa.repository.JpaRepository;

import java.util.Optional;

public interface UserJpa extends JpaRepository<User, Long> {

Optional<User> findByUuid(String uuid);

void delete(User user);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@

import com.nexters.moyeomoyeo.team_building.domain.entity.User;
import com.nexters.moyeomoyeo.team_building.domain.repository.UserRepository;
import java.util.Optional;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Repository;

import java.util.Optional;

@Repository
@RequiredArgsConstructor
public class UserRepositoryImpl implements UserRepository {
Expand All @@ -17,6 +18,11 @@ public User save(User user) {
return jpa.save(user);
}

@Override
public void delete(User user) {
jpa.delete(user);
}

@Override
public Optional<User> findByUuid(String uuid) {
return jpa.findByUuid(uuid);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ public TeamBuildingResponse createTeamBuilding(TeamBuildingRequest teamBuildingR


@Transactional
public UserPickResponse pickUsers(String uuid, String teamUuid, UserPickRequest userPickRequest) {
final TeamBuilding teamBuilding = findWithTeamsAndUsers(uuid);
public UserPickResponse pickUsers(String teamBuildingUuid, String teamUuid, UserPickRequest userPickRequest) {
final TeamBuilding teamBuilding = findWithTeamsAndUsers(teamBuildingUuid);

if (RoundStatus.COMPLETE == teamBuilding.getRoundStatus()) {
throw ExceptionInfo.COMPLETED_TEAM_BUILDING.exception();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package com.nexters.moyeomoyeo.team_building.service;

import static com.nexters.moyeomoyeo.team_building.controller.dto.response.UserInfo.makeUserInfo;

import com.nexters.moyeomoyeo.common.constant.ExceptionInfo;
import com.nexters.moyeomoyeo.notification.service.NotificationService;
import com.nexters.moyeomoyeo.team_building.controller.dto.request.UserRequest;
Expand All @@ -10,12 +8,13 @@
import com.nexters.moyeomoyeo.team_building.domain.entity.UserChoice;
import com.nexters.moyeomoyeo.team_building.domain.repository.UserRepository;
import jakarta.transaction.Transactional;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import static com.nexters.moyeomoyeo.team_building.controller.dto.response.UserInfo.makeUserInfo;

@Service
@RequiredArgsConstructor
Expand Down Expand Up @@ -44,7 +43,7 @@ public UserInfo createUser(String teamBuildingUuid, UserRequest request) {

@Transactional
public UserInfo adjustUser(String teamBuildingUuid, String userUuid, String teamUuid) {
final User user = userRepository.findByUuid(userUuid).orElseThrow(ExceptionInfo.INVALID_USER_UUID::exception);
final User user = findUser(userUuid);

user.adjustTeam(teamService.findByUuid(teamUuid).orElse(null));
UserInfo userInfo = makeUserInfo(user);
Expand All @@ -53,6 +52,10 @@ public UserInfo adjustUser(String teamBuildingUuid, String userUuid, String team
return userInfo;
}

private User findUser(String userUuid) {
return userRepository.findByUuid(userUuid).orElseThrow(ExceptionInfo.INVALID_USER_UUID::exception);
}

private static User makeUser(UserRequest request) {
final User user = User.builder()
.name(request.getName())
Expand All @@ -76,4 +79,14 @@ private List<UserChoice> createUserChoices(List<String> teamUuids) {
}
return choices;
}

@Transactional
public void deleteUser(String teamBuildingUuid, String userUuid) {
final User targetUser = findUser(userUuid);

userRepository.delete(targetUser);
notificationService.broadCast(teamBuildingUuid, "delete-user", userUuid);


}
}
4 changes: 2 additions & 2 deletions src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ spring:

jpa:
hibernate:
ddl-auto: create
ddl-auto: update
properties:
hibernate:
format_sql: true
Expand All @@ -25,7 +25,7 @@ logging.level:
org.hibernate.type: info
com.jpa: debug

springdoc:
spring-doc:
swagger-ui:
path: /swagger-ui.html
groups-order: DESC
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
package com.nexters.moyeomoyeo;

import static org.junit.jupiter.api.Assertions.assertEquals;

import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;


@SpringBootTest(properties = {"spring.config.location=classpath:application-test.yml"})
@MoyeoMoyeoTest
class MoyeoMoyeoApplicationTests {

@Autowired
private Environment environment;

@Test
void contextLoads() {
assertEquals("test", environment.getActiveProfiles()[0]);
}

}
18 changes: 18 additions & 0 deletions src/test/java/com/nexters/moyeomoyeo/MoyeoMoyeoTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.nexters.moyeomoyeo;

import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ActiveProfiles;

@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Documented
@SpringBootTest(properties = {"spring.config.location=classpath:application-test.yml"})
@ActiveProfiles("test")
public @interface MoyeoMoyeoTest {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package com.nexters.moyeomoyeo.team_building.service;

import static org.junit.jupiter.api.Assertions.assertEquals;

import com.nexters.moyeomoyeo.MoyeoMoyeoTest;
import com.nexters.moyeomoyeo.team_building.controller.dto.request.TeamBuildingRequest;
import com.nexters.moyeomoyeo.team_building.controller.dto.request.TeamRequest;
import com.nexters.moyeomoyeo.team_building.controller.dto.response.TeamBuildingResponse;
import com.nexters.moyeomoyeo.team_building.domain.constant.Position;
import com.nexters.moyeomoyeo.team_building.domain.constant.RoundStatus;
import java.util.List;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;

@MoyeoMoyeoTest
class TeamBuildingServiceTest {

@Autowired
private TeamBuildingService teamBuildingService;


@Test
void createTeamBuilding() {
final var saveResponse = saveTeamBuildingWithTeams();
final TeamBuildingResponse findResponse = teamBuildingService.findTeamBuildingAndTeams(
saveResponse.getTeamBuildingInfo().getTeamBuildingUrl());

// team building
assertEquals(saveResponse.getTeamBuildingInfo().getTeamBuildingUrl(),
findResponse.getTeamBuildingInfo().getTeamBuildingUrl());
assertEquals(RoundStatus.FIRST_ROUND, findResponse.getTeamBuildingInfo().getRoundStatus());

//team
assertEquals(saveResponse.getTeamInfoList().get(0).getTeamName(),
findResponse.getTeamInfoList().get(0).getTeamName());
assertEquals(saveResponse.getTeamInfoList().get(1).getTeamName(),
findResponse.getTeamInfoList().get(1).getTeamName());
}

private TeamBuildingResponse saveTeamBuildingWithTeams() {
return teamBuildingService.createTeamBuilding(TeamBuildingRequest.builder()
.name("team-Building")
.teams(List.of(
TeamRequest.builder()
.name("team1")
.pmName("pm1")
.pmPosition(Position.FRONT_END)
.build(),
TeamRequest.builder()
.name("team2")
.pmName("pm2")
.pmPosition(Position.BACK_END)
.build()))
.build());
}
}
2 changes: 1 addition & 1 deletion src/test/resources/application-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ spring:
path: /h2-console

datasource:
url: jdbc:h2:mem:test
url: jdbc:h2:mem:test;NON_KEYWORDS=USER
username: sa
password:
driver-class-name: org.h2.Driver
Expand Down

0 comments on commit f67a879

Please sign in to comment.