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(); + } }