-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
48 additions
and
23 deletions.
There are no files selected for viewing
23 changes: 0 additions & 23 deletions
23
src/main/java/com/example/wonderwoman/mail/service/MemberService.java
This file was deleted.
Oops, something went wrong.
48 changes: 48 additions & 0 deletions
48
src/main/java/com/example/wonderwoman/member/service/MemberService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package com.example.wonderwoman.member.service; | ||
|
||
import com.example.wonderwoman.auth.service.AuthService; | ||
import com.example.wonderwoman.exception.ErrorCode; | ||
import com.example.wonderwoman.exception.WonderException; | ||
import com.example.wonderwoman.member.entity.Member; | ||
import com.example.wonderwoman.member.repository.MemberRepository; | ||
import com.example.wonderwoman.member.request.ChangeMemberInfoRequest; | ||
import com.example.wonderwoman.member.response.MemberResponseDto; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.security.crypto.password.PasswordEncoder; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
@Transactional(readOnly = true) | ||
public class MemberService { | ||
private final MemberRepository memberRepository; | ||
|
||
private final PasswordEncoder passwordEncoder; | ||
|
||
private final AuthService authService; | ||
|
||
public MemberResponseDto getMyInfo(Member currentMember) { | ||
return memberRepository.findById(currentMember.getId()) | ||
.map(MemberResponseDto::of) | ||
.orElseThrow(() -> new WonderException(ErrorCode.MEMBER_NOT_FOUND)); | ||
} | ||
|
||
@Transactional | ||
public void changeMemberInfo(Member member, ChangeMemberInfoRequest request) { | ||
if (authService.findMemberByNickname(request.getNickname())) | ||
throw new WonderException(ErrorCode.DUPLICATE_NICKNAME); | ||
|
||
member.updateNickname(request.getNickname()); | ||
|
||
if (request.getPassword() != null) | ||
member.updatePassword(passwordEncoder.encode(request.getPassword())); | ||
|
||
member.updateImage(request.getImgUrl()); | ||
memberRepository.save(member); | ||
} | ||
|
||
public Member findByEmail(String email) { | ||
return memberRepository.findByEmail(email).orElseThrow(() -> new RuntimeException("가입되지 않은 이메일입니다")); | ||
} | ||
} |