2.상품 등록
인증된 사용자는 자신의 상품을 등록할 수 있음
| 메서드 | URI |
|---|---|
| POST | /api/products |
1-1. 세부 요구사항
- 인증된 사용자만 상품 등록 가능(JWT 기반,
Bearer) - HATEOAS 링크 포함(
_links)profile: 상품 등록에 대한 API 문서 참조 링크self: 등록된 상품의 상세 조회 API(/{id})list-products: 상품 목록 조회 APIupdate-product: 상품 수정 APIdelete-product: 상품 제거 API
1-2. 요청 헤더
요청 헤더에는 로그인 과정에서 발급받은 액세스 토큰을 전달해야 함
| 헤더명 | 필수 여부 | 설명 |
|---|---|---|
| Authorization | 필수 | 로그인 후 발급받은 액세스 토큰, Bearer |
1-3. 요청 예시
요청 예시는 다음과 같음
Record타입 활용Bean Validation을 통한 유효성 처리 적용
JSON 포맷
{
"name": "상품명", // 필수, 공백 x
"description": "상품 설명", // 1000자 미만
"price": 10000, // 최소 0원 이상
"stock": 50, // 재고는 최소 1개 이상
"category": "전자제품" // 필수, 공백 x
}1-4. 응답 예시
응답 예시는 다음과 같음
JSON 포맷
{
"id": 14,
"name": "맥북 pro",
"description": "M3 칩이 탑재된 고성능 노트북",
"price": 3500000,
"stock": 5,
"category": "전자제품",
"userId": 1,
"_links": {
"self": {
"href": "http://localhost:8080/api/products/14"
},
"profile": {
"href": "/swagger-ui/index.html"
},
"list-products": {
"href": "http://localhost:8080/api/products?page=0&size=10{&category}",
"type": "GET",
"templated": true
},
"update-product": {
"href": "http://localhost:8080/api/products/14",
"type": "PUT"
},
"delete-product": {
"href": "http://localhost:8080/api/products/14",
"type": "DELETE"
}
}
}1-5. 응답 코드
- 201 Created: 상품 등록 성공
- 400 Bad Request: 유효성 검증 실패
- 401 Unauthorized: 인증 실패
- 403 Forbidden: 권한 없음
Last updated on