-
Notifications
You must be signed in to change notification settings - Fork 0
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
1 parent
bbe81f2
commit ea142bc
Showing
1 changed file
with
10 additions
and
6 deletions.
There are no files selected for viewing
16 changes: 10 additions & 6 deletions
16
...ementExample/src/main/java/com/example/MemberManagementExample/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 |
---|---|---|
@@ -1,29 +1,33 @@ | ||
package com.example.MemberManagementExample.service; | ||
|
||
import com.example.MemberManagementExample.domain.Member; | ||
import com.example.MemberManagementExample.repository.MemoryMemberRepository; | ||
import com.example.MemberManagementExample.repository.MemberRepository; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
public class MemberService { | ||
private final MemoryMemberRepository memoryMemberRepository = new MemoryMemberRepository(); | ||
private final MemberRepository memberRepository; | ||
|
||
public MemberService(MemberRepository memberRepository) { | ||
this.memberRepository = memberRepository; | ||
} | ||
|
||
public Long join(Member member) { | ||
//중복 제거 | ||
memoryMemberRepository.findByName(member.getName()) | ||
memberRepository.findByName(member.getName()) | ||
.ifPresent(member1 -> { | ||
throw new IllegalStateException("이미 존재하는 회원입니다."); | ||
}); | ||
memoryMemberRepository.save(member); | ||
memberRepository.save(member); | ||
return member.getId(); | ||
} | ||
|
||
public List<Member> findMembers() { | ||
return memoryMemberRepository.findAll(); | ||
return memberRepository.findAll(); | ||
} | ||
|
||
public Optional<Member> findOne(Long memberId) { | ||
return memoryMemberRepository.findById(memberId); | ||
return memberRepository.findById(memberId); | ||
} | ||
} |