Skip to content

Commit

Permalink
refactor: DTO type을 record로 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
U-Geon committed Sep 20, 2024
1 parent 563ec46 commit 191b912
Show file tree
Hide file tree
Showing 18 changed files with 148 additions and 224 deletions.
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
package bootcamp.wssrs.domain.Member.dto.request;

import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Pattern;
import lombok.Getter;
import lombok.Setter;

@Getter @Setter
public class FindMemberRequestDTO {
@Pattern(regexp = "^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}$", message = "올바르지 않은 이메일 형식입니다.")
@NotBlank(message = "이메일을 입력해주세요.")
private String email;
public record FindMemberRequestDTO(
@Pattern(regexp = "^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}$", message = "올바르지 않은 이메일 형식입니다.")
@NotBlank(message = "이메일을 입력해주세요.")
String email,

@NotBlank(message = "학번을 입력해주세요.")
@Pattern(regexp = "^\\d{8}$", message = "올바르지 않은 형식입니다.")
private String studentId;
}
@NotBlank(message = "학번을 입력해주세요.")
@Pattern(regexp = "^\\d{8}$", message = "올바르지 않은 형식입니다.")
String studentId
) {}
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,13 @@

import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.Pattern;
import lombok.Getter;
import lombok.Setter;

@Getter @Setter
public class LoginRequestDTO {
@Pattern(regexp = "^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}$", message = "올바르지 않은 이메일 형식입니다.")
@NotBlank(message = "이메일을 입력해주세요.")
private String email;
public record LoginRequestDTO(
@Pattern(regexp = "^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}$", message = "올바르지 않은 이메일 형식입니다.")
@NotBlank(message = "이메일을 입력해주세요.")
String email,

@Pattern(regexp = "^(?=.*[a-zA-Z])(?=.*\\d)(?=.*[~!@#$%^&*()_+`\\-={}|:\";'<>?,./]).{8,}$", message = "영문자, 숫자, 특수문자를 각각 최소 1개 이상 사용해주세요.")
@NotBlank(message = "비밀번호를 입력해주세요.")
private String password;
}
@Pattern(regexp = "^(?=.*[a-zA-Z])(?=.*\\d)(?=.*[~!@#$%^&*()_+`\\-={}|:\";'<>?,./]).{8,}$", message = "영문자, 숫자, 특수문자를 각각 최소 1개 이상 사용해주세요.")
@NotBlank(message = "비밀번호를 입력해주세요.")
String password
) {}
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
import lombok.Setter;

@Getter @Setter
public class PasswordUpdateRequestDTO {
@Pattern(regexp = "^(?=.*[a-zA-Z])(?=.*\\d)(?=.*[~!@#$%^&*()_+`\\-={}|:\";'<>?,./]).{8,}$", message = "영문자, 숫자, 특수문자를 각각 최소 1개 이상 사용해주세요.")
@NotBlank(message = "비밀번호를 입력해주세요.")
private String newPassword;
}
public record PasswordUpdateRequestDTO(
@Pattern(regexp = "^(?=.*[a-zA-Z])(?=.*\\d)(?=.*[~!@#$%^&*()_+`\\-={}|:\";'<>?,./]).{8,}$", message = "영문자, 숫자, 특수문자를 각각 최소 1개 이상 사용해주세요.")
@NotBlank(message = "비밀번호를 입력해주세요.")
String newPassword
) {}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import lombok.Setter;

@Getter @Setter
public class ReissueAccessTokenRequestDTO {
@NotBlank(message = "토큰이 존재하지 않습니다.")
private String refreshToken;
}
public record ReissueAccessTokenRequestDTO(
@NotBlank(message = "토큰이 존재하지 않습니다.")
String refreshToken
) {}
Original file line number Diff line number Diff line change
@@ -1,26 +1,22 @@
package bootcamp.wssrs.domain.Member.dto.request;

import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Pattern;
import lombok.Getter;
import lombok.Setter;

