Skip to content

Commit 72bbe23

Browse files
dohy-eonjucheonsusi-zero
authored
feat: 솜커톤 API GitHub & 포트폴리오 링크 추가
* [hotfix] 조직도 API 코드 수정 * hotfix: 조직도에 setter 추가 * hotfix: setter 임포트문 추가 * fix: 코드 수정 * test: 솜커톤 참가자 생성, 조회, 삭제 기능 테스트 - SomParticipantServiceTest (테스트) * feat: 솜커톤 참가자 GitHub/포트폴리오 링크 추가 - SomParticipant (엔티티) - SomParticipantRequestDto (요청 DTO) - SomParticipantResponseDto (응답 DTO) - SomParticipantService (서비스) * refactor: 깃허브 링크 필수 제약 조건 제거 - SomParticipant (엔티티) - SomParticipantRequestDto (요청 DTO) * test: 솜커톤 참가자 CRUD 테스트 - SomParticipantServiceTest - Setter 방식 -> Builder 방식 - Update 테스트 코드 추가 * refactor: 솜커톤 참가자 관련 리팩토링 - SomParticipant : toResponseDto 메서드 추가 및 구조 개선 - SomParticipantRequestDto : 불변 객체 및 빌더 패턴으로 변경 - SomParticipantService : DTO 변환 로직 엔티티로 위임 --------- Co-authored-by: JOO <[email protected]> Co-authored-by: Youwol <[email protected]> Co-authored-by: si-zero <[email protected]>
1 parent ab66613 commit 72bbe23

File tree

5 files changed

+304
-29
lines changed

5 files changed

+304
-29
lines changed

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

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,40 +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;
11+
import org.hibernate.validator.constraints.URL;
1012

1113
@Getter
12-
@Setter
14+
@Builder
15+
@AllArgsConstructor
1316
@Schema(description = "솜커톤 참가자 요청 DTO")
1417
public class SomParticipantRequestDto {
18+
1519
@NotBlank(message = "참가자 이름은 필수 입력 값입니다.")
1620
@Size(max = 50, message = "참가자 이름은 최대 50자까지 입력 가능합니다.")
1721
@Schema(description = "참가자 이름", example = "유승완", required = true)
18-
private String participantName; // 참가자 이름
22+
private final String participantName; // 참가자 이름
1923

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

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

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

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

4044
@NotBlank(message = "이메일은 필수 입력 값입니다.")
4145
@Email(message = "올바른 이메일 형식이 아닙니다.")
4246
@Schema(description = "이메일 주소", example = "[email protected]", required = true)
43-
private String email; // 이메일
47+
private final String email; // 이메일
48+
49+
@URL(protocol = "https", host = "github.com", message = "GitHub URL이 올바르지 않습니다.")
50+
@Schema(description = "GitHub 주소", example = "https://github.com/username")
51+
private final String githubLink; // 깃허브 주소
52+
53+
@NotBlank(message = "포트폴리오 주소는 필수 입력 값입니다.")
54+
@URL(protocol = "https", message = "포트폴리오 URL이 올바르지 않습니다.")
55+
@Schema(description = "포트폴리오 주소", example = "https://portfolio.com/username", required = true)
56+
private final String portfolioLink; // 포트폴리오 주소
4457
}

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,10 @@ public class SomParticipantResponseDto {
3131

3232
@Schema(description = "이메일 주소", example = "[email protected]", required = true)
3333
private String email; // 이메일
34-
}
34+
35+
@Schema(description = "깃허브 주소", example = "https://github.com/username", required = true)
36+
private String githubLink; // 깃허브 주소
37+
38+
@Schema(description = "포트폴리오 주소", example = "https://portfolio.com/username", required = true)
39+
private String portfolioLink; // 포트폴리오 주소
40+
}

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

Lines changed: 26 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;
@@ -39,12 +40,37 @@ public class SomParticipant extends BaseEntity {
3940
@Column(nullable = false)
4041
private String email; // 이메일
4142

43+
@Column
44+
private String githubLink; // 깃허브 링크
45+
46+
@Column(nullable = false)
47+
private String portfolioLink; // 포트폴리오 링크
48+
4249
public void update(SomParticipantRequestDto requestDto) {
4350
this.participantName = requestDto.getParticipantName();
4451
this.studentId = requestDto.getStudentId();
4552
this.department = requestDto.getDepartment();
4653
this.grade = requestDto.getGrade();
4754
this.contact = requestDto.getContact();
4855
this.email = requestDto.getEmail();
56+
this.githubLink = requestDto.getGithubLink();
57+
this.portfolioLink = requestDto.getPortfolioLink();
58+
}
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();
4975
}
5076
}

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

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -29,19 +29,21 @@ public SomParticipantResponseDto createParticipant(SomParticipantRequestDto requ
2929
.grade(requestDto.getGrade())
3030
.contact(requestDto.getContact())
3131
.email(requestDto.getEmail())
32+
.githubLink(requestDto.getGithubLink())
33+
.portfolioLink(requestDto.getPortfolioLink())
3234
.build();
3335

3436
SomParticipant saved = somParticipantRepository.save(participant);
3537

36-
return toResponseDto(saved);
38+
return saved.toResponseDto(saved);
3739
}
3840

3941
/**
4042
* 모든 참가자 조회 (Read)
4143
*/
4244
public List<SomParticipantResponseDto> getAllParticipants() {
4345
return somParticipantRepository.findAll().stream()
44-
.map(this::toResponseDto)
46+
.map(p -> p.toResponseDto(p))
4547
.collect(Collectors.toList());
4648
}
4749

@@ -51,15 +53,18 @@ public List<SomParticipantResponseDto> getAllParticipants() {
5153
public SomParticipantResponseDto getParticipant(Long id){
5254
SomParticipant participant = findParticipantById(id);
5355

54-
return toResponseDto(participant);
56+
return participant.toResponseDto(participant);
5557
}
5658

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

6065
participant.update(requestDto);
6166

62-
return toResponseDto(participant);
67+
return participant.toResponseDto(participant);
6368
}
6469

6570
/**
@@ -70,22 +75,6 @@ public void deleteParticipant(Long id) {
7075
somParticipantRepository.deleteById(id);
7176
}
7277

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

0 commit comments

Comments
 (0)