Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#318 Feat: 이메일, 비번, 닉네임 수정 가능하게 구현 #319

Merged
merged 1 commit into from
Feb 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.PropertyNamingStrategies;
import com.fasterxml.jackson.databind.annotation.JsonNaming;
import java.time.LocalDate;
import lombok.Builder;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.web.multipart.MultipartFile;

import java.time.LocalDate;

public class MemberRequestDTO {

// 회원가입 요청 DTO
Expand Down Expand Up @@ -64,6 +63,9 @@ public record MemberProfileImageRequestDTO(MultipartFile image) {
@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class)
@Builder
public record MemberInfoDTO(
String email,
String password,
String nickname,
String birth,
String introduction,
String github,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,12 +125,15 @@ public Member(String email, String password, String nickname, String birth, Stri
this.image = new MemberImage(this, "");
}

public void updateInfo(MemberRequestDTO.MemberInfoDTO memberInfo) {
this.birth = memberInfo.birth();
this.introduction = memberInfo.introduction();
this.github = memberInfo.github();
this.linkedin = memberInfo.linkedin();
this.discord = memberInfo.discord();
public void updateInfo(MemberRequestDTO.MemberInfoDTO memberInfo, String password) {
this.nickname = memberInfo.nickname() != null ? memberInfo.nickname() : this.nickname;
this.password = password != null ? password : this.password;
this.email = memberInfo.email() != null ? memberInfo.email() : this.email;
this.birth = memberInfo.birth() != null ? memberInfo.birth() : this.birth;
this.introduction = memberInfo.introduction() != null ? memberInfo.introduction() : this.introduction;
this.github = memberInfo.github() != null ? memberInfo.github() : this.github;
this.linkedin = memberInfo.linkedin() != null ? memberInfo.linkedin() : this.linkedin;
this.discord = memberInfo.discord() != null ? memberInfo.discord() : this.discord;
}

public void setImage(MemberImage image) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.util.UUID;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

Expand All @@ -38,6 +39,7 @@ public class MemberCommandService {
private final AmazonS3Manager s3Manager;
private final MemberImageRepository memberImageRepository;
private final TechStackRepository techStackRepository;
private final PasswordEncoder passwordEncoder;

@Transactional
public Member getRequester() {
Expand Down Expand Up @@ -87,7 +89,8 @@ public ApiResponse<String> deleteProfileImage(Long memberId) {
@Transactional
public Member updateMemberInfo(Long memberId, MemberRequestDTO.MemberInfoDTO request){
Member member = memberRepository.findById(memberId).orElseThrow(() -> new GeneralException(ErrorStatus.MEMBER_NOT_FOUND));
member.updateInfo(request);
String password = request.password() != null ? passwordEncoder.encode(request.password()) : null;
member.updateInfo(request, password);
return memberRepository.save(member);
}

Expand Down
Loading