-
Notifications
You must be signed in to change notification settings - Fork 0
[feat] : 가이드 확인 여부를 조회/저장/삭제한다 #300
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 5 commits
968db36
1f0d2e8
998cc36
ab6884b
af128f2
c8adde0
5009f6a
0397ff0
4b1e54a
b7b2f1c
1a3a623
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| package side.onetime.domain; | ||
|
|
||
| import jakarta.persistence.*; | ||
| import lombok.AccessLevel; | ||
| import lombok.Builder; | ||
| import lombok.Getter; | ||
| import lombok.NoArgsConstructor; | ||
| import side.onetime.domain.enums.GuideType; | ||
|
|
||
| import java.time.LocalDateTime; | ||
|
|
||
| @Entity | ||
| @NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
| @Getter | ||
| @Table( | ||
| name = "guide_view_status", | ||
| uniqueConstraints = { | ||
| @UniqueConstraint(name = "unique_user_guide_type", columnNames = {"users_id", "guide_type"}) | ||
| } | ||
| ) | ||
| public class GuideViewStatus { | ||
|
|
||
| @Id | ||
| @GeneratedValue(strategy = GenerationType.IDENTITY) | ||
| @Column(name = "guide_view_status_id") | ||
| private Long id; | ||
|
|
||
| @ManyToOne(fetch = FetchType.LAZY) | ||
| @JoinColumn(name = "users_id", foreignKey = @ForeignKey(name = "guide_view_status_fk_users_id"), nullable = false) | ||
| private User user; | ||
|
|
||
| @Enumerated(EnumType.STRING) | ||
| @Column(name = "guide_type", nullable = false) | ||
| private GuideType guideType; | ||
|
|
||
| @Column(name = "is_viewed", nullable = false) | ||
| private Boolean isViewed; | ||
|
|
||
| @Column(name = "viewed_at", nullable = false) | ||
| private LocalDateTime viewedAt; | ||
|
|
||
| @Builder | ||
| public GuideViewStatus(User user, GuideType guideType) { | ||
| this.user = user; | ||
| this.guideType = guideType; | ||
| this.isViewed = true; | ||
| this.viewedAt = LocalDateTime.now(); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| package side.onetime.domain.enums; | ||
|
|
||
| public enum GuideType { | ||
|
|
||
| SCHEDULE_GUIDE_MODAL_001, | ||
| ; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| package side.onetime.dto.user.request; | ||
|
|
||
| import com.fasterxml.jackson.annotation.JsonInclude; | ||
| import com.fasterxml.jackson.databind.PropertyNamingStrategies; | ||
| import com.fasterxml.jackson.databind.annotation.JsonNaming; | ||
| import side.onetime.domain.enums.GuideType; | ||
|
|
||
| @JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class) | ||
| @JsonInclude(JsonInclude.Include.NON_NULL) | ||
| public record CreateGuideViewStatusRequest( | ||
| GuideType guideType | ||
| ) { | ||
coderabbitai[bot] marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| package side.onetime.dto.user.response; | ||
|
|
||
| import com.fasterxml.jackson.annotation.JsonInclude; | ||
| import com.fasterxml.jackson.databind.PropertyNamingStrategies; | ||
| import com.fasterxml.jackson.databind.annotation.JsonNaming; | ||
| import side.onetime.domain.User; | ||
coderabbitai[bot] marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| @JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class) | ||
| @JsonInclude(JsonInclude.Include.NON_NULL) | ||
| public record GetGuideViewStatusResponse( | ||
| boolean isViewed | ||
| ) { | ||
| public static GetGuideViewStatusResponse from(boolean isViewed) { | ||
| return new GetGuideViewStatusResponse(isViewed); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| package side.onetime.repository; | ||
|
|
||
| import org.springframework.data.jpa.repository.JpaRepository; | ||
| import side.onetime.domain.GuideViewStatus; | ||
| import side.onetime.domain.User; | ||
| import side.onetime.domain.enums.GuideType; | ||
|
|
||
| public interface GuideViewStatusRepository extends JpaRepository<GuideViewStatus, Long> { | ||
|
|
||
| boolean existsByUserAndGuideType(User user, GuideType guideType); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,18 +15,14 @@ | |
| import side.onetime.auth.service.CustomUserDetailsService; | ||
| import side.onetime.configuration.ControllerTestConfig; | ||
| import side.onetime.controller.UserController; | ||
| import side.onetime.domain.enums.GuideType; | ||
| import side.onetime.domain.enums.Language; | ||
| import side.onetime.dto.user.request.OnboardUserRequest; | ||
| import side.onetime.dto.user.request.UpdateUserPolicyAgreementRequest; | ||
| import side.onetime.dto.user.request.UpdateUserProfileRequest; | ||
| import side.onetime.dto.user.request.UpdateUserSleepTimeRequest; | ||
| import side.onetime.dto.user.response.GetUserPolicyAgreementResponse; | ||
| import side.onetime.dto.user.response.GetUserProfileResponse; | ||
| import side.onetime.dto.user.response.GetUserSleepTimeResponse; | ||
| import side.onetime.dto.user.response.OnboardUserResponse; | ||
| import side.onetime.dto.user.request.*; | ||
| import side.onetime.dto.user.response.*; | ||
| import side.onetime.service.UserService; | ||
| import side.onetime.util.JwtUtil; | ||
|
|
||
| import static com.epages.restdocs.apispec.ResourceDocumentation.parameterWithName; | ||
| import static com.epages.restdocs.apispec.ResourceDocumentation.resource; | ||
| import static org.mockito.ArgumentMatchers.any; | ||
| import static org.springframework.restdocs.operation.preprocess.Preprocessors.*; | ||
|
|
@@ -460,4 +456,85 @@ public void logoutUser() throws Exception { | |
| ) | ||
| )); | ||
| } | ||
|
|
||
| @Test | ||
| @DisplayName("가이드 확인 여부를 저장한다.") | ||
| public void createGuideViewStatus() throws Exception { | ||
| // given | ||
| CreateGuideViewStatusRequest request = new CreateGuideViewStatusRequest(GuideType.SCHEDULE_GUIDE_MODAL_001); | ||
| String requestContent = objectMapper.writeValueAsString(request); | ||
|
|
||
| // when | ||
| Mockito.doNothing().when(userService).createGuideViewStatus(any(CreateGuideViewStatusRequest.class)); | ||
|
|
||
| // then | ||
| mockMvc.perform(RestDocumentationRequestBuilders.post("/api/v1/users/guides/view-status") | ||
| .content(requestContent) | ||
| .contentType(MediaType.APPLICATION_JSON) | ||
| .accept(MediaType.APPLICATION_JSON)) | ||
| .andExpect(status().isCreated()) | ||
| .andExpect(jsonPath("$.is_success").value(true)) | ||
| .andExpect(jsonPath("$.code").value("201")) | ||
| .andExpect(jsonPath("$.message").value("유저 가이드 확인 여부 저장에 성공했습니다.")) | ||
| .andDo(MockMvcRestDocumentationWrapper.document("user/create-guide-view-status", | ||
| preprocessRequest(prettyPrint()), | ||
| preprocessResponse(prettyPrint()), | ||
| resource( | ||
| ResourceSnippetParameters.builder() | ||
| .tag("User API") | ||
| .description("가이드 확인 여부를 저장한다.") | ||
| .requestFields( | ||
| fieldWithPath("guide_type").type(JsonFieldType.STRING).description("가이드 타입") | ||
| ) | ||
| .responseFields( | ||
| fieldWithPath("is_success").type(JsonFieldType.BOOLEAN).description("성공 여부"), | ||
| fieldWithPath("code").type(JsonFieldType.STRING).description("응답 코드"), | ||
| fieldWithPath("message").type(JsonFieldType.STRING).description("응답 메시지") | ||
| ) | ||
| .requestSchema(Schema.schema("CreateGuideViewStatusRequestSchema")) | ||
| .build() | ||
| ) | ||
| )); | ||
| } | ||
|
|
||
| @Test | ||
| @DisplayName("가이드 확인 여부를 조회한다.") | ||
| public void getGuideViewStatus() throws Exception { | ||
| // given | ||
| GuideType guideType = GuideType.SCHEDULE_GUIDE_MODAL_001; | ||
| GetGuideViewStatusResponse response = GetGuideViewStatusResponse.from(true); | ||
|
|
||
| // when | ||
| Mockito.when(userService.getGuideViewStatus(any(GuideType.class))).thenReturn(response); | ||
|
|
||
| // then | ||
| mockMvc.perform(RestDocumentationRequestBuilders.get("/api/v1/users/guides/view-status") | ||
| .queryParam("guide_type", guideType.name()) | ||
| .contentType(MediaType.APPLICATION_JSON) | ||
| .accept(MediaType.APPLICATION_JSON)) | ||
| .andExpect(status().isOk()) | ||
| .andExpect(jsonPath("$.is_success").value(true)) | ||
| .andExpect(jsonPath("$.code").value("200")) | ||
| .andExpect(jsonPath("$.message").value("유저 가이드 확인 여부 조회에 성공했습니다.")) | ||
| .andDo(MockMvcRestDocumentationWrapper.document("user/get-guide-view-status", | ||
| preprocessRequest(prettyPrint()), | ||
| preprocessResponse(prettyPrint()), | ||
| resource( | ||
| ResourceSnippetParameters.builder() | ||
| .tag("User API") | ||
| .description("가이드 확인 여부를 조회한다.") | ||
| .queryParameters( | ||
| parameterWithName("guide_type").description("가이드 타입") | ||
| ) | ||
| .responseFields( | ||
| fieldWithPath("is_success").type(JsonFieldType.BOOLEAN).description("성공 여부"), | ||
| fieldWithPath("code").type(JsonFieldType.STRING).description("응답 코드"), | ||
| fieldWithPath("message").type(JsonFieldType.STRING).description("응답 메시지"), | ||
| fieldWithPath("payload.is_viewed").type(JsonFieldType.BOOLEAN).description("가이드 확인 여부") | ||
| ) | ||
| .responseSchema(Schema.schema("GetGuideViewStatusResponseSchema")) | ||
| .build() | ||
| ) | ||
| )); | ||
| } | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 여기에 400 409 예외 처리 테스트 코드도 추가해주시면 좋을 것 같아요~!
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 400{
"code": "E_BAD_REQUEST",
"message": "올바르지 않은 enum 값입니다. 허용되지 않은 값: SCHEDULE_GUIDE_MODAL_0013232",
"is_success": false
}
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 409{
"code": "USER-005",
"message": "이미 조회한 가이드입니다.",
"is_success": false
}
|
||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.