Skip to content

Commit

Permalink
Merge pull request #317 from Team-Sopetit/feat/#316-daily-routines-ad…
Browse files Browse the repository at this point in the history
…d-api

[FEAT] 데일리 루틴 다중 추가 api
  • Loading branch information
thguss authored Aug 15, 2024
2 parents cda934a + 9fa3197 commit 08d559a
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.soptie.server.memberroutine.controller.v1.dto.request;

import java.util.List;

import io.swagger.v3.oas.annotations.media.Schema;

public record MemberDailyRoutinesCreateRequest(
@Schema(description = "추가하려는 루틴 id 목록", example = "[1, 2, 3]")
List<Long> routineIds
) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,16 @@

import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.soptie.server.common.dto.BaseResponse;
import com.soptie.server.common.dto.SuccessResponse;
import com.soptie.server.memberroutine.controller.v1.dto.request.MemberDailyRoutinesCreateRequest;
import com.soptie.server.memberroutine.controller.v2.docs.MemberDailyRoutineControllerV2Docs;
import com.soptie.server.memberroutine.controller.v2.dto.response.MemberDailyRoutineListAcquireResponseV2;
import com.soptie.server.memberroutine.service.MemberRoutineCreateService;
import com.soptie.server.memberroutine.service.MemberRoutineReadService;
import com.soptie.server.memberroutine.service.dto.request.MemberDailyRoutineListAcquireServiceRequest;

Expand All @@ -25,6 +29,7 @@
public class MemberDailyRoutineControllerV2 implements MemberDailyRoutineControllerV2Docs {

private final MemberRoutineReadService memberRoutineReadService;
private final MemberRoutineCreateService memberRoutineCreateService;

@GetMapping
public ResponseEntity<SuccessResponse<MemberDailyRoutineListAcquireResponseV2>> acquireAll(
Expand All @@ -35,4 +40,14 @@ public ResponseEntity<SuccessResponse<MemberDailyRoutineListAcquireResponseV2>>
.of(memberRoutineReadService.acquireAll(MemberDailyRoutineListAcquireServiceRequest.of(memberId)));
return ResponseEntity.ok(success(SUCCESS_GET_ROUTINE.getMessage(), response));
}

@PostMapping
public ResponseEntity<BaseResponse> createMemberDailyRoutines(
Principal principal,
MemberDailyRoutinesCreateRequest request
) {
val memberId = Long.parseLong(principal.getName());
memberRoutineCreateService.createDailyRoutines(memberId, request);
return ResponseEntity.ok(SuccessResponse.success(SUCCESS_CREATE_ROUTINE.getMessage()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@
import java.security.Principal;

import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestBody;

import com.soptie.server.common.dto.BaseResponse;
import com.soptie.server.common.dto.ErrorResponse;
import com.soptie.server.common.dto.SuccessResponse;
import com.soptie.server.memberroutine.controller.v1.dto.request.MemberDailyRoutinesCreateRequest;
import com.soptie.server.memberroutine.controller.v2.dto.response.MemberDailyRoutineListAcquireResponseV2;

import io.swagger.v3.oas.annotations.Operation;
Expand Down Expand Up @@ -39,4 +42,30 @@ public interface MemberDailyRoutineControllerV2Docs {
ResponseEntity<SuccessResponse<MemberDailyRoutineListAcquireResponseV2>> acquireAll(
@Parameter(hidden = true) Principal principal
);

@Operation(
summary = "데일리 루틴 다중 추가",
description = "회원의 데일리 루틴을 다중으로 추가한다.",
responses = {
@ApiResponse(
responseCode = "200",
description = "성공",
content = @Content(schema = @Schema(implementation = SuccessResponse.class))),
@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<BaseResponse> createMemberDailyRoutines(
@Parameter(hidden = true) Principal principal,
@RequestBody MemberDailyRoutinesCreateRequest request
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.soptie.server.member.entity.Member;
import com.soptie.server.memberroutine.adapter.MemberRoutineFinder;
import com.soptie.server.memberroutine.adapter.MemberRoutineSaver;
import com.soptie.server.memberroutine.controller.v1.dto.request.MemberDailyRoutinesCreateRequest;
import com.soptie.server.memberroutine.service.dto.request.MemberDailyRoutineCreateServiceRequest;
import com.soptie.server.memberroutine.service.dto.request.MemberHappinessRoutineCreateServiceRequest;
import com.soptie.server.memberroutine.service.dto.response.MemberDailyRoutineCreateServiceResponse;
Expand Down Expand Up @@ -40,6 +41,12 @@ public MemberDailyRoutineCreateServiceResponse createDailyRoutine(MemberDailyRou
return MemberDailyRoutineCreateServiceResponse.of(savedMemberRoutine);
}

public void createDailyRoutines(long memberId, MemberDailyRoutinesCreateRequest request) {
val member = memberFinder.findById(memberId);
val routines = routineFinder.findDailyByIds(request.routineIds());
routines.forEach(routine -> memberRoutineSaver.checkHasDeletedAndSave(member, routine));
}

public MemberHappinessRoutineCreateServiceResponse createHappinessRoutine(
MemberHappinessRoutineCreateServiceRequest request
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ public Routine findById(long id) {
.orElseThrow(() -> new RoutineException(INVALID_ROUTINE));
}

public List<Routine> findDailyByIds(List<Long> ids) {
return routineRepository.findByIdsAndType(ids, RoutineType.DAILY);
}

public List<Routine> findChallengeRoutinesByTheme(Long themeId) {
return routineRepository.findByTypeAndThemeId(RoutineType.CHALLENGE, themeId);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,6 @@ public interface RoutineCustomRepository {
List<Routine> findByTypeAndThemeAndNotMember(long memberId, RoutineType type, long themeId);

List<Routine> findByTypeAndThemeId(RoutineType type, Long themeId);

List<Routine> findByIdsAndType(List<Long> ids, RoutineType type);
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,17 @@ public List<Routine> findByTypeAndThemeId(RoutineType type, Long themeId) {
.fetch();
}

@Override
public List<Routine> findByIdsAndType(List<Long> ids, RoutineType type) {
return queryFactory
.selectFrom(routine)
.where(
routine.id.in(ids),
routine.type.eq(type)
)
.fetch();
}

private BooleanExpression themeEq(Long themeId) {
return (isNull(themeId) || themeId == 0L) ? null : routine.theme.id.eq(themeId);
}
Expand Down

0 comments on commit 08d559a

Please sign in to comment.