Skip to content

Commit 1942bd5

Browse files
authored
Merge pull request #62 from YAPP-Github/feat/T3-164
[T3-164] 루틴 완료 여부 갱신 API
2 parents bdc67c9 + ff8c74a commit 1942bd5

7 files changed

Lines changed: 95 additions & 1 deletion

File tree

src/main/java/bitnagil/bitnagil_backend/routine/controller/spec/RoutineSpec.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public interface RoutineSpec {
3939
ErrorCode.ROUTINE_USER_NOT_MATCHED})
4040
CustomResponseDto<Object> updateRoutine(User user, UpdateRoutineRequest updateRoutineRequest);
4141

42-
@Operation(summary = "루틴 및 서브 루틴을 모두 삭제합니다.")
42+
@Operation(summary = "(V2) 모든 날짜에서 루틴을 삭제합니다. (루틴 전체 삭제)")
4343
@ApiErrorCodeExamples({ErrorCode.NOT_FOUND_ROUTINE, ErrorCode.ROUTINE_USER_NOT_MATCHED})
4444
CustomResponseDto<Object> deleteRoutine(User user, String routineId);
4545

src/main/java/bitnagil/bitnagil_backend/routineV2/controller/RoutineV2Controller.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package bitnagil.bitnagil_backend.routineV2.controller;
22

3+
import bitnagil.bitnagil_backend.routineV2.request.UpdateRoutineCompletionRequest;
34
import bitnagil.bitnagil_backend.routineV2.response.RoutineV2SearchResponse;
45
import bitnagil.bitnagil_backend.routineV2.response.RoutineV2SearchResultDto;
56
import jakarta.validation.constraints.NotNull;
@@ -43,4 +44,18 @@ public CustomResponseDto<Object> registerRoutine(@CurrentUser User user, @Reques
4344

4445
return CustomResponseDto.from(null);
4546
}
47+
48+
/*
49+
* 루틴 완료 여부를 갱신하는 API 입니다.
50+
* 멱등성이 보장되는 업데이트 API이므로 PUT Method를 사용했습니다.
51+
*/
52+
@PutMapping("")
53+
public CustomResponseDto<Object> updateRoutineCompletionStatus(
54+
@CurrentUser User user, @RequestBody UpdateRoutineCompletionRequest request) {
55+
56+
routineV2Service.updateRoutineCompletionStatus(user, request);
57+
58+
return CustomResponseDto.from(null);
59+
}
60+
4661
}

src/main/java/bitnagil/bitnagil_backend/routineV2/controller/spec/RoutineV2Spec.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
package bitnagil.bitnagil_backend.routineV2.controller.spec;
22

3+
import bitnagil.bitnagil_backend.global.annotation.CurrentUser;
34
import bitnagil.bitnagil_backend.global.errorcode.ErrorCode;
45
import bitnagil.bitnagil_backend.global.response.CustomResponseDto;
56
import bitnagil.bitnagil_backend.global.swagger.ApiErrorCodeExamples;
67
import bitnagil.bitnagil_backend.global.swagger.ApiTags;
78
import bitnagil.bitnagil_backend.routineV2.request.RegisterRoutineV2Request;
9+
import bitnagil.bitnagil_backend.routineV2.request.UpdateRoutineCompletionRequest;
810
import bitnagil.bitnagil_backend.routineV2.response.RoutineV2SearchResponse;
911
import bitnagil.bitnagil_backend.routineV2.response.RoutineV2SearchResultDto;
1012
import bitnagil.bitnagil_backend.user.domain.User;
@@ -17,6 +19,8 @@
1719
import java.time.LocalDate;
1820
import java.util.UUID;
1921

