Skip to content

Commit

Permalink
THT-Server-250 [App] 회원가입전 계정 문의하기 API
Browse files Browse the repository at this point in the history
  • Loading branch information
thalals committed Aug 3, 2024
1 parent 71c4bfc commit cdcf9d4
Show file tree
Hide file tree
Showing 5 changed files with 126 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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());
}

}
25 changes: 25 additions & 0 deletions tht-apis/src/main/java/com/tht/thtapis/ui/InquiryController.java
Original file line number Diff line number Diff line change
@@ -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<Object> inquiryUserJoin(@RequestBody @Valid InquiryRequest request) {

inquiryFacade.inquiryForLogin(request);
return ResponseEntity.status(HttpStatus.CREATED).build();
}
}
Original file line number Diff line number Diff line change
@@ -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());

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}

0 comments on commit cdcf9d4

Please sign in to comment.