Skip to content

Commit 369a9b8

Browse files
authored
[refactor] 조직도 API 요청 파라미터 수정 (DASOMBE-21)
1 parent d884a28 commit 369a9b8

File tree

8 files changed

+143
-32
lines changed

8 files changed

+143
-32
lines changed

src/main/java/dmu/dasom/api/domain/executive/dto/ExecutiveListResponseDto.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package dmu.dasom.api.domain.executive.dto;
22

3+
import dmu.dasom.api.domain.executive.enums.Team;
34
import io.swagger.v3.oas.annotations.media.Schema;
45
import lombok.AllArgsConstructor;
56
import lombok.Builder;
@@ -22,7 +23,15 @@ public class ExecutiveListResponseDto {
2223
@Schema(description = "임원진 직책", example = "회장")
2324
private String position;
2425

25-
@Schema(description = "임원진 깃허브 주소", example = "https://github.com/dasom")
26-
private String githubUrl;
26+
@Schema(description = "수정할 임원진 역할", example = "동아리 운영 총괄", nullable = true)
27+
private String role;
28+
29+
@Schema(description = "임원진 깃허브 이름", example = "DASOM")
30+
private String github_username;
31+
32+
@Schema(description = "소속 팀", example = "president, tech, academic, pr, management")
33+
private Team team;
34+
35+
private Integer sortOrder;
2736

2837
}

src/main/java/dmu/dasom/api/domain/executive/dto/ExecutiveRequestDto.java

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package dmu.dasom.api.domain.executive.dto;
22

33
import dmu.dasom.api.domain.executive.entity.ExecutiveEntity;
4+
import dmu.dasom.api.domain.executive.enums.Team;
45
import io.swagger.v3.oas.annotations.media.Schema;
56
import jakarta.validation.constraints.NotBlank;
67
import jakarta.validation.constraints.Size;
@@ -21,17 +22,30 @@ public class ExecutiveRequestDto {
2122
@Schema(description = "임원진 이름", example = "김다솜")
2223
private String name;
2324

24-
@NotBlank(message = "임원진 역할은 필수 입력 사항입니다.")
25-
@Schema(description = "임원진 역할", example = "회장")
25+
@NotBlank(message = "임원진 직책은 필수 입력 사항입니다.")
26+
@Schema(description = "임원진 직책", example = "회장")
2627
private String position;
2728

28-
private String githubUrl;
29+
@NotBlank(message = "임원진 역할은 필수 입력 사항입니다.")
30+
@Schema(description = "임원진 역할", example = "동아리 운영 총괄")
31+
private String role;
32+
33+
@Schema(description = "임원진 깃허브 이름", example = "DASOM")
34+
private String github_username;
35+
36+
@Schema(description = "소속 팀", example = "president, tech, academic, pr, management")
37+
private Team team;
38+
39+
private Integer sortOrder;
2940

3041
public ExecutiveEntity toEntity() {
3142
return ExecutiveEntity.builder()
3243
.name(this.name)
3344
.position(this.position)
34-
.githubUrl(this.githubUrl)
45+
.role(this.role)
46+
.githubUsername(this.github_username)
47+
.team(this.team)
48+
.sortOrder(this.sortOrder)
3549
.build();
3650
}
3751
}

src/main/java/dmu/dasom/api/domain/executive/dto/ExecutiveResponseDto.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package dmu.dasom.api.domain.executive.dto;
22

3+
import dmu.dasom.api.domain.executive.enums.Team;
34
import io.swagger.v3.oas.annotations.media.Schema;
45
import lombok.AllArgsConstructor;
56
import lombok.Builder;
@@ -22,6 +23,14 @@ public class ExecutiveResponseDto {
2223
@Schema(description = "임원진 직책", example = "회장")
2324
private String position;
2425

25-
@Schema(description = "임원진 깃허브", example = "https://github.com/dasom")
26-
private String githubUrl;
26+
@Schema(description = "수정할 임원진 역할", example = "동아리 운영 총괄")
27+
private String role;
28+
29+
@Schema(description = "임원진 깃허브 이름", example = "DASOM")
30+
private String github_username;
31+
32+
@Schema(description = "소속 팀", example = "president, tech, academic, pr, management")
33+
private Team team;
34+
35+
private Integer sortOrder;
2736
}

