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 all 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
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,7 @@ out/
.vscode/

### configuration ###
application-secret.yml
application-secret.yml

### JPAQueryFactory ###
generated
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 All @@ -36,7 +36,7 @@ public List<MemberRoutine> findAchieved() {
return memberRoutineRepository.findByIsAchieve(true);
}

public List<MemberRoutineResponse> findDailyRoutinesByMember(Member member) {
public List<MemberRoutineResponse> findAllByMember(Member member) {
return memberRoutineRepository.findByTypeAndMember(DAILY, member);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import com.soptie.server.memberRoutine.controller.v1.api.MemberDailyRoutineApi;
import com.soptie.server.memberRoutine.controller.v1.dto.response.MemberDailyRoutineAchieveResponse;
import com.soptie.server.memberRoutine.controller.v1.dto.response.MemberDailyRoutineCreateResponse;
import com.soptie.server.memberRoutine.controller.v1.dto.response.MemberDailyRoutineListGetResponse;
import com.soptie.server.memberRoutine.controller.v1.dto.response.MemberDailyRoutineListAcquireResponse;
import com.soptie.server.memberRoutine.service.MemberRoutineCreateService;
import com.soptie.server.memberRoutine.controller.v1.dto.request.MemberDailyRoutineCreateRequest;
import com.soptie.server.memberRoutine.service.MemberRoutineDeleteService;
Expand All @@ -32,7 +32,7 @@
import com.soptie.server.memberRoutine.service.dto.request.MemberRoutineAchieveServiceRequest;
import com.soptie.server.memberRoutine.service.dto.request.MemberDailyRoutineCreateServiceRequest;
import com.soptie.server.memberRoutine.service.dto.request.MemberRoutinesDeleteServiceRequest;
import com.soptie.server.memberRoutine.service.dto.request.MemberDailyRoutineListGetServiceRequest;
import com.soptie.server.memberRoutine.service.dto.request.MemberDailyRoutineListAcquireServiceRequest;

import lombok.RequiredArgsConstructor;
import lombok.val;
Expand Down Expand Up @@ -83,12 +83,12 @@ public ResponseEntity<SuccessResponse<MemberDailyRoutineAchieveResponse>> achiev
}

@GetMapping
public ResponseEntity<SuccessResponse<MemberDailyRoutineListGetResponse>> getMemberDailyRoutines(
public ResponseEntity<SuccessResponse<MemberDailyRoutineListAcquireResponse>> getMemberDailyRoutines(
Principal principal
) {
val memberId = Long.parseLong(principal.getName());
val response = MemberDailyRoutineListGetResponse
.of(memberRoutineReadService.getDailyRoutines(MemberDailyRoutineListGetServiceRequest.of(memberId)));
val response = MemberDailyRoutineListAcquireResponse
.of(memberRoutineReadService.getDailyRoutines(MemberDailyRoutineListAcquireServiceRequest.of(memberId)));
return ResponseEntity.ok(success(SUCCESS_GET_ROUTINE.getMessage(), response));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import com.soptie.server.memberRoutine.controller.v1.dto.response.MemberDailyRoutineAchieveResponse;
import com.soptie.server.memberRoutine.controller.v1.dto.request.MemberDailyRoutineCreateRequest;
import com.soptie.server.memberRoutine.controller.v1.dto.response.MemberDailyRoutineCreateResponse;
import com.soptie.server.memberRoutine.controller.v1.dto.response.MemberDailyRoutineListGetResponse;
import com.soptie.server.memberRoutine.controller.v1.dto.response.MemberDailyRoutineListAcquireResponse;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
Expand Down Expand Up @@ -144,7 +144,7 @@ ResponseEntity<SuccessResponse<MemberDailyRoutineAchieveResponse>> achieveMember
)
}
)
ResponseEntity<SuccessResponse<MemberDailyRoutineListGetResponse>> getMemberDailyRoutines(
ResponseEntity<SuccessResponse<MemberDailyRoutineListAcquireResponse>> getMemberDailyRoutines(
@Parameter(hidden = true) Principal principal
);
}
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
package com.soptie.server.memberRoutine.controller.v1.dto.response;

