Skip to content

Commit

Permalink
Feat: /api/auth/member 관련 MemberService 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
Taejin1221 committed Sep 2, 2024
1 parent 3a59994 commit a025c6e
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/main/java/kaboo/kaboo_auth/domain/entity/Member.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package kaboo.kaboo_auth.repository;

import java.util.List;
import java.util.Optional;

import org.springframework.data.jpa.repository.JpaRepository;
Expand All @@ -8,4 +9,8 @@

public interface MemberRepository extends JpaRepository<Member, Long> {
Optional<Member> findByUsername(String username);

List<Member> findByClassNum(int classNum);

Optional<Member> findByKoreaName(String koreaName);
}
51 changes: 51 additions & 0 deletions src/main/java/kaboo/kaboo_auth/service/MemberService.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -16,4 +23,48 @@ public Member getMemberByUsername(String username) {
new IllegalStateException("존재하지 않는 ID 입니다.")
);
}

public MemberListResponse getAllMembers() {
List<Member> members = memberRepository.findAll();
return new MemberListResponse(members, 0);
}

public MemberListResponse getMembersByClassNum(int classNum) {
List<Member> 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);
}
}

0 comments on commit a025c6e

Please sign in to comment.