-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add(.footprint) : 발자취 생성 기능 및 API 추가 (#185)
<!-- PR 내용 어떤 작업을 했는지 작성해주세요! PR이 너무 크면 너무 많은 내용이 들어가겠죠? --> # 🔍 어떤 PR인가요? - 발자취 생성 기능과 API를 구현했습니다. - pr 단위를 작게 하기 위해 태그 저장부분은 반영하지 않았습니다. - 태그는 담당자와 논의한 뒤 새로 PR을 만들어 개선하고 발자취에 반영하려고 합니다. <!-- 리뷰어에게 어떤 부분을 자세하게 리뷰할지 서술해주세요. --> # 😋 To Reviewer - 기존 `Requset` 와 역할 구분이 어려웠던 `FootprintParam` 을 연관관계를 가지지 않는 발자취 데이터로 변경했습니다. - `FootprintParam` 탬플릿에 따른 요청, 응답값 데이터 변경 관리를 할 수 있는 엔드 포인트입니다. - 변경사항을 쉽게 관리하기 위해 표현 계층에서 사용하는 객체와, param의 관계는 다음과 같습니다. ``` Request { static Create{ Param.Create param; } } ``` - 표현 계층에서 사용하는 request 가 서비스 로직까지 오는 것을 최대한 방지하고자 했습니다. - 발자취 생성 API url 에 대한 피드백 부탁드립니다. 최대한 자원 식별을 할 수 있는 계층 구조를 생각해봤습니다. `/targets/{target-id}/footprints` <!-- 테스트 반영한 테스트 메서드 이름과 어떤 테스트를 했는지 작성해주세요. (ex. save_Fail_ByDuplicateEmail) --> - url 구성에 따라 controller 테스트에서도 "{}{}{}_END_POINT" 사용을 보류했습니다. - url 피드백 이후 반영하도록 하겠습니다 # ✅ 작성한 테스트 - [x] createFootPrint_Success_With_NoExceptions - [x] createFootprint_Fail_By_NotFountTarget - [x] createFootprint_Success_With_NoExceptions - [x] createFootprint_Fail_By_InvalidContents <!-- 관련 이슈 프론트에서 작성해준 이슈와 연관되는 PR이라면 주석을 풀고 작성해주세요! --> [//]: # (# 🫡 관련 Issue )
- Loading branch information
Showing
18 changed files
with
319 additions
and
128 deletions.
There are no files selected for viewing
30 changes: 30 additions & 0 deletions
30
src/main/java/me/ajaja/module/footprint/adapter/in/web/CreateFootprintController.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 me.ajaja.module.footprint.adapter.in.web; | ||
|
||
import static org.springframework.http.HttpStatus.*; | ||
|
||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.ResponseStatus; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import me.ajaja.global.common.AjajaResponse; | ||
import me.ajaja.global.security.annotation.Authorization; | ||
import me.ajaja.global.util.SecurityUtil; | ||
import me.ajaja.module.footprint.application.port.in.CreateFootprintUseCase; | ||
import me.ajaja.module.footprint.dto.FootprintRequest; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
public class CreateFootprintController { | ||
private final CreateFootprintUseCase createFootprintUseCase; | ||
|
||
@Authorization | ||
@PostMapping("/footprints") | ||
@ResponseStatus(CREATED) | ||
public AjajaResponse<Void> createFootprint(@RequestBody FootprintRequest.Create request) { | ||
Long userId = SecurityUtil.getUserId(); | ||
createFootprintUseCase.create(userId, request); | ||
return AjajaResponse.ok(); | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
src/main/java/me/ajaja/module/footprint/application/port/CreateFootprintService.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,23 @@ | ||
package me.ajaja.module.footprint.application.port; | ||
|
||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import me.ajaja.module.footprint.application.port.in.CreateFootprintUseCase; | ||
import me.ajaja.module.footprint.application.port.out.CreateFootprintPort; | ||
import me.ajaja.module.footprint.domain.Footprint; | ||
import me.ajaja.module.footprint.dto.FootprintRequest; | ||
|
||
@Service | ||
@Transactional | ||
@RequiredArgsConstructor | ||
public class CreateFootprintService implements CreateFootprintUseCase { | ||
private final CreateFootprintPort createFootprintPort; | ||
|
||
@Override | ||
public void create(Long userId, FootprintRequest.Create param) { | ||
Footprint footprint = Footprint.init(userId, param); | ||
createFootprintPort.create(footprint); | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
src/main/java/me/ajaja/module/footprint/application/port/in/CreateFootprintUseCase.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,7 @@ | ||
package me.ajaja.module.footprint.application.port.in; | ||
|
||
import me.ajaja.module.footprint.dto.FootprintRequest; | ||
|
||
public interface CreateFootprintUseCase { | ||
void create(Long userId, FootprintRequest.Create param); | ||
} |
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 |
---|---|---|
|
@@ -4,5 +4,4 @@ | |
|
||
public interface GetFootprintPort { | ||
Footprint getFootprint(Long id); | ||
|
||
} |
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
31 changes: 0 additions & 31 deletions
31
src/main/java/me/ajaja/module/footprint/domain/FootprintFactory.java
This file was deleted.
Oops, something went wrong.
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
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
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
39 changes: 0 additions & 39 deletions
39
src/main/java/me/ajaja/module/footprint/dto/FootprintParam.java
This file was deleted.
Oops, something went wrong.
21 changes: 21 additions & 0 deletions
21
src/main/java/me/ajaja/module/footprint/dto/FootprintRequest.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,21 @@ | ||
package me.ajaja.module.footprint.dto; | ||
|
||
import java.util.List; | ||
|
||
import lombok.Data; | ||
import me.ajaja.module.footprint.domain.Footprint; | ||
|
||
public final class FootprintRequest { | ||
@Data | ||
public static class Create { | ||
private final Long targetId; | ||
private final Footprint.Type type; | ||
private final String title; | ||
private final boolean visible; | ||
private final String content; | ||
private final String keepContent; | ||
private final String problemContent; | ||
private final String tryContent; | ||
private final List<String> tags; | ||
} | ||
} |
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
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
93 changes: 93 additions & 0 deletions
93
src/test/java/me/ajaja/module/footprint/adapter/in/web/CreateFootprintControllerTest.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,93 @@ | ||
package me.ajaja.module.footprint.adapter.in.web; | ||
|
||
import static me.ajaja.global.exception.ErrorCode.*; | ||
import static org.mockito.ArgumentMatchers.*; | ||
import static org.mockito.Mockito.*; | ||
import static org.springframework.http.HttpStatus.*; | ||
import static org.springframework.http.MediaType.*; | ||
import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.*; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; | ||
|
||
import java.util.List; | ||
|
||
import org.junit.jupiter.api.DisplayName; | ||
import org.springframework.http.HttpHeaders; | ||
|
||
import jakarta.validation.ConstraintViolationException; | ||
import me.ajaja.common.annotation.ApiTest; | ||
import me.ajaja.common.support.WebMvcTestSupport; | ||
import me.ajaja.common.util.ApiTag; | ||
import me.ajaja.common.util.RestDocument; | ||
import me.ajaja.module.footprint.domain.Footprint; | ||
import me.ajaja.module.footprint.dto.FootprintRequest; | ||
|
||
class CreateFootprintControllerTest extends WebMvcTestSupport { | ||
|
||
@ApiTest | ||
@DisplayName("발자취 유형에 맞는 형식에 요청 값에 대해 발자취 생성에 성공한다.") | ||
void createFootprint_Success_With_NoExceptions() throws Exception { | ||
// given | ||
FootprintRequest.Create request = sut.giveMeBuilder(FootprintRequest.Create.class) | ||
.set("param.type", Footprint.Type.FREE) | ||
.set("param.content", "contents") | ||
.set("tags", List.of("tag1", "tag2")) | ||
.sample(); | ||
|
||
doNothing().when(createFootprintUseCase).create(anyLong(), any()); | ||
|
||
// when | ||
var result = mockMvc.perform(post(FOOTPRINT_END_POINT) | ||
.header(HttpHeaders.AUTHORIZATION, BEARER_TOKEN) | ||
.accept(APPLICATION_JSON) | ||
.contentType(APPLICATION_JSON) | ||
.content(objectMapper.writeValueAsString(request))); | ||
|
||
// then | ||
result.andExpect(status().isCreated()); | ||
|
||
// docs | ||
result.andDo(RestDocument.builder() | ||
.identifier("footprint-create-success") | ||
.tag(ApiTag.FOOTPRINT) | ||
.summary("발자취 생성 API") | ||
.description("발자취 유형에 맞는 항목에 빈 문자가 아닌 상태로 요청할 떄 발자취 정보를 생성 합니다.") | ||
.secured(true) | ||
.result(result) | ||
.generateDocs()); | ||
} | ||
|
||
@ApiTest | ||
@DisplayName("발자취 유형에 해당 하는 항목 값이 빈 문자일 때 대해 발자취 생성에 실패한다.") | ||
void createFootprint_Fail_By_InvalidContents() throws Exception { | ||
// given | ||
FootprintRequest.Create request = sut.giveMeBuilder(FootprintRequest.Create.class) | ||
.set("param.content", "") | ||
.set("tags", List.of("tag1", "tag2")) | ||
.sample(); | ||
|
||
doThrow(ConstraintViolationException.class).when(createFootprintUseCase) | ||
.create(anyLong(), any()); | ||
|
||
// when | ||
var result = mockMvc.perform(post(FOOTPRINT_END_POINT) | ||
.header(HttpHeaders.AUTHORIZATION, BEARER_TOKEN) | ||
.accept(APPLICATION_JSON) | ||
.contentType(APPLICATION_JSON) | ||
.content(objectMapper.writeValueAsString(request))); | ||
|
||
result.andExpectAll( | ||
status().isBadRequest(), | ||
jsonPath("$.httpStatus").value(BAD_REQUEST.name()), | ||
jsonPath("$.errorName").value(BEAN_VALIDATION_FAIL_EXCEPTION.name()), | ||
jsonPath("$.errorMessage").value(BEAN_VALIDATION_FAIL_EXCEPTION.getMessage()) | ||
); | ||
|
||
// docs | ||
result.andDo(RestDocument.builder() | ||
.identifier("footprint-create-fail-invalid-type-contents") | ||
.tag(ApiTag.FOOTPRINT) | ||
.secured(true) | ||
.result(result) | ||
.generateDocs()); | ||
} | ||
} |
Oops, something went wrong.