From 51af84dfad45fcf56a2c76aa186895c55d1497f8 Mon Sep 17 00:00:00 2001 From: JoonHyeok Han Date: Sun, 6 Oct 2024 21:51:52 +0900 Subject: [PATCH 1/6] =?UTF-8?q?:sparkles:=20feat:=20=EC=B1=8C=EB=A6=B0?= =?UTF-8?q?=EC=A7=80=201=ED=9A=8C=20=EC=8B=A4=ED=8C=A8=EB=8B=B9=20?= =?UTF-8?q?=EB=B2=8C=EA=B8=88=20=EC=A1=B0=ED=9A=8C=20API=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84=20#256?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/challenge/api/ChallengeApi.java | 5 +++++ .../application/ChallengeDetailsService.java | 11 ++++++++++- .../dto/ChallengeFeePerAbsenceResponse.java | 18 ++++++++++++++++++ 3 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 src/main/java/com/habitpay/habitpay/domain/challenge/dto/ChallengeFeePerAbsenceResponse.java diff --git a/src/main/java/com/habitpay/habitpay/domain/challenge/api/ChallengeApi.java b/src/main/java/com/habitpay/habitpay/domain/challenge/api/ChallengeApi.java index b1cee7a0..b5e3d558 100644 --- a/src/main/java/com/habitpay/habitpay/domain/challenge/api/ChallengeApi.java +++ b/src/main/java/com/habitpay/habitpay/domain/challenge/api/ChallengeApi.java @@ -46,6 +46,11 @@ public SuccessResponse getChallengeDetails(@PathVariab return challengeDetailsService.getChallengeDetails(id, user.getMember()); } + @GetMapping("/challenges/{id}/fees/absence") + public SuccessResponse getChallengeFeePerAbsence(@PathVariable("id") Long id) { + return challengeDetailsService.getChallengeFeePerAbsence(id); + } + @PostMapping("/challenges") public SuccessResponse createChallenge(@RequestBody ChallengeCreationRequest challengeCreationRequest, @AuthenticationPrincipal CustomUserDetails user) { diff --git a/src/main/java/com/habitpay/habitpay/domain/challenge/application/ChallengeDetailsService.java b/src/main/java/com/habitpay/habitpay/domain/challenge/application/ChallengeDetailsService.java index a81d2674..45db8f76 100644 --- a/src/main/java/com/habitpay/habitpay/domain/challenge/application/ChallengeDetailsService.java +++ b/src/main/java/com/habitpay/habitpay/domain/challenge/application/ChallengeDetailsService.java @@ -2,9 +2,9 @@ import com.habitpay.habitpay.domain.challenge.domain.Challenge; import com.habitpay.habitpay.domain.challenge.dto.ChallengeDetailsResponse; +import com.habitpay.habitpay.domain.challenge.dto.ChallengeFeePerAbsenceResponse; import com.habitpay.habitpay.domain.challengeenrollment.dao.ChallengeEnrollmentRepository; import com.habitpay.habitpay.domain.challengeenrollment.domain.ChallengeEnrollment; -import com.habitpay.habitpay.domain.member.application.MemberSearchService; import com.habitpay.habitpay.domain.member.domain.Member; import com.habitpay.habitpay.global.config.aws.S3FileService; import com.habitpay.habitpay.global.response.SuccessCode; @@ -47,4 +47,13 @@ public SuccessResponse getChallengeDetails(Long challe isMemberEnrolledInChallenge) ); } + + public SuccessResponse getChallengeFeePerAbsence(Long challengeId) { + Challenge challenge = challengeSearchService.getChallengeById(challengeId); + + return SuccessResponse.of( + SuccessCode.NO_MESSAGE, + ChallengeFeePerAbsenceResponse.from(challenge) + ); + } } diff --git a/src/main/java/com/habitpay/habitpay/domain/challenge/dto/ChallengeFeePerAbsenceResponse.java b/src/main/java/com/habitpay/habitpay/domain/challenge/dto/ChallengeFeePerAbsenceResponse.java new file mode 100644 index 00000000..d2cd5f76 --- /dev/null +++ b/src/main/java/com/habitpay/habitpay/domain/challenge/dto/ChallengeFeePerAbsenceResponse.java @@ -0,0 +1,18 @@ +package com.habitpay.habitpay.domain.challenge.dto; + +import com.habitpay.habitpay.domain.challenge.domain.Challenge; +import lombok.Builder; +import lombok.Getter; + +@Getter +@Builder +public class ChallengeFeePerAbsenceResponse { + + private int feePerAbsence; + + public static ChallengeFeePerAbsenceResponse from(Challenge challenge) { + return ChallengeFeePerAbsenceResponse.builder() + .feePerAbsence(challenge.getFeePerAbsence()) + .build(); + } +} From 7913b5d984a5b945e87ecf99a55741291674c741 Mon Sep 17 00:00:00 2001 From: JoonHyeok Han Date: Sun, 6 Oct 2024 21:52:50 +0900 Subject: [PATCH 2/6] =?UTF-8?q?:white=5Fcheck=5Fmark:=20test:=20=EC=B1=8C?= =?UTF-8?q?=EB=A6=B0=EC=A7=80=201=ED=9A=8C=20=EC=8B=A4=ED=8C=A8=EB=8B=B9?= =?UTF-8?q?=20=EB=B2=8C=EA=B8=88=20=EC=A1=B0=ED=9A=8C=20API=20=ED=85=8C?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8=20=EA=B5=AC=ED=98=84=20#256?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/docs/asciidoc/api/challenge.adoc | 14 +++++ .../challenge/api/ChallengeApiTest.java | 56 +++++++++++++++++++ 2 files changed, 70 insertions(+) diff --git a/src/docs/asciidoc/api/challenge.adoc b/src/docs/asciidoc/api/challenge.adoc index a5cc9ad7..c5ea4c33 100644 --- a/src/docs/asciidoc/api/challenge.adoc +++ b/src/docs/asciidoc/api/challenge.adoc @@ -43,6 +43,20 @@ operation::challenge/get-challenge-details[snippets='http-request,http-response, operation::challenge/get-challenge-details-not-found-exception[snippets='http-request,http-response,response-fields'] +=== 챌린지 1회 실패당 벌금 조회 + +첼린지 1회 실패당 벌금을 조회합니다. + +operation::challenge/get-challenge-fee-per-absence[snippets='http-request,http-response,response-fields'] + +==== 에러 응답 + +===== 챌린지가 존재하지 않는 경우 (404 Not Found) + +존재하지 않는 챌린지를 조회한 경우입니다. + +operation::challenge/get-challenge-fee-per-absence-not-found-exception[snippets='http-request,http-response,response-fields'] + === 챌린지 생성 새로운 첼린지를 생성합니다. diff --git a/src/test/java/com/habitpay/habitpay/domain/challenge/api/ChallengeApiTest.java b/src/test/java/com/habitpay/habitpay/domain/challenge/api/ChallengeApiTest.java index d0817e2f..933d3731 100644 --- a/src/test/java/com/habitpay/habitpay/domain/challenge/api/ChallengeApiTest.java +++ b/src/test/java/com/habitpay/habitpay/domain/challenge/api/ChallengeApiTest.java @@ -269,6 +269,62 @@ void getChallengeDetailsNotFoundException() throws Exception { )); } + @Test + @WithMockOAuth2User + @DisplayName("챌린지 1회 실패당 벌금 조회") + void getChallengeFeePerAbsence() throws Exception { + + // given + ChallengeFeePerAbsenceResponse challengeFeePerAbsenceResponse = ChallengeFeePerAbsenceResponse.builder() + .feePerAbsence(1000) + .build(); + + given(challengeDetailsService.getChallengeFeePerAbsence(anyLong())) + .willReturn(SuccessResponse.of(SuccessCode.NO_MESSAGE, challengeFeePerAbsenceResponse)); + + // when + ResultActions result = mockMvc.perform(get("/api/challenges/{id}/fees/absence", 1L) + .header(HttpHeaders.AUTHORIZATION, AUTHORIZATION_HEADER_PREFIX + "ACCESS_TOKEN")); + + // then + result.andExpect(status().isOk()) + .andDo(document("challenge/get-challenge-fee-per-absence", + requestHeaders( + headerWithName(HttpHeaders.AUTHORIZATION).description("액세스 토큰") + ), + responseFields( + fieldWithPath("message").description("메세지"), + fieldWithPath("data.feePerAbsence").description("미참여 1회당 벌금") + ) + )); + } + + @Test + @WithMockOAuth2User + @DisplayName("챌린지 1회 실패당 벌금 조회 예외처리 - 존재하지 않는 챌린지 (404 Not Found)") + void getChallengeFeePerAbsenceNotFoundException() throws Exception { + + // given + given(challengeDetailsService.getChallengeFeePerAbsence(anyLong())) + .willThrow(new ChallengeNotFoundException(0L)); + + // when + ResultActions result = mockMvc.perform(get("/api/challenges/{id}/fees/absence", 0L) + .header(HttpHeaders.AUTHORIZATION, AUTHORIZATION_HEADER_PREFIX + "ACCESS_TOKEN")); + + // then + result.andExpect(status().isNotFound()) + .andDo(document("challenge/get-challenge-fee-per-absence-not-found-exception", + requestHeaders( + headerWithName(HttpHeaders.AUTHORIZATION).description("액세스 토큰") + ), + responseFields( + fieldWithPath("code").description("오류 응답 코드"), + fieldWithPath("message").description("오류 메세지") + ) + )); + } + @Test @WithMockOAuth2User @DisplayName("챌린지 생성") From 1a067847cf147ec8445cb345db07ea19ca7fd37d Mon Sep 17 00:00:00 2001 From: JoonHyeok Han Date: Sun, 6 Oct 2024 22:05:48 +0900 Subject: [PATCH 3/6] =?UTF-8?q?:white=5Fcheck=5Fmark:=20test:=20=EC=B1=8C?= =?UTF-8?q?=EB=A6=B0=EC=A7=80=20=EC=A7=84=ED=96=89=20=EA=B8=B0=EA=B0=84=20?= =?UTF-8?q?=EC=A1=B0=ED=9A=8C=20API=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84=20#256?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/docs/asciidoc/api/challenge.adoc | 14 +++++ .../challenge/api/ChallengeApiTest.java | 59 +++++++++++++++++++ 2 files changed, 73 insertions(+) diff --git a/src/docs/asciidoc/api/challenge.adoc b/src/docs/asciidoc/api/challenge.adoc index c5ea4c33..a4973986 100644 --- a/src/docs/asciidoc/api/challenge.adoc +++ b/src/docs/asciidoc/api/challenge.adoc @@ -57,6 +57,20 @@ operation::challenge/get-challenge-fee-per-absence[snippets='http-request,http-r operation::challenge/get-challenge-fee-per-absence-not-found-exception[snippets='http-request,http-response,response-fields'] +=== 챌린지 진행 기간 조회 + +첼린지 1회 실패당 벌금을 조회합니다. + +operation::challenge/get-challenge-dates[snippets='http-request,http-response,response-fields'] + +==== 에러 응답 + +===== 챌린지가 존재하지 않는 경우 (404 Not Found) + +존재하지 않는 챌린지를 조회한 경우입니다. + +operation::challenge/get-challenge-dates-not-found-exception[snippets='http-request,http-response,response-fields'] + === 챌린지 생성 새로운 첼린지를 생성합니다. diff --git a/src/test/java/com/habitpay/habitpay/domain/challenge/api/ChallengeApiTest.java b/src/test/java/com/habitpay/habitpay/domain/challenge/api/ChallengeApiTest.java index 933d3731..2ba734a8 100644 --- a/src/test/java/com/habitpay/habitpay/domain/challenge/api/ChallengeApiTest.java +++ b/src/test/java/com/habitpay/habitpay/domain/challenge/api/ChallengeApiTest.java @@ -325,6 +325,65 @@ void getChallengeFeePerAbsenceNotFoundException() throws Exception { )); } + + @Test + @WithMockOAuth2User + @DisplayName("챌린지 진행 기간 조회") + void getChallengeDates() throws Exception { + + // given + ChallengeDatesResponse challengeDatesResponse = ChallengeDatesResponse.builder() + .startDate(ZonedDateTime.now()) + .endDate(ZonedDateTime.now().plusDays(2)) + .build(); + + given(challengeDetailsService.getChallengeDates(anyLong())) + .willReturn(SuccessResponse.of(SuccessCode.NO_MESSAGE, challengeDatesResponse)); + + // when + ResultActions result = mockMvc.perform(get("/api/challenges/{id}/dates", 1L) + .header(HttpHeaders.AUTHORIZATION, AUTHORIZATION_HEADER_PREFIX + "ACCESS_TOKEN")); + + // then + result.andExpect(status().isOk()) + .andDo(document("challenge/get-challenge-dates", + requestHeaders( + headerWithName(HttpHeaders.AUTHORIZATION).description("액세스 토큰") + ), + responseFields( + fieldWithPath("message").description("메세지"), + fieldWithPath("data.startDate").description("챌린지 시작 날짜"), + fieldWithPath("data.endDate").description("챌린지 종료 날짜") + ) + )); + } + + @Test + @WithMockOAuth2User + @DisplayName("챌린지 진행 기간 조회 예외처리 - 존재하지 않는 챌린지 (404 Not Found)") + void getChallengeDatesNotFoundException() throws Exception { + + // given + given(challengeDetailsService.getChallengeDates(anyLong())) + .willThrow(new ChallengeNotFoundException(0L)); + + // when + ResultActions result = mockMvc.perform(get("/api/challenges/{id}/dates", 0L) + .header(HttpHeaders.AUTHORIZATION, AUTHORIZATION_HEADER_PREFIX + "ACCESS_TOKEN")); + + // then + result.andExpect(status().isNotFound()) + .andDo(document("challenge/get-challenge-dates-not-found-exception", + requestHeaders( + headerWithName(HttpHeaders.AUTHORIZATION).description("액세스 토큰") + ), + responseFields( + fieldWithPath("code").description("오류 응답 코드"), + fieldWithPath("message").description("오류 메세지") + ) + )); + } + @Test @WithMockOAuth2User @DisplayName("챌린지 생성") From 06d58f3566f65f59f60b4dbbeae62383b8c35635 Mon Sep 17 00:00:00 2001 From: JoonHyeok Han Date: Sun, 6 Oct 2024 22:06:08 +0900 Subject: [PATCH 4/6] =?UTF-8?q?:sparkles:=20feat:=20=EC=B1=8C=EB=A6=B0?= =?UTF-8?q?=EC=A7=80=20=EC=A7=84=ED=96=89=20=EA=B8=B0=EA=B0=84=20=EC=A1=B0?= =?UTF-8?q?=ED=9A=8C=20API=20=EA=B5=AC=ED=98=84=20#256?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/challenge/api/ChallengeApi.java | 5 +++++ .../application/ChallengeDetailsService.java | 10 +++++++++ .../challenge/dto/ChallengeDatesResponse.java | 22 +++++++++++++++++++ 3 files changed, 37 insertions(+) create mode 100644 src/main/java/com/habitpay/habitpay/domain/challenge/dto/ChallengeDatesResponse.java diff --git a/src/main/java/com/habitpay/habitpay/domain/challenge/api/ChallengeApi.java b/src/main/java/com/habitpay/habitpay/domain/challenge/api/ChallengeApi.java index b5e3d558..593b89c5 100644 --- a/src/main/java/com/habitpay/habitpay/domain/challenge/api/ChallengeApi.java +++ b/src/main/java/com/habitpay/habitpay/domain/challenge/api/ChallengeApi.java @@ -51,6 +51,11 @@ public SuccessResponse getChallengeFeePerAbsence return challengeDetailsService.getChallengeFeePerAbsence(id); } + @GetMapping("/challenges/{id}/dates") + public SuccessResponse getChallengeDates(@PathVariable("id") Long id) { + return challengeDetailsService.getChallengeDates(id); + } + @PostMapping("/challenges") public SuccessResponse createChallenge(@RequestBody ChallengeCreationRequest challengeCreationRequest, @AuthenticationPrincipal CustomUserDetails user) { diff --git a/src/main/java/com/habitpay/habitpay/domain/challenge/application/ChallengeDetailsService.java b/src/main/java/com/habitpay/habitpay/domain/challenge/application/ChallengeDetailsService.java index 45db8f76..ecdfc4c7 100644 --- a/src/main/java/com/habitpay/habitpay/domain/challenge/application/ChallengeDetailsService.java +++ b/src/main/java/com/habitpay/habitpay/domain/challenge/application/ChallengeDetailsService.java @@ -1,6 +1,7 @@ package com.habitpay.habitpay.domain.challenge.application; import com.habitpay.habitpay.domain.challenge.domain.Challenge; +import com.habitpay.habitpay.domain.challenge.dto.ChallengeDatesResponse; import com.habitpay.habitpay.domain.challenge.dto.ChallengeDetailsResponse; import com.habitpay.habitpay.domain.challenge.dto.ChallengeFeePerAbsenceResponse; import com.habitpay.habitpay.domain.challengeenrollment.dao.ChallengeEnrollmentRepository; @@ -56,4 +57,13 @@ public SuccessResponse getChallengeFeePerAbsence ChallengeFeePerAbsenceResponse.from(challenge) ); } + + public SuccessResponse getChallengeDates(Long challengeId) { + Challenge challenge = challengeSearchService.getChallengeById(challengeId); + + return SuccessResponse.of( + SuccessCode.NO_MESSAGE, + ChallengeDatesResponse.from(challenge) + ); + } } diff --git a/src/main/java/com/habitpay/habitpay/domain/challenge/dto/ChallengeDatesResponse.java b/src/main/java/com/habitpay/habitpay/domain/challenge/dto/ChallengeDatesResponse.java new file mode 100644 index 00000000..4ffc0d1c --- /dev/null +++ b/src/main/java/com/habitpay/habitpay/domain/challenge/dto/ChallengeDatesResponse.java @@ -0,0 +1,22 @@ +package com.habitpay.habitpay.domain.challenge.dto; + +import com.habitpay.habitpay.domain.challenge.domain.Challenge; +import lombok.Builder; +import lombok.Getter; + +import java.time.ZonedDateTime; + +@Getter +@Builder +public class ChallengeDatesResponse { + + private ZonedDateTime startDate; + private ZonedDateTime endDate; + + public static ChallengeDatesResponse from(Challenge challenge) { + return ChallengeDatesResponse.builder() + .startDate(challenge.getStartDate()) + .endDate(challenge.getEndDate()) + .build(); + } +} From e8a8fe2559240dae6086ee8882a0add88e749c26 Mon Sep 17 00:00:00 2001 From: JoonHyeok Han Date: Sun, 6 Oct 2024 22:35:00 +0900 Subject: [PATCH 5/6] =?UTF-8?q?:sparkles:=20feat:=20=EC=B1=8C=EB=A6=B0?= =?UTF-8?q?=EC=A7=80=20=EC=B0=B8=EC=97=AC=20=EC=9A=94=EC=9D=BC=20=EC=A1=B0?= =?UTF-8?q?=ED=9A=8C=20API=20=EA=B5=AC=ED=98=84=20#256?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/challenge/api/ChallengeApi.java | 5 +++ .../application/ChallengeDetailsService.java | 10 +++++ .../ChallengeParticipatingDaysResponse.java | 38 +++++++++++++++++++ 3 files changed, 53 insertions(+) create mode 100644 src/main/java/com/habitpay/habitpay/domain/challenge/dto/ChallengeParticipatingDaysResponse.java diff --git a/src/main/java/com/habitpay/habitpay/domain/challenge/api/ChallengeApi.java b/src/main/java/com/habitpay/habitpay/domain/challenge/api/ChallengeApi.java index 593b89c5..8ffd0f49 100644 --- a/src/main/java/com/habitpay/habitpay/domain/challenge/api/ChallengeApi.java +++ b/src/main/java/com/habitpay/habitpay/domain/challenge/api/ChallengeApi.java @@ -56,6 +56,11 @@ public SuccessResponse getChallengeDates(@PathVariable(" return challengeDetailsService.getChallengeDates(id); } + @GetMapping("/challenges/{id}/participating-days") + public SuccessResponse getChallengeParticipatingDays(@PathVariable("id") Long id) { + return challengeDetailsService.getChallengeParticipatingDays(id); + } + @PostMapping("/challenges") public SuccessResponse createChallenge(@RequestBody ChallengeCreationRequest challengeCreationRequest, @AuthenticationPrincipal CustomUserDetails user) { diff --git a/src/main/java/com/habitpay/habitpay/domain/challenge/application/ChallengeDetailsService.java b/src/main/java/com/habitpay/habitpay/domain/challenge/application/ChallengeDetailsService.java index ecdfc4c7..ed353b49 100644 --- a/src/main/java/com/habitpay/habitpay/domain/challenge/application/ChallengeDetailsService.java +++ b/src/main/java/com/habitpay/habitpay/domain/challenge/application/ChallengeDetailsService.java @@ -4,6 +4,7 @@ import com.habitpay.habitpay.domain.challenge.dto.ChallengeDatesResponse; import com.habitpay.habitpay.domain.challenge.dto.ChallengeDetailsResponse; import com.habitpay.habitpay.domain.challenge.dto.ChallengeFeePerAbsenceResponse; +import com.habitpay.habitpay.domain.challenge.dto.ChallengeParticipatingDaysResponse; import com.habitpay.habitpay.domain.challengeenrollment.dao.ChallengeEnrollmentRepository; import com.habitpay.habitpay.domain.challengeenrollment.domain.ChallengeEnrollment; import com.habitpay.habitpay.domain.member.domain.Member; @@ -66,4 +67,13 @@ public SuccessResponse getChallengeDates(Long challengeI ChallengeDatesResponse.from(challenge) ); } + + public SuccessResponse getChallengeParticipatingDays(Long challengeId) { + Challenge challenge = challengeSearchService.getChallengeById(challengeId); + + return SuccessResponse.of( + SuccessCode.NO_MESSAGE, + ChallengeParticipatingDaysResponse.from(challenge) + ); + } } diff --git a/src/main/java/com/habitpay/habitpay/domain/challenge/dto/ChallengeParticipatingDaysResponse.java b/src/main/java/com/habitpay/habitpay/domain/challenge/dto/ChallengeParticipatingDaysResponse.java new file mode 100644 index 00000000..143dc560 --- /dev/null +++ b/src/main/java/com/habitpay/habitpay/domain/challenge/dto/ChallengeParticipatingDaysResponse.java @@ -0,0 +1,38 @@ +package com.habitpay.habitpay.domain.challenge.dto; + +import com.habitpay.habitpay.domain.challenge.domain.Challenge; +import lombok.Builder; +import lombok.Getter; + +import java.time.DayOfWeek; +import java.time.format.TextStyle; +import java.util.EnumSet; +import java.util.Locale; + +@Getter +@Builder +public class ChallengeParticipatingDaysResponse { + + private String[] participatingDays; + + public static ChallengeParticipatingDaysResponse from(Challenge challenge) { + return ChallengeParticipatingDaysResponse.builder() + .participatingDays(extractDaysFromBits(challenge.getParticipatingDays())) + .build(); + } + + public static String[] extractDaysFromBits(int participatingDays) { + EnumSet daysOfParticipatingDays = EnumSet.noneOf(DayOfWeek.class); + + for (int bit = 0; bit <= 6; bit += 1) { + int todayBitPosition = 6 - bit; + if ((participatingDays & (1 << todayBitPosition)) != 0) { + daysOfParticipatingDays.add(DayOfWeek.of(bit + 1)); + } + } + + return daysOfParticipatingDays.stream() + .map(day -> day.getDisplayName(TextStyle.SHORT, Locale.KOREAN)) + .toArray(String[]::new); + } +} From 994569c4fdc864041bd80a842ef92d0d3949df18 Mon Sep 17 00:00:00 2001 From: JoonHyeok Han Date: Sun, 6 Oct 2024 22:35:18 +0900 Subject: [PATCH 6/6] =?UTF-8?q?:white=5Fcheck=5Fmark:=20test:=20=EC=B1=8C?= =?UTF-8?q?=EB=A6=B0=EC=A7=80=20=EC=B0=B8=EC=97=AC=20=EC=9A=94=EC=9D=BC=20?= =?UTF-8?q?=EC=A1=B0=ED=9A=8C=20API=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84=20#256?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/docs/asciidoc/api/challenge.adoc | 14 +++++ .../challenge/api/ChallengeApiTest.java | 58 ++++++++++++++++++- 2 files changed, 71 insertions(+), 1 deletion(-) diff --git a/src/docs/asciidoc/api/challenge.adoc b/src/docs/asciidoc/api/challenge.adoc index a4973986..092d37ee 100644 --- a/src/docs/asciidoc/api/challenge.adoc +++ b/src/docs/asciidoc/api/challenge.adoc @@ -71,6 +71,20 @@ operation::challenge/get-challenge-dates[snippets='http-request,http-response,re operation::challenge/get-challenge-dates-not-found-exception[snippets='http-request,http-response,response-fields'] +=== 챌린지 참여 요일 조회 + +첼린지 참여 요일을 조회합니다. + +operation::challenge/get-challenge-participating-days[snippets='http-request,http-response,response-fields'] + +==== 에러 응답 + +===== 챌린지가 존재하지 않는 경우 (404 Not Found) + +존재하지 않는 챌린지를 조회한 경우입니다. + +operation::challenge/get-challenge-participating-days-not-found-exception[snippets='http-request,http-response,response-fields'] + === 챌린지 생성 새로운 첼린지를 생성합니다. diff --git a/src/test/java/com/habitpay/habitpay/domain/challenge/api/ChallengeApiTest.java b/src/test/java/com/habitpay/habitpay/domain/challenge/api/ChallengeApiTest.java index 2ba734a8..dedfd0f7 100644 --- a/src/test/java/com/habitpay/habitpay/domain/challenge/api/ChallengeApiTest.java +++ b/src/test/java/com/habitpay/habitpay/domain/challenge/api/ChallengeApiTest.java @@ -325,7 +325,6 @@ void getChallengeFeePerAbsenceNotFoundException() throws Exception { )); } - @Test @WithMockOAuth2User @DisplayName("챌린지 진행 기간 조회") @@ -384,6 +383,63 @@ void getChallengeDatesNotFoundException() throws Exception { )); } + @Test + @WithMockOAuth2User + @DisplayName("챌린지 참여 요일 조회") + void getChallengeParticipatingDays() throws Exception { + + // given + String[] participatingDays = {"월", "화"}; + ChallengeParticipatingDaysResponse challengeParticipatingDaysResponse = ChallengeParticipatingDaysResponse.builder() + .participatingDays(participatingDays) + .build(); + + given(challengeDetailsService.getChallengeParticipatingDays(anyLong())) + .willReturn(SuccessResponse.of(SuccessCode.NO_MESSAGE, challengeParticipatingDaysResponse)); + + // when + ResultActions result = mockMvc.perform(get("/api/challenges/{id}/participating-days", 1L) + .header(HttpHeaders.AUTHORIZATION, AUTHORIZATION_HEADER_PREFIX + "ACCESS_TOKEN")); + + // then + result.andExpect(status().isOk()) + .andDo(document("challenge/get-challenge-participating-days", + requestHeaders( + headerWithName(HttpHeaders.AUTHORIZATION).description("액세스 토큰") + ), + responseFields( + fieldWithPath("message").description("메세지"), + fieldWithPath("data.participatingDays").description("챌린지 참여 요일") + ) + )); + } + + @Test + @WithMockOAuth2User + @DisplayName("챌린지 참여 요일 조회 예외처리 - 존재하지 않는 챌린지 (404 Not Found)") + void getChallengeParticipatingDaysNotFoundException() throws Exception { + + // given + given(challengeDetailsService.getChallengeParticipatingDays(anyLong())) + .willThrow(new ChallengeNotFoundException(0L)); + + // when + ResultActions result = mockMvc.perform(get("/api/challenges/{id}/participating-days", 0L) + .header(HttpHeaders.AUTHORIZATION, AUTHORIZATION_HEADER_PREFIX + "ACCESS_TOKEN")); + + // then + result.andExpect(status().isNotFound()) + .andDo(document("challenge/get-challenge-participating-days-not-found-exception", + requestHeaders( + headerWithName(HttpHeaders.AUTHORIZATION).description("액세스 토큰") + ), + responseFields( + fieldWithPath("code").description("오류 응답 코드"), + fieldWithPath("message").description("오류 메세지") + ) + )); + } + @Test @WithMockOAuth2User @DisplayName("챌린지 생성")