From 6c3d794cd011f27c0a00f706da81be6c334ea1b9 Mon Sep 17 00:00:00 2001 From: JungTae Kwon Date: Thu, 8 Aug 2024 17:26:20 +0900 Subject: [PATCH 1/2] docs: Add CI issue template --- .../\342\231\273\357\270\217--refactor-.md" | 34 +++++++++---------- .../ISSUE_TEMPLATE/\342\234\250--feat--.md" | 34 +++++++++---------- .../ISSUE_TEMPLATE/\360\237\220\233--bug-.md" | 34 +++++++++---------- .../ISSUE_TEMPLATE/\360\237\222\232--ci-.md" | 27 +++++++++------ 4 files changed, 68 insertions(+), 61 deletions(-) diff --git "a/.github/ISSUE_TEMPLATE/\342\231\273\357\270\217--refactor-.md" "b/.github/ISSUE_TEMPLATE/\342\231\273\357\270\217--refactor-.md" index 1487b7e..815b8ef 100644 --- "a/.github/ISSUE_TEMPLATE/\342\231\273\357\270\217--refactor-.md" +++ "b/.github/ISSUE_TEMPLATE/\342\231\273\357\270\217--refactor-.md" @@ -1,17 +1,17 @@ ---- -name: "♻️ [REFACTOR]" -about: 리팩토링 이슈 템플릿입니다. -title: "♻️ [REFACTOR]" -labels: "\U0001F41B bug, ♻️ refactor" -assignees: oxdjww - ---- - -# Title -- tmp - -# Content -- tmp - -# TODO -- [ ] tmp +--- +name: "♻️ [REFACTOR]" +about: 리팩토링 이슈 템플릿입니다. +title: "♻️ [REFACTOR]" +labels: '' +assignees: oxdjww + +--- + +# Title +- tmp + +# Content +- tmp + +# TODO +- [ ] tmp diff --git "a/.github/ISSUE_TEMPLATE/\342\234\250--feat--.md" "b/.github/ISSUE_TEMPLATE/\342\234\250--feat--.md" index 1dcb624..c04e767 100644 --- "a/.github/ISSUE_TEMPLATE/\342\234\250--feat--.md" +++ "b/.github/ISSUE_TEMPLATE/\342\234\250--feat--.md" @@ -1,17 +1,17 @@ ---- -name: "✨ [FEAT] " -about: 기능 개발 이슈 템플릿입니다. -title: "✨ [FEAT] " -labels: "✨ feature" -assignees: '' - ---- - -# Title -- tmp - -# Content -- tmp - -# TODO -- [ ] tmp +--- +name: "✨ [FEAT] " +about: 기능 개발 이슈 템플릿입니다. +title: "✨ [FEAT] " +labels: '' +assignees: '' + +--- + +# Title +- tmp + +# Content +- tmp + +# TODO +- [ ] tmp diff --git "a/.github/ISSUE_TEMPLATE/\360\237\220\233--bug-.md" "b/.github/ISSUE_TEMPLATE/\360\237\220\233--bug-.md" index fa0ee94..8d36cc4 100644 --- "a/.github/ISSUE_TEMPLATE/\360\237\220\233--bug-.md" +++ "b/.github/ISSUE_TEMPLATE/\360\237\220\233--bug-.md" @@ -1,17 +1,17 @@ ---- -name: "\U0001F41B [BUG]" -about: 버그 이슈 템플릿입니다. -title: "\U0001F41B [BUG]" -labels: "\U0001F41B bug" -assignees: '' - ---- - -# Title -- tmp - -# Content -- tmp - -# TODO -- [ ] tmp +--- +name: "\U0001F41B [BUG]" +about: 버그 이슈 템플릿입니다. +title: "\U0001F41B [BUG]" +labels: '' +assignees: '' + +--- + +# Title +- tmp + +# Content +- tmp + +# TODO +- [ ] tmp diff --git "a/.github/ISSUE_TEMPLATE/\360\237\222\232--ci-.md" "b/.github/ISSUE_TEMPLATE/\360\237\222\232--ci-.md" index 46176da..134e1bf 100644 --- "a/.github/ISSUE_TEMPLATE/\360\237\222\232--ci-.md" +++ "b/.github/ISSUE_TEMPLATE/\360\237\222\232--ci-.md" @@ -1,10 +1,17 @@ ---- -name: "\U0001F49A [CI]" -about: CI 이슈 템플릿입니다 -title: "\U0001F49A [CI]" -labels: "\U0001F49A CI" -assignees: '' - ---- - - +--- +name: "\U0001F49A [CI]" +about: CI 이슈 템플릿입니다 +title: "\U0001F49A [CI]" +labels: '' +assignees: '' + +--- + +# Title +- tmp + +# Content +- tmp + +# TODO +- [ ] tmp From 989b0dfebc2f427212a52e8b9d0d3c10f69e346c Mon Sep 17 00:00:00 2001 From: oxdjww Date: Sat, 10 Aug 2024 01:23:07 +0900 Subject: [PATCH 2/2] =?UTF-8?q?feat:=20=EB=A9=98=ED=86=A0=20=EC=83=81?= =?UTF-8?q?=EC=84=B8=20=EC=A0=95=EB=B3=B4=20=EC=A1=B0=ED=9A=8C=20API=20?= =?UTF-8?q?=EA=B0=9C=EB=B0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/Exception/CustomException.java | 13 +++ .../Exception/enums/MentorErrorCode.java | 18 +++++ .../controller/MentorController.java | 81 +++++++++++-------- .../soongsil/CoffeeChat/dto/MentorDto.java | 7 +- .../CoffeeChat/dto/ResponseMentorInfo.java | 33 ++++++++ .../CoffeeChat/entity/Introduction.java | 2 + .../soongsil/CoffeeChat/entity/Mentor.java | 23 +++--- .../CoffeeChat/service/MentorService.java | 32 +++++--- 8 files changed, 152 insertions(+), 57 deletions(-) create mode 100644 src/main/java/com/soongsil/CoffeeChat/controller/Exception/CustomException.java create mode 100644 src/main/java/com/soongsil/CoffeeChat/controller/Exception/enums/MentorErrorCode.java create mode 100644 src/main/java/com/soongsil/CoffeeChat/dto/ResponseMentorInfo.java diff --git a/src/main/java/com/soongsil/CoffeeChat/controller/Exception/CustomException.java b/src/main/java/com/soongsil/CoffeeChat/controller/Exception/CustomException.java new file mode 100644 index 0000000..3bd24eb --- /dev/null +++ b/src/main/java/com/soongsil/CoffeeChat/controller/Exception/CustomException.java @@ -0,0 +1,13 @@ +package com.soongsil.CoffeeChat.controller.Exception; + +import org.springframework.http.HttpStatusCode; + +import lombok.Getter; +import lombok.RequiredArgsConstructor; + +@Getter +@RequiredArgsConstructor +public class CustomException extends RuntimeException{ + private final HttpStatusCode errorCode; + private final String errorMessage; +} diff --git a/src/main/java/com/soongsil/CoffeeChat/controller/Exception/enums/MentorErrorCode.java b/src/main/java/com/soongsil/CoffeeChat/controller/Exception/enums/MentorErrorCode.java new file mode 100644 index 0000000..a4c2b25 --- /dev/null +++ b/src/main/java/com/soongsil/CoffeeChat/controller/Exception/enums/MentorErrorCode.java @@ -0,0 +1,18 @@ +package com.soongsil.CoffeeChat.controller.Exception.enums; + +import org.springframework.http.HttpStatus; +import org.springframework.http.HttpStatusCode; + +import lombok.Getter; +import lombok.RequiredArgsConstructor; + +@Getter +@RequiredArgsConstructor +public enum MentorErrorCode { + // 400 + MEMBER_NOT_FOUND(HttpStatus.NOT_FOUND, "MENTOR_404", "멘토를 찾을 수 없습니다."); + + private final HttpStatusCode httpStatusCode; + private final String errorCode; + private final String errorMessage; +} diff --git a/src/main/java/com/soongsil/CoffeeChat/controller/MentorController.java b/src/main/java/com/soongsil/CoffeeChat/controller/MentorController.java index 13e28bb..66c3145 100644 --- a/src/main/java/com/soongsil/CoffeeChat/controller/MentorController.java +++ b/src/main/java/com/soongsil/CoffeeChat/controller/MentorController.java @@ -5,7 +5,9 @@ import java.util.List; import com.soongsil.CoffeeChat.dto.Oauth.CustomOAuth2User; +import com.soongsil.CoffeeChat.dto.ResponseMentorInfo; import com.soongsil.CoffeeChat.entity.Mentor; + import org.springframework.http.ResponseEntity; import org.springframework.security.core.Authentication; import org.springframework.web.bind.annotation.*; @@ -20,46 +22,55 @@ @RequestMapping(MENTOR_URI) @RestController -@Tag(name="MENTOR", description = "멘토 관련 api") +@Tag(name = "MENTOR", description = "멘토 관련 api") public class MentorController { - private final MentorService mentorService; - public MentorController(MentorService mentorService){ - this.mentorService=mentorService; - } + private final MentorService mentorService; + + public MentorController(MentorService mentorService) { + this.mentorService = mentorService; + } + + private String getUserNameByAuthentication(Authentication authentication) throws Exception { + CustomOAuth2User principal = (CustomOAuth2User)authentication.getPrincipal(); + if (principal == null) + throw new Exception(); //TODO : Exception 만들기 + return principal.getUsername(); + } - private String getUserNameByAuthentication(Authentication authentication) throws Exception { - CustomOAuth2User principal= (CustomOAuth2User)authentication.getPrincipal(); - if(principal==null) throw new Exception(); //TODO : Exception 만들기 - return principal.getUsername(); - } + @GetMapping("/{mentorId}") + @Operation(summary = "멘토 상세 정보 조회") + @ApiResponse(responseCode = "200", description = "멘토 상세 정보 DTO 반환") + public ResponseEntity getMentorInfo(@PathVariable("mentorId") Long mentorId) { + return ResponseEntity.ok().body(mentorService.getMentorDtobyId(mentorId)); + } - @GetMapping("/{part}") - @Operation(summary="파트별 멘토 리스트 가져오기") - @ApiResponse(responseCode = "200", description = "DTO LIST형식으로 정보 반환") - public ResponseEntity> getMentorListByPart(@PathVariable("part") int part){ - return ResponseEntity.ok().body(mentorService.getMentorDtoListByPart(part)); - } + @GetMapping("/{part}") + @Operation(summary = "파트별 멘토 리스트 가져오기") + @ApiResponse(responseCode = "200", description = "DTO LIST형식으로 정보 반환") + public ResponseEntity> getMentorListByPart(@PathVariable("part") int part) { + return ResponseEntity.ok().body(mentorService.getMentorDtoListByPart(part)); + } - @GetMapping("/{club}") - @Operation(summary="동아리별 멘토 리스트 가져오기") - @ApiResponse(responseCode = "200", description = "DTO LIST형식으로 정보 반환") - public ResponseEntity> getMentorListByClub(@PathVariable("club") int club){ - return ResponseEntity.ok().body(mentorService.getMentorDtoListByClub(club)); - } + @GetMapping("/{club}") + @Operation(summary = "동아리별 멘토 리스트 가져오기") + @ApiResponse(responseCode = "200", description = "DTO LIST형식으로 정보 반환") + public ResponseEntity> getMentorListByClub(@PathVariable("club") int club) { + return ResponseEntity.ok().body(mentorService.getMentorDtoListByClub(club)); + } - @GetMapping("/{part}/{club}") - @Operation(summary="파트+동아리별 멘토 리스트 가져오기") - @ApiResponse(responseCode = "200", description = "DTO LIST형식으로 정보 반환") - public ResponseEntity> getMentorListByClub(@PathVariable("part") int part, - @PathVariable("club") int club){ - return ResponseEntity.ok().body(mentorService.getMentorDtoListByPartAndClub(part, club)); - } + @GetMapping("/{part}/{club}") + @Operation(summary = "파트+동아리별 멘토 리스트 가져오기") + @ApiResponse(responseCode = "200", description = "DTO LIST형식으로 정보 반환") + public ResponseEntity> getMentorListByClub(@PathVariable("part") int part, + @PathVariable("club") int club) { + return ResponseEntity.ok().body(mentorService.getMentorDtoListByPartAndClub(part, club)); + } - @GetMapping("/possibleDates/{username}") - @Operation(summary="멘토의 username으로 커피챗가능시간 불러오기") - @ApiResponse(responseCode = "200", description = "DTO LIST형식으로 정보 반환") - public ResponseEntity> getPossibleDates(@PathVariable("username") String username){ - return ResponseEntity.ok().body(mentorService.findPossibleDateListByMentor(username)); - } + @GetMapping("/possibleDates/{username}") + @Operation(summary = "멘토의 username으로 커피챗가능시간 불러오기") + @ApiResponse(responseCode = "200", description = "DTO LIST형식으로 정보 반환") + public ResponseEntity> getPossibleDates(@PathVariable("username") String username) { + return ResponseEntity.ok().body(mentorService.findPossibleDateListByMentor(username)); + } } diff --git a/src/main/java/com/soongsil/CoffeeChat/dto/MentorDto.java b/src/main/java/com/soongsil/CoffeeChat/dto/MentorDto.java index acde99f..6636466 100644 --- a/src/main/java/com/soongsil/CoffeeChat/dto/MentorDto.java +++ b/src/main/java/com/soongsil/CoffeeChat/dto/MentorDto.java @@ -1,11 +1,14 @@ package com.soongsil.CoffeeChat.dto; +import com.soongsil.CoffeeChat.enums.ClubEnum; +import com.soongsil.CoffeeChat.enums.PartEnum; + import lombok.Getter; import lombok.Setter; @Getter @Setter public class MentorDto { - private int part; - private int club; + private PartEnum part; + private ClubEnum club; } diff --git a/src/main/java/com/soongsil/CoffeeChat/dto/ResponseMentorInfo.java b/src/main/java/com/soongsil/CoffeeChat/dto/ResponseMentorInfo.java new file mode 100644 index 0000000..c28ce8e --- /dev/null +++ b/src/main/java/com/soongsil/CoffeeChat/dto/ResponseMentorInfo.java @@ -0,0 +1,33 @@ +package com.soongsil.CoffeeChat.dto; + +import com.soongsil.CoffeeChat.entity.Mentor; +import com.soongsil.CoffeeChat.entity.User; + +import lombok.Builder; +import lombok.Getter; + +@Getter +@Builder +public class ResponseMentorInfo { + Long mentorId; + String mentorName; + String part; + String introductionTitle; + String introductionDescription; + String introductionAnswer1; + String introductionAnswer2; + String imageUrl; + + public static ResponseMentorInfo of(Mentor mentor, User user) { + return ResponseMentorInfo.builder() + .mentorId(mentor.getId()) + .mentorName(user.getName()) + .imageUrl(user.getPicture()) + .part(String.valueOf(mentor.getPart())) + .introductionTitle(mentor.getIntroduction().getTitle()) + .introductionDescription(mentor.getIntroduction().getDescription()) + .introductionAnswer1(mentor.getIntroduction().getAnswer1()) + .introductionAnswer2(mentor.getIntroduction().getAnswer2()) + .build(); + } +} diff --git a/src/main/java/com/soongsil/CoffeeChat/entity/Introduction.java b/src/main/java/com/soongsil/CoffeeChat/entity/Introduction.java index da08d62..cd9b362 100644 --- a/src/main/java/com/soongsil/CoffeeChat/entity/Introduction.java +++ b/src/main/java/com/soongsil/CoffeeChat/entity/Introduction.java @@ -1,8 +1,10 @@ package com.soongsil.CoffeeChat.entity; import jakarta.persistence.*; +import lombok.Getter; @Entity +@Getter public class Introduction { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "introduction_id") diff --git a/src/main/java/com/soongsil/CoffeeChat/entity/Mentor.java b/src/main/java/com/soongsil/CoffeeChat/entity/Mentor.java index fdf3e62..39befbd 100644 --- a/src/main/java/com/soongsil/CoffeeChat/entity/Mentor.java +++ b/src/main/java/com/soongsil/CoffeeChat/entity/Mentor.java @@ -4,6 +4,9 @@ import java.util.Set; import com.soongsil.CoffeeChat.dto.MentorDto; +import com.soongsil.CoffeeChat.dto.ResponseMentorInfo; +import com.soongsil.CoffeeChat.enums.ClubEnum; +import com.soongsil.CoffeeChat.enums.PartEnum; import jakarta.persistence.*; import lombok.*; @@ -14,7 +17,7 @@ @Builder @Getter @Setter -@ToString(of = {"id","part", "club"}) +@ToString(of = {"id", "part", "club"}) //@DiscriminatorValue("mentor") //@PrimaryKeyJoinColumn(name = "mentor_id") public class Mentor { @@ -24,10 +27,12 @@ public class Mentor { private Long id; @Column - private int part; + @Enumerated(EnumType.STRING) + private PartEnum part; @Column - private int club; + @Enumerated(EnumType.STRING) + private ClubEnum club; @OneToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY) @JoinColumn(name = "mentor_introduction", referencedColumnName = "introduction_id") @@ -42,16 +47,16 @@ public class Mentor { private Set possibleDates = new HashSet<>(); @Builder - public Mentor(int club, int part) { - this.club=club; - this.part = part; + public Mentor(String club, String part) { + this.club = ClubEnum.valueOf(club); + this.part = PartEnum.valueOf(part); } public static Mentor from(MentorDto dto) { return Mentor.builder() - .club(dto.getClub()) - .part(dto.getPart()) - .build(); + .club(dto.getClub()) + .part(dto.getPart()) + .build(); } public void addPossibleDate(PossibleDate possibleDate) { diff --git a/src/main/java/com/soongsil/CoffeeChat/service/MentorService.java b/src/main/java/com/soongsil/CoffeeChat/service/MentorService.java index a9ef1fe..db146c1 100644 --- a/src/main/java/com/soongsil/CoffeeChat/service/MentorService.java +++ b/src/main/java/com/soongsil/CoffeeChat/service/MentorService.java @@ -2,31 +2,29 @@ import java.util.List; - -import com.soongsil.CoffeeChat.repository.PossibleDate.PossibleDateRepository; -import jakarta.transaction.Transactional; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import com.soongsil.CoffeeChat.controller.Exception.CustomException; +import com.soongsil.CoffeeChat.controller.Exception.enums.MentorErrorCode; import com.soongsil.CoffeeChat.dto.PossibleDateRequestDto; +import com.soongsil.CoffeeChat.dto.ResponseMentorInfo; import com.soongsil.CoffeeChat.dto.ResponseMentorListInfo; import com.soongsil.CoffeeChat.entity.Mentor; -import com.soongsil.CoffeeChat.entity.User; import com.soongsil.CoffeeChat.repository.Mentor.MentorRepository; +import com.soongsil.CoffeeChat.repository.PossibleDate.PossibleDateRepository; import com.soongsil.CoffeeChat.repository.User.UserRepository; +import lombok.RequiredArgsConstructor; + @Service +@RequiredArgsConstructor +@Transactional(readOnly = true) public class MentorService { private final MentorRepository mentorRepository; private final UserRepository userRepository; private final PossibleDateRepository possibleDateRepository; - public MentorService(MentorRepository mentorRepository, - UserRepository userRepository, PossibleDateRepository possibleDateRepository) { - this.mentorRepository = mentorRepository; - this.userRepository = userRepository; - this.possibleDateRepository=possibleDateRepository; - } - public List getMentorDtoListByPart(int part) { return mentorRepository.getMentorListByPart(part); //일반join } @@ -42,4 +40,16 @@ public List getMentorDtoListByPartAndClub(int part, int public List findPossibleDateListByMentor(String username) { return possibleDateRepository.getPossibleDatesByUsername(username); } + + public ResponseMentorInfo getMentorDtobyId(Long mentorId) { + Mentor findMentor = mentorRepository.findById(mentorId) + .orElseThrow(() -> new CustomException( + MentorErrorCode.MEMBER_NOT_FOUND.getHttpStatusCode(), + MentorErrorCode.MEMBER_NOT_FOUND.getErrorMessage()) + ); + return ResponseMentorInfo.of( + findMentor, + userRepository.findByMentor(findMentor) + ); + } }