Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEAT] 회원의 데일리 루틴 목록 조회 #278

Merged
merged 20 commits into from
Jun 21, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import com.soptie.server.conversation.adapter.ConversationFinder;
import com.soptie.server.conversation.entity.Conversation;
import com.soptie.server.conversation.repository.ConversationRepository;
import com.soptie.server.doll.adapter.DollFinder;
import com.soptie.server.doll.entity.DollType;
import com.soptie.server.member.adapter.MemberDeleter;
Expand All @@ -13,13 +12,9 @@
import com.soptie.server.member.service.dto.response.MemberHomeInfoGetServiceResponse;
import com.soptie.server.member.service.dto.request.MemberProfileCreateServiceRequest;
import com.soptie.server.member.entity.Member;
import com.soptie.server.member.exception.MemberException;
import com.soptie.server.member.repository.MemberRepository;
import com.soptie.server.memberDoll.adapter.MemberDollSaver;
import com.soptie.server.memberDoll.entity.MemberDoll;
import com.soptie.server.memberDoll.service.MemberDollService;
import com.soptie.server.memberRoutine.adapter.MemberRoutineSaver;
import com.soptie.server.memberRoutine.service.MemberRoutineCreateService;

import com.soptie.server.routine.adapter.RoutineFinder;
import lombok.RequiredArgsConstructor;
Expand All @@ -29,8 +24,6 @@

import java.util.List;

import static com.soptie.server.member.message.ErrorCode.*;

@Service
@RequiredArgsConstructor
@Transactional(readOnly = true)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
package com.soptie.server.memberRoutine.adapter;

import static com.soptie.server.routine.entity.RoutineType.*;
import static com.soptie.server.routine.message.RoutineErrorCode.*;

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

import com.soptie.server.common.support.RepositoryAdapter;
import com.soptie.server.member.entity.Member;
import com.soptie.server.memberRoutine.entity.MemberRoutine;
Expand All @@ -14,9 +8,15 @@
import com.soptie.server.memberRoutine.repository.dto.MemberRoutineResponse;
import com.soptie.server.routine.entity.Routine;
import com.soptie.server.routine.exception.RoutineException;

import lombok.RequiredArgsConstructor;

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

import static com.soptie.server.routine.entity.RoutineType.CHALLENGE;
import static com.soptie.server.routine.entity.RoutineType.DAILY;
import static com.soptie.server.routine.message.RoutineErrorCode.INVALID_ROUTINE;

