Skip to content

Commit

Permalink
Merge pull request #50 from choboss00/feature/3-branch-mentoring
Browse files Browse the repository at this point in the history
contact 기능, done 기능 구현 완료
  • Loading branch information
sjmjys954646 authored Nov 3, 2023
2 parents cf6799f + 8d62d69 commit 88d5196
Show file tree
Hide file tree
Showing 19 changed files with 731 additions and 154 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ public interface MentorPostJPARepostiory extends JpaRepository<MentorPost, Integ
@Query("select m from MentorPost m where m.writer.id = :writer and m.state = 'ACTIVE'")
List<MentorPost> findAllByWriter(@Param("writer") int writer);

@Query("select m from MentorPost m where m.writer.id = :writer and m.state = 'DONE'")
List<MentorPost> findAllByWriterDone(@Param("writer") int writer);

@Query("select m from MentorPost m where m.title like :keyword")
Page<MentorPost> findAllByTitleKeyword(@Param("keyword") String keyword, Pageable pageable);

Expand All @@ -32,6 +35,4 @@ public interface MentorPostJPARepostiory extends JpaRepository<MentorPost, Integ
@Query("select count(*) from MentorPost m where m.writer.id = :userId and m.state = 'DONE'")
int countDoneByMentorId(int userId);

@Query("SELECT m FROM MentorPost m INNER JOIN NotConnectedRegisterUser ncru ON m.id = ncru.mentorPost.id WHERE ncru.menteeUser.id = :menteeUserId")
List<MentorPost> findAllByMenteeUserId(@Param("menteeUserId") int menteeUserId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public void createMentorPost(MentorPostRequest.CreateDTO createDTO, User writer)
}

MentorPost mentorPost = new MentorPost( writer, createDTO.getTitle(), createDTO.getContent());

try {
mentorPostJPARepository.save(mentorPost);
} catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package com.example.demo.mentoring.contact;

import com.example.demo.mentoring.MentorPost;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

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

Expand All @@ -14,4 +16,13 @@ public interface ContactJPARepository extends JpaRepository<NotConnectedRegister

@Query("SELECT ncru FROM NotConnectedRegisterUser ncru WHERE ncru.mentorPost.id = :mentorPostId AND ncru.menteeUser.id = :menteeId")
Optional<NotConnectedRegisterUser> findByMentorPostIdAndMenteeUserId(int mentorPostId, int menteeId);

@Query("SELECT count(*) FROM NotConnectedRegisterUser ncru WHERE ncru.menteeUser.id = :userId")
int countContactByMenteeId(int userId);

@Query("SELECT ncru FROM NotConnectedRegisterUser ncru WHERE ncru.menteeUser.id = :menteeId")
List<NotConnectedRegisterUser> findAllByMenteeId(int menteeId);

@Query("SELECT ncru FROM NotConnectedRegisterUser ncru WHERE ncru.mentorPost.writer.id = :mentorId")
List<NotConnectedRegisterUser> findAllByMentorId(int mentorId);
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.example.demo.mentoring.contact;

