Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@

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.ApiResponses;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import jakarta.validation.constraints.PastOrPresent;
Expand All @@ -53,25 +50,6 @@ public class HabitController {
summary = "습관 목록 조회 (무한 스크롤)",
description = "생성일자 기준으로 내림차순 정렬된 습관 목록을 페이지네이션으로 조회합니다. 각 습관의 오늘 체크 여부도 함께 반환됩니다."
)
@ApiResponses(value = {
@io.swagger.v3.oas.annotations.responses.ApiResponse(
responseCode = "200",
description = "습관 목록 조회 성공",
content = @Content(schema = @Schema(implementation = HabitSliceResponseDTO.class))
),
@io.swagger.v3.oas.annotations.responses.ApiResponse(
responseCode = "400",
description = "잘못된 요청 파라미터"
),
@io.swagger.v3.oas.annotations.responses.ApiResponse(
responseCode = "401",
description = "인증 실패"
),
@io.swagger.v3.oas.annotations.responses.ApiResponse(
responseCode = "500",
description = "서버 내부 오류"
)
})
public ApiResponse<HabitSliceResponseDTO> getHabits(
@Parameter(description = "페이지 번호 (0부터 시작)", example = "0")
@RequestParam(required = false, defaultValue = "0") Integer page,
Expand All @@ -88,29 +66,6 @@ public ApiResponse<HabitSliceResponseDTO> getHabits(
summary = "습관 생성",
description = "새로운 습관을 생성합니다. 습관 이름과 색상 코드를 입력받아 저장합니다."
)
@ApiResponses(value = {
@io.swagger.v3.oas.annotations.responses.ApiResponse(
responseCode = "200",
description = "습관 생성 성공",
content = @Content(schema = @Schema(implementation = HabitResponseDTO.class))
),
@io.swagger.v3.oas.annotations.responses.ApiResponse(
responseCode = "400",
description = "잘못된 요청 데이터 (필수 필드 누락, 유효성 검증 실패 등)"
),
@io.swagger.v3.oas.annotations.responses.ApiResponse(
responseCode = "401",
description = "인증 실패"
),
@io.swagger.v3.oas.annotations.responses.ApiResponse(
responseCode = "409",
description = "동일한 이름의 습관이 이미 존재함"
),
@io.swagger.v3.oas.annotations.responses.ApiResponse(
responseCode = "500",
description = "서버 내부 오류"
)
})
public ApiResponse<HabitResponseDTO> createHabit(
@Valid @RequestBody CreateHabitRequestDTO request
) {
Expand All @@ -123,47 +78,11 @@ public ApiResponse<HabitResponseDTO> createHabit(
summary = "습관 수정",
description = "기존 습관의 정보를 수정합니다. 본인이 생성한 습관만 수정 가능합니다."
)
@ApiResponses(value = {
@io.swagger.v3.oas.annotations.responses.ApiResponse(
responseCode = "200",
description = "습관 수정 성공",
content = @Content(schema = @Schema(implementation = HabitResponseDTO.class))
),
@io.swagger.v3.oas.annotations.responses.ApiResponse(
responseCode = "400",
description = "잘못된 요청 데이터 (유효성 검증 실패 등)"
),
@io.swagger.v3.oas.annotations.responses.ApiResponse(
responseCode = "401",
description = "인증 실패"
),
@io.swagger.v3.oas.annotations.responses.ApiResponse(
responseCode = "403",
description = "권한 없음 (다른 사용자의 습관 수정 시도)"
),
@io.swagger.v3.oas.annotations.responses.ApiResponse(
responseCode = "404",
description = "습관을 찾을 수 없음"
),
@io.swagger.v3.oas.annotations.responses.ApiResponse(
responseCode = "409",
description = "변경하려는 이름의 습관이 이미 존재함"
),
@io.swagger.v3.oas.annotations.responses.ApiResponse(
responseCode = "500",
description = "서버 내부 오류"
)
})
public ApiResponse<HabitResponseDTO> updateHabit(

@Parameter(description = "습관 ID", required = true, example = "1")
@PathVariable Long habitId,

@io.swagger.v3.oas.annotations.parameters.RequestBody(
description = "습관 수정 요청 데이터",
required = true,
content = @Content(schema = @Schema(implementation = UpdateHabitRequestDTO.class))
)
@RequestBody UpdateHabitRequestDTO request
) {
Long userId = Utils.getUserId();
Expand All @@ -175,29 +94,6 @@ public ApiResponse<HabitResponseDTO> updateHabit(
summary = "습관 삭제",
description = "특정 습관을 삭제합니다. 본인이 생성한 습관만 삭제 가능하며, 관련된 모든 체크 기록도 함께 삭제됩니다."
)
@ApiResponses(value = {
@io.swagger.v3.oas.annotations.responses.ApiResponse(
responseCode = "200",
description = "습관 삭제 성공",
content = @Content(schema = @Schema(implementation = Void.class))
),
@io.swagger.v3.oas.annotations.responses.ApiResponse(
responseCode = "401",
description = "인증 실패"
),
@io.swagger.v3.oas.annotations.responses.ApiResponse(
responseCode = "403",
description = "권한 없음 (다른 사용자의 습관 삭제 시도)"
),
@io.swagger.v3.oas.annotations.responses.ApiResponse(
responseCode = "404",
description = "습관을 찾을 수 없음"
),
@io.swagger.v3.oas.annotations.responses.ApiResponse(
responseCode = "500",
description = "서버 내부 오류"
)
})
public ApiResponse<Void> deleteHabit(
@Parameter(description = "습관 ID", required = true, example = "1")
@PathVariable Long habitId
Expand All @@ -211,42 +107,11 @@ public ApiResponse<Void> deleteHabit(
summary = "습관 체크 상태 토글",
description = "특정 날짜의 습관 체크 상태를 토글합니다. 체크되지 않은 상태면 체크하고, 체크된 상태면 체크를 해제합니다."
)
@ApiResponses(value = {
@io.swagger.v3.oas.annotations.responses.ApiResponse(
responseCode = "200",
description = "습관 체크 상태 토글 성공",
content = @Content(schema = @Schema(implementation = HabitResponseDTO.class))
),
@io.swagger.v3.oas.annotations.responses.ApiResponse(
responseCode = "400",
description = "잘못된 요청 데이터 (유효성 검증 실패, 미래 날짜 등)"
),
@io.swagger.v3.oas.annotations.responses.ApiResponse(
responseCode = "401",
description = "인증 실패"
),
@io.swagger.v3.oas.annotations.responses.ApiResponse(
responseCode = "403",
description = "권한 없음 (다른 사용자의 습관 체크 시도)"
),
@io.swagger.v3.oas.annotations.responses.ApiResponse(
responseCode = "404",
description = "습관을 찾을 수 없음"
),
@io.swagger.v3.oas.annotations.responses.ApiResponse(
responseCode = "500",
description = "서버 내부 오류"
)
})
public ApiResponse<HabitResponseDTO> updateHabitCheck(

@Parameter(description = "습관 ID", required = true, example = "1")
@PathVariable Long habitId,

@io.swagger.v3.oas.annotations.parameters.RequestBody(
description = "습관 체크 토글 요청 데이터",
required = true,
content = @Content(schema = @Schema(implementation = ToggleCheckRequestDTO.class))
)
@Valid @RequestBody ToggleCheckRequestDTO request
) {
Long userId = Utils.getUserId();
Expand All @@ -258,25 +123,6 @@ public ApiResponse<HabitResponseDTO> updateHabitCheck(
summary = "특정 날짜 습관 체크 상태 조회",
description = "특정 날짜에 대한 모든 습관의 체크 상태를 조회합니다. 각 습관별로 해당 날짜에 체크되었는지 여부를 반환합니다."
)
@ApiResponses(value = {
@io.swagger.v3.oas.annotations.responses.ApiResponse(
responseCode = "200",
description = "일일 습관 체크 상태 조회 성공",
content = @Content(schema = @Schema(implementation = HabitResponseDTO.class))
),
@io.swagger.v3.oas.annotations.responses.ApiResponse(
responseCode = "400",
description = "잘못된 요청 파라미터 (미래 날짜, 잘못된 날짜 형식 등)"
),
@io.swagger.v3.oas.annotations.responses.ApiResponse(
responseCode = "401",
description = "인증 실패"
),
@io.swagger.v3.oas.annotations.responses.ApiResponse(
responseCode = "500",
description = "서버 내부 오류"
)
})
public ApiResponse<List<HabitResponseDTO>> getDailyHabitCheckedState(
@Parameter(description = "조회할 날짜 (과거 또는 오늘만 가능)", required = true, example = "2025-01-01")
@RequestParam @PastOrPresent LocalDate date
Expand All @@ -290,25 +136,6 @@ public ApiResponse<List<HabitResponseDTO>> getDailyHabitCheckedState(
summary = "주간 습관 체크 현황 조회",
description = "지정된 시작 날짜부터 7일간의 습관 체크 현황을 조회합니다. 각 습관별로 주간 체크 패턴을 확인할 수 있습니다."
)
@ApiResponses(value = {
@io.swagger.v3.oas.annotations.responses.ApiResponse(
responseCode = "200",
description = "주간 습관 체크 현황 조회 성공",
content = @Content(schema = @Schema(implementation = HabitWeeklyChecksResponseDTO.class))
),
@io.swagger.v3.oas.annotations.responses.ApiResponse(
responseCode = "400",
description = "잘못된 요청 파라미터 (잘못된 날짜 형식 등)"
),
@io.swagger.v3.oas.annotations.responses.ApiResponse(
responseCode = "401",
description = "인증 실패"
),
@io.swagger.v3.oas.annotations.responses.ApiResponse(
responseCode = "500",
description = "서버 내부 오류"
)
})
public ApiResponse<List<HabitWeeklyChecksResponseDTO>> getWeeklyChecks(
@Parameter(description = "주간 조회 시작 날짜", required = true, example = "2025-01-01")
@RequestParam LocalDate startDate
Expand All @@ -322,25 +149,6 @@ public ApiResponse<List<HabitWeeklyChecksResponseDTO>> getWeeklyChecks(
summary = "월간 습관 체크 현황 조회",
description = "지정된 월의 습관 체크 현황을 조회합니다. 각 습관별로 월간 체크 패턴과 통계를 확인할 수 있습니다."
)
@ApiResponses(value = {
@io.swagger.v3.oas.annotations.responses.ApiResponse(
responseCode = "200",
description = "월간 습관 체크 현황 조회 성공",
content = @Content(schema = @Schema(implementation = HabitMonthlyChecksResponseDTO.class))
),
@io.swagger.v3.oas.annotations.responses.ApiResponse(
responseCode = "400",
description = "잘못된 요청 파라미터 (잘못된 년월 형식 등)"
),
@io.swagger.v3.oas.annotations.responses.ApiResponse(
responseCode = "401",
description = "인증 실패"
),
@io.swagger.v3.oas.annotations.responses.ApiResponse(
responseCode = "500",
description = "서버 내부 오류"
)
})
public ApiResponse<List<HabitMonthlyChecksResponseDTO>> getMonthlyChecks(
@Parameter(description = "조회할 년월 (yyyy-MM 형식)", required = true, example = "2025-01")
@RequestParam
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public void updateHabitCheck(User user, LocalDate checkDate, Boolean checked) {
}

// 상태 업데이트
targetLog.updateCheck(checked);
targetLog.updateCheck(checked, checkDate);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ public static void createHabitLog(Habit habit) {
}

//== 더티체킹 메서드 ==//
public void updateCheck(Boolean isChecked) {
public void updateCheck(Boolean isChecked, LocalDate checkedAt) {
this.isChecked = isChecked;
this.checkedAt = isChecked ? LocalDate.now() : null;
this.checkedAt = checkedAt;
}
}
Loading