Skip to content

Commit

Permalink
Merge pull request #92 from Soongsil-CoffeeChat/refactor/#91
Browse files Browse the repository at this point in the history
feat: 멘토 상세 정보 조회 API 개발
  • Loading branch information
KimKyoHwee authored Aug 10, 2024
2 parents 9e7fc42 + db6cbcc commit a698959
Show file tree
Hide file tree
Showing 12 changed files with 217 additions and 116 deletions.
34 changes: 17 additions & 17 deletions .github/ISSUE_TEMPLATE/♻️--refactor-.md
Original file line number Diff line number Diff line change
@@ -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
34 changes: 17 additions & 17 deletions .github/ISSUE_TEMPLATE/✨--feat--.md
Original file line number Diff line number Diff line change
@@ -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
34 changes: 17 additions & 17 deletions .github/ISSUE_TEMPLATE/🐛--bug-.md
Original file line number Diff line number Diff line change
@@ -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
27 changes: 17 additions & 10 deletions .github/ISSUE_TEMPLATE/💚--ci-.md
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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.*;
Expand All @@ -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<ResponseMentorInfo> getMentorInfo(@PathVariable("mentorId") Long mentorId) {
return ResponseEntity.ok().body(mentorService.getMentorDtobyId(mentorId));
}

@GetMapping("/{part}")
@Operation(summary="파트별 멘토 리스트 가져오기")
@ApiResponse(responseCode = "200", description = "DTO LIST형식으로 정보 반환")
public ResponseEntity<List<ResponseMentorListInfo>> getMentorListByPart(@PathVariable("part") int part){
return ResponseEntity.ok().body(mentorService.getMentorDtoListByPart(part));
}
@GetMapping("/{part}")
@Operation(summary = "파트별 멘토 리스트 가져오기")
@ApiResponse(responseCode = "200", description = "DTO LIST형식으로 정보 반환")
public ResponseEntity<List<ResponseMentorListInfo>> getMentorListByPart(@PathVariable("part") int part) {
return ResponseEntity.ok().body(mentorService.getMentorDtoListByPart(part));
}

@GetMapping("/{club}")
@Operation(summary="동아리별 멘토 리스트 가져오기")
@ApiResponse(responseCode = "200", description = "DTO LIST형식으로 정보 반환")
public ResponseEntity<List<ResponseMentorListInfo>> getMentorListByClub(@PathVariable("club") int club){
return ResponseEntity.ok().body(mentorService.getMentorDtoListByClub(club));
}
@GetMapping("/{club}")
@Operation(summary = "동아리별 멘토 리스트 가져오기")
@ApiResponse(responseCode = "200", description = "DTO LIST형식으로 정보 반환")
public ResponseEntity<List<ResponseMentorListInfo>> 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<List<ResponseMentorListInfo>> 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<List<ResponseMentorListInfo>> 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<List<PossibleDateRequestDto>> 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<List<PossibleDateRequestDto>> getPossibleDates(@PathVariable("username") String username) {
return ResponseEntity.ok().body(mentorService.findPossibleDateListByMentor(username));
}

}
7 changes: 5 additions & 2 deletions src/main/java/com/soongsil/CoffeeChat/dto/MentorDto.java
Original file line number Diff line number Diff line change
@@ -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 String part;
private int club;
private PartEnum part;
private ClubEnum club;
}
33 changes: 33 additions & 0 deletions src/main/java/com/soongsil/CoffeeChat/dto/ResponseMentorInfo.java
Original file line number Diff line number Diff line change
@@ -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();
}
}
Original file line number Diff line number Diff line change
@@ -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")
Expand Down
18 changes: 11 additions & 7 deletions src/main/java/com/soongsil/CoffeeChat/entity/Mentor.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
import java.util.Set;

import com.soongsil.CoffeeChat.dto.MentorDto;
import com.soongsil.CoffeeChat.enums.MentorPart;
import com.soongsil.CoffeeChat.dto.ResponseMentorInfo;
import com.soongsil.CoffeeChat.enums.ClubEnum;
import com.soongsil.CoffeeChat.enums.PartEnum;


import jakarta.persistence.CascadeType;
import jakarta.persistence.Column;
Expand Down Expand Up @@ -43,10 +46,11 @@ public class Mentor {

@Column
@Enumerated(EnumType.STRING)
private MentorPart part;
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")
Expand All @@ -61,15 +65,15 @@ public class Mentor {
private Set<PossibleDate> possibleDates = new HashSet<>();

@Builder
public Mentor(int club, String part) {
this.club = club;
this.part = MentorPart.valueOf(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(MentorPart.valueOf(dto.getPart()))
.part(dto.getPart())
.build();
}

Expand Down
Loading

0 comments on commit a698959

Please sign in to comment.