@Getter @Setter
public class SignupRequestDTO {
@NotBlank(message = "학번을 입력해주세요.")
@Pattern(regexp = "^\\d{8}$", message = "8자리의 숫자만 입력해주세요.")
private String studentId;
public record SignupRequestDTO(
@NotBlank(message = "학번을 입력해주세요.")
@Pattern(regexp = "^\\d{8}$", message = "8자리의 숫자만 입력해주세요.")
String studentId,

@Pattern(regexp = "^(?=.*[a-zA-Z])(?=.*\\d)(?=.*[~!@#$%^&*()_+`\\-={}|:\";'<>?,./]).{8,}$", message = "영문자, 숫자, 특수문자를 각각 최소 1개 이상 사용해주세요.")
@NotBlank(message = "비밀번호를 입력해주세요.")
private String password;
@Pattern(regexp = "^(?=.*[a-zA-Z])(?=.*\\d)(?=.*[~!@#$%^&*()_+`\\-={}|:\";'<>?,./]).{8,}$", message = "영문자, 숫자, 특수문자를 각각 최소 1개 이상 사용해주세요.")
@NotBlank(message = "비밀번호를 입력해주세요.")
String password,

@Pattern(regexp = "^[a-zA-Z가-힣]+$", message = "올바르지 않은 형식입니다.")
@NotBlank(message = "이름을 입력해주세요.")
private String username;
@Pattern(regexp = "^[a-zA-Z가-힣]+$", message = "올바르지 않은 형식입니다.")
@NotBlank(message = "이름을 입력해주세요.")
String username,

@Pattern(regexp = "^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}$", message = "올바르지 않은 이메일 형식입니다.")
@NotBlank(message = "이메일을 입력해주세요.")
private String email;
}
@Pattern(regexp = "^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}$", message = "올바르지 않은 이메일 형식입니다.")
@NotBlank(message = "이메일을 입력해주세요.")
String email
) {}
Original file line number Diff line number Diff line change
@@ -1,16 +1,8 @@
package bootcamp.wssrs.domain.Member.dto.response;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

@Getter @Setter
@NoArgsConstructor
@AllArgsConstructor
public class LoginResponseDTO {
private String accessToken;
private String refreshToken;
private String username;
private String studentId;
}
public record LoginResponseDTO(
String accessToken,
String refreshToken,
String username,
String studentId
) {}
Original file line number Diff line number Diff line change
@@ -1,18 +1,10 @@
package bootcamp.wssrs.domain.Member.dto.response;

import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

