Skip to content

Commit

Permalink
Merge pull request #24 from With-Mate/fix/profile/sh
Browse files Browse the repository at this point in the history
Refator(MemberRelation, Relation) : 리팩토링 및 dto 작성
  • Loading branch information
seohyun-lee authored Feb 17, 2024
2 parents 32c18d1 + 06212b9 commit 7dd0b6c
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public ResponseEntity<?> getMatchingInfo() {
public ResponseEntity<?> getPersonMatching(@RequestParam Category category) {
MatchingResDto matchingResDto = matchingService.getMatchingByCategory(category);
if (matchingResDto == null)
return ResponseEntity.ok().body("매칭 가능한 상대방이 없습니다"); // 사람이 없음; 매칭 대기 띄워야 함
return ResponseEntity.ok().body("매칭 가능한 상대방이 없습니다."); // 사람이 없음; 매칭 대기 띄워야 함
return ResponseEntity.ok().body(matchingResDto);
}

Expand All @@ -53,7 +53,7 @@ public ResponseEntity<?> getPersonMatching(@RequestParam Category category) {
public ResponseEntity<?> getPeopleMatching() {
List<MatchingResDto> matchingList = matchingService.getCurrentMatchingList();
if (matchingList.isEmpty())
return ResponseEntity.ok().body("매칭 가능한 상대방이 없습니다"); // 사람이 없음; 매칭 대기 띄워야 함
return ResponseEntity.ok().body("매칭 가능한 상대방이 없습니다."); // 사람이 없음; 매칭 대기 띄워야 함
return ResponseEntity.ok().body(matchingList);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.gdscewha.withmate.domain.member.entity.Member;
import com.gdscewha.withmate.domain.member.service.MemberService;
import com.gdscewha.withmate.domain.memberrelation.dto.MRUpdateDto;
import com.gdscewha.withmate.domain.memberrelation.entity.MemberRelation;
import com.gdscewha.withmate.domain.memberrelation.service.MemberRelationService;
import lombok.RequiredArgsConstructor;
Expand All @@ -16,22 +17,24 @@ public class MemberRelationController {
private final MemberRelationService mRService;
private final MemberService memberService;

// TODO: 응답 dto로 바꿔서 보내야 함
// 내 목표 업데이트
@PatchMapping("/self/goal/update")
public ResponseEntity<?> updateGoal(@RequestParam String goal) {
Member member = memberService.getCurrentMember(); // 나중에 다르게 변경 예정임
Member member = memberService.getCurrentMember();
if (!member.getIsRelationed())
return ResponseEntity.badRequest().build(); // 메이트가 없어서 바꿀 수 없음
MemberRelation memberRelation = mRService.updateMRGoal(member, goal);
return ResponseEntity.ok().body(memberRelation);
MRUpdateDto mrUpdateDto = mRService.updateMRGoal(member, goal);
return ResponseEntity.ok().body(mrUpdateDto);
}

// 내 응원 메시지 업데이트
@PatchMapping("/self/message/update")
public ResponseEntity<?> updateMessage(@RequestParam String message) {
Member member = memberService.getCurrentMember(); // 나중에 다르게 변경 예정임
Member member = memberService.getCurrentMember();
if (!member.getIsRelationed())
return ResponseEntity.badRequest().build(); // 메이트가 없어서 바꿀 수 없음
MemberRelation memberRelation = mRService.updateMRMessage(member, message);
return ResponseEntity.ok().body(memberRelation);
MRUpdateDto mrUpdateDto = mRService.updateMRMessage(member, message);
return ResponseEntity.ok().body(mrUpdateDto);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.gdscewha.withmate.domain.memberrelation.dto;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class MRUpdateDto {
private String nickname;
private String message;
private String goal;
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.gdscewha.withmate.domain.matching.entity.Matching;
import com.gdscewha.withmate.domain.member.entity.Member;
import com.gdscewha.withmate.domain.member.repository.MemberRepository;
import com.gdscewha.withmate.domain.memberrelation.dto.MRUpdateDto;
import com.gdscewha.withmate.domain.memberrelation.entity.MemberRelation;
import com.gdscewha.withmate.domain.memberrelation.repository.MemberRelationRepository;
import com.gdscewha.withmate.domain.relation.entity.Relation;
Expand Down Expand Up @@ -101,20 +102,30 @@ public void endIsRelationedOfMembers(Relation relation) {
}

// Member의 Goal 업데이트
public MemberRelation updateMRGoal(Member member, String newGoal) {
public MRUpdateDto updateMRGoal(Member member, String newGoal) {
MemberRelation memberRelation = findLastMROfMember(member);
if (memberRelation == null)
throw new MemberRelationException(ErrorCode.MEMBERRELATION_NOT_FOUND);
memberRelation.setGoal(newGoal);
return mRRepository.save(memberRelation);
mRRepository.save(memberRelation);
return MRUpdateDto.builder()
.nickname(memberRelation.getMember().getNickname())
.goal(newGoal)
.message(memberRelation.getMessage())
.build();
}

// Member의 Message 업데이트
public MemberRelation updateMRMessage(Member member, String newMessage) {
public MRUpdateDto updateMRMessage(Member member, String newMessage) {
MemberRelation memberRelation = findLastMROfMember(member);
if (memberRelation == null)
throw new MemberRelationException(ErrorCode.MEMBERRELATION_NOT_FOUND);
memberRelation.setMessage(newMessage);
return mRRepository.save(memberRelation);
mRRepository.save(memberRelation);
return MRUpdateDto.builder()
.nickname(memberRelation.getMember().getNickname())
.goal(memberRelation.getGoal())
.message(newMessage)
.build();
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.gdscewha.withmate.domain.relation.controller;

import com.gdscewha.withmate.common.response.exception.ErrorCode;
import com.gdscewha.withmate.common.response.exception.MemberRelationException;
import com.gdscewha.withmate.domain.relation.dto.RelationHomeDto;
import com.gdscewha.withmate.domain.relation.dto.RelationManageDto;
import com.gdscewha.withmate.domain.relation.dto.RelationReportDto;
Expand Down Expand Up @@ -31,18 +33,18 @@ public ResponseEntity<?> getHomeInfo() {
public ResponseEntity<?> getMateManageInfo() {
RelationManageDto relationManageDto = relationMateService.getRelationManageInfo();
if (relationManageDto == null)
return ResponseEntity.ok().header("Location", "/api/match").build();
return ResponseEntity.badRequest().header("Location", "/api/match").build();
return ResponseEntity.ok().body(relationManageDto);
}

// 메이트 끊기
@PatchMapping("/mate/unrelate")
public ResponseEntity<?> unrelateMate(@RequestBody RelationReportDto relationReportDto){
if (relationReportDto.getMyName() != null && relationReportDto.getMateName() != null) {
public ResponseEntity<?> unrelateMate(){ //@RequestBody RelationReportDto relationReportDto
Relation relation = relationMateService.endCurrentRelation();
return ResponseEntity.ok().body("메이트와의 관계를 끊었습니다. " + relation);
}
return ResponseEntity.badRequest().body("신고자 또는 상대방의 userName이 잘못되었습니다.");
if (relation == null)
return ResponseEntity.badRequest().body("관계를 끊을 메이트가 없습니다.");
return ResponseEntity.ok().body("메이트와의 관계를 끊었습니다.\n"
+ relation.getStartDate() + "부터 " + relation.getEndDate() + "까지 함께했습니다.");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
@NoArgsConstructor
public class RelationProfileDto {
// 내 정보
private String member1Name;
private String member1Goal;
private String nickname1;
private String goal1;
// 상대방 정보
private String member2Name;
private String member2Goal;
private String nickname2;
private String goal2;
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public Relation endCurrentRelation(){
Member member = memberService.getCurrentMember();
Relation relation = getCurrentRelation(member);
if (relation == null)
throw new MemberRelationException(ErrorCode.RELATION_NOT_FOUND);
return null;
mRService.endIsRelationedOfMembers(relation);
relation.setEndDate(LocalDate.now());
relation.setIsProceed(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,10 @@ else if (index > mRList.size())
public RelationProfileDto getStickerRelationInfoByRelation(Relation relation) {
List<MemberRelation> mRList = mRRepository.findAllByRelation(relation);
return RelationProfileDto.builder()
.member1Name(mRList.get(0).getMember().getNickname())
.member1Goal(mRList.get(0).getGoal())
.member2Name(mRList.get(1).getMember().getNickname())
.member2Goal(mRList.get(1).getGoal())
.nickname1(mRList.get(0).getMember().getNickname())
.goal1(mRList.get(0).getGoal())
.nickname2(mRList.get(1).getMember().getNickname())
.goal2(mRList.get(1).getGoal())
.build();
}

Expand Down

0 comments on commit 7dd0b6c

Please sign in to comment.