-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
[FEAT] 인형 이미지 조회
- Loading branch information
Showing
11 changed files
with
212 additions
and
0 deletions.
There are no files selected for viewing
30 changes: 30 additions & 0 deletions
30
src/main/java/com/soptie/server/doll/controller/DollController.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.soptie.server.doll.controller; | ||
|
||
import static com.soptie.server.common.dto.Response.*; | ||
import static com.soptie.server.doll.message.ResponseMessage.*; | ||
|
||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import com.soptie.server.common.dto.Response; | ||
import com.soptie.server.doll.entity.DollType; | ||
import com.soptie.server.doll.service.DollService; | ||
|
||
import lombok.*; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("/api/v1/dolls") | ||
public class DollController { | ||
|
||
private final DollService dollService; | ||
|
||
@GetMapping("/image/{type}") | ||
public ResponseEntity<Response> getDollImages(@PathVariable DollType type) { | ||
val response = dollService.getDollImage(type); | ||
return ResponseEntity.ok(success(SUCCESS_GET_IMAGE.getMessage(), response)); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
src/main/java/com/soptie/server/doll/dto/DollImageResponse.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,12 @@ | ||
package com.soptie.server.doll.dto; | ||
|
||
import com.soptie.server.doll.entity.Doll; | ||
|
||
public record DollImageResponse( | ||
String faceImageUrl | ||
) { | ||
|
||
public static DollImageResponse of(Doll doll) { | ||
return new DollImageResponse(doll.getImageInfo().getFaceImageUrl()); | ||
} | ||
} |
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
13 changes: 13 additions & 0 deletions
13
src/main/java/com/soptie/server/doll/message/ErrorMessage.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,13 @@ | ||
package com.soptie.server.doll.message; | ||
|
||
import lombok.Getter; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@RequiredArgsConstructor | ||
@Getter | ||
public enum ErrorMessage { | ||
INVALID_TYPE("유효하지 않은 인형 타입입니다."), | ||
; | ||
|
||
private final String message; | ||
} |
13 changes: 13 additions & 0 deletions
13
src/main/java/com/soptie/server/doll/message/ResponseMessage.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,13 @@ | ||
package com.soptie.server.doll.message; | ||
|
||
import lombok.Getter; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@RequiredArgsConstructor | ||
@Getter | ||
public enum ResponseMessage { | ||
SUCCESS_GET_IMAGE("인형 이미지 조회 성공"), | ||
; | ||
|
||
private final String message; | ||
} |
12 changes: 12 additions & 0 deletions
12
src/main/java/com/soptie/server/doll/repository/DollRepository.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,12 @@ | ||
package com.soptie.server.doll.repository; | ||
|
||
import java.util.Optional; | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
import com.soptie.server.doll.entity.Doll; | ||
import com.soptie.server.doll.entity.DollType; | ||
|
||
public interface DollRepository extends JpaRepository<Doll, Long> { | ||
Optional<Doll> findByDollType(DollType type); | ||
} |
8 changes: 8 additions & 0 deletions
8
src/main/java/com/soptie/server/doll/service/DollService.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,8 @@ | ||
package com.soptie.server.doll.service; | ||
|
||
import com.soptie.server.doll.dto.DollImageResponse; | ||
import com.soptie.server.doll.entity.DollType; | ||
|
||
public interface DollService { | ||
DollImageResponse getDollImage(DollType type); | ||
} |
33 changes: 33 additions & 0 deletions
33
src/main/java/com/soptie/server/doll/service/DollServiceImpl.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.soptie.server.doll.service; | ||
|
||
import static com.soptie.server.doll.message.ErrorMessage.*; | ||
|
||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import com.soptie.server.doll.dto.DollImageResponse; | ||
import com.soptie.server.doll.entity.Doll; | ||
import com.soptie.server.doll.entity.DollType; | ||
import com.soptie.server.doll.repository.DollRepository; | ||
|
||
import jakarta.persistence.EntityNotFoundException; | ||
import lombok.*; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
@Transactional(readOnly = true) | ||
public class DollServiceImpl implements DollService { | ||
|
||
private final DollRepository dollRepository; | ||
|
||
@Override | ||
public DollImageResponse getDollImage(DollType type) { | ||
val doll = getDoll(type); | ||
return DollImageResponse.of(doll); | ||
} | ||
|
||
private Doll getDoll(DollType type) { | ||
return dollRepository.findByDollType(type) | ||
.orElseThrow(() -> new EntityNotFoundException(INVALID_TYPE.getMessage())); | ||
} | ||
} |
75 changes: 75 additions & 0 deletions
75
src/test/java/com/soptie/server/doll/controller/DollControllerTest.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,75 @@ | ||
package com.soptie.server.doll.controller; | ||
|
||
import static com.epages.restdocs.apispec.ResourceDocumentation.*; | ||
import static org.mockito.Mockito.*; | ||
import static org.springframework.restdocs.operation.preprocess.Preprocessors.*; | ||
import static org.springframework.restdocs.payload.JsonFieldType.*; | ||
import static org.springframework.restdocs.payload.PayloadDocumentation.*; | ||
import static org.springframework.restdocs.request.RequestDocumentation.parameterWithName; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; | ||
|
||
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.http.ResponseEntity; | ||
import org.springframework.restdocs.mockmvc.MockMvcRestDocumentation; | ||
import org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders; | ||
|
||
import com.epages.restdocs.apispec.ResourceSnippetParameters; | ||
import com.soptie.server.base.BaseControllerTest; | ||
import com.soptie.server.common.dto.Response; | ||
import com.soptie.server.doll.dto.DollImageResponse; | ||
import com.soptie.server.doll.entity.DollType; | ||
import com.soptie.server.doll.fixture.DollFixture; | ||
|
||
@WebMvcTest(DollController.class) | ||
class DollControllerTest extends BaseControllerTest { | ||
|
||
@MockBean | ||
DollController controller; | ||
|
||
private final String DEFAULT_URL = "/api/v1/dolls"; | ||
private final String TAG = "DOLL"; | ||
|
||
@Test | ||
@DisplayName("인형 이미지 조회 성공") | ||
void success_getDollImage() throws Exception { | ||
// given | ||
DollType dollType = DollType.BEAR; | ||
DollImageResponse dollImage = DollFixture.createDollImageResponseDTO(); | ||
ResponseEntity<Response> response = ResponseEntity.ok(Response.success("인형 이미지 조회 성공", dollImage)); | ||
|
||
// when | ||
when(controller.getDollImages(dollType)).thenReturn(response); | ||
|
||
// then | ||
mockMvc | ||
.perform( | ||
RestDocumentationRequestBuilders.get(DEFAULT_URL + "/image/{type}", dollType) | ||
.contentType(MediaType.APPLICATION_JSON) | ||
.accept(MediaType.APPLICATION_JSON)) | ||
.andDo( | ||
MockMvcRestDocumentation.document( | ||
"get-doll-image-docs", | ||
preprocessRequest(prettyPrint()), | ||
preprocessResponse(prettyPrint()), | ||
resource( | ||
ResourceSnippetParameters.builder() | ||
.tag(TAG) | ||
.description("인형 이미지 조회") | ||
.pathParameters( | ||
parameterWithName("type").description("인형 타입") | ||
) | ||
.requestFields() | ||
.responseFields( | ||
fieldWithPath("success").type(BOOLEAN).description("응답 성공 여부"), | ||
fieldWithPath("message").type(STRING).description("응답 메시지"), | ||
fieldWithPath("data").type(OBJECT).description("응답 데이터"), | ||
fieldWithPath("data.faceImageUrl").type(STRING).description("인형 얼굴 이미지 url") | ||
) | ||
.build()))) | ||
.andExpect(status().isOk()); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
src/test/java/com/soptie/server/doll/fixture/DollFixture.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,12 @@ | ||
package com.soptie.server.doll.fixture; | ||
|
||
import com.soptie.server.doll.dto.DollImageResponse; | ||
|
||
public class DollFixture { | ||
|
||
private static final String FACE_IMAGE_URL = "face-image-url"; | ||
|
||
public static DollImageResponse createDollImageResponseDTO() { | ||
return new DollImageResponse(FACE_IMAGE_URL); | ||
} | ||
} |