Skip to content

Commit 1052852

Browse files
committed
refactor: 솜커톤 참가자 관련 리팩토링
- SomParticipant : toResponseDto 메서드 추가 및 구조 개선 - SomParticipantRequestDto : 불변 객체 및 빌더 패턴으로 변경 - SomParticipantService : DTO 변환 로직 엔티티로 위임
1 parent 5616eef commit 1052852

File tree

3 files changed

+39
-33
lines changed

3 files changed

+39
-33
lines changed

src/main/java/dmu/dasom/api/domain/somkathon/dto/SomParticipantRequestDto.java

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,50 +5,53 @@
55
import jakarta.validation.constraints.NotBlank;
66
import jakarta.validation.constraints.Pattern;
77
import jakarta.validation.constraints.Size;
8+
import lombok.AllArgsConstructor;
9+
import lombok.Builder;
810
import lombok.Getter;
9-
import lombok.Setter;
1011
import org.hibernate.validator.constraints.URL;
1112

1213
@Getter
13-
@Setter
14+
@Builder
15+
@AllArgsConstructor
1416
@Schema(description = "솜커톤 참가자 요청 DTO")
1517
public class SomParticipantRequestDto {
18+
1619
@NotBlank(message = "참가자 이름은 필수 입력 값입니다.")
1720
@Size(max = 50, message = "참가자 이름은 최대 50자까지 입력 가능합니다.")
1821
@Schema(description = "참가자 이름", example = "유승완", required = true)
19-
private String participantName; // 참가자 이름
22+
private final String participantName; // 참가자 이름
2023

2124
@NotBlank(message = "학번은 필수 입력 값입니다.")
2225
@Pattern(regexp = "^[0-9]{8}$", message = "학번은 8자리 숫자여야 합니다.")
2326
@Schema(description = "학번 (8자리 숫자)", example = "20250001", required = true)
24-
private String studentId;
27+
private final String studentId;
2528

2629
@NotBlank(message = "학과는 필수 입력 값입니다.")
2730
@Size(max = 100, message = "학과는 최대 100자까지 입력 가능합니다.")
2831
@Schema(description = "학과", example = "컴퓨터소프트웨어공학과", required = true)
29-
private String department; // 학과
32+
private final String department; // 학과
3033

3134
@NotBlank(message = "학년은 필수 입력 값입니다.")
3235
@Pattern(regexp = "^[1-4]$", message = "학년은 1~4 사이의 숫자여야 합니다.")
3336
@Schema(description = "학년 (1~4)", example = "3", required = true)
34-
private String grade; // 학년
37+
private final String grade; // 학년
3538

3639
@NotBlank(message = "연락처는 필수 입력 값입니다.")
3740
@Pattern(regexp = "^010-[0-9]{4}-[0-9]{4}$", message = "연락처는 '010-XXXX-XXXX' 형식이어야 합니다.")
3841
@Schema(description = "연락처 (010-XXXX-XXXX 형식)", example = "010-1234-5678", required = true)
39-
private String contact; // 연락처
42+
private final String contact; // 연락처
4043

4144
@NotBlank(message = "이메일은 필수 입력 값입니다.")
4245
@Email(message = "올바른 이메일 형식이 아닙니다.")
4346
@Schema(description = "이메일 주소", example = "[email protected]", required = true)
44-
private String email; // 이메일
47+
private final String email; // 이메일
4548

4649
@URL(protocol = "https", host = "github.com", message = "GitHub URL이 올바르지 않습니다.")
47-
@Schema(description = "GitHub 주소", example = "https://github.com/username", required = true)
48-
private String githubLink; // 깃허브 주소
50+
@Schema(description = "GitHub 주소", example = "https://github.com/username")
51+
private final String githubLink; // 깃허브 주소
4952

5053
@NotBlank(message = "포트폴리오 주소는 필수 입력 값입니다.")
5154
@URL(protocol = "https", message = "포트폴리오 URL이 올바르지 않습니다.")
5255
@Schema(description = "포트폴리오 주소", example = "https://portfolio.com/username", required = true)
53-
private String portfolioLink; // 포트폴리오 주소
56+
private final String portfolioLink; // 포트폴리오 주소
5457
}

