Skip to content

Commit

Permalink
feat : 상대 목표 복사 (#244)
Browse files Browse the repository at this point in the history
  • Loading branch information
SIWON990327 authored Dec 4, 2024
1 parent cf31401 commit 08db0d5
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 3 deletions.
46 changes: 46 additions & 0 deletions src/main/java/com/groom/orbit/goal/app/MemberGoalService.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.groom.orbit.goal.app.dto.response.GetQuestResponseDto;
import com.groom.orbit.goal.app.query.GoalQueryService;
import com.groom.orbit.goal.dao.MemberGoalRepository;
import com.groom.orbit.goal.dao.QuestRepository;
import com.groom.orbit.goal.dao.entity.Goal;
import com.groom.orbit.goal.dao.entity.MemberGoal;
import com.groom.orbit.goal.dao.entity.Quest;
Expand All @@ -38,6 +39,7 @@ public class MemberGoalService {
private final GoalQueryService goalQueryService;
private final GoalCommandService goalCommandService;
private final VectorService vectorService;
private final QuestRepository questRepository;

@Transactional(readOnly = true)
public MemberGoal findMemberGoal(Long memberId, Long goalId) {
Expand Down Expand Up @@ -240,4 +242,48 @@ public CommonSuccessDto updateMemberGoalIsComplete(Long memberId, Long memberGoa

return CommonSuccessDto.fromEntity(true);
}

public GetMemberGoalResponseDto createOtherGoal(Long memberId, Long memberGoalId) {

MemberGoal memberGoal = findMemberGoal(memberGoalId);

Goal goal = goalQueryService.findGoal(memberGoal.getMemberGoalId());

Member member = memberQueryService.findMember(memberId);

int memberGoalLen = memberGoalRepository.findAllByMemberIdAndIsCompleteFalse(memberId).size();

MemberGoal copyMemberGoal = new MemberGoal().copyMemberGoal(member, goal, memberGoalLen);

memberGoalRepository.save(copyMemberGoal);

List<Quest> copQuestList =
memberGoal.getQuests().stream()
.map(originQuest -> Quest.copyQuest(originQuest.getTitle(), copyMemberGoal))
.toList();

questRepository.saveAll(copQuestList);

List<GetQuestResponseDto> questDtos =
copQuestList.stream()
.map(
quest ->
new GetQuestResponseDto(
quest.getQuestId(),
quest.getTitle(),
quest.getDeadline(),
quest.getIsComplete()))
.toList();

return new GetMemberGoalResponseDto(
copyMemberGoal.getMemberGoalId(),
copyMemberGoal.getTitle(),
copyMemberGoal.getGoal().getCategory(),
copyMemberGoal.getIsComplete(),
copyMemberGoal.getSequence(),
copyMemberGoal.getIsResume(),
copyMemberGoal.getCreatedAt().toLocalDate(),
copyMemberGoal.getCompletedDate().toLocalDate(),
questDtos);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,10 @@ public ResponseDto<CommonSuccessDto> updateMemberGoalIsComplete(
@AuthMember Long memberId, @PathVariable("member_goal_id") Long memberGoalId) {
return ResponseDto.ok(memberGoalService.updateMemberGoalIsComplete(memberId, memberGoalId));
}

@PostMapping("/copy/{member_goal_id}")
public ResponseDto<GetMemberGoalResponseDto> copyMemberGoal(
@AuthMember Long memberId, @PathVariable("member_goal_id") Long otherMemberGoalId) {
return ResponseDto.ok(memberGoalService.createOtherGoal(memberId, otherMemberGoalId));
}
}
17 changes: 15 additions & 2 deletions src/main/java/com/groom/orbit/goal/dao/entity/MemberGoal.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,13 @@
import com.groom.orbit.common.dao.entity.BaseTimeEntity;
import com.groom.orbit.member.dao.jpa.entity.Member;

import lombok.Getter;
import lombok.Setter;
import lombok.*;

@Entity
@Getter
@Builder
@AllArgsConstructor
@NoArgsConstructor
@DynamicUpdate
@Table(name = "member_goal")
public class MemberGoal extends BaseTimeEntity {
Expand Down Expand Up @@ -87,4 +89,15 @@ public void updateGoal(Goal goal) {
public void validateMember(Long memberId) {
this.member.validateId(memberId);
}

public MemberGoal copyMemberGoal(Member member, Goal goal, Integer memberGoalLen) {
return MemberGoal.builder()
.member(member)
.goal(goal)
.isComplete(false)
.sequence(memberGoalLen + 1)
.isResume(false)
.completedDate(this.completedDate)
.build();
}
}
9 changes: 8 additions & 1 deletion src/main/java/com/groom/orbit/goal/dao/entity/Quest.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ public class Quest extends BaseTimeEntity {

private LocalDate deadline;

@Column(nullable = false)
private Integer sequence;

@ManyToOne(fetch = FetchType.LAZY)
Expand Down Expand Up @@ -97,4 +96,12 @@ public void update(String title, Boolean isComplete, LocalDate deadline) {
public void updateSequence(int sequence) {
this.sequence = sequence;
}

public static Quest copyQuest(String title, MemberGoal memberGoal) {
Quest quest = new Quest();
quest.title = title;
quest.memberGoal = memberGoal;

return quest;
}
}

0 comments on commit 08db0d5

Please sign in to comment.