-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
[FEAT] 도전 루틴 목록 조회
- Loading branch information
Showing
14 changed files
with
406 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
src/main/java/com/soptie/server/routine/controller/v2/ChallengeRoutineControllerV2.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package com.soptie.server.routine.controller.v2; | ||
|
||
import java.security.Principal; | ||
|
||
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.RequestParam; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import com.soptie.server.common.dto.SuccessResponse; | ||
import com.soptie.server.routine.controller.v2.docs.ChallengeRoutineControllerV2Docs; | ||
import com.soptie.server.routine.controller.v2.dto.response.ChallengeRoutineListAcquireResponseV2; | ||
import com.soptie.server.routine.message.RoutineSuccessMessage; | ||
import com.soptie.server.routine.service.RoutineService; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import lombok.val; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("/api/v2/routines/challenge") | ||
public class ChallengeRoutineControllerV2 implements ChallengeRoutineControllerV2Docs { | ||
|
||
private final RoutineService routineService; | ||
|
||
@GetMapping | ||
public ResponseEntity<SuccessResponse<ChallengeRoutineListAcquireResponseV2>> acquireAllByTheme( | ||
Principal principal, | ||
@RequestParam long themeId | ||
) { | ||
val memberId = Long.parseLong(principal.getName()); | ||
val response = routineService.acquireAllInChallengeWithThemeId(memberId, themeId); | ||
return ResponseEntity.ok(SuccessResponse.success( | ||
RoutineSuccessMessage.SUCCESS_GET_CHALLENGE_ROUTINE.getMessage(), | ||
ChallengeRoutineListAcquireResponseV2.from(response))); | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
...n/java/com/soptie/server/routine/controller/v2/docs/ChallengeRoutineControllerV2Docs.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package com.soptie.server.routine.controller.v2.docs; | ||
|
||
import java.security.Principal; | ||
|
||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
|
||
import com.soptie.server.common.dto.ErrorResponse; | ||
import com.soptie.server.common.dto.SuccessResponse; | ||
import com.soptie.server.routine.controller.v2.dto.response.ChallengeRoutineListAcquireResponseV2; | ||
|
||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.Parameter; | ||
import io.swagger.v3.oas.annotations.enums.ParameterIn; | ||
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; | ||
|
||
@Tag(name = "challenge routines V2", description = "도전 루틴 API Version2") | ||
public interface ChallengeRoutineControllerV2Docs { | ||
|
||
@Operation( | ||
summary = "테마별 도전 루틴 목록 조회", | ||
description = "테마에 해당되는 도전 루틴 목록을 조회한다.", | ||
responses = { | ||
@ApiResponse(responseCode = "200", description = "성공"), | ||
@ApiResponse( | ||
responseCode = "4xx", | ||
description = "클라이언트(요청) 오류", | ||
content = @Content(schema = @Schema(implementation = ErrorResponse.class))), | ||
@ApiResponse( | ||
responseCode = "500", | ||
description = "서버 내부 오류", | ||
content = @Content(schema = @Schema(implementation = ErrorResponse.class)))} | ||
) | ||
ResponseEntity<SuccessResponse<ChallengeRoutineListAcquireResponseV2>> acquireAllByTheme( | ||
@Parameter(hidden = true) Principal principal, | ||
@Parameter( | ||
name = "themeId", | ||
description = "조회할 도전 루틴 테마 id", | ||
in = ParameterIn.QUERY, | ||
example = "1" | ||
) @RequestParam long themeId | ||
); | ||
} |
64 changes: 64 additions & 0 deletions
64
...ptie/server/routine/controller/v2/dto/response/ChallengeRoutineListAcquireResponseV2.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package com.soptie.server.routine.controller.v2.dto.response; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import com.soptie.server.routine.service.dto.response.ChallengeRoutineListAcquireServiceResponse; | ||
|
||
import lombok.AccessLevel; | ||
import lombok.Builder; | ||
import lombok.NonNull; | ||
|
||
@Builder(access = AccessLevel.PRIVATE) | ||
public record ChallengeRoutineListAcquireResponseV2( | ||
@NonNull List<RoutineResponse> routines | ||
) { | ||
|
||
public static ChallengeRoutineListAcquireResponseV2 from( | ||
Map<String, ChallengeRoutineListAcquireServiceResponse> challengesMap | ||
) { | ||
return ChallengeRoutineListAcquireResponseV2.builder() | ||
.routines(challengesMap.keySet() | ||
.stream() | ||
.map(key -> RoutineResponse.from(key, challengesMap.get(key))) | ||
.toList()) | ||
.build(); | ||
} | ||
|
||
@Builder(access = AccessLevel.PRIVATE) | ||
private record RoutineResponse( | ||
@NonNull String title, | ||
@NonNull List<ChallengeResponse> challenges | ||
) { | ||
|
||
private static RoutineResponse from(String title, ChallengeRoutineListAcquireServiceResponse challenges) { | ||
return RoutineResponse.builder() | ||
.title(title) | ||
.challenges(challenges.challenges().stream().map(ChallengeResponse::from).toList()) | ||
.build(); | ||
} | ||
} | ||
|
||
@Builder(access = AccessLevel.PRIVATE) | ||
private record ChallengeResponse( | ||
long challengeId, | ||
@NonNull String content, | ||
@NonNull String description, | ||
@NonNull String requiredTime, | ||
@NonNull String place, | ||
boolean hasRoutine | ||
) { | ||
|
||
private static ChallengeResponse from( | ||
ChallengeRoutineListAcquireServiceResponse.ChallengeRoutineAcquireResponse challenge) { | ||
return ChallengeResponse.builder() | ||
.challengeId(challenge.challenge().challengeId()) | ||
.content(challenge.challenge().content()) | ||
.description(challenge.challenge().description()) | ||
.requiredTime(challenge.challenge().requiredTime()) | ||
.place(challenge.challenge().place()) | ||
.hasRoutine(challenge.hasRoutine()) | ||
.build(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
...optie/server/routine/service/dto/response/ChallengeRoutineListAcquireServiceResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package com.soptie.server.routine.service.dto.response; | ||
|
||
import static lombok.AccessLevel.PRIVATE; | ||
|
||
import java.util.List; | ||
|
||
import com.soptie.server.routine.service.vo.ChallengeVO; | ||
|
||
import lombok.Builder; | ||
import lombok.NonNull; | ||
|
||
@Builder(access = PRIVATE) | ||
public record ChallengeRoutineListAcquireServiceResponse( | ||
@NonNull List<ChallengeRoutineAcquireResponse> challenges | ||
) { | ||
|
||
public static ChallengeRoutineListAcquireServiceResponse of(List<ChallengeVO> challenges, long challengeId) { | ||
return ChallengeRoutineListAcquireServiceResponse.builder() | ||
.challenges(challenges.stream() | ||
.map(challenge -> ChallengeRoutineAcquireResponse.of(challenge, challengeId)) | ||
.toList()) | ||
.build(); | ||
} | ||
|
||
@Builder(access = PRIVATE) | ||
public record ChallengeRoutineAcquireResponse( | ||
ChallengeVO challenge, | ||
boolean hasRoutine | ||
) { | ||
|
||
public static ChallengeRoutineAcquireResponse of(ChallengeVO challenge, long challengeId) { | ||
return ChallengeRoutineAcquireResponse.builder() | ||
.challenge(challenge) | ||
.hasRoutine(challenge.challengeId() == challengeId) | ||
.build(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
src/main/java/com/soptie/server/routine/service/vo/ChallengeVO.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package com.soptie.server.routine.service.vo; | ||
|
||
import com.soptie.server.routine.entity.Challenge; | ||
|
||
import lombok.AccessLevel; | ||
import lombok.Builder; | ||
import lombok.NonNull; | ||
|
||
@Builder(access = AccessLevel.PRIVATE) | ||
public record ChallengeVO( | ||
long challengeId, | ||
@NonNull String content, | ||
@NonNull String description, | ||
@NonNull String requiredTime, | ||
@NonNull String place | ||
) { | ||
|
||
public static ChallengeVO from(Challenge challenge) { | ||
return ChallengeVO.builder() | ||
.challengeId(challenge.getId()) | ||
.content(challenge.getContent()) | ||
.description(challenge.getDescription()) | ||
.requiredTime(challenge.getRequiredTime()) | ||
.place(challenge.getPlace()) | ||
.build(); | ||
} | ||
} |
Oops, something went wrong.