@RepositoryAdapter
@RequiredArgsConstructor
public class MemberRoutineFinder {
Expand Down
Chan531 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
package com.soptie.server.memberRoutine.controller.v1.dto.response;

import static lombok.AccessLevel.*;

import java.util.List;

import com.soptie.server.memberRoutine.service.dto.response.MemberDailyRoutineListGetServiceResponse;
import com.soptie.server.memberRoutine.service.dto.response.MemberDailyRoutineListGetServiceResponse.MemberDailyRoutineServiceResponse;

import lombok.Builder;
import lombok.NonNull;

import java.util.List;

import static lombok.AccessLevel.PRIVATE;

@Builder(access = PRIVATE)
public record MemberDailyRoutineListGetResponse(
@NonNull List<MemberDailyRoutineResponse> routines
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.soptie.server.memberRoutine.controller.v2;

import com.soptie.server.common.dto.SuccessResponse;
import com.soptie.server.memberRoutine.controller.v2.api.MemberDailyRoutineApi;
import com.soptie.server.memberRoutine.controller.v2.dto.response.MemberDailyRoutineListGetResponse;
import com.soptie.server.memberRoutine.service.MemberRoutineReadService;
import com.soptie.server.memberRoutine.service.dto.request.MemberDailyRoutineListGetServiceRequest;
import lombok.RequiredArgsConstructor;
import lombok.val;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.security.Principal;

import static com.soptie.server.common.dto.SuccessResponse.success;
import static com.soptie.server.memberRoutine.message.SuccessMessage.SUCCESS_GET_ROUTINE;

@RestController
@RequiredArgsConstructor
@RequestMapping("/api/v2/routines/daily/member")
public class MemberDailyRoutineControllerV2 implements MemberDailyRoutineApi {

private final MemberRoutineReadService memberRoutineReadService;

@GetMapping
public ResponseEntity<SuccessResponse<MemberDailyRoutineListGetResponse>> getMemberDailyRoutines(
thguss marked this conversation as resolved.
Show resolved Hide resolved
Principal principal
) {
val memberId = Long.parseLong(principal.getName());
val response = MemberDailyRoutineListGetResponse
.of(memberRoutineReadService.getDailyRoutinesV2(MemberDailyRoutineListGetServiceRequest.of(memberId)));
thguss marked this conversation as resolved.
Show resolved Hide resolved
return ResponseEntity.ok(success(SUCCESS_GET_ROUTINE.getMessage(), response));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package com.soptie.server.memberRoutine.controller.v2.api;

import com.soptie.server.common.dto.ErrorResponse;
import com.soptie.server.common.dto.SuccessResponse;
import com.soptie.server.memberRoutine.controller.v2.dto.response.MemberDailyRoutineListGetResponse;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.http.ResponseEntity;

import java.security.Principal;

@Tag(name = "member daily routines V2", description = "회원의 데일리 루틴 API Version2")
public interface MemberDailyRoutineApi {

@Operation(
summary = "회원의 데일리 루틴 목록 조회",
description = "회원의 데일리 루틴을 무지개 순으로 정렬된 테마와 사전순으로 정렬된 루틴 목록으로 조회한다.",
responses = {
@ApiResponse(responseCode = "200", description = "성공"),
@ApiResponse(
responseCode = "401",
description = "유효하지 않은 토큰",
content = @Content(schema = @Schema(implementation = ErrorResponse.class))
),
@ApiResponse(
responseCode = "4xx",
description = "클라이언트(요청) 오류",
content = @Content(schema = @Schema(implementation = ErrorResponse.class))
),
@ApiResponse(
responseCode = "500",
description = "서버 내부 오류",
content = @Content(schema = @Schema(implementation = ErrorResponse.class))
)
}
)
ResponseEntity<SuccessResponse<MemberDailyRoutineListGetResponse>> getMemberDailyRoutines(
@Parameter(hidden = true) Principal principal
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.soptie.server.memberRoutine.controller.v2.dto.response;

import com.soptie.server.memberRoutine.service.dto.response.MemberDailyRoutineGetServiceResponseV2;
import com.soptie.server.memberRoutine.service.dto.response.MemberDailyRoutineListGetServiceResponseV2;
import lombok.Builder;
import lombok.NonNull;

import java.util.List;

import static lombok.AccessLevel.PRIVATE;

@Builder(access = PRIVATE)
public record MemberDailyRoutineListGetResponse(
@NonNull List<MemberDailyRoutineGetServiceResponseV2> routines
) {

public static MemberDailyRoutineListGetResponse of(MemberDailyRoutineListGetServiceResponseV2 tempB) {
thguss marked this conversation as resolved.
Show resolved Hide resolved
return MemberDailyRoutineListGetResponse.builder()
.routines(tempB.routines())
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ public record MemberRoutineResponse(
String content,
String iconImageUrl,
String dailyIconImageUrl,
Long themeId,
thguss marked this conversation as resolved.
Show resolved Hide resolved
String themeName,
int achieveCount,
boolean isAchieve
) {
Expand All @@ -20,6 +22,8 @@ public MemberRoutineResponse(MemberRoutine memberRoutine, Routine routine) {
routine.getContent(),
routine.getTheme().getImageInfo().getIconImageUrl(),
routine.getTheme().getImageInfo().getDailyIconImageUrl(),
routine.getTheme().getId(),
routine.getTheme().getName(),
memberRoutine.getAchieveCount(),
memberRoutine.isAchieve()
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
package com.soptie.server.memberRoutine.service;

import static com.soptie.server.routine.message.RoutineErrorCode.*;

import java.util.List;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.soptie.server.member.adapter.MemberFinder;
import com.soptie.server.member.entity.Member;
import com.soptie.server.memberRoutine.adapter.MemberRoutineFinder;
Expand All @@ -19,9 +12,13 @@
import com.soptie.server.routine.adapter.RoutineFinder;
import com.soptie.server.routine.entity.Routine;
import com.soptie.server.routine.exception.RoutineException;

import lombok.RequiredArgsConstructor;
import lombok.val;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import static com.soptie.server.routine.message.RoutineErrorCode.CANNOT_ADD_MEMBER_ROUTINE;
import static com.soptie.server.routine.message.RoutineErrorCode.DUPLICATED_ROUTINE;

@Service
@RequiredArgsConstructor
Expand Down
thguss marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
package com.soptie.server.memberRoutine.service;

import java.util.Optional;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.soptie.server.member.adapter.MemberFinder;
import com.soptie.server.memberRoutine.adapter.MemberRoutineFinder;
import com.soptie.server.memberRoutine.repository.dto.MemberRoutineResponse;
import com.soptie.server.memberRoutine.service.dto.request.MemberDailyRoutineListGetServiceRequest;
import com.soptie.server.memberRoutine.service.dto.request.MemberHappinessRoutineGetServiceRequest;
import com.soptie.server.memberRoutine.service.dto.response.MemberDailyRoutineGetServiceResponseV2;
import com.soptie.server.memberRoutine.service.dto.response.MemberDailyRoutineListGetServiceResponse;
import com.soptie.server.memberRoutine.service.dto.response.MemberDailyRoutineListGetServiceResponseV2;
import com.soptie.server.memberRoutine.service.dto.response.MemberHappinessRoutineGetServiceResponse;

import lombok.RequiredArgsConstructor;
import lombok.val;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Comparator;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

@Service
@RequiredArgsConstructor
Expand All @@ -36,4 +40,26 @@ public Optional<MemberHappinessRoutineGetServiceResponse> getHappinessRoutine(
val memberRoutine = memberRoutineFinder.findChallengeByMember(member);
return memberRoutine.map(MemberHappinessRoutineGetServiceResponse::of);
}

public MemberDailyRoutineListGetServiceResponseV2 getDailyRoutinesV2(
thguss marked this conversation as resolved.
Show resolved Hide resolved
MemberDailyRoutineListGetServiceRequest request
) {
val member = memberFinder.findById(request.memberId());
val routines = memberRoutineFinder.findDailyRoutinesByMember(member);
val routinesByTheme = getDailyRoutinesByTheme(routines);
return MemberDailyRoutineListGetServiceResponseV2.of(routinesByTheme);
}

private List<MemberDailyRoutineGetServiceResponseV2> getDailyRoutinesByTheme(List<MemberRoutineResponse> routines) {
val routinesByTheme = routines.stream().collect(Collectors.groupingBy(MemberRoutineResponse::themeId));
return routinesByTheme.values().stream()
.map(this::sortRoutines)
.map(MemberDailyRoutineGetServiceResponseV2::of).toList();
}

private List<MemberRoutineResponse> sortRoutines(List<MemberRoutineResponse> routines) {
return routines.stream()
.sorted(Comparator.comparing(MemberRoutineResponse::content))
.toList();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package com.soptie.server.memberRoutine.service.dto.response;

import com.soptie.server.memberRoutine.repository.dto.MemberRoutineResponse;
import lombok.Builder;
import lombok.NonNull;

import java.util.List;

import static lombok.AccessLevel.PRIVATE;

@Builder(access = PRIVATE)
public record MemberDailyRoutineGetServiceResponseV2(
thguss marked this conversation as resolved.
Show resolved Hide resolved
long themeId,
@NonNull String themeName,
@NonNull List<MemberDailyRoutineServiceResponse> routines
) {

public static MemberDailyRoutineGetServiceResponseV2 of(List<MemberRoutineResponse> routines) {
return MemberDailyRoutineGetServiceResponseV2.builder()
.themeId(routines.get(0).themeId())
.themeName(routines.get(0).themeName())
.routines(routines.stream().map(MemberDailyRoutineServiceResponse::of).toList())
.build();
}

@Builder(access = PRIVATE)
public record MemberDailyRoutineServiceResponse(
long routineId,
@NonNull String content,
int achieveCount,
boolean isAchieve
) {

private static MemberDailyRoutineServiceResponse of(MemberRoutineResponse routine) {
return MemberDailyRoutineServiceResponse.builder()
.routineId(routine.id())
.content(routine.content())
.achieveCount(routine.achieveCount())
.isAchieve(routine.isAchieve())
.build();
}
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
package com.soptie.server.memberRoutine.service.dto.response;

import static lombok.AccessLevel.*;

import java.util.List;

import com.soptie.server.memberRoutine.repository.dto.MemberRoutineResponse;

import lombok.Builder;
import lombok.NonNull;

import java.util.List;

import static lombok.AccessLevel.PRIVATE;

@Builder(access = PRIVATE)
public record MemberDailyRoutineListGetServiceResponse(
@NonNull List<MemberDailyRoutineServiceResponse> routines
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.soptie.server.memberRoutine.service.dto.response;

import lombok.Builder;
import lombok.NonNull;

import java.util.List;

import static lombok.AccessLevel.PRIVATE;

@Builder(access = PRIVATE)
public record MemberDailyRoutineListGetServiceResponseV2(
@NonNull List<MemberDailyRoutineGetServiceResponseV2> routines
) {

public static MemberDailyRoutineListGetServiceResponseV2 of(List<MemberDailyRoutineGetServiceResponseV2> routines) {
return MemberDailyRoutineListGetServiceResponseV2.builder()
.routines(routines)
.build();
}
}
Loading
Loading