Skip to content

Commit

Permalink
feat: 스터디 멘토 목록 조회 api 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
Sangwook02 committed Aug 28, 2024
1 parent 12519a9 commit e5b7134
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.gdschongik.gdsc.domain.member.dao;

import com.gdschongik.gdsc.domain.member.domain.Member;
import com.gdschongik.gdsc.domain.member.domain.MemberStudyRole;
import java.util.List;
import java.util.Optional;
import org.springframework.data.jpa.repository.JpaRepository;

Expand All @@ -14,4 +16,6 @@ public interface MemberRepository extends JpaRepository<Member, Long>, MemberCus
Optional<Member> findByDiscordUsername(String discordUsername);

Optional<Member> findByOauthId(String oauthId);

List<Member> findAllByStudyRole(MemberStudyRole studyRole);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.gdschongik.gdsc.domain.study.application.AdminStudyService;
import com.gdschongik.gdsc.domain.study.dto.request.StudyCreateRequest;
import com.gdschongik.gdsc.domain.study.dto.response.StudyMentorResponse;
import com.gdschongik.gdsc.domain.study.dto.response.StudyResponse;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
Expand Down Expand Up @@ -36,4 +37,11 @@ public ResponseEntity<List<StudyResponse>> getStudies() {
List<StudyResponse> response = adminStudyService.getAllStudies();
return ResponseEntity.ok(response);
}

@Operation(summary = "멘토 목록 조회", description = "모든 멘토 목록을 조회합니다. 코어멤버만 접근 가능합니다.")
@GetMapping("/mentors")
public ResponseEntity<List<StudyMentorResponse>> getMentors() {
List<StudyMentorResponse> response = adminStudyService.getAllMentors();
return ResponseEntity.ok(response);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@

import com.gdschongik.gdsc.domain.member.dao.MemberRepository;
import com.gdschongik.gdsc.domain.member.domain.Member;
import com.gdschongik.gdsc.domain.member.domain.MemberStudyRole;
import com.gdschongik.gdsc.domain.study.dao.StudyDetailRepository;
import com.gdschongik.gdsc.domain.study.dao.StudyRepository;
import com.gdschongik.gdsc.domain.study.domain.Study;
import com.gdschongik.gdsc.domain.study.domain.StudyDetail;
import com.gdschongik.gdsc.domain.study.dto.request.StudyCreateRequest;
import com.gdschongik.gdsc.domain.study.dto.response.StudyMentorResponse;
import com.gdschongik.gdsc.domain.study.dto.response.StudyResponse;
import com.gdschongik.gdsc.domain.study.factory.StudyDomainFactory;
import com.gdschongik.gdsc.global.exception.CustomException;
Expand Down Expand Up @@ -60,4 +62,11 @@ private Member getMemberById(Long memberId) {
public List<StudyResponse> getAllStudies() {
return studyRepository.findAll().stream().map(StudyResponse::from).toList();
}

@Transactional(readOnly = true)
public List<StudyMentorResponse> getAllMentors() {
return memberRepository.findAllByStudyRole(MemberStudyRole.MENTOR).stream()
.map(StudyMentorResponse::from)
.toList();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.gdschongik.gdsc.domain.study.dto.response;

import com.gdschongik.gdsc.domain.member.domain.Member;

public record StudyMentorResponse(Long mentorId, String mentorName) {
public static StudyMentorResponse from(Member mentor) {
return new StudyMentorResponse(mentor.getId(), mentor.getName());
}
}

0 comments on commit e5b7134

Please sign in to comment.