src/main/java/dmu/dasom/api/domain/executive/dto/ExecutiveUpdateRequestDto.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package dmu.dasom.api.domain.executive.dto;
22

3+
import dmu.dasom.api.domain.executive.enums.Team;
34
import io.swagger.v3.oas.annotations.media.Schema;
45
import jakarta.validation.constraints.Size;
56
import lombok.AllArgsConstructor;
@@ -19,6 +20,15 @@ public class ExecutiveUpdateRequestDto {
1920
@Schema(description = "수정할 임원진 직책", example = "회장", nullable = true)
2021
private String position;
2122

22-
@Schema(description = "수정할 임원진 깃허브 주소", example = "https://github.com/dasom", nullable = true)
23-
private String githubUrl;
23+
@Schema(description = "수정할 임원진 역할", example = "동아리 운영 총괄", nullable = true)
24+
private String role;
25+
26+
@Schema(description = "임원진 깃허브 이름", example = "DASOM")
27+
private String github_username;
28+
29+
@Schema(description = "소속 팀", example = "president, tech, academic, pr, management")
30+
private Team team;
31+
32+
private Integer sortOrder;
33+
2434
}

src/main/java/dmu/dasom/api/domain/executive/entity/ExecutiveEntity.java

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,12 @@
33
import dmu.dasom.api.domain.common.BaseEntity; // BaseEntity 상속 받음
44
import dmu.dasom.api.domain.executive.dto.ExecutiveListResponseDto;
55
import dmu.dasom.api.domain.executive.dto.ExecutiveResponseDto;
6+
import dmu.dasom.api.domain.executive.dto.ExecutiveUpdateRequestDto;
7+
import dmu.dasom.api.domain.executive.enums.Team;
68
import io.swagger.v3.oas.annotations.media.Schema;
79
import jakarta.persistence.*; // JPA 어노테이션 패키지 ( DB 매핑 관련 )
810
import lombok.*; // 보일러플레이트 코드 자동 생성 라이브러리
11+
import org.checkerframework.checker.units.qual.C;
912

