From a025c6e3946847e7c7b431c0a52c15170f25a700 Mon Sep 17 00:00:00 2001 From: taejin1221 Date: Mon, 2 Sep 2024 15:26:26 +0900 Subject: [PATCH] =?UTF-8?q?Feat:=20/api/auth/member=20=EA=B4=80=EB=A0=A8?= =?UTF-8?q?=20MemberService=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Related to: #2 --- .../kaboo_auth/domain/entity/Member.java | 11 ++++ .../repository/MemberRepository.java | 5 ++ .../kaboo_auth/service/MemberService.java | 51 +++++++++++++++++++ 3 files changed, 67 insertions(+) diff --git a/src/main/java/kaboo/kaboo_auth/domain/entity/Member.java b/src/main/java/kaboo/kaboo_auth/domain/entity/Member.java index 2af74bf..bbd68c9 100644 --- a/src/main/java/kaboo/kaboo_auth/domain/entity/Member.java +++ b/src/main/java/kaboo/kaboo_auth/domain/entity/Member.java @@ -53,4 +53,15 @@ public Member(String username, String email, String koreaName, String englishNam this.course = course; this.role = role; } + + public void updateInfo(String koreaName, String englishName, int classNum, Course course) { + this.koreaName = koreaName; + this.englishName = englishName; + this.classNum = classNum; + this.course = course; + } + + public void updateIntroduce(String introduce) { + this.introduce = introduce; + } } diff --git a/src/main/java/kaboo/kaboo_auth/repository/MemberRepository.java b/src/main/java/kaboo/kaboo_auth/repository/MemberRepository.java index 4893242..22b742d 100644 --- a/src/main/java/kaboo/kaboo_auth/repository/MemberRepository.java +++ b/src/main/java/kaboo/kaboo_auth/repository/MemberRepository.java @@ -1,5 +1,6 @@ package kaboo.kaboo_auth.repository; +import java.util.List; import java.util.Optional; import org.springframework.data.jpa.repository.JpaRepository; @@ -8,4 +9,8 @@ public interface MemberRepository extends JpaRepository { Optional findByUsername(String username); + + List findByClassNum(int classNum); + + Optional findByKoreaName(String koreaName); } diff --git a/src/main/java/kaboo/kaboo_auth/service/MemberService.java b/src/main/java/kaboo/kaboo_auth/service/MemberService.java index af06403..91efc45 100644 --- a/src/main/java/kaboo/kaboo_auth/service/MemberService.java +++ b/src/main/java/kaboo/kaboo_auth/service/MemberService.java @@ -1,7 +1,14 @@ package kaboo.kaboo_auth.service; +import java.util.List; + import org.springframework.stereotype.Service; +import kaboo.kaboo_auth.domain.dto.request.MemberInfoUpdateRequest; +import kaboo.kaboo_auth.domain.dto.request.MemberIntroduceUpdateRequest; +import kaboo.kaboo_auth.domain.dto.response.MemberInfoResponse; +import kaboo.kaboo_auth.domain.dto.response.MemberIntroduceResponse; +import kaboo.kaboo_auth.domain.dto.response.MemberListResponse; import kaboo.kaboo_auth.domain.entity.Member; import kaboo.kaboo_auth.repository.MemberRepository; import lombok.RequiredArgsConstructor; @@ -16,4 +23,48 @@ public Member getMemberByUsername(String username) { new IllegalStateException("존재하지 않는 ID 입니다.") ); } + + public MemberListResponse getAllMembers() { + List members = memberRepository.findAll(); + return new MemberListResponse(members, 0); + } + + public MemberListResponse getMembersByClassNum(int classNum) { + List members = memberRepository.findByClassNum(classNum); + return new MemberListResponse(members, classNum); + } + + public MemberInfoResponse getMemberInfoByKoreaName(String koreaName) { + return new MemberInfoResponse( + memberRepository.findByKoreaName(koreaName) + .orElseThrow(() -> new IllegalStateException(koreaName + "을 찾을 수 없습니다. 다시 한번 확인해주세요."))); + } + + public MemberInfoResponse updateMemberInfoByKoreaName(String koreaName, MemberInfoUpdateRequest request) { + Member member = memberRepository.findByKoreaName(koreaName) + .orElseThrow(() -> new IllegalStateException(koreaName + "을 찾을 수 없습니다. 다시 한번 확인해주세요.")); + + member.updateInfo(request.getKoreaName(), request.getEnglishName(), request.getClassNum(), request.getCourse()); + + memberRepository.save(member); + + return new MemberInfoResponse(member); + } + + public MemberIntroduceResponse getMemberIntroduceByKoreaName(String koreaName) { + return new MemberIntroduceResponse( + memberRepository.findByKoreaName(koreaName) + .orElseThrow(() -> new IllegalStateException(koreaName + "을 찾을 수 없습니다. 다시 한번 확인해주세요."))); + } + + public MemberIntroduceResponse updateMemberIntroduceByKoreaName(String koreaName, + MemberIntroduceUpdateRequest request) { + Member member = memberRepository.findByKoreaName(koreaName) + .orElseThrow(() -> new IllegalStateException(koreaName + "을 찾을 수 없습니다. 다시 한번 확인해주세요.")); + member.updateIntroduce(request.getIntroduce()); + + memberRepository.save(member); + + return new MemberIntroduceResponse(member); + } }