22+
import org.springframework.web.bind.annotation.RequestBody;
23+
2024
@Tag(name = ApiTags.ROUTINEV2)
2125
public interface RoutineV2Spec {
2226

@@ -35,4 +39,9 @@ public interface RoutineV2Spec {
3539

3640
@Operation(summary = "루틴 정보 등록 및 루틴 시작, 종료일자 사이에서 반복요일에 해당하는 날짜로 루틴 데이터를 생성합니다.")
3741
CustomResponseDto<Object> registerRoutine(User user, RegisterRoutineV2Request request);
42+
43+
@Operation(summary = "여러 루틴의 완료 여부를 갱신합니다. (여러 루틴의 완료 여부를 리스트로 만들어 요청하는 방식입니다.)")
44+
@ApiErrorCodeExamples({ErrorCode.NOT_FOUND_ROUTINE})
45+
CustomResponseDto<Object> updateRoutineCompletionStatus(
46+
@CurrentUser User user, @RequestBody UpdateRoutineCompletionRequest request);
3847
}

src/main/java/bitnagil/bitnagil_backend/routineV2/domain/RoutineV2.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,4 +63,10 @@ public RoutineV2(LocalDate routineDate, Boolean routineCompleteYn, List<String>
6363
this.subRoutineCompleteYn = subRoutineCompleteYn;
6464
this.routineInfo = routineInfo;
6565
}
66+
67+
// 루틴 완료 여부 갱신
68+
public void updateRoutineCompleteYn(Boolean routineCompleteYn, List<Boolean> subRoutineCompleteYn) {
69+
this.routineCompleteYn = routineCompleteYn;
70+
this.subRoutineCompleteYn = subRoutineCompleteYn;
71+
}
6672
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package bitnagil.bitnagil_backend.routineV2.request;
2+
3+
import java.util.List;
4+
5+
import io.swagger.v3.oas.annotations.media.Schema;
6+
import jakarta.validation.constraints.NotNull;
7+
import lombok.Getter;
8+
import lombok.NoArgsConstructor;
9+
10+
@Getter
11+
@NoArgsConstructor
12+
public class UpdateRoutineCompletionInfo {
13+
14+
@Schema(description = "루틴 완료 여부를 갱신할 루틴 ID 값입니다.",
15+
example = "4",
16+
required = true)
17+
@NotNull
18+
private Long routineId;
19+
20+
@Schema(description = "메인 루틴의 완료 여부입니다.",
21+
example = "true",
22+
required = true)
23+
@NotNull
24+
private Boolean routineCompleteYn;
25+
26+
@Schema(description = "서브루틴 완료 여부 리스트입니다.",
27+
example = "[true, false, true]",
28+
required = true)
29+
@NotNull
30+
private List<Boolean> subRoutineCompleteYn;
31+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package bitnagil.bitnagil_backend.routineV2.request;
2+
3+
import java.util.List;
4+
5+
import io.swagger.v3.oas.annotations.media.Schema;
6+
import jakarta.validation.constraints.NotNull;
7+
import lombok.Getter;
8+
import lombok.NoArgsConstructor;
9+
10+
@Getter
11+
@NoArgsConstructor
12+
@Schema(description = "루틴 완료 여부 갱신 DTO")
13+
public class UpdateRoutineCompletionRequest {
14+
15+
@Schema(description = "루틴 완료 여부를 갱신할 루틴 정보 리스트입니다.",
16+
required = true)
17+
@NotNull
18+
List<UpdateRoutineCompletionInfo> routineCompletionInfos;
19+
}

src/main/java/bitnagil/bitnagil_backend/routineV2/service/RoutineV2Service.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
import bitnagil.bitnagil_backend.global.errorcode.ErrorCode;
88
import bitnagil.bitnagil_backend.global.exception.CustomException;
9+
import bitnagil.bitnagil_backend.routineV2.request.UpdateRoutineCompletionInfo;
10+
import bitnagil.bitnagil_backend.routineV2.request.UpdateRoutineCompletionRequest;
911
import bitnagil.bitnagil_backend.routineV2.response.RoutineV2SearchResponse;
1012
import bitnagil.bitnagil_backend.routineV2.response.RoutineV2SearchResultDto;
1113
import org.springframework.stereotype.Service;
@@ -101,6 +103,18 @@ public void registerRoutineV2(User user, RegisterRoutineV2Request request) {
101103
routineV2Repository.saveAll(routinesToRegister);
102104
}
103105

106+
// 루틴 완료 여부를 업데이트 하는 메서드
107+
@Transactional
108+
public void updateRoutineCompletionStatus(User user, UpdateRoutineCompletionRequest request) {
109+
for (UpdateRoutineCompletionInfo info : request.getRoutineCompletionInfos()) {
110+
RoutineV2 routineV2 = routineV2Repository.findByUserAndRoutineId(user, info.getRoutineId())
111+
.orElseThrow(() -> new CustomException(ErrorCode.NOT_FOUND_ROUTINE));
112+
113+
// 루틴, 서브루틴 완료 여부 갱신
114+
routineV2.updateRoutineCompleteYn(info.getRoutineCompleteYn(), info.getSubRoutineCompleteYn());
115+
}
116+
}
117+
104118
/**
105119
* 날짜 범위에서 주어진 요일(repeatDays)에 해당하는 날짜만 반환
106120
*/

0 commit comments

Comments
 (0)