1013
@Getter
1114
@Entity
@@ -28,15 +31,31 @@ public class ExecutiveEntity extends BaseEntity {
2831
@Column(nullable=false, length = 50)
2932
private String position;
3033

31-
// 깃허브 주소
32-
@Column(nullable=false, length = 255)
33-
private String githubUrl;
34+
// 역할
35+
@Column(nullable = false, length = 50)
36+
private String role;
37+
38+
// 깃허브 이름
39+
@Column(name = "github_username")
40+
private String githubUsername;
41+
42+
// 소속팀 (president/tech/academic/pr/management)
43+
@Enumerated(EnumType.STRING)
44+
@Column(nullable = false, length = 20)
45+
private Team team;
46+
47+
@Column(name = "sort_order", nullable = false)
48+
@Builder.Default
49+
private Integer sortOrder = 9999;
3450

3551
// 엔티티 업데이트 메소드
36-
public void update(String name, String position, String githubUrl) {
37-
this.name = name;
38-
this.position = position;
39-
this.githubUrl = githubUrl;
52+
public void update(ExecutiveUpdateRequestDto dto) {
53+
if (dto.getName() != null) this.name = dto.getName();
54+
if (dto.getPosition() != null) this.position = dto.getPosition();
55+
if (dto.getRole() != null) this.role = dto.getRole();
56+
if (dto.getGithub_username() != null) this.githubUsername = dto.getGithub_username();
57+
if (dto.getTeam() != null) this.team = dto.getTeam();
58+
if (dto.getSortOrder() != null) this.sortOrder = dto.getSortOrder();
4059
}
4160

4261
// 엔티티 -> DTO 변환 책임
@@ -45,7 +64,9 @@ public ExecutiveResponseDto toResponseDto() {
4564
.id(this.id)
4665
.name(this.name)
4766
.position(this.position)
48-
.githubUrl(this.githubUrl)
67+
.role(this.role)
68+
.github_username(this.githubUsername)
69+
.team(this.team)
4970
.build();
5071
}
5172

@@ -55,7 +76,9 @@ public ExecutiveListResponseDto toListResponseDto() {
5576
.id(this.id)
5677
.name(this.name)
5778
.position(this.position)
58-
.githubUrl(this.githubUrl)
79+
.role(this.role)
80+
.github_username(this.githubUsername)
81+
.team(this.team)
5982
.build();
6083
}
6184
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package dmu.dasom.api.domain.executive.enums;
2+
3+
import lombok.AllArgsConstructor;
4+
import lombok.Getter;
5+
6+
@AllArgsConstructor
7+
@Getter
8+
public enum Team {
9+
PRESIDENT("president"),
10+
TECH("tech"),
11+
ACADEMIC("academic"),
12+
MANAGEMENT("management"),
13+
PR("pr")
14+
;
15+
16+
private String name;
17+
}

src/main/java/dmu/dasom/api/domain/executive/service/ExecutiveServiceImpl.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import dmu.dasom.api.domain.executive.entity.ExecutiveEntity;
77
import dmu.dasom.api.domain.executive.repository.ExecutiveRepository;
88
import lombok.RequiredArgsConstructor;
9+
import org.springframework.data.domain.Sort;
910
import org.springframework.stereotype.Service;
1011
import org.springframework.transaction.annotation.Transactional;
1112

@@ -31,11 +32,13 @@ public ExecutiveResponseDto getExecutiveById(Long id) {
3132
// 임원진 전체 조회
3233
// 이름, 직책, 깃허브 주소 출력
3334
public List<ExecutiveListResponseDto> getAllExecutives() {
34-
List<ExecutiveEntity> executives = executiveRepository.findAll();
35+
// 전체 조회 시 정렬
36+
// 기준 sortOrder -> 직책 -> 이름
37+
Sort sort = Sort.by(Sort.Direction.ASC, "sortOrder")
38+
.and(Sort.by(Sort.Direction.ASC, "position"))
39+
.and(Sort.by(Sort.Direction.DESC, "name"));
3540

36-
List<Long> executiveIds = executives.stream()
37-
.map(ExecutiveEntity::getId)
38-
.toList();
41+
List<ExecutiveEntity> executives = executiveRepository.findAll(sort);
3942

4043
return executives.stream()
4144
.map(executiveEntity -> executiveEntity.toListResponseDto())
@@ -62,7 +65,7 @@ public ExecutiveResponseDto updateExecutive(Long id, ExecutiveUpdateRequestDto r
6265
ExecutiveEntity executive = executiveRepository.findById(id)
6366
.orElseThrow(() -> new CustomException(ErrorCode.EXECUTIVE_NOT_FOUND));
6467

65-
executive.update(requestDto.getName(), requestDto.getPosition(), requestDto.getGithubUrl());
68+
executive.update(requestDto);
6669

6770
return executive.toResponseDto();
6871
}

src/test/java/dmu/dasom/api/domain/executive/service/ExecutiveServiceTest.java

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import dmu.dasom.api.domain.executive.dto.ExecutiveResponseDto;
88
import dmu.dasom.api.domain.executive.dto.ExecutiveUpdateRequestDto;
99
import dmu.dasom.api.domain.executive.entity.ExecutiveEntity;
10+
import dmu.dasom.api.domain.executive.enums.Team;
1011
import dmu.dasom.api.domain.executive.repository.ExecutiveRepository;
1112
import org.junit.jupiter.api.DisplayName;
1213
import org.junit.jupiter.api.Test;
@@ -43,7 +44,9 @@ void getExecutiveById_success() {
4344
.id(1L)
4445
.name("김다솜")
4546
.position("회장")
46-
.githubUrl("https://github.com/dasom")
47+
.role("동아리 운영 총괄")
48+
.githubUsername("DASOM")
49+
.team(Team.PRESIDENT)
4750
.build();
4851

4952
when(executiveRepository.findById(id)).thenReturn(Optional.of(entity));
@@ -55,7 +58,9 @@ void getExecutiveById_success() {
5558
assertThat(responseDto.getId()).isEqualTo(id);
5659
assertThat(responseDto.getName()).isEqualTo("김다솜");
5760
assertThat(responseDto.getPosition()).isEqualTo("회장");
58-
assertThat(responseDto.getGithubUrl()).isEqualTo("https://github.com/dasom");
61+
assertThat(responseDto.getRole()).isEqualTo("동아리 운영 총괄");
62+
assertThat(responseDto.getGithub_username()).isEqualTo("DASOM");
63+
assertThat(responseDto.getTeam()).isEqualTo(Team.PRESIDENT);
5964

6065
// verify ( 호출 검증 )
6166
verify(executiveRepository, times(1)).findById(id); // 메소드를 정확히 한 번만 호출했는지?
@@ -83,14 +88,22 @@ void createExecutive_success() {
8388
// given
8489
Long id = 1L;
8590
ExecutiveRequestDto dto = new ExecutiveRequestDto(
86-
id, "김다솜", "회장", "https://github.com/dasom"
91+
id,
92+
"김다솜",
93+
"회장",
94+
"동아리 운영 총괄",
95+
"DASOM",
96+
Team.PRESIDENT,
97+
1
8798
);
8899

89100
ExecutiveEntity entity = ExecutiveEntity.builder()
90101
.id(1L)
91102
.name("김다솜")
92103
.position("회장")
93-
.githubUrl("https://github.com/dasom")
104+
.role("동아리 운영 총괄")
105+
.githubUsername("DASOM")
106+
.team(Team.PRESIDENT)
94107
.build();
95108

96109
when(executiveRepository.save(any(ExecutiveEntity.class))).thenReturn(entity);
@@ -119,7 +132,9 @@ void deleteExecutive_success() {
119132
.id(1L)
120133
.name("김다솜")
121134
.position("회장")
122-
.githubUrl("https://github.com/dasom")
135+
.role("동아리 운영 총괄")
136+
.githubUsername("DASOM")
137+
.team(Team.PRESIDENT)
123138
.build();
124139

125140
when(executiveRepository.findById(id)).thenReturn(Optional.of(entity));
@@ -158,10 +173,19 @@ void updateExecutive_success() {
158173
.id(1L)
159174
.name("김다솜")
160175
.position("회장")
161-
.githubUrl("https://github.com/dasom")
176+
.role("동아리 운영 총괄")
177+
.githubUsername("DASOM")
178+
.team(Team.PRESIDENT)
162179
.build();
163180

164-
ExecutiveUpdateRequestDto updateEntity = new ExecutiveUpdateRequestDto("김솜다", "부회장", "https://github.com/dasom");
181+
ExecutiveUpdateRequestDto updateEntity = new ExecutiveUpdateRequestDto(
182+
"김솜다",
183+
"부회장",
184+
"동아리 운영 총괄",
185+
"MOSAD",
186+
Team.ACADEMIC,
187+
1
188+
);
165189

166190
when(executiveRepository.findById(id)).thenReturn(Optional.of(entity));
167191

@@ -171,7 +195,9 @@ void updateExecutive_success() {
171195
//then
172196
assertThat(updateExecutive.getName()).isEqualTo("김솜다");
173197
assertThat(updateExecutive.getPosition()).isEqualTo("부회장");
174-
assertThat(updateExecutive.getGithubUrl()).isEqualTo("https://github.com/dasom");
198+
assertThat(updateExecutive.getRole()).isEqualTo("동아리 운영 총괄");
199+
assertThat(updateExecutive.getGithub_username()).isEqualTo("MOSAD");
200+
assertThat(updateExecutive.getTeam()).isEqualTo(Team.ACADEMIC);
175201

176202
// verify ( 호출 검증 )
177203
verify(executiveRepository, times(1)).findById(id); // 메소드를 정확히 한 번만 호출했는지?

0 commit comments

Comments
 (0)