Skip to content

Commit

Permalink
멤버 리포지토리를 외부에서 바꿔주도록 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
Yoochanhong committed Mar 19, 2023
1 parent bbe81f2 commit ea142bc
Showing 1 changed file with 10 additions and 6 deletions.
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);
}
}

0 comments on commit ea142bc

Please sign in to comment.