Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PatchMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
Expand Down Expand Up @@ -84,13 +85,14 @@ public ResponseEntity<SuccessResponse<ItemQueryResponse>> queryMyEggs(
@ApiResponse(responseCode = "400", description = "잘못된 요청 데이터"),
@ApiResponse(responseCode = "401", description = "인증 실패")
})
@PatchMapping
@PatchMapping("{incubatingEggId}")
public ResponseEntity<SuccessResponse<UseLovePointResponse>> useLovePointToEgg(
@UserId Long userId,
@PathVariable Long incubatingEggId,
@Valid @RequestBody UseLovePointRequest request
) {
UseLovePointResponse useLovePointResponse = giveLovePointToEggUsecase.execute(
new UseLovePointCommand(userId, request.incubatingEggId(), request.lovePointAmount())
new UseLovePointCommand(userId, incubatingEggId, request.lovePointAmount())
);
return ResponseEntity.ok().body(
SuccessResponse.of(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,10 @@
description = "사랑의 포인트 사용 요청",
example = """
{
"incubating_egg_id": 1,
"love_point_amount": 100
}
""")
public record UseLovePointRequest(
@Schema(description = "부화중인 알 ID", example = "1")
Long incubatingEggId,
@Schema(description = "사용할 사랑의 포인트", example = "100")
Long lovePointAmount
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,14 @@ void tearDown() {
@Sql(scripts = "/sql/incubating_egg_test_data.sql", executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD)
void 부화중인_알에_애정을_부여() throws JsonProcessingException {
String token = "Bearer " + jwtTokenFactory.generateAccessToken("test-user-uuid-1");
UseLovePointRequest request = new UseLovePointRequest(1L, 20L);
Long incubatingEggId = 1L;
UseLovePointRequest request = new UseLovePointRequest(20L);
given()
.header("Authorization", token)
.contentType(ContentType.JSON)
.body(objectMapper.writeValueAsString(request))
.when()
.patch("/api/v1/users/eggs")
.patch("/api/v1/users/eggs/{incubatingEggId}", incubatingEggId)
.then()
.log().all()
.statusCode(200)
Expand All @@ -115,6 +116,7 @@ void tearDown() {
// given
String userUuid = "test-user-uuid-1";
String token = "Bearer " + jwtTokenFactory.generateAccessToken(userUuid);
Long incubatingEggId = 1L;

// 사용자의 초기 애정 포인트 조회
Integer initialLovePoint = given()
Expand All @@ -130,15 +132,15 @@ void tearDown() {
// when
// 20포인트의 애정을 부여
Long useLovePointAmount = 20L;
UseLovePointRequest request = new UseLovePointRequest(1L, useLovePointAmount);
UseLovePointRequest request = new UseLovePointRequest(useLovePointAmount);

// 알에 애정 부여 요청
given()
.header("Authorization", token)
.contentType(ContentType.JSON)
.body(objectMapper.writeValueAsString(request))
.when()
.patch("/api/v1/users/eggs")
.patch("/api/v1/users/eggs/{incubatingEggId}", incubatingEggId)
.then()
.log().all()
.statusCode(200)
Expand All @@ -164,6 +166,7 @@ void tearDown() {
// given
String userUuid = "test-user-uuid-1";
String token = "Bearer " + jwtTokenFactory.generateAccessToken(userUuid);
Long incubatingEggId = 1L;

// 사용자의 초기 애정 포인트 조회
given()
Expand All @@ -179,15 +182,15 @@ void tearDown() {
// when
// 20포인트의 애정을 부여
Long useLovePointAmount = 25L;
UseLovePointRequest request = new UseLovePointRequest(1L, useLovePointAmount);
UseLovePointRequest request = new UseLovePointRequest(useLovePointAmount);

// 알에 애정 부여 요청
given()
.header("Authorization", token)
.contentType(ContentType.JSON)
.body(objectMapper.writeValueAsString(request))
.when()
.patch("/api/v1/users/eggs")
.patch("/api/v1/users/eggs/{incubatingEggId}", incubatingEggId)
.then()
.log().all()
.statusCode(400);
Expand All @@ -199,6 +202,7 @@ void tearDown() {
// given
String userUuid = "test-user-uuid-1";
String token = "Bearer " + jwtTokenFactory.generateAccessToken(userUuid);
Long incubatingEggId = 1L;

// 사용자의 초기 애정 포인트 조회
Integer initialLovePoint = given()
Expand All @@ -214,15 +218,15 @@ void tearDown() {
// when
// 20포인트의 애정을 부여
Long useLovePointAmount = 25L;
UseLovePointRequest request = new UseLovePointRequest(1L, useLovePointAmount);
UseLovePointRequest request = new UseLovePointRequest(useLovePointAmount);

// 알에 애정 부여 요청
given()
.header("Authorization", token)
.contentType(ContentType.JSON)
.body(objectMapper.writeValueAsString(request))
.when()
.patch("/api/v1/users/eggs")
.patch("/api/v1/users/eggs/{incubatingEggId}", incubatingEggId)
.then()
.log().all()
.statusCode(400);
Expand Down