Skip to content

Commit 82d1f47

Browse files
committed
feat: sortOrder 정렬 기준 추가 (DASOMBE-14)
1 parent 6c116b3 commit 82d1f47

File tree

6 files changed

+35
-7
lines changed

6 files changed

+35
-7
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,7 @@ public class ExecutiveListResponseDto {
2525
@Schema(description = "임원진 깃허브 주소", example = "https://github.com/dasom")
2626
private String githubUrl;
2727

28+
@Schema(description = "정렬 기준")
29+
private Integer sortOrder;
30+
2831
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ public class ExecutiveRequestDto {
2727

2828
private String githubUrl;
2929

30+
private Integer sortOrder;
31+
3032
public ExecutiveEntity toEntity() {
3133
return ExecutiveEntity.builder()
3234
.name(this.name)

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,7 @@ public class ExecutiveResponseDto {
2424

2525
@Schema(description = "임원진 깃허브", example = "https://github.com/dasom")
2626
private String githubUrl;
27+
28+
@Schema(description = "정렬 기준")
29+
private Integer sortOrder;
2730
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,7 @@ public class ExecutiveUpdateRequestDto {
2121

2222
@Schema(description = "수정할 임원진 깃허브 주소", example = "https://github.com/dasom", nullable = true)
2323
private String githubUrl;
24+
25+
@Schema(description = "정렬 기준")
26+
private Integer sortOrder;
2427
}

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,16 @@ public class ExecutiveEntity extends BaseEntity {
3232
@Column(nullable=false, length = 255)
3333
private String githubUrl;
3434

35+
// 프론트 정렬 기준 제공
36+
@Column(name = "sort_order", nullable = false)
37+
private Integer sortOrder;
38+
3539
// 엔티티 업데이트 메소드
36-
public void update(String name, String position, String githubUrl) {
40+
public void update(String name, String position, String githubUrl, Integer sortOrder) {
3741
this.name = name;
3842
this.position = position;
3943
this.githubUrl = githubUrl;
44+
this.sortOrder = sortOrder;
4045
}
4146

4247
// 엔티티 -> DTO 변환 책임
@@ -46,6 +51,7 @@ public ExecutiveResponseDto toResponseDto() {
4651
.name(this.name)
4752
.position(this.position)
4853
.githubUrl(this.githubUrl)
54+
.sortOrder(this.sortOrder)
4955
.build();
5056
}
5157

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

Lines changed: 17 additions & 6 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,11 @@ public ExecutiveResponseDto getExecutiveById(Long id) {
3132
// 임원진 전체 조회
3233
// 이름, 직책, 깃허브 주소 출력
3334
public List<ExecutiveListResponseDto> getAllExecutives() {
34-
List<ExecutiveEntity> executives = executiveRepository.findAll();
35+
Sort sort = Sort.by(Sort.Direction.ASC, "sortOrder")
36+
.and(Sort.by(Sort.Direction.ASC, "position"))
37+
.and(Sort.by(Sort.Direction.ASC, "name"));
3538

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

4041
return executives.stream()
4142
.map(executiveEntity -> executiveEntity.toListResponseDto())
@@ -44,7 +45,17 @@ public List<ExecutiveListResponseDto> getAllExecutives() {
4445

4546
// 임원진 멤버 생성
4647
public ExecutiveCreationResponseDto createExecutive(ExecutiveRequestDto requestDto) {
47-
return new ExecutiveCreationResponseDto(executiveRepository.save(requestDto.toEntity()).getId());
48+
Integer sortOrder = requestDto.getSortOrder() != null ? requestDto.getSortOrder() : 9999;
49+
50+
ExecutiveEntity executiveEntity = ExecutiveEntity.builder()
51+
.name(requestDto.getName())
52+
.position(requestDto.getPosition())
53+
.githubUrl(requestDto.getGithubUrl())
54+
.sortOrder(sortOrder)
55+
.build();
56+
57+
Long id = executiveRepository.save(executiveEntity).getId();
58+
return new ExecutiveCreationResponseDto(id);
4859
}
4960

5061
// 임원진 멤버 삭제
@@ -62,7 +73,7 @@ public ExecutiveResponseDto updateExecutive(Long id, ExecutiveUpdateRequestDto r
6273
ExecutiveEntity executive = executiveRepository.findById(id)
6374
.orElseThrow(() -> new CustomException(ErrorCode.EXECUTIVE_NOT_FOUND));
6475

65-
executive.update(requestDto.getName(), requestDto.getPosition(), requestDto.getGithubUrl());
76+
executive.update(requestDto.getName(), requestDto.getPosition(), requestDto.getGithubUrl(), requestDto.getSortOrder());
6677

6778
return executive.toResponseDto();
6879
}

0 commit comments

Comments
 (0)