import static lombok.AccessLevel.*;
import com.soptie.server.memberRoutine.service.dto.response.MemberDailyRoutinesAcquireServiceResponse;
import com.soptie.server.memberRoutine.service.dto.response.MemberDailyRoutinesAcquireServiceResponse.MemberDailyRoutineServiceResponse;
import lombok.Builder;
import lombok.NonNull;

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 static lombok.AccessLevel.PRIVATE;

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

public static MemberDailyRoutineListGetResponse of(MemberDailyRoutineListGetServiceResponse response) {
return MemberDailyRoutineListGetResponse.builder()
public static MemberDailyRoutineListAcquireResponse of(MemberDailyRoutinesAcquireServiceResponse response) {
return MemberDailyRoutineListAcquireResponse.builder()
.routines(response.routines().stream().map(MemberDailyRoutineResponse::of).toList())
.build();
}
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.MemberDailyRoutineListAcquireResponseV2;
import com.soptie.server.memberRoutine.service.MemberRoutineReadService;
import com.soptie.server.memberRoutine.service.dto.request.MemberDailyRoutineListAcquireServiceRequest;
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<MemberDailyRoutineListAcquireResponseV2>> acquireAll(
Principal principal
) {
val memberId = Long.parseLong(principal.getName());
val response = MemberDailyRoutineListAcquireResponseV2
.of(memberRoutineReadService.acquireAll(MemberDailyRoutineListAcquireServiceRequest.of(memberId)));
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.MemberDailyRoutineListAcquireResponseV2;
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<MemberDailyRoutineListAcquireResponseV2>> acquireAll(
@Parameter(hidden = true) Principal principal
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package com.soptie.server.memberRoutine.controller.v2.dto.response;

import com.soptie.server.memberRoutine.service.dto.response.MemberDailyRoutinesAcquireServiceResponse;
import com.soptie.server.memberRoutine.service.dto.response.MemberDailyRoutineListAcquireServiceResponse;
import lombok.Builder;
import lombok.NonNull;

import java.util.List;

import static lombok.AccessLevel.PRIVATE;

@Builder(access = PRIVATE)
public record MemberDailyRoutineListAcquireResponseV2(
@NonNull List<MemberDailyRoutineListResponse> routines
) {

public static MemberDailyRoutineListAcquireResponseV2 of(MemberDailyRoutineListAcquireServiceResponse response) {
return MemberDailyRoutineListAcquireResponseV2.builder()
.routines(response.routines().stream()
.map(MemberDailyRoutineListResponse::of)
.toList())
.build();
}

@Builder(access = PRIVATE)
public record MemberDailyRoutineListResponse(
long themeId,
@NonNull String themeName,
@NonNull List<MemberDailyRoutineResponse> routines
) {

public static MemberDailyRoutineListResponse of(MemberDailyRoutinesAcquireServiceResponse routines) {
return MemberDailyRoutineListResponse.builder()
.themeId(routines.themeId())
.themeName(routines.themeName())
.routines(routines.routines().stream().map(MemberDailyRoutineResponse::of).toList())
.build();
}

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

private static MemberDailyRoutineResponse of(
MemberDailyRoutinesAcquireServiceResponse.MemberDailyRoutineServiceResponse routine
) {
return MemberDailyRoutineResponse.builder()
.routineId(routine.routineId())
.content(routine.content())
.achieveCount(routine.achieveCount())
.isAchieve(routine.isAchieve())
.build();
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@
import com.querydsl.core.annotations.QueryProjection;
import com.soptie.server.memberRoutine.entity.MemberRoutine;
import com.soptie.server.routine.entity.Routine;
import lombok.NonNull;

public record MemberRoutineResponse(
Long id,
String content,
String iconImageUrl,
String dailyIconImageUrl,
long id,
@NonNull String content,
@NonNull String iconImageUrl,
@NonNull String dailyIconImageUrl,
long themeId,
@NonNull String themeName,
int achieveCount,
boolean isAchieve
) {
Expand All @@ -20,6 +23,8 @@ public MemberRoutineResponse(MemberRoutine memberRoutine, Routine routine) {
routine.getContent(),
routine.getTheme().getImageLinks().getIconImageUrl(),
routine.getTheme().getImageLinks().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
Loading
Loading