src/main/java/dmu/dasom/api/domain/somkathon/entity/SomParticipant.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import dmu.dasom.api.domain.common.BaseEntity;
44
import dmu.dasom.api.domain.somkathon.dto.SomParticipantRequestDto;
5+
import dmu.dasom.api.domain.somkathon.dto.SomParticipantResponseDto;
56
import jakarta.persistence.*;
67
import lombok.AllArgsConstructor;
78
import lombok.Builder;
@@ -55,4 +56,21 @@ public void update(SomParticipantRequestDto requestDto) {
5556
this.githubLink = requestDto.getGithubLink();
5657
this.portfolioLink = requestDto.getPortfolioLink();
5758
}
59+
60+
/**
61+
* Entity → Response DTO 변환 메서드
62+
*/
63+
public SomParticipantResponseDto toResponseDto(SomParticipant participant) {
64+
return SomParticipantResponseDto.builder()
65+
.id(participant.getId())
66+
.participantName(participant.getParticipantName())
67+
.studentId(participant.getStudentId())
68+
.department(participant.getDepartment())
69+
.grade(participant.getGrade())
70+
.contact(participant.getContact())
71+
.email(participant.getEmail())
72+
.githubLink(participant.getGithubLink())
73+
.portfolioLink(participant.getPortfolioLink())
74+
.build();
75+
}
5876
}

src/main/java/dmu/dasom/api/domain/somkathon/service/SomParticipantService.java

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,15 @@ public SomParticipantResponseDto createParticipant(SomParticipantRequestDto requ
3535

3636
SomParticipant saved = somParticipantRepository.save(participant);
3737

38-
return toResponseDto(saved);
38+
return saved.toResponseDto(saved);
3939
}
4040

4141
/**
4242
* 모든 참가자 조회 (Read)
4343
*/
4444
public List<SomParticipantResponseDto> getAllParticipants() {
4545
return somParticipantRepository.findAll().stream()
46-
.map(this::toResponseDto)
46+
.map(p -> p.toResponseDto(p))
4747
.collect(Collectors.toList());
4848
}
4949

@@ -53,15 +53,18 @@ public List<SomParticipantResponseDto> getAllParticipants() {
5353
public SomParticipantResponseDto getParticipant(Long id){
5454
SomParticipant participant = findParticipantById(id);
5555

56-
return toResponseDto(participant);
56+
return participant.toResponseDto(participant);
5757
}
5858

59+
/**
60+
* 참가자 수정 (Put)
61+
*/
5962
public SomParticipantResponseDto updateParticipant(Long id, SomParticipantRequestDto requestDto){
6063
SomParticipant participant = findParticipantById(id);
6164

6265
participant.update(requestDto);
6366

64-
return toResponseDto(participant);
67+
return participant.toResponseDto(participant);
6568
}
6669

6770
/**
@@ -72,24 +75,6 @@ public void deleteParticipant(Long id) {
7275
somParticipantRepository.deleteById(id);
7376
}
7477

75-
76-
/**
77-
* Entity → Response DTO 변환 메서드
78-
*/
79-
private SomParticipantResponseDto toResponseDto(SomParticipant participant) {
80-
return SomParticipantResponseDto.builder()
81-
.id(participant.getId())
82-
.participantName(participant.getParticipantName())
83-
.studentId(participant.getStudentId())
84-
.department(participant.getDepartment())
85-
.grade(participant.getGrade())
86-
.contact(participant.getContact())
87-
.email(participant.getEmail())
88-
.githubLink(participant.getGithubLink())
89-
.portfolioLink(participant.getPortfolioLink())
90-
.build();
91-
}
92-
9378
/**
9479
* ID로 참가자 조회 (공통 처리)
9580
*/

0 commit comments

Comments
 (0)