Skip to content

Commit

Permalink
Feature: 케이크 샵 간단조회 API 구현
Browse files Browse the repository at this point in the history
Feature: 케이크 샵 간단조회 API 구현
  • Loading branch information
lcomment authored May 24, 2024
2 parents 44e62d7 + af402a6 commit ff0e7d3
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 8 deletions.
4 changes: 0 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@ on:
branches:
- develop
- master
push:
branches:
- develop
- master

permissions: write-all

Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/prod-app-api-cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ on:
push:
branches:
- master
# paths:
# - cakk-api/**
# - cakk-domain/**
# - cakk-common/**
paths:
- cakk-api/**
- cakk-domain/**
- cakk-common/**

permissions: write-all

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

import jakarta.validation.Valid;

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 All @@ -16,6 +18,7 @@
import com.cakk.api.dto.request.user.CertificationRequest;
import com.cakk.api.service.shop.ShopService;
import com.cakk.common.response.ApiResponse;
import com.cakk.domain.dto.param.shop.CakeShopSimpleResponse;
import com.cakk.domain.entity.user.User;

@RestController
Expand Down Expand Up @@ -49,4 +52,12 @@ public ApiResponse<Void> promoteUser(
return ApiResponse.success();
}

@GetMapping("/{cakeShopId}/simple")
public ApiResponse<CakeShopSimpleResponse> simple(
@PathVariable Long cakeShopId
) {
final CakeShopSimpleResponse response = shopService.searchSimpleById(cakeShopId);
return ApiResponse.success(response);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package com.cakk.api.integration.shop;

import static org.junit.Assert.*;
import static org.springframework.test.context.jdbc.Sql.ExecutionPhase.*;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatusCode;
import org.springframework.http.ResponseEntity;
import org.springframework.test.context.jdbc.Sql;
import org.springframework.test.context.jdbc.SqlGroup;
import org.springframework.web.util.UriComponents;
import org.springframework.web.util.UriComponentsBuilder;

import com.cakk.api.common.annotation.TestWithDisplayName;
import com.cakk.api.common.base.IntegrationTest;
import com.cakk.common.enums.ReturnCode;
import com.cakk.common.response.ApiResponse;
import com.cakk.domain.dto.param.shop.CakeShopSimpleResponse;
import com.cakk.domain.entity.shop.CakeShop;
import com.cakk.domain.repository.reader.CakeShopReader;

@SqlGroup({
@Sql(scripts = "/sql/insert-cake-shop.sql", executionPhase = BEFORE_TEST_METHOD),
@Sql(scripts = "/sql/delete-all.sql", executionPhase = AFTER_TEST_METHOD)
})
public class ShopIntegrationTest extends IntegrationTest {

private static final String API_URL = "/api/v1/shops";

@Autowired
private CakeShopReader cakeShopReader;

@TestWithDisplayName("케이크 샵을 간단 조회에 성공한다.")
void simple1() {
final String url = "%s%d%s".formatted(BASE_URL, port, API_URL);
final Long cakeShopId = 1L;
final UriComponents uriComponents = UriComponentsBuilder
.fromUriString(url)
.path("/{cakeShopId}/simple")
.buildAndExpand(cakeShopId);

// when
final ResponseEntity<ApiResponse> responseEntity = restTemplate.getForEntity(uriComponents.toUriString(), ApiResponse.class);

// then
final ApiResponse response = objectMapper.convertValue(responseEntity.getBody(), ApiResponse.class);
final CakeShopSimpleResponse data = objectMapper.convertValue(response.getData(), CakeShopSimpleResponse.class);

assertEquals(HttpStatusCode.valueOf(200), responseEntity.getStatusCode());
assertEquals(ReturnCode.SUCCESS.getCode(), response.getReturnCode());
assertEquals(ReturnCode.SUCCESS.getMessage(), response.getReturnMessage());

final CakeShop cakeShop = cakeShopReader.findById(cakeShopId);
assertEquals(cakeShop.getId(), data.cakeShopId());
assertEquals(cakeShop.getThumbnailUrl(), data.thumbnailUrl());
assertEquals(cakeShop.getShopName(), data.cakeShopName());
assertEquals(cakeShop.getShopBio(), data.cakeShopBio());
}

@TestWithDisplayName("없는 케이크 샵일 경우, 간단 조회에 실패한다.")
void simple2() {
final String url = "%s%d%s".formatted(BASE_URL, port, API_URL);
final Long cakeShopId = 1000L;
final UriComponents uriComponents = UriComponentsBuilder
.fromUriString(url)
.path("/{cakeShopId}/simple")
.buildAndExpand(cakeShopId);

// when
final ResponseEntity<ApiResponse> responseEntity = restTemplate.getForEntity(uriComponents.toUriString(), ApiResponse.class);

// then
final ApiResponse response = objectMapper.convertValue(responseEntity.getBody(), ApiResponse.class);
final CakeShopSimpleResponse data = objectMapper.convertValue(response.getData(), CakeShopSimpleResponse.class);

assertEquals(HttpStatusCode.valueOf(400), responseEntity.getStatusCode());
assertEquals(ReturnCode.NOT_EXIST_CAKE_SHOP.getCode(), response.getReturnCode());
assertEquals(ReturnCode.NOT_EXIST_CAKE_SHOP.getMessage(), response.getReturnMessage());
}

}
5 changes: 5 additions & 0 deletions cakk-api/src/test/resources/sql/insert-cake-shop.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
insert into cake_shop (shop_id, thumbnail_url, shop_name, shop_bio, shop_description, latitude, longitude, like_count, linked_flag,
created_at, updated_at)
values (1, 'thumbnail_url1', '케이크 맛집1', '케이크 맛집입니다.', '케이크 맛집입니다.', 37.123456, 127.123456, 0, false, now(), now()),
(2, 'thumbnail_url2', '케이크 맛집2', '케이크 맛집입니다.', '케이크 맛집입니다.', 38.123456, 128.123456, 0, false, now(), now()),
(3, 'thumbnail_url3', '케이크 맛집3', '케이크 맛집입니다.', '케이크 맛집입니다.', 39.123456, 129.123456, 0, false, now(), now());

0 comments on commit ff0e7d3

Please sign in to comment.