Skip to content

Commit

Permalink
Merge pull request #22 from With-Mate/fix/profile/sh
Browse files Browse the repository at this point in the history
Feat(Profile) : 사용자 여정, 각 주차와 주차별 스티커 조회 개발
  • Loading branch information
seohyun-lee authored Feb 17, 2024
2 parents 6a43c49 + 1e5ca0d commit ec885d6
Show file tree
Hide file tree
Showing 15 changed files with 191 additions and 125 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.gdscewha.withmate.domain.journey.dto;

import com.gdscewha.withmate.domain.relation.dto.RelationProfileDto;
import com.gdscewha.withmate.domain.week.dto.WeekStickersDto;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.util.List;


@Getter
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class JourneyStickersDto {
private int journeyIndex;
private int weekCount;
private RelationProfileDto relationInfo;
private List<WeekStickersDto> weekBoards;
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@ public class Journey {
@Column(name = "journeyId")
private Long id;

@Column(nullable = false, name = "journeyNum")
private Long journeyNum;

@Column(nullable = false, name = "weekCount")
private Long weekCount;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.gdscewha.withmate.domain.journey.repository;

import com.gdscewha.withmate.domain.journey.entity.Journey;
import com.gdscewha.withmate.domain.member.entity.Member;
import com.gdscewha.withmate.domain.relation.entity.Relation;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
Expand All @@ -11,6 +12,5 @@
@Repository
public interface JourneyRepository extends JpaRepository<Journey, Long> {
Optional<Journey> findById(Long id);
List<Journey> findAllByRelation(Relation relation);
Optional<Journey> findByRelationAndJourneyNum(Relation relation, Long JourneyNum);
Optional<Journey> findByRelation(Relation relation);
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

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

@Service
Expand All @@ -25,9 +24,7 @@ public class JourneyService {
public Journey createJourney(Relation relation) {
if (relation == null)
throw new JourneyException(ErrorCode.RELATION_NOT_FOUND);
List<Journey> existingJourneyList = journeyRepository.findAllByRelation(relation);
Journey journey = Journey.builder()
.journeyNum(Long.valueOf(existingJourneyList.size())) // 처음에 1L
.weekCount(0L) // 처음에 0L
.relation(relation)
.build();
Expand All @@ -45,9 +42,9 @@ public Journey updateWeekCountOfCurrentJourney(){
return journeyRepository.save(journey);
}

// 단일 Journey 조회: Relation과 index로
public Journey getJourneyByRelationAndIndex(Relation relation, Long index) {
Optional<Journey> journeyOptional = journeyRepository.findByRelationAndJourneyNum(relation, index);
// 단일 Journey 조회: Relation으로
public Journey getJourneyByRelation(Relation relation) {
Optional<Journey> journeyOptional = journeyRepository.findByRelation(relation);
if (journeyOptional.isPresent())
return journeyOptional.get();
throw new JourneyException(ErrorCode.JOURNEY_NOT_FOUND);
Expand All @@ -58,23 +55,9 @@ public Journey getCurrentJourney(Member member) {
Relation relation = relationMateService.getCurrentRelation(member);
if (relation == null)
throw new JourneyException(ErrorCode.RELATION_NOT_FOUND);
List<Journey> existingJourneyList = journeyRepository.findAllByRelation(relation);
if (existingJourneyList == null || existingJourneyList.isEmpty())
Optional<Journey> currentJourney = journeyRepository.findByRelation(relation);
if (currentJourney == null || currentJourney.isEmpty())
return null;
Integer index = existingJourneyList.size() - 1;
return existingJourneyList.get(index);
}

public Journey getNthJourneyInProfile(Member member, Long journeyNum) {
Relation relation = relationMateService.getCurrentRelation(member);
if (journeyNum == null) {
Journey journey = getCurrentJourney(member);
return journey;
}
else if (journeyNum <= 0) {
throw new JourneyException(ErrorCode.JOURNEY_NOT_FOUND); // journeyNum은 1에서 시작하므로
}
Journey journey = getJourneyByRelationAndIndex(relation, journeyNum);
return journey;
return currentJourney.get();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,32 @@ public class MemberRelationService {
// Member의 모든 MR을 반환한다
public List<MemberRelation> findAllMROfMember(Member member) {
List<MemberRelation> mRList = mRRepository.findAllByMember(member);
if (mRList != null && !mRList.isEmpty()) {
return mRList;
}
return null; // 찾지 못했음
if (mRList == null || mRList.isEmpty())
return null;
return mRList; // 찾지 못했음
}

// Member의 N번째 MR을 반환한다
/*public MemberRelation findNthMROfMember(Member member, Long index) {
List<MemberRelation> mRList = mRRepository.findAllByMember(member);
if (mRList == null || mRList.isEmpty())
return null;
if (index == null)
return mRList.get(mRList.size() - 1);
if (index > mRList.size())
return null;
return mRList.get(index.intValue());
}*/

// Member에게 가장 최신인 MR 하나를 반환한다
public MemberRelation findLastMROfMember(Member member) {
List<MemberRelation> mRList = findAllMROfMember(member);
if (mRList == null) {
List<MemberRelation> mRList = mRRepository.findAllByMember(member);
if (mRList == null || mRList.isEmpty())
return null;
}
MemberRelation lastMR = mRList.get(mRList.size() - 1);
if (lastMR.getRelation().getIsProceed() == true) { // 지속중이라면
return lastMR;
}
return null; // 찾지 못했음
if (!lastMR.getRelation().getIsProceed())
return null;
return lastMR;
}

// MR 두 개 만들고 저장, 두 Member의 isRelationed는 MatchingService에서 바꿔줌
Expand Down Expand Up @@ -101,6 +110,7 @@ public MemberRelation updateMRGoal(Member member, String newGoal) {
memberRelation.setGoal(newGoal);
return mRRepository.save(memberRelation);
}

// Member의 Message 업데이트
public MemberRelation updateMRMessage(Member member, String newMessage) {
MemberRelation memberRelation = findLastMROfMember(member);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@

import com.gdscewha.withmate.domain.relation.dto.RelationHomeDto;
import com.gdscewha.withmate.domain.relation.dto.RelationManageDto;
import com.gdscewha.withmate.domain.relation.dto.RelationReportDto;
import com.gdscewha.withmate.domain.relation.entity.Relation;
import com.gdscewha.withmate.domain.relation.service.RelationMateService;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PatchMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;


@RequiredArgsConstructor
Expand Down Expand Up @@ -39,9 +37,12 @@ public ResponseEntity<?> getMateManageInfo() {

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

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.gdscewha.withmate.domain.relation.dto;

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

@Getter
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class RelationProfileDto {
// 내 정보
private String member1Name;
private String member1Goal;
// 상대방 정보
private String member2Name;
private String member2Goal;
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@
@AllArgsConstructor
@NoArgsConstructor
public class RelationReportDto {
// 신고자 정보
private String myName;
// 상대방 정보
private String mateName;
private String mateCategory;
private String reason; // ""로 전달 후 내용 받을 예정
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.gdscewha.withmate.domain.relation.service;

import com.gdscewha.withmate.common.response.exception.ErrorCode;
import com.gdscewha.withmate.common.response.exception.JourneyException;
import com.gdscewha.withmate.common.response.exception.MemberRelationException;
import com.gdscewha.withmate.domain.journey.entity.Journey;
import com.gdscewha.withmate.domain.member.entity.Member;
import com.gdscewha.withmate.domain.member.service.MemberService;
import com.gdscewha.withmate.domain.memberrelation.entity.MemberRelation;
Expand All @@ -15,6 +17,8 @@

import java.time.LocalDate;
import java.time.temporal.ChronoUnit;
import java.util.List;
import java.util.Optional;


@RequiredArgsConstructor
Expand Down Expand Up @@ -105,4 +109,12 @@ public RelationManageDto getRelationManageInfo() {
.mateMessage(mateMR.getMessage())
.build();
}

// N번째 MR의 Relation을 반환한다
/*public Relation getRelationOfNthMR(Member member, Long index) {
MemberRelation memberRelation = mRService.findNthMROfMember(member, index);
if (memberRelation == null)
return null;
return memberRelation.getRelation();
}*/
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package com.gdscewha.withmate.domain.sticker.controller;

import com.gdscewha.withmate.domain.journey.dto.JourneyStickersDto;
import com.gdscewha.withmate.domain.member.entity.Member;
import com.gdscewha.withmate.domain.member.service.MemberService;
import com.gdscewha.withmate.domain.sticker.dto.*;
import com.gdscewha.withmate.domain.sticker.entity.Sticker;
import com.gdscewha.withmate.domain.sticker.service.StickerService;
import com.gdscewha.withmate.domain.week.dto.WeekStickersDto;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
Expand All @@ -17,13 +18,13 @@ public class StickerController {
private final MemberService memberService;
private final StickerService stickerService;

// 내 이름, 목표 와 메이트 이름과 목표
// 내 이름, 목표와 메이트 이름과 목표
@GetMapping("/sticker/relation")
public ResponseEntity<?> getMeAndMateInfo() {
Member member = memberService.getCurrentMember();
if (!member.getIsRelationed())
return ResponseEntity.badRequest().body("현재 메이트를 맺은 상태가 아닙니다.");
StickerRelationDto stickerRelationDto = stickerService.getStickerRelationInfo();
StickerRelationDto stickerRelationDto = stickerService.getStickerRelationInfo(member);
if (stickerRelationDto == null)
return ResponseEntity.ok().header("Location", "/api/match").build();
return ResponseEntity.ok().body(stickerRelationDto);
Expand All @@ -35,10 +36,31 @@ public ResponseEntity<?> getStickersPreview() {
Member member = memberService.getCurrentMember();
if (!member.getIsRelationed())
return ResponseEntity.badRequest().body("현재 메이트를 맺은 상태가 아닙니다.");
WeekStickersDto weekStickersDto = stickerService.getStickersForAWeek(member);
WeekStickersDto weekStickersDto = stickerService.getStickersForCurrentWeek(member);
return ResponseEntity.ok().body(weekStickersDto);
}

// 내 n번째 여정 조회
@GetMapping("/self/journey")
public ResponseEntity<?> getMyNthJourney(@RequestParam(required = false) Long index) {
Member member = memberService.getCurrentMember();
JourneyStickersDto journeyStickersDto = stickerService.getStickersForAJourney(member, index);
if (journeyStickersDto == null)
return ResponseEntity.badRequest().body("여정이 없습니다.");
return ResponseEntity.ok().body(journeyStickersDto);
}

// 메이트의 n번째 여정 조회
@GetMapping("/mate/journey")
public ResponseEntity<?> getMateNthJourney(@RequestParam(required = false) Long index) {
Member mate = memberService.getCurrentMate();
JourneyStickersDto journeyStickersDto = stickerService.getStickersForAJourney(mate, index);
if (journeyStickersDto == null)
return ResponseEntity.badRequest().body("여정이 없습니다.");
return ResponseEntity.ok().body(journeyStickersDto);
}


// 모달 스티커 작성
@PostMapping("/sticker/create")
public ResponseEntity<?> createSticker(@RequestBody StickerCreateDTO stickerCreateDTO){
Expand Down
Loading

0 comments on commit ec885d6

Please sign in to comment.