@Getter @Setter
@NoArgsConstructor
public class PasswordUpdateResponseDTO {

private String msg;
private String newPassword;

public record PasswordUpdateResponseDTO(
String msg,
String newPassword
) {
public PasswordUpdateResponseDTO(String newPassword) {
this.msg = "ok";
this.newPassword = newPassword;
this("ok", newPassword);
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
package bootcamp.wssrs.domain.Member.dto.response;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.Setter;

@Getter @Setter
@AllArgsConstructor
public class ReissueAccessTokenResponseDTO {
private String newAccessToken;
}
public record ReissueAccessTokenResponseDTO(
String newAccessToken
) {}
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
package bootcamp.wssrs.domain.Member.dto.response;

import bootcamp.wssrs.domain.Member.entity.Member;
import lombok.Getter;
import lombok.Setter;

@Getter @Setter
public class SearchStudentIdResponseDTO {
private String msg;
private String password;

public record SearchStudentIdResponseDTO(
String msg,
String password
) {
public SearchStudentIdResponseDTO(Member member) {
this.msg = "ok";
this.password = member.getPassword();
this("ok", member.getPassword());
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
package bootcamp.wssrs.domain.Member.dto.response;

import lombok.Getter;
import lombok.Setter;

@Getter @Setter
public class SignupResponseDTO {
private String msg;
}
public record SignupResponseDTO(
String msg
) {}
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ public class AuthService {

// 로그인
public LoginResponseDTO login(LoginRequestDTO requestDTO) {
String email = requestDTO.getEmail();
String email = requestDTO.email();
Member member = authRepository.findByEmail(email).orElseThrow(() -> new CustomException(ErrorCode.MEMBER_NOT_FOUND));
if(!passwordEncoder.matches(requestDTO.getPassword(), member.getPassword())) {
if(!passwordEncoder.matches(requestDTO.password(), member.getPassword())) {
throw new CustomException(ErrorCode.INVALID_PASSWORD);
}

Expand Down Expand Up @@ -73,10 +73,10 @@ public Member signUp(SignupRequestDTO requestDTO) {

// 회원 조회
public TokenDTO findMember(FindMemberRequestDTO requestDTO) {
Member member = authRepository.findByEmailAndStudentId(requestDTO.getEmail(), requestDTO.getStudentId())
Member member = authRepository.findByEmailAndStudentId(requestDTO.email(), requestDTO.studentId())
.orElseThrow(() -> new CustomException(ErrorCode.MEMBER_NOT_FOUND));

String accessToken = jwtProvider.createAccessToken(requestDTO.getEmail(), member.getRole().toString());
String accessToken = jwtProvider.createAccessToken(requestDTO.email(), member.getRole().toString());

return new TokenDTO(accessToken);
}
Expand All @@ -86,8 +86,8 @@ public TokenDTO findMember(FindMemberRequestDTO requestDTO) {
public PasswordUpdateResponseDTO updatePassword(String email, PasswordUpdateRequestDTO requestDTO) {
return authRepository.findByEmail(email)
.map(member -> {
member.setPassword(requestDTO.getNewPassword(), passwordEncoder); // 새 비밀번호를 암호화하도록 수정
return new PasswordUpdateResponseDTO(requestDTO.getNewPassword());
member.setPassword(requestDTO.newPassword(), passwordEncoder); // 새 비밀번호를 암호화하도록 수정
return new PasswordUpdateResponseDTO(requestDTO.newPassword());
}).orElseThrow(() -> new CustomException(ErrorCode.MEMBER_NOT_FOUND));
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
package bootcamp.wssrs.domain.Notice.dto.request;

import jakarta.validation.constraints.NotNull;
import lombok.Getter;
import lombok.Setter;

import java.util.List;

@Getter @Setter
public class AdminConfirmRequestDTO {
@NotNull(message = "근무 지원 ID를 선택해주세요.")
private List<Long> recruitIds;
}
public record AdminConfirmRequestDTO(
@NotNull(message = "근무 지원 ID를 선택해주세요.")
List<Long> recruitIds
) {}
Original file line number Diff line number Diff line change
@@ -1,27 +1,22 @@
package bootcamp.wssrs.domain.Notice.dto.request;


import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Pattern;
import lombok.Getter;
import lombok.Setter;

import java.util.List;

@Getter @Setter
public class UserRecruitRequestDTO {
@NotBlank(message = "근무 코드를 입력해주세요.")
private String code;
public record UserRecruitRequestDTO(
@NotBlank(message = "근무 코드를 입력해주세요.")
String code,

@Pattern(regexp = "^(01[016789]-?\\d{3,4}-?\\d{4}|\\d{2,3}-?\\d{3,4}-?\\d{4})$")
@NotBlank(message = "전화번호를 입력해주세요.")
private String phoneNum;
@Pattern(regexp = "^(01[016789]-?\\d{3,4}-?\\d{4}|\\d{2,3}-?\\d{3,4}-?\\d{4})$")
@NotBlank(message = "전화번호를 입력해주세요.")
String phoneNum,

@NotEmpty(message = "근무 날짜를 한 개 이상 선택해주세요.") // @NotBlank는 문자열(String) 타입에만 적용 가능, 컬렉션 객체에 사용.
private List<String> day;
@NotEmpty(message = "근무 날짜를 한 개 이상 선택해주세요.")
List<String> day,

@NotNull(message = "조합원 가입 유무에 체크해주세요.")
private Boolean isUnion; // @NotBlank는 문자열(String) 타입에만 적용 가능
}
@NotNull(message = "조합원 가입 유무에 체크해주세요.")
Boolean isUnion
) {}
Original file line number Diff line number Diff line change
@@ -1,33 +1,25 @@
package bootcamp.wssrs.domain.Notice.dto.response;

import bootcamp.wssrs.domain.Notice.entity.Notice;
import lombok.Getter;
import lombok.Setter;
import org.springframework.data.domain.Page;

import java.time.LocalDateTime;
import java.util.List;

@Getter @Setter
public class AdminFindAllNoticeDTO {
private Long totalCount;
private List<AdminFindAllNoticeInnerClass> notices;

public record AdminFindAllNoticeDTO(
Long totalCount,
List<AdminFindAllNoticeInnerClass> notices
) {
public AdminFindAllNoticeDTO(Long totalCount, Page<Notice> pages) {
this.notices = pages.stream().map(AdminFindAllNoticeInnerClass::new).toList();
this.totalCount = totalCount;
this(totalCount, pages.stream().map(AdminFindAllNoticeInnerClass::new).toList());
}

@Getter @Setter
static class AdminFindAllNoticeInnerClass {
private Long id;
private String title;
private LocalDateTime createdAt;

public record AdminFindAllNoticeInnerClass(
Long id,
String title,
LocalDateTime createdAt
) {
public AdminFindAllNoticeInnerClass(Notice notice) {
this.id = notice.getId();
this.title = notice.getTitle();
this.createdAt = notice.getCreatedAt();
this(notice.getId(), notice.getTitle(), notice.getCreatedAt());
}
}
}
Loading

0 comments on commit 191b912

Please sign in to comment.