스프링부트 핵심 가이드의 내용을 참고 했습니다.
설계한 API 중 다음 4개의 API 를 직접 개발 (JDBC Template 만을 활용하여)
server:
port: 9000
spring:
application:
name: demo
datasource:
url: jdbc:mysql://localhost:3309/asac?useSSL=false&allowPublicKeyRetrieval=true&useUnicode=true&serverTimezone=Asia/Seoul
username: root
password: inhatc # password
driver-class-name: com.mysql.cj.jdbc.Driver # mysql 8버전
# driver-class-name: com.mysql.jdbc.Driver # mysql 5버전
sql:
init:
platform: mysql
SELECT products.*, product_Detail.*
FROM products
JOIN product_Detail
ON products.productid = product_Detail.products_productid
WHERE products.productid = ?;
public GetProductRes getProductDeatilById(int productId){
String getProductQuery = "SELECT products.*, product_Detail.*\n" +
"FROM products\n" +
"JOIN product_Detail ON products.productid = product_Detail.products_productid\n" +
"WHERE products.productid = ?;";
int getProductParams = productId;
return this.jdbcTemplate.queryForObject(getProductQuery,
(rs, rowNum) -> new GetProductRes(
rs.getInt("ProductId"),
rs.getString("ProductName"),
rs.getString("ProductPrice"),
rs.getInt("seller_sellerid"),
rs.getString("ProductComment"),
rs.getString("ProductPhone")),
getProductParams);
}
@ResponseBody
@GetMapping("/{productId}") // (GET) 127.0.0.1:9000/api/products/:productId
public BaseResponse<GetProductRes> getProductDeatilById(@PathVariable("productId") int productId) {
// Get Users
try{
GetProductRes getProductRes = productService.getProductDeatilById(productId);
return new BaseResponse<>(getProductRes);
} catch(BaseException exception){
return new BaseResponse<>((exception.getStatus()));
}
}
상품 디테일을 추가할 수 있는 어드민에 대한 권한을 줘야 한다고 생각을 함.
각 유저들에게 권한을 부여하여 관리자 권한 이라면 POST
Error Code: 1175. You are using safe update mode and you tried to update a table without a WHERE that uses a KEY column. To disable safe mode, toggle the option in Preferences -> SQL Editor and reconnect.
MySQL의 "Safe Update Mode" 때문에 발생,
Safe Update Mode에서는 WHERE 절에서 KEY(column)을 사용하지 않고 전체 테이블을 업데이트 하는 것을 방지
/api/products/:productId/admin/productdetail
필자의 기분이 안좋음에 따라 무기한 연기