import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import javax.validation.constraints.NotNull;
Expand All @@ -9,18 +10,37 @@
public class ContactRequest {

@Getter @Setter
public static class AcceptDTO {
public static class ContactCreateDTO {
private int mentorPostId;
private List<MentorAndMenteeDTO> mentorsAndMentees;
@Getter @Setter
public static class MentorAndMenteeDTO {
@NotNull
private int mentorId;
private int mentorId;
private int menteeId;
}

@Getter @Setter
public static class ContactRefuseDTO {
private int mentorPostId;
private int mentorId;
private List<RefuseMenteeDTO> mentees;
@Getter @Setter @NoArgsConstructor
public static class RefuseMenteeDTO {
@NotNull
private int menteeId;
public RefuseMenteeDTO(int menteeId) {
this.menteeId = menteeId;
}
}
}

public MentorAndMenteeDTO(int mentorId, int menteeId) {
this.mentorId = mentorId;
@Getter @Setter
public static class ContactAcceptDTO {
private int mentorPostId;
private int mentorId;
private List<AcceptMenteeDTO> mentees;
@Getter @Setter @NoArgsConstructor
public static class AcceptMenteeDTO {
@NotNull
private int menteeId;
public AcceptMenteeDTO(int menteeId) {
this.menteeId = menteeId;
}
}
Expand Down
118 changes: 59 additions & 59 deletions src/main/java/com/example/demo/mentoring/contact/ContactResponse.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,28 @@
public class ContactResponse {

@Getter @Setter
public static class postCountDTO {
public static class PostCountDTO {
private int contactCount;
private int doneCount;

public postCountDTO(int contactCount, int doneCount) {
public PostCountDTO(int contactCount, int doneCount) {
this.contactCount = contactCount;
this.doneCount = doneCount;
}
}

@Getter @Setter
public static class MenteeContactDTO {
public static class ContactDashBoardMenteeDTO {
private int postId;
private String title;
private MentorDTO mentor;
private ContactMentorDTO mentor;
private int menteeId;

public MenteeContactDTO(MentorPost mentorPost, MentorDTO mentor) {
public ContactDashBoardMenteeDTO(MentorPost mentorPost, ContactMentorDTO mentor, NotConnectedRegisterUser notConnectedRegisterUser) {
this.postId = mentorPost.getId();
this.title = mentorPost.getTitle();
this.mentor = mentor;
this.menteeId = notConnectedRegisterUser.getId();
}
}
/**
Expand All @@ -45,73 +47,71 @@ public MenteeContactDTO(MentorPost mentorPost, MentorDTO mentor) {
*
* **/
@Getter @Setter
public static class MentorPostDTO {
public static class ContactDashboardMentorDTO {
private int postId;
private String title;
private MentorDTO mentor;
private List<MenteeDTO> mentees;
private ContactMentorDTO mentor;
private List<ContactMenteeDTO> mentees;

public MentorPostDTO(MentorPost mentorPost, MentorDTO mentor, List<MenteeDTO> mentees) {
public ContactDashboardMentorDTO(MentorPost mentorPost, ContactMentorDTO mentor, List<ContactMenteeDTO> mentees) {
this.postId = mentorPost.getId();
this.title = mentorPost.getTitle();
this.mentor = mentor;
this.mentees = mentees;
}
}

@Getter @Setter
public static class MentorDTO {
private int mentorId;
private String profileImage;
private String name;
private String country;
private int age;
private Role role;
private List<String> favorites;
@Getter @Setter
public static class ContactMentorDTO {
private int mentorId;
private String profileImage;
private String name;
private String country;
private int age;
private Role role;
private List<String> favorites;

public MentorDTO(User user, List<UserInterest> userInterests) {
this.mentorId = user.getId();
this.profileImage = user.getProfileImage();
this.name = user.getFirstName() + " " + user.getLastName();
this.country = user.getCountry();
this.age = user.getAge();
this.role = user.getRole();
this.favorites = userInterests.stream()
.filter(userInterest -> userInterest.getUser().getId() == user.getId())
.map(userInterest -> userInterest.getInterest().getCategory())
.collect(Collectors.toList());
}
public ContactMentorDTO(User mentor, List<UserInterest> userInterests) {
this.mentorId = mentor.getId();
this.profileImage = mentor.getProfileImage();
this.name = mentor.getFirstName() + " " + mentor.getLastName();
this.country = mentor.getCountry();
this.age = mentor.getAge();
this.role = mentor.getRole();
this.favorites = userInterests.stream()
.map(userInterest -> userInterest.getInterest().getCategory())
.collect(Collectors.toList());
}
@Getter @Setter
public static class MenteeDTO {
private int menteeId;
private String profileImage;
private String name;
private String country;
private int age;
private Role role;
private NotConnectedRegisterUser.State state;
private List<String> favorites; // 고민할 부분 : 유저의 favorite List 를 어떻게 가져올 것 인가?
}
@Getter @Setter
public static class ContactMenteeDTO {
private int menteeId;
private String profileImage;
private String name;
private String country;
private int age;
private Role role;
private ContactStateEnum state;
private List<String> favorites; // 고민할 부분 : 유저의 favorite List 를 어떻게 가져올 것 인가?

/**
* 유저의 favorite List 를 가져오기 위해
* userInterest 를 입력으로 받음
* userInterest 의 userId 와 현재 신청한 멘티 ( notConnectedRegitserUser ) 의 id 값이 일치하는 경우
* 그럴 경우에만 tag 값들을 가져오기
* **/
/**
* 유저의 favorite List 를 가져오기 위해
* userInterest 를 입력으로 받음
* userInterest 의 userId 와 현재 신청한 멘티 ( notConnectedRegitserUser ) 의 id 값이 일치하는 경우
* 그럴 경우에만 tag 값들을 가져오기
* **/

public MenteeDTO(NotConnectedRegisterUser notConnectedRegisterUser, List<UserInterest> userInterests) {
this.menteeId = notConnectedRegisterUser.getMenteeUser().getId();
this.profileImage = notConnectedRegisterUser.getMenteeUser().getProfileImage();
this.name = notConnectedRegisterUser.getMenteeUser().getFirstName() + " " + notConnectedRegisterUser.getMenteeUser().getLastName();
this.country = notConnectedRegisterUser.getMenteeUser().getCountry();
this.age = notConnectedRegisterUser.getMenteeUser().getAge();
this.role = notConnectedRegisterUser.getMenteeUser().getRole();
this.state = notConnectedRegisterUser.getState();
this.favorites = userInterests.stream()
.filter(userInterest -> userInterest.getUser().getId() == notConnectedRegisterUser.getMenteeUser().getId())
.map(userInterest -> userInterest.getInterest().getCategory())
.collect(Collectors.toList());
}
public ContactMenteeDTO(NotConnectedRegisterUser notConnectedRegisterUser, List<UserInterest> userInterests) {
this.menteeId = notConnectedRegisterUser.getId();
this.profileImage = notConnectedRegisterUser.getMenteeUser().getProfileImage();
this.name = notConnectedRegisterUser.getMenteeUser().getFirstName() + " " + notConnectedRegisterUser.getMenteeUser().getLastName();
this.country = notConnectedRegisterUser.getMenteeUser().getCountry();
this.age = notConnectedRegisterUser.getMenteeUser().getAge();
this.role = notConnectedRegisterUser.getMenteeUser().getRole();
this.state = notConnectedRegisterUser.getState();
this.favorites = userInterests.stream()
.map(userInterest -> userInterest.getInterest().getCategory())
.collect(Collectors.toList());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.example.demo.config.auth.CustomUserDetails;
import com.example.demo.config.utils.ApiUtils;
import com.example.demo.mentoring.done.DoneService;
import com.example.demo.user.Role;
import io.swagger.v3.oas.annotations.Operation;
import lombok.RequiredArgsConstructor;
Expand All @@ -21,12 +22,12 @@ public class ContactRestController {

@GetMapping(value = "/contacts")
@Operation(summary = "contact 화면 조회", description = "멘토, 멘티 화면에 따라 적절한 화면을 보여준다.")
public ResponseEntity<?> findAll(@AuthenticationPrincipal CustomUserDetails userDetails) {
public ResponseEntity<?> findAllContacts(@AuthenticationPrincipal CustomUserDetails userDetails) {
if ( userDetails.getUser().getRole() == Role.MENTEE ) {
List<ContactResponse.MenteeContactDTO> responseDTO = contactService.findAllByMentee(userDetails.getUser().getId());
List<ContactResponse.ContactDashBoardMenteeDTO> responseDTO = contactService.findAllByMentee(userDetails.getUser());
return ResponseEntity.ok(ApiUtils.success(responseDTO));
}
List<ContactResponse.MentorPostDTO> responseDTO = contactService.findAllByMentor(userDetails.getUser().getId());
List<ContactResponse.ContactDashboardMentorDTO> responseDTO = contactService.findAllByMentor(userDetails.getUser());
return ResponseEntity.ok(ApiUtils.success(responseDTO));
}

Expand All @@ -40,21 +41,44 @@ public ResponseEntity<?> postCounts(@AuthenticationPrincipal CustomUserDetails u
Role role = userDetails.getUser().getRole();

if ( role == Role.MENTEE ) {
return null;
ContactResponse.PostCountDTO responseDTO = contactService.postCountsMyMentee(userDetails.getUser().getId());
return ResponseEntity.ok(ApiUtils.success(responseDTO));
}

ContactResponse.postCountDTO responseDTO = contactService.postCountsByMentor(userDetails.getUser().getId());
ContactResponse.PostCountDTO responseDTO = contactService.postCountsByMentor(userDetails.getUser().getId());
return ResponseEntity.ok(ApiUtils.success(responseDTO));
}

@PostMapping(value = "/contacts/{id}/accept")
@PostMapping(value = "/contacts/accept")
@Operation(summary = "멘토링 신청 수락", description = "멘토링 신청을 수락한다.")
public ResponseEntity<?> acceptContact(@PathVariable int id, @RequestBody @Valid ContactRequest.AcceptDTO acceptDTO, Error errors, @AuthenticationPrincipal CustomUserDetails userDetails) {
public ResponseEntity<?> acceptContact(@RequestBody @Valid ContactRequest.ContactAcceptDTO contactAcceptDTO, Error errors, @AuthenticationPrincipal CustomUserDetails userDetails) {
// TO-DO : 멘토링 신청 수락 API 로직 만들기
contactService.acceptContact(id, acceptDTO, userDetails.getUser());
contactService.acceptContact(contactAcceptDTO, userDetails.getUser());
return ResponseEntity.status(HttpStatus.OK).body(ApiUtils.successWithNoContent());
}

@PatchMapping(value = "/contacts/refuse")
@Operation(summary = "멘토링 신청 거절", description = "멘토링 신청을 거절한다.")
public ResponseEntity<?> refuseContact(@RequestBody @Valid ContactRequest.ContactRefuseDTO contactRefuseDTO, Error errors, @AuthenticationPrincipal CustomUserDetails userDetails) {
// TO-DO : 멘토링 신청 거절 API 로직 만들기
contactService.refuseContact(contactRefuseDTO, userDetails.getUser());
return ResponseEntity.status(HttpStatus.OK).body(ApiUtils.successWithNoContent());
}

@PostMapping(value = "/contacts")
@Operation(summary = "멘티의 멘토링 신청", description = "멘토가 작성한 글을 보고, 멘티는 멘토링 신청을 할 수 있다.")
public ResponseEntity<?> createContact(@RequestBody @Valid ContactRequest.ContactCreateDTO contactCreateDTO, Error errors, @AuthenticationPrincipal CustomUserDetails userDetails) {
// TO-DO : 멘토링 신청 API 로직 만들기
contactService.createContact(contactCreateDTO, userDetails.getUser());
return ResponseEntity.status(HttpStatus.OK).body(ApiUtils.successWithNoContent());
}

@DeleteMapping(value = "/contacts")
@Operation(summary = "멘티의 멘토링 신청 취소", description = "멘티는 신청한 멘토링을 취소할 수 있다.")
public ResponseEntity<?> deleteContact(@RequestHeader("contactId") List<Integer> contactId, Error errors, @AuthenticationPrincipal CustomUserDetails userDetails) {
// TO-DO : 멘토링 신청 취소 API 로직 만들기
contactService.deleteContact(contactId, userDetails.getUser());
return ResponseEntity.status(HttpStatus.OK).body(ApiUtils.successWithNoContent());
}

}
Loading

0 comments on commit 88d5196

Please sign in to comment.