Skip to content

Commit 6899774

Browse files
committed
feat: 활동 연혁 DTO 정의 (DASOMBE-15)
1 parent 2d827cd commit 6899774

File tree

3 files changed

+161
-0
lines changed

3 files changed

+161
-0
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package dmu.dasom.api.domain.activity.dto;
2+
3+
import dmu.dasom.api.domain.activity.entity.ActivityHistory;
4+
import io.swagger.v3.oas.annotations.media.Schema;
5+
import jakarta.validation.constraints.Min;
6+
import jakarta.validation.constraints.NotBlank;
7+
import jakarta.validation.constraints.NotNull;
8+
import jakarta.validation.constraints.Size;
9+
import lombok.Getter;
10+
11+
@Getter
12+
@Schema(name = "ActivityHistoryRequestDto", description = "활동 연혁 생성/수정 요청 DTO")
13+
public class ActivityHistoryRequestDto {
14+
15+
@NotNull(message = "연도는 필수입니다.")
16+
@Min(value = 1992, message = "연도는 1992년 이상이어야 합니다.")
17+
@Schema(description = "활동 연도", example = "2024", minimum = "1992", maximum = "2050")
18+
private int year;
19+
20+
@NotBlank(message = "섹션 제목은 필수입니다.")
21+
@Size(max = 50, message = "섹션은 50자 이내로 입력해주세요.")
22+
@Schema(description = "활동 섹션", example = "교내 경진대회", maxLength = 50)
23+
private String section;
24+
25+
@NotBlank(message = "활동 제목은 필수입니다.")
26+
@Size(max = 50, message = "제목은 50자 이내로 입력해주세요.")
27+
@Schema(description = "활동 제목", example = "컴퓨터 공학부 경진대회", maxLength = 50)
28+
private String title;
29+
30+
@Size(max = 50, message = "수상 내역은 50자 이내로 입력해주세요.")
31+
@Schema(description = "수상 내역 (선택 사항)", example = "최우수상", maxLength = 50)
32+
private String award;
33+
34+
public ActivityHistory toEntity() {
35+
return ActivityHistory.builder()
36+
.year(this.year)
37+
.section(this.section)
38+
.title(this.title)
39+
.award(this.award)
40+
.build();
41+
}
42+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package dmu.dasom.api.domain.activity.dto;
2+
3+
import dmu.dasom.api.domain.activity.entity.ActivityHistory;
4+
import io.swagger.v3.oas.annotations.media.Schema;
5+
import lombok.Builder;
6+
import lombok.Getter;
7+
8+
@Getter
9+
@Builder
10+
@Schema(name = "ActivityHistoryResponseDto", description = "활동 연혁 단일 조회 응답 DTO")
11+
public class ActivityHistoryResponseDto { // 생성, 수정 응답 DTO
12+
13+
@Schema(description = "활동 연혁 고유 ID", example = "1")
14+
private final Long id;
15+
16+
@Schema(description = "활동 연도", example = "2024")
17+
private final int year;
18+
19+
@Schema(description = "활동 섹션", example = "교내 경진대회")
20+
private final String section;
21+
22+
@Schema(description = "활동 제목", example = "컴퓨터 공학부 경진대회")
23+
private final String title;
24+
25+
@Schema(description = "수상 내역", example = "최우수상")
26+
private final String award;
27+
28+
public static ActivityHistoryResponseDto toDto(ActivityHistory history) {
29+
return ActivityHistoryResponseDto.builder()
30+
.id(history.getId())
31+
.year(history.getYear())
32+
.section(history.getSection())
33+
.title(history.getTitle())
34+
.award(history.getAward())
35+
.build();
36+
}
37+
}
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
package dmu.dasom.api.domain.activity.dto;
2+
3+
import dmu.dasom.api.domain.activity.entity.ActivityHistory;
4+
import io.swagger.v3.oas.annotations.media.Schema;
5+
import lombok.Builder;
6+
import lombok.Getter;
7+
8+
import java.util.Comparator;
9+
import java.util.List;
10+
import java.util.stream.Collectors;
11+
12+
@Getter
13+
@Builder
14+
@Schema(name = "GroupedActivityHistoryDto", description = "활동 연혁 전체 조회 응답 DTO (연도별/섹션별 그룹화)")
15+
public class GroupedActivityHistoryDto { // 전체 조회 응답 DTO
16+
17+
@Schema(description = "활동 연도", example = "2024")
18+
private final int year;
19+
20+
@Schema(description = "해당 연도 섹션")
21+
private final List<SectionItemDto> sections;
22+
23+
@Getter @Builder
24+
@Schema(name = "SectionItemDto", description = "섹션별 활동 목록")
25+
public static class SectionItemDto {
26+
27+
@Schema(description = "활동 섹션", example = "교내 경진대회")
28+
private final String section;
29+
30+
@Schema(description = "활동 목록")
31+
private final List<ActivityItemDto> activities;
32+
}
33+
34+
@Getter @Builder
35+
@Schema(name = "ActivityItemDto", description = "개별 활동 목록")
36+
public static class ActivityItemDto {
37+
38+
@Schema(description = "활동 연혁 고유 ID", example = "1")
39+
private final Long id;
40+
41+
@Schema(description = "활동 제목", example = "컴퓨터 공학부 경진대회")
42+
private final String title;
43+
44+
@Schema(description = "수상 내역", example = "최우수상")
45+
private final String award;
46+
47+
public static ActivityItemDto toDto(ActivityHistory history) {
48+
return ActivityItemDto.builder()
49+
.id(history.getId()).title(history.getTitle())
50+
.award(history.getAward())
51+
.build();
52+
}
53+
}
54+
55+
// 응답 DTO를 계층적으로 그룹핑하는 함수
56+
public static List<GroupedActivityHistoryDto> groupedActivityHistoryDto(List<ActivityHistory> histories) {
57+
return histories.stream()
58+
.collect(Collectors.groupingBy(ActivityHistory::getYear))
59+
.entrySet().stream()
60+
.sorted(Comparator.comparing(java.util.Map.Entry::getKey, Comparator.reverseOrder()))
61+
.map(entryByYear -> {
62+
List<SectionItemDto> sectionItems = entryByYear.getValue().stream()
63+
.collect(Collectors.groupingBy(ActivityHistory::getSection))
64+
.entrySet().stream()
65+
.map(entryBySection -> {
66+
List<ActivityItemDto> activityItems = entryBySection.getValue().stream()
67+
.map(ActivityItemDto::toDto)
68+
.collect(Collectors.toList());
69+
return SectionItemDto.builder()
70+
.section(entryBySection.getKey())
71+
.activities(activityItems)
72+
.build();
73+
})
74+
.collect(Collectors.toList());
75+
return GroupedActivityHistoryDto.builder()
76+
.year(entryByYear.getKey())
77+
.sections(sectionItems)
78+
.build();
79+
})
80+
.collect(Collectors.toList());
81+
}
82+
}

0 commit comments

Comments
 (0)