-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #204 from Re-4aliens/feat/#203_inquire
문의하기 기능 개발
- Loading branch information
Showing
9 changed files
with
223 additions
and
0 deletions.
There are no files selected for viewing
33 changes: 33 additions & 0 deletions
33
src/main/java/com/aliens/backend/global/response/success/InquirySuccess.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package com.aliens.backend.global.response.success; | ||
|
||
import org.springframework.http.HttpStatus; | ||
|
||
public enum InquirySuccess implements SuccessCode { | ||
CREATE_INQUIRY_SUCCESS(HttpStatus.OK, "I001", "문의 등록에 성공했습니다."), | ||
; | ||
|
||
private final HttpStatus httpStatus; | ||
private final String code; | ||
private final String message; | ||
|
||
InquirySuccess(final HttpStatus httpStatus, final String code, final String message) { | ||
this.httpStatus = httpStatus; | ||
this.code = code; | ||
this.message = message; | ||
} | ||
|
||
@Override | ||
public HttpStatus getHttpStatus() { | ||
return httpStatus; | ||
} | ||
|
||
@Override | ||
public String getCode() { | ||
return code; | ||
} | ||
|
||
@Override | ||
public String getMessage() { | ||
return message; | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
src/main/java/com/aliens/backend/inquire/InquiryController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package com.aliens.backend.inquire; | ||
|
||
import com.aliens.backend.auth.controller.dto.LoginMember; | ||
import com.aliens.backend.global.config.resolver.Login; | ||
import com.aliens.backend.global.response.SuccessResponse; | ||
import com.aliens.backend.global.response.success.InquirySuccess; | ||
import com.aliens.backend.inquire.controller.request.InquiryCreateRequest; | ||
import com.aliens.backend.inquire.service.InquiryService; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RequestMapping("/inquiries") | ||
@RestController | ||
public class InquiryController { | ||
|
||
private final InquiryService inquiryService; | ||
|
||
public InquiryController(final InquiryService inquiryService) { | ||
this.inquiryService = inquiryService; | ||
} | ||
|
||
@PostMapping() | ||
public SuccessResponse<?> createInquiry(@Login final LoginMember loginMember, | ||
@RequestBody final InquiryCreateRequest request) { | ||
inquiryService.createInquiry(request, loginMember); | ||
return SuccessResponse.of(InquirySuccess.CREATE_INQUIRY_SUCCESS); | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
src/main/java/com/aliens/backend/inquire/controller/request/InquiryCreateRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package com.aliens.backend.inquire.controller.request; | ||
|
||
public record InquiryCreateRequest(String content) { | ||
} |
29 changes: 29 additions & 0 deletions
29
src/main/java/com/aliens/backend/inquire/domain/Inquiry.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package com.aliens.backend.inquire.domain; | ||
|
||
import jakarta.persistence.*; | ||
|
||
@Entity | ||
public class Inquiry { | ||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
@Column(name = "inquiryId") | ||
private Long id; | ||
|
||
@Column | ||
private String content; | ||
|
||
@Column | ||
private Long memberId; | ||
|
||
public Inquiry(String content, Long memberId) { | ||
this.content = content; | ||
this.memberId = memberId; | ||
} | ||
|
||
protected Inquiry() { | ||
} | ||
|
||
public String getContent() { | ||
return content; | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
src/main/java/com/aliens/backend/inquire/repository/InquiryRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.aliens.backend.inquire.repository; | ||
|
||
import com.aliens.backend.inquire.domain.Inquiry; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.stereotype.Repository; | ||
|
||
@Repository | ||
public interface InquiryRepository extends JpaRepository<Inquiry, Long> { | ||
} |
20 changes: 20 additions & 0 deletions
20
src/main/java/com/aliens/backend/inquire/service/InquiryService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.aliens.backend.inquire.service; | ||
|
||
import com.aliens.backend.auth.controller.dto.LoginMember; | ||
import com.aliens.backend.inquire.controller.request.InquiryCreateRequest; | ||
import com.aliens.backend.inquire.domain.Inquiry; | ||
import com.aliens.backend.inquire.repository.InquiryRepository; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
public class InquiryService { | ||
private final InquiryRepository inquiryRepository; | ||
|
||
public InquiryService(final InquiryRepository inquiryRepository) { | ||
this.inquiryRepository = inquiryRepository; | ||
} | ||
|
||
public void createInquiry(final InquiryCreateRequest request, final LoginMember loginMember) { | ||
inquiryRepository.save(new Inquiry(request.content(), loginMember.memberId())); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
src/test/java/com/aliens/backend/docs/InquiryRestDocsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package com.aliens.backend.docs; | ||
|
||
import com.aliens.backend.auth.domain.Member; | ||
import com.aliens.backend.global.response.SuccessResponse; | ||
import com.aliens.backend.global.response.success.InquirySuccess; | ||
import com.aliens.backend.inquire.controller.request.InquiryCreateRequest; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.http.MediaType; | ||
|
||
import static org.mockito.ArgumentMatchers.any; | ||
import static org.mockito.Mockito.doReturn; | ||
import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.document; | ||
import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.post; | ||
import static org.springframework.restdocs.payload.PayloadDocumentation.*; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; | ||
|
||
class InquiryRestDocsTest extends BaseRestDocsTest { | ||
@BeforeEach | ||
void setUp() { | ||
Member member = dummyGenerator.generateSingleMember(); | ||
GIVEN_ACCESS_TOKEN = dummyGenerator.generateAccessToken(member); | ||
} | ||
|
||
@Test | ||
@DisplayName("API - 문의 생성") | ||
void createInquiry() throws Exception { | ||
InquiryCreateRequest request = new InquiryCreateRequest("문의 내용"); | ||
final SuccessResponse<?> response = SuccessResponse.of(InquirySuccess.CREATE_INQUIRY_SUCCESS); | ||
doReturn(response).when(inquiryController).createInquiry(any(), any()); | ||
|
||
mockMvc.perform(post("/inquiries") | ||
.contentType(MediaType.APPLICATION_JSON) | ||
.content(objectMapper.writeValueAsString(request)) | ||
.header("Authorization", GIVEN_ACCESS_TOKEN) | ||
) | ||
.andExpect(status().isOk()) | ||
.andDo(document("inquiry-create", | ||
requestFields( | ||
fieldWithPath("content").description("문의 내용") | ||
), | ||
responseFields( | ||
fieldWithPath("code").description("응답 코드"), | ||
fieldWithPath("result").description("문의 생성 결과 메시지") | ||
) | ||
)); | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
src/test/java/com/aliens/backend/inquire/service/InquiryServiceTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package com.aliens.backend.inquire.service; | ||
|
||
import com.aliens.backend.auth.controller.dto.LoginMember; | ||
import com.aliens.backend.auth.domain.Member; | ||
import com.aliens.backend.global.BaseIntegrationTest; | ||
import com.aliens.backend.global.DummyGenerator; | ||
import com.aliens.backend.inquire.controller.request.InquiryCreateRequest; | ||
import com.aliens.backend.inquire.domain.Inquiry; | ||
import com.aliens.backend.inquire.repository.InquiryRepository; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
|
||
class InquiryServiceTest extends BaseIntegrationTest { | ||
@Autowired | ||
InquiryService inquiryService; | ||
@Autowired | ||
DummyGenerator dummyGenerator; | ||
@Autowired | ||
InquiryRepository inquiryRepository; | ||
|
||
Member givenMember; | ||
LoginMember givenLoginMember; | ||
|
||
@BeforeEach | ||
void setUp() { | ||
givenMember = dummyGenerator.generateSingleMember(); | ||
givenLoginMember = givenMember.getLoginMember(); | ||
} | ||
|
||
@Test | ||
@DisplayName("문의 생성") | ||
void blockPartner() { | ||
//Given | ||
InquiryCreateRequest request = new InquiryCreateRequest("문의 내용"); | ||
|
||
//When | ||
inquiryService.createInquiry(request, givenLoginMember); | ||
|
||
//Then | ||
Inquiry inquiry = inquiryRepository.findAll().get(0); | ||
Assertions.assertEquals(request.content(), inquiry.getContent()); | ||
} | ||
} |