diff --git a/src/main/java/dmu/dasom/api/domain/executive/dto/ExecutiveListResponseDto.java b/src/main/java/dmu/dasom/api/domain/executive/dto/ExecutiveListResponseDto.java index 7ae845d..c50b4dd 100644 --- a/src/main/java/dmu/dasom/api/domain/executive/dto/ExecutiveListResponseDto.java +++ b/src/main/java/dmu/dasom/api/domain/executive/dto/ExecutiveListResponseDto.java @@ -1,5 +1,6 @@ package dmu.dasom.api.domain.executive.dto; +import dmu.dasom.api.domain.executive.enums.Team; import io.swagger.v3.oas.annotations.media.Schema; import lombok.AllArgsConstructor; import lombok.Builder; @@ -22,7 +23,15 @@ public class ExecutiveListResponseDto { @Schema(description = "임원진 직책", example = "회장") private String position; - @Schema(description = "임원진 깃허브 주소", example = "https://github.com/dasom") - private String githubUrl; + @Schema(description = "수정할 임원진 역할", example = "동아리 운영 총괄", nullable = true) + private String role; + + @Schema(description = "임원진 깃허브 이름", example = "DASOM") + private String github_username; + + @Schema(description = "소속 팀", example = "president, tech, academic, pr, management") + private Team team; + + private Integer sortOrder; } diff --git a/src/main/java/dmu/dasom/api/domain/executive/dto/ExecutiveRequestDto.java b/src/main/java/dmu/dasom/api/domain/executive/dto/ExecutiveRequestDto.java index 2ba32e8..8d87f00 100644 --- a/src/main/java/dmu/dasom/api/domain/executive/dto/ExecutiveRequestDto.java +++ b/src/main/java/dmu/dasom/api/domain/executive/dto/ExecutiveRequestDto.java @@ -1,6 +1,7 @@ package dmu.dasom.api.domain.executive.dto; import dmu.dasom.api.domain.executive.entity.ExecutiveEntity; +import dmu.dasom.api.domain.executive.enums.Team; import io.swagger.v3.oas.annotations.media.Schema; import jakarta.validation.constraints.NotBlank; import jakarta.validation.constraints.Size; @@ -21,17 +22,30 @@ public class ExecutiveRequestDto { @Schema(description = "임원진 이름", example = "김다솜") private String name; - @NotBlank(message = "임원진 역할은 필수 입력 사항입니다.") - @Schema(description = "임원진 역할", example = "회장") + @NotBlank(message = "임원진 직책은 필수 입력 사항입니다.") + @Schema(description = "임원진 직책", example = "회장") private String position; - private String githubUrl; + @NotBlank(message = "임원진 역할은 필수 입력 사항입니다.") + @Schema(description = "임원진 역할", example = "동아리 운영 총괄") + private String role; + + @Schema(description = "임원진 깃허브 이름", example = "DASOM") + private String github_username; + + @Schema(description = "소속 팀", example = "president, tech, academic, pr, management") + private Team team; + + private Integer sortOrder; public ExecutiveEntity toEntity() { return ExecutiveEntity.builder() .name(this.name) .position(this.position) - .githubUrl(this.githubUrl) + .role(this.role) + .githubUsername(this.github_username) + .team(this.team) + .sortOrder(this.sortOrder) .build(); } } diff --git a/src/main/java/dmu/dasom/api/domain/executive/dto/ExecutiveResponseDto.java b/src/main/java/dmu/dasom/api/domain/executive/dto/ExecutiveResponseDto.java index a9007ff..0e96fb6 100644 --- a/src/main/java/dmu/dasom/api/domain/executive/dto/ExecutiveResponseDto.java +++ b/src/main/java/dmu/dasom/api/domain/executive/dto/ExecutiveResponseDto.java @@ -1,5 +1,6 @@ package dmu.dasom.api.domain.executive.dto; +import dmu.dasom.api.domain.executive.enums.Team; import io.swagger.v3.oas.annotations.media.Schema; import lombok.AllArgsConstructor; import lombok.Builder; @@ -22,6 +23,14 @@ public class ExecutiveResponseDto { @Schema(description = "임원진 직책", example = "회장") private String position; - @Schema(description = "임원진 깃허브", example = "https://github.com/dasom") - private String githubUrl; + @Schema(description = "수정할 임원진 역할", example = "동아리 운영 총괄") + private String role; + + @Schema(description = "임원진 깃허브 이름", example = "DASOM") + private String github_username; + + @Schema(description = "소속 팀", example = "president, tech, academic, pr, management") + private Team team; + + private Integer sortOrder; } diff --git a/src/main/java/dmu/dasom/api/domain/executive/dto/ExecutiveUpdateRequestDto.java b/src/main/java/dmu/dasom/api/domain/executive/dto/ExecutiveUpdateRequestDto.java index e66f2e9..286dcdb 100644 --- a/src/main/java/dmu/dasom/api/domain/executive/dto/ExecutiveUpdateRequestDto.java +++ b/src/main/java/dmu/dasom/api/domain/executive/dto/ExecutiveUpdateRequestDto.java @@ -1,5 +1,6 @@ package dmu.dasom.api.domain.executive.dto; +import dmu.dasom.api.domain.executive.enums.Team; import io.swagger.v3.oas.annotations.media.Schema; import jakarta.validation.constraints.Size; import lombok.AllArgsConstructor; @@ -19,6 +20,15 @@ public class ExecutiveUpdateRequestDto { @Schema(description = "수정할 임원진 직책", example = "회장", nullable = true) private String position; - @Schema(description = "수정할 임원진 깃허브 주소", example = "https://github.com/dasom", nullable = true) - private String githubUrl; + @Schema(description = "수정할 임원진 역할", example = "동아리 운영 총괄", nullable = true) + private String role; + + @Schema(description = "임원진 깃허브 이름", example = "DASOM") + private String github_username; + + @Schema(description = "소속 팀", example = "president, tech, academic, pr, management") + private Team team; + + private Integer sortOrder; + } diff --git a/src/main/java/dmu/dasom/api/domain/executive/entity/ExecutiveEntity.java b/src/main/java/dmu/dasom/api/domain/executive/entity/ExecutiveEntity.java index 849406f..45b1a22 100644 --- a/src/main/java/dmu/dasom/api/domain/executive/entity/ExecutiveEntity.java +++ b/src/main/java/dmu/dasom/api/domain/executive/entity/ExecutiveEntity.java @@ -3,9 +3,12 @@ import dmu.dasom.api.domain.common.BaseEntity; // BaseEntity 상속 받음 import dmu.dasom.api.domain.executive.dto.ExecutiveListResponseDto; import dmu.dasom.api.domain.executive.dto.ExecutiveResponseDto; +import dmu.dasom.api.domain.executive.dto.ExecutiveUpdateRequestDto; +import dmu.dasom.api.domain.executive.enums.Team; import io.swagger.v3.oas.annotations.media.Schema; import jakarta.persistence.*; // JPA 어노테이션 패키지 ( DB 매핑 관련 ) import lombok.*; // 보일러플레이트 코드 자동 생성 라이브러리 +import org.checkerframework.checker.units.qual.C; @Getter @Entity @@ -28,15 +31,31 @@ public class ExecutiveEntity extends BaseEntity { @Column(nullable=false, length = 50) private String position; - // 깃허브 주소 - @Column(nullable=false, length = 255) - private String githubUrl; + // 역할 + @Column(nullable = false, length = 50) + private String role; + + // 깃허브 이름 + @Column(name = "github_username") + private String githubUsername; + + // 소속팀 (president/tech/academic/pr/management) + @Enumerated(EnumType.STRING) + @Column(nullable = false, length = 20) + private Team team; + + @Column(name = "sort_order", nullable = false) + @Builder.Default + private Integer sortOrder = 9999; // 엔티티 업데이트 메소드 - public void update(String name, String position, String githubUrl) { - this.name = name; - this.position = position; - this.githubUrl = githubUrl; + public void update(ExecutiveUpdateRequestDto dto) { + if (dto.getName() != null) this.name = dto.getName(); + if (dto.getPosition() != null) this.position = dto.getPosition(); + if (dto.getRole() != null) this.role = dto.getRole(); + if (dto.getGithub_username() != null) this.githubUsername = dto.getGithub_username(); + if (dto.getTeam() != null) this.team = dto.getTeam(); + if (dto.getSortOrder() != null) this.sortOrder = dto.getSortOrder(); } // 엔티티 -> DTO 변환 책임 @@ -45,7 +64,9 @@ public ExecutiveResponseDto toResponseDto() { .id(this.id) .name(this.name) .position(this.position) - .githubUrl(this.githubUrl) + .role(this.role) + .github_username(this.githubUsername) + .team(this.team) .build(); } @@ -55,7 +76,9 @@ public ExecutiveListResponseDto toListResponseDto() { .id(this.id) .name(this.name) .position(this.position) - .githubUrl(this.githubUrl) + .role(this.role) + .github_username(this.githubUsername) + .team(this.team) .build(); } } diff --git a/src/main/java/dmu/dasom/api/domain/executive/enums/Team.java b/src/main/java/dmu/dasom/api/domain/executive/enums/Team.java new file mode 100644 index 0000000..2921b1f --- /dev/null +++ b/src/main/java/dmu/dasom/api/domain/executive/enums/Team.java @@ -0,0 +1,17 @@ +package dmu.dasom.api.domain.executive.enums; + +import lombok.AllArgsConstructor; +import lombok.Getter; + +@AllArgsConstructor +@Getter +public enum Team { + PRESIDENT("president"), + TECH("tech"), + ACADEMIC("academic"), + MANAGEMENT("management"), + PR("pr") + ; + + private String name; +} diff --git a/src/main/java/dmu/dasom/api/domain/executive/service/ExecutiveServiceImpl.java b/src/main/java/dmu/dasom/api/domain/executive/service/ExecutiveServiceImpl.java index 7d039b9..42563d6 100644 --- a/src/main/java/dmu/dasom/api/domain/executive/service/ExecutiveServiceImpl.java +++ b/src/main/java/dmu/dasom/api/domain/executive/service/ExecutiveServiceImpl.java @@ -6,6 +6,7 @@ import dmu.dasom.api.domain.executive.entity.ExecutiveEntity; import dmu.dasom.api.domain.executive.repository.ExecutiveRepository; import lombok.RequiredArgsConstructor; +import org.springframework.data.domain.Sort; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -31,11 +32,13 @@ public ExecutiveResponseDto getExecutiveById(Long id) { // 임원진 전체 조회 // 이름, 직책, 깃허브 주소 출력 public List getAllExecutives() { - List executives = executiveRepository.findAll(); + // 전체 조회 시 정렬 + // 기준 sortOrder -> 직책 -> 이름 + Sort sort = Sort.by(Sort.Direction.ASC, "sortOrder") + .and(Sort.by(Sort.Direction.ASC, "position")) + .and(Sort.by(Sort.Direction.DESC, "name")); - List executiveIds = executives.stream() - .map(ExecutiveEntity::getId) - .toList(); + List executives = executiveRepository.findAll(sort); return executives.stream() .map(executiveEntity -> executiveEntity.toListResponseDto()) @@ -62,7 +65,7 @@ public ExecutiveResponseDto updateExecutive(Long id, ExecutiveUpdateRequestDto r ExecutiveEntity executive = executiveRepository.findById(id) .orElseThrow(() -> new CustomException(ErrorCode.EXECUTIVE_NOT_FOUND)); - executive.update(requestDto.getName(), requestDto.getPosition(), requestDto.getGithubUrl()); + executive.update(requestDto); return executive.toResponseDto(); } diff --git a/src/test/java/dmu/dasom/api/domain/executive/service/ExecutiveServiceTest.java b/src/test/java/dmu/dasom/api/domain/executive/service/ExecutiveServiceTest.java index 4b8a492..93825df 100644 --- a/src/test/java/dmu/dasom/api/domain/executive/service/ExecutiveServiceTest.java +++ b/src/test/java/dmu/dasom/api/domain/executive/service/ExecutiveServiceTest.java @@ -7,6 +7,7 @@ import dmu.dasom.api.domain.executive.dto.ExecutiveResponseDto; import dmu.dasom.api.domain.executive.dto.ExecutiveUpdateRequestDto; import dmu.dasom.api.domain.executive.entity.ExecutiveEntity; +import dmu.dasom.api.domain.executive.enums.Team; import dmu.dasom.api.domain.executive.repository.ExecutiveRepository; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; @@ -43,7 +44,9 @@ void getExecutiveById_success() { .id(1L) .name("김다솜") .position("회장") - .githubUrl("https://github.com/dasom") + .role("동아리 운영 총괄") + .githubUsername("DASOM") + .team(Team.PRESIDENT) .build(); when(executiveRepository.findById(id)).thenReturn(Optional.of(entity)); @@ -55,7 +58,9 @@ void getExecutiveById_success() { assertThat(responseDto.getId()).isEqualTo(id); assertThat(responseDto.getName()).isEqualTo("김다솜"); assertThat(responseDto.getPosition()).isEqualTo("회장"); - assertThat(responseDto.getGithubUrl()).isEqualTo("https://github.com/dasom"); + assertThat(responseDto.getRole()).isEqualTo("동아리 운영 총괄"); + assertThat(responseDto.getGithub_username()).isEqualTo("DASOM"); + assertThat(responseDto.getTeam()).isEqualTo(Team.PRESIDENT); // verify ( 호출 검증 ) verify(executiveRepository, times(1)).findById(id); // 메소드를 정확히 한 번만 호출했는지? @@ -83,14 +88,22 @@ void createExecutive_success() { // given Long id = 1L; ExecutiveRequestDto dto = new ExecutiveRequestDto( - id, "김다솜", "회장", "https://github.com/dasom" + id, + "김다솜", + "회장", + "동아리 운영 총괄", + "DASOM", + Team.PRESIDENT, + 1 ); ExecutiveEntity entity = ExecutiveEntity.builder() .id(1L) .name("김다솜") .position("회장") - .githubUrl("https://github.com/dasom") + .role("동아리 운영 총괄") + .githubUsername("DASOM") + .team(Team.PRESIDENT) .build(); when(executiveRepository.save(any(ExecutiveEntity.class))).thenReturn(entity); @@ -119,7 +132,9 @@ void deleteExecutive_success() { .id(1L) .name("김다솜") .position("회장") - .githubUrl("https://github.com/dasom") + .role("동아리 운영 총괄") + .githubUsername("DASOM") + .team(Team.PRESIDENT) .build(); when(executiveRepository.findById(id)).thenReturn(Optional.of(entity)); @@ -158,10 +173,19 @@ void updateExecutive_success() { .id(1L) .name("김다솜") .position("회장") - .githubUrl("https://github.com/dasom") + .role("동아리 운영 총괄") + .githubUsername("DASOM") + .team(Team.PRESIDENT) .build(); - ExecutiveUpdateRequestDto updateEntity = new ExecutiveUpdateRequestDto("김솜다", "부회장", "https://github.com/dasom"); + ExecutiveUpdateRequestDto updateEntity = new ExecutiveUpdateRequestDto( + "김솜다", + "부회장", + "동아리 운영 총괄", + "MOSAD", + Team.ACADEMIC, + 1 + ); when(executiveRepository.findById(id)).thenReturn(Optional.of(entity)); @@ -171,7 +195,9 @@ void updateExecutive_success() { //then assertThat(updateExecutive.getName()).isEqualTo("김솜다"); assertThat(updateExecutive.getPosition()).isEqualTo("부회장"); - assertThat(updateExecutive.getGithubUrl()).isEqualTo("https://github.com/dasom"); + assertThat(updateExecutive.getRole()).isEqualTo("동아리 운영 총괄"); + assertThat(updateExecutive.getGithub_username()).isEqualTo("MOSAD"); + assertThat(updateExecutive.getTeam()).isEqualTo(Team.ACADEMIC); // verify ( 호출 검증 ) verify(executiveRepository, times(1)).findById(id); // 메소드를 정확히 한 번만 호출했는지?