From cdcf9d4ccfdb39a177509b9c75a1ff25987a2daf Mon Sep 17 00:00:00 2001 From: thalals Date: Sat, 3 Aug 2024 15:57:40 +0900 Subject: [PATCH] =?UTF-8?q?THT-Server-250=20[App]=20=ED=9A=8C=EC=9B=90?= =?UTF-8?q?=EA=B0=80=EC=9E=85=EC=A0=84=20=EA=B3=84=EC=A0=95=20=EB=AC=B8?= =?UTF-8?q?=EC=9D=98=ED=95=98=EA=B8=B0=20API?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../thtapis/facade/user/InquiryFacade.java | 21 +++++++ .../com/tht/thtapis/ui/InquiryController.java | 25 ++++++++ .../thtapis/documentation/InquiryDocs.java | 62 +++++++++++++++++++ .../domain/entity/inquiry/InquiryService.java | 5 ++ .../domain/entity/inquiry/UserInquiry.java | 13 ++++ 5 files changed, 126 insertions(+) create mode 100644 tht-apis/src/main/java/com/tht/thtapis/facade/user/InquiryFacade.java create mode 100644 tht-apis/src/main/java/com/tht/thtapis/ui/InquiryController.java create mode 100644 tht-apis/src/test/java/com/tht/thtapis/documentation/InquiryDocs.java diff --git a/tht-apis/src/main/java/com/tht/thtapis/facade/user/InquiryFacade.java b/tht-apis/src/main/java/com/tht/thtapis/facade/user/InquiryFacade.java new file mode 100644 index 00000000..80b3d5de --- /dev/null +++ b/tht-apis/src/main/java/com/tht/thtapis/facade/user/InquiryFacade.java @@ -0,0 +1,21 @@ +package com.tht.thtapis.facade.user; + +import com.tht.domain.entity.inquiry.InquiryService; +import com.tht.thtapis.facade.Facade; +import com.tht.thtapis.facade.setting.InquiryRequest; +import lombok.RequiredArgsConstructor; +import org.springframework.transaction.annotation.Transactional; + +@Facade +@RequiredArgsConstructor +@Transactional(readOnly = true) +public class InquiryFacade { + + private final InquiryService inquiryService; + + @Transactional + public void inquiryForLogin(final InquiryRequest request) { + inquiryService.beforeLogin(request.contents(), request.userEmail(), request.isEmailAgree()); + } + +} diff --git a/tht-apis/src/main/java/com/tht/thtapis/ui/InquiryController.java b/tht-apis/src/main/java/com/tht/thtapis/ui/InquiryController.java new file mode 100644 index 00000000..7bf013df --- /dev/null +++ b/tht-apis/src/main/java/com/tht/thtapis/ui/InquiryController.java @@ -0,0 +1,25 @@ +package com.tht.thtapis.ui; + +import com.tht.thtapis.facade.setting.InquiryRequest; +import com.tht.thtapis.facade.user.InquiryFacade; +import jakarta.validation.Valid; +import lombok.RequiredArgsConstructor; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequiredArgsConstructor +public class InquiryController { + + private final InquiryFacade inquiryFacade; + + @PostMapping("/users/login/inquiry") + public ResponseEntity inquiryUserJoin(@RequestBody @Valid InquiryRequest request) { + + inquiryFacade.inquiryForLogin(request); + return ResponseEntity.status(HttpStatus.CREATED).build(); + } +} diff --git a/tht-apis/src/test/java/com/tht/thtapis/documentation/InquiryDocs.java b/tht-apis/src/test/java/com/tht/thtapis/documentation/InquiryDocs.java new file mode 100644 index 00000000..7f70fe48 --- /dev/null +++ b/tht-apis/src/test/java/com/tht/thtapis/documentation/InquiryDocs.java @@ -0,0 +1,62 @@ +package com.tht.thtapis.documentation; + +import com.epages.restdocs.apispec.ResourceSnippetParameters; +import com.epages.restdocs.apispec.Schema; +import com.tht.thtapis.controller.config.ControllerTestConfig; +import com.tht.thtapis.facade.setting.InquiryRequest; +import com.tht.thtapis.facade.user.InquiryFacade; +import com.tht.thtapis.fixture.setting.InquiryRequestFixture; +import com.tht.thtapis.ui.InquiryController; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; +import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.http.MediaType; +import org.springframework.test.web.servlet.ResultActions; + +import static com.epages.restdocs.apispec.MockMvcRestDocumentationWrapper.document; +import static com.epages.restdocs.apispec.ResourceDocumentation.resource; +import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.post; +import static org.springframework.restdocs.operation.preprocess.Preprocessors.*; +import static org.springframework.restdocs.payload.PayloadDocumentation.fieldWithPath; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + +@WebMvcTest(InquiryController.class) +class InquiryDocs extends ControllerTestConfig { + + @MockBean + InquiryFacade inquiryFacade; + + @Test + @DisplayName("로그인 및 회원가입 전 문의하기 docs") + void inquiryDocs() throws Exception { + + InquiryRequest request = InquiryRequestFixture.make(); + String requestBody = ControllerTestConfig.objectMapper.writeValueAsString(request); + + final ResultActions resultActions = mockMvc.perform(post("/users/login/inquiry") + .contentType(MediaType.APPLICATION_JSON) + .accept(MediaType.APPLICATION_JSON) + .content(requestBody) + ).andDo( + document("로그인 및 회원가입 전 문의하기", + preprocessRequest(prettyPrint()), + preprocessResponse(prettyPrint()), + resource( + ResourceSnippetParameters.builder() + .tag("유저 - 로그인") + .description("로그인 및 회원가입 전 문의하기") + .requestFields( + fieldWithPath("userEmail").description("문의 답장 받을 이메일"), + fieldWithPath("contents").description("유저 디바이스 키"), + fieldWithPath("isEmailAgree").description("메일 정보동의 제공 여부") + ) + .requestSchema(Schema.schema("InquiryRequest")) + .build() + )) + ); + + resultActions.andExpect(status().isCreated()); + + } +} diff --git a/tht-core/domain/src/main/java/com/tht/domain/entity/inquiry/InquiryService.java b/tht-core/domain/src/main/java/com/tht/domain/entity/inquiry/InquiryService.java index 51c155e7..84b4c74d 100644 --- a/tht-core/domain/src/main/java/com/tht/domain/entity/inquiry/InquiryService.java +++ b/tht-core/domain/src/main/java/com/tht/domain/entity/inquiry/InquiryService.java @@ -17,4 +17,9 @@ public void receiptInquiry(final String userUuid, final String contents, final S repository.save(userInquiry); } + @Transactional + public void beforeLogin(final String contents, final String userEmail, final boolean emailAgree) { + final UserInquiry anonymous = UserInquiry.createForAnonymous(contents, userEmail, emailAgree); + repository.save(anonymous); + } } diff --git a/tht-core/domain/src/main/java/com/tht/domain/entity/inquiry/UserInquiry.java b/tht-core/domain/src/main/java/com/tht/domain/entity/inquiry/UserInquiry.java index a27bb0da..6c71d325 100644 --- a/tht-core/domain/src/main/java/com/tht/domain/entity/inquiry/UserInquiry.java +++ b/tht-core/domain/src/main/java/com/tht/domain/entity/inquiry/UserInquiry.java @@ -63,4 +63,17 @@ public static UserInquiry createInquiry(final String userUuid, final String cont .inquiryStatus(InquiryStatus.RECEPTION) .build(); } + + public static UserInquiry createForAnonymous(final String contents, final String userEmail, final boolean emailAgree) { + if (!emailAgree) { + throw UserInquiryException.isFalseEmailAgree(); + } + + return UserInquiry.builder() + .contents(contents) + .userEmail(userEmail) + .isEmailAgree(emailAgree) + .inquiryStatus(InquiryStatus.RECEPTION) + .build(); + } }