Skip to content
Merged
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,7 @@ out/
### dev ###
application-dev.yml

# local/dev only
.dev/
docker-compose.yml
init-user.sql
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import jakarta.validation.constraints.Size;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.Setter;
import lombok.NoArgsConstructor;

@Getter
Expand All @@ -15,8 +16,6 @@
@Schema(name = "ExecutiveRequestDto", description = "임원진 요청 DTO")
public class ExecutiveRequestDto {

private Long id;

@NotBlank(message = "임원진 이름은 필수 입력 사항입니다.")
@Size(max = 50, message = "임원진 이름은 최대 50자입니다.")
@Schema(description = "임원진 이름", example = "김다솜")
Expand Down Expand Up @@ -45,7 +44,7 @@ public ExecutiveEntity toEntity() {
.role(this.role)
.githubUsername(this.github_username)
.team(this.team)
.sortOrder(this.sortOrder)
.sortOrder(sortOrder != null ? sortOrder : 9999)
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,15 @@ public void update(ExecutiveUpdateRequestDto dto) {
if (dto.getSortOrder() != null) this.sortOrder = dto.getSortOrder();
}

@PrePersist
public void prePersist() {
if (sortOrder == null) sortOrder = 9999;
}
@PreUpdate
public void preUpdate() {
if (sortOrder == null) sortOrder = 9999;
}

// 엔티티 -> DTO 변환 책임
public ExecutiveResponseDto toResponseDto() {
return ExecutiveResponseDto.builder()
Expand All @@ -67,6 +76,7 @@ public ExecutiveResponseDto toResponseDto() {
.role(this.role)
.github_username(this.githubUsername)
.team(this.team)
.sortOrder(this.sortOrder)
.build();
}

Expand All @@ -79,6 +89,7 @@ public ExecutiveListResponseDto toListResponseDto() {
.role(this.role)
.github_username(this.githubUsername)
.team(this.team)
.sortOrder(this.sortOrder)
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ public List<ExecutiveListResponseDto> getAllExecutives() {

// 임원진 멤버 생성
public ExecutiveCreationResponseDto createExecutive(ExecutiveRequestDto requestDto) {
return new ExecutiveCreationResponseDto(executiveRepository.save(requestDto.toEntity()).getId());
ExecutiveEntity saved = executiveRepository.save(requestDto.toEntity());
return new ExecutiveCreationResponseDto(saved.getId());
}

// 임원진 멤버 삭제
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,40 +5,53 @@
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.Pattern;
import jakarta.validation.constraints.Size;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.validator.constraints.URL;

@Getter
@Setter
@Builder
@AllArgsConstructor
@Schema(description = "솜커톤 참가자 요청 DTO")
public class SomParticipantRequestDto {

@NotBlank(message = "참가자 이름은 필수 입력 값입니다.")
@Size(max = 50, message = "참가자 이름은 최대 50자까지 입력 가능합니다.")
@Schema(description = "참가자 이름", example = "유승완", required = true)
private String participantName; // 참가자 이름
private final String participantName; // 참가자 이름

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

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

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

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

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

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

@NotBlank(message = "포트폴리오 주소는 필수 입력 값입니다.")
@URL(protocol = "https", message = "포트폴리오 URL이 올바르지 않습니다.")
@Schema(description = "포트폴리오 주소", example = "https://portfolio.com/username", required = true)
private final String portfolioLink; // 포트폴리오 주소
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,10 @@ public class SomParticipantResponseDto {

@Schema(description = "이메일 주소", example = "[email protected]", required = true)
private String email; // 이메일
}

@Schema(description = "깃허브 주소", example = "https://github.com/username", required = true)
private String githubLink; // 깃허브 주소

@Schema(description = "포트폴리오 주소", example = "https://portfolio.com/username", required = true)
private String portfolioLink; // 포트폴리오 주소
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SomParticipantService.toResponseDto() 로직을 여기 하단에 추가해주심 됩니다. 엔티티 캡슐화나 책임 분리? 라는 내용으로 찾아보심 될 것 같아요

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

넵 리뷰 감사합니다! 수정 완료했습니다!

Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import dmu.dasom.api.domain.common.BaseEntity;
import dmu.dasom.api.domain.somkathon.dto.SomParticipantRequestDto;
import dmu.dasom.api.domain.somkathon.dto.SomParticipantResponseDto;
import jakarta.persistence.*;
import lombok.AllArgsConstructor;
import lombok.Builder;
Expand Down Expand Up @@ -39,12 +40,37 @@ public class SomParticipant extends BaseEntity {
@Column(nullable = false)
private String email; // 이메일

@Column
private String githubLink; // 깃허브 링크

@Column(nullable = false)
private String portfolioLink; // 포트폴리오 링크

public void update(SomParticipantRequestDto requestDto) {
this.participantName = requestDto.getParticipantName();
this.studentId = requestDto.getStudentId();
this.department = requestDto.getDepartment();
this.grade = requestDto.getGrade();
this.contact = requestDto.getContact();
this.email = requestDto.getEmail();
this.githubLink = requestDto.getGithubLink();
this.portfolioLink = requestDto.getPortfolioLink();
}

/**
* Entity → Response DTO 변환 메서드
*/
public SomParticipantResponseDto toResponseDto(SomParticipant participant) {
return SomParticipantResponseDto.builder()
.id(participant.getId())
.participantName(participant.getParticipantName())
.studentId(participant.getStudentId())
.department(participant.getDepartment())
.grade(participant.getGrade())
.contact(participant.getContact())
.email(participant.getEmail())
.githubLink(participant.getGithubLink())
.portfolioLink(participant.getPortfolioLink())
.build();
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/**
 * Entity → Response DTO 변환 메서드
 */
private SomParticipantResponseDto toResponseDto(SomParticipant participant) {
    return SomParticipantResponseDto.builder()
            .id(participant.getId())
            .participantName(participant.getParticipantName())
            .studentId(participant.getStudentId())
            .department(participant.getDepartment())
            .grade(participant.getGrade())
            .contact(participant.getContact())
            .email(participant.getEmail())
            .githubLink(participant.getGithubLink())
            .portfolioLink(participant.getPortfolioLink())
            .build();

이 부분을 서비스단에서 처리하는게 아니라 엔티티 단계에서 처리하도록 수정해주세요!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

넵 리뷰 감사합니다! 수정 완료했습니다!

Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,21 @@ public SomParticipantResponseDto createParticipant(SomParticipantRequestDto requ
.grade(requestDto.getGrade())
.contact(requestDto.getContact())
.email(requestDto.getEmail())
.githubLink(requestDto.getGithubLink())
.portfolioLink(requestDto.getPortfolioLink())
.build();

SomParticipant saved = somParticipantRepository.save(participant);

return toResponseDto(saved);
return saved.toResponseDto(saved);
}

/**
* 모든 참가자 조회 (Read)
*/
public List<SomParticipantResponseDto> getAllParticipants() {
return somParticipantRepository.findAll().stream()
.map(this::toResponseDto)
.map(p -> p.toResponseDto(p))
.collect(Collectors.toList());
}

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

return toResponseDto(participant);
return participant.toResponseDto(participant);
}

/**
* 참가자 수정 (Put)
*/
public SomParticipantResponseDto updateParticipant(Long id, SomParticipantRequestDto requestDto){
SomParticipant participant = findParticipantById(id);

participant.update(requestDto);

return toResponseDto(participant);
return participant.toResponseDto(participant);
}

/**
Expand All @@ -70,22 +75,6 @@ public void deleteParticipant(Long id) {
somParticipantRepository.deleteById(id);
}


/**
* Entity → Response DTO 변환 메서드
*/
private SomParticipantResponseDto toResponseDto(SomParticipant participant) {
return SomParticipantResponseDto.builder()
.id(participant.getId())
.participantName(participant.getParticipantName())
.studentId(participant.getStudentId())
.department(participant.getDepartment())
.grade(participant.getGrade())
.contact(participant.getContact())
.email(participant.getEmail())
.build();
}

/**
* ID로 참가자 조회 (공통 처리)
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ void createExecutive_success() {
// given
Long id = 1L;
ExecutiveRequestDto dto = new ExecutiveRequestDto(
id,
"김다솜",
"회장",
"동아리 운영 총괄",
Expand Down
Loading
Loading