-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMemberService.java
51 lines (42 loc) · 1.86 KB
/
MemberService.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package team05.integrated_feed_backend.module.member.service;
import static team05.integrated_feed_backend.common.code.StatusCode.*;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import lombok.RequiredArgsConstructor;
import team05.integrated_feed_backend.exception.custom.DuplicateResourceException;
import team05.integrated_feed_backend.module.member.dto.request.MemberSignupReq;
import team05.integrated_feed_backend.module.member.entity.Member;
import team05.integrated_feed_backend.module.member.entity.vo.Email;
import team05.integrated_feed_backend.module.member.event.publisher.MemberEventPublisher;
import team05.integrated_feed_backend.module.member.repository.MemberRepository;
@Service
@Transactional(readOnly = true)
@RequiredArgsConstructor
public class MemberService {
private final PasswordEncoder passwordEncoder;
private final MemberRepository memberRepository;
private final MemberEventPublisher memberEventPublisher;
@Transactional
public void signUp(MemberSignupReq request) {
// 계정 중복 검사
validateAccountUnique(request.account());
// 이메일 중복 검사
validateEmailUnique(request.email());
// 회원 생성 및 저장
Member member = Member.signUp(request.account(), request.password(), request.email(), passwordEncoder);
memberRepository.save(member);
// 회원 가입 완료 이벤트 생성
memberEventPublisher.publishSignedUpEvent(member);
}
private void validateAccountUnique(String account) {
if (memberRepository.existsByAccount(account)) {
throw new DuplicateResourceException(DUPLICATE_ACCOUNT);
}
}
private void validateEmailUnique(String email) {
if (memberRepository.existsByEmail(Email.from(email))) {
throw new DuplicateResourceException(DUPLICATE_EMAIL);
}
}
}