Skip to content

Latest commit

 

History

History
483 lines (393 loc) · 7.1 KB

API_SPEC.md

File metadata and controls

483 lines (393 loc) · 7.1 KB

API 명세

1️⃣ 잔액 충전 / 조회 API

잔액 충전
POST /api/v1/balances

Swagger-잔액충전-Request

  • Request Header
{
  "Content-Type": "application/json"
}
  • Request Body
{
  "userId": 12345,
  "amount": 10000
}

Swagger-잔액충전-Response

  • Response Body

200 OK

{
  "userId": 12345,
  "chargedAmount": 10000,
  "currentBalance": 30000
}

400 Bad Request (충전 실패)

{
  "error": "충전 금액 에러",
  "status": 400
}
잔액 조회
GET /api/v1/balances/users/{userId}

Swagger-잔액조회-Request

  • Request Header
{
  "Content-Type": "application/json"
}

Swagger-잔액조회-Response

  • Response Body

200 OK

{
  "userId": 12345,
  "currentBalance": 30000
}

404 Not Found (사용자 없음)

{
  "error": "사용자 없음",
  "status": 404
}

2️⃣ 상품 조회 API

상품 목록 조회
GET /api/v1/products?page=1&size=10

Swagger-상품목록조회-Request

  • Request Header
{
  "Content-Type": "application/json"
}

Swagger-상품목록조회-Response

  • Response Body

200 OK

{
  "items": [
    {
      "id": 1,
      "name": "상품 A",
      "price": 5000,
      "stockQuantity": 10
    },
    {
      "id": 2,
      "name": "상품 B",
      "price": 10000,
      "stockQuantity": 5
    },
  ]
}

404 Not Found (상품 없음)

{
  "error": "상품 없음",
  "status": 404
}
특정 상품 조회
GET /api/v1/products/{productId}

Swagger-특정상품조회-Request

  • Request Header
{
  "Content-Type": "application/json"
}

Swagger-특정상품조회-Response

  • Response Body

200 OK

{
  "id": 1,
  "name": "상품 A",
  "price": 5000,
  "stockQuantity": 10
}

404 Not Found (상품 없음)

{
  "error": "상품 없음",
  "status": 404
}

3️⃣ 주문 / 결제 API

주문
POST /api/v1/orders

Swagger-주문-Request

  • Request Header
{
  "Content-Type": "application/json"
}
  • Request Body
{
  "userId": 12345,
  "orderItems": [
    {
      "productDetailId": 1,
      "quantity": 2
    },
    {
      "productDetailId": 2,
      "quantity": 1
    }
  ]
}

Swagger-주문-Response

  • Response Body

200 OK

{
  "orderId": 98765,
  "userId": 12345,
  "orderDate": "2024-10-06T12:00:01",
  "totalPrice": 23000,
  "status": "ORDER_COMPLETE",
  "orderItems": [
    {
      "productDetailId": 1,
      "quantity": 2,
      "price": 10000
    },
    {
      "productDetailId": 2,
      "quantity": 1,
      "price": 3000
    }
  ]
}

400 Bad Request (잔액 부족)

{
  "error": "잔액 부족",
  "status": 400
}

400 Bad Request (재고 부족)

{
  "error": "재고 부족",
  "status": 400
}
결제
POST /api/v1/payments

Swagger-결제-Request

  • Request Header
{
  "Content-Type": "application/json"
}
  • Request Body
{
  "userId": 12345,
  "orderId": 98765
}

Swagger-결제-Response

  • Response Body

200 OK

{
  "paymentId": 123,
  "orderId": 98765,
  "currentBalance": 17000,
  "paymentDate": "2024-10-06T12:01:10"
}

400 Bad Request (잔액 부족)

{
  "error": "잔액 부족",
  "status": 400
}

404 Not Found (주문 정보 없음)

{
  "error": "주문 정보 없음",
  "status": 404
}

4️⃣ 상위 상품 조회 API

GET /api/v1/statistics/products/top

Swagger-상위상품조회-Request

  • Request Header
{
  "Content-Type": "application/json"
}

Swagger-상위상품조회-Response

  • Response Body

200 OK

{
  "items": [
    {
      "productId": 1,
      "name": "상품 A",
      "totalSold": 50
    }
    {
      "productId": 2,
      "name": "상품 B",
      "totalSold": 40
    }
  ]
}

404 Not Found (상품 없음)

{
  "error": "상품 없음",
  "status": 404
}

5️⃣ 장바구니 기능

장바구니 상품 추가
POST /api/v1/carts

Swagger-장바구니추가-Request

  • Request Header
{
  "Content-Type": "application/json"
}
  • Request Body
{
  "userId": 12345,
  "productId": 1,
  "quantity": 2
}

Swagger-장바구니추가-Response

  • Response Body

200 OK

{
  "message": "상품을 장바구니에 추가했습니다.",
  "userId": 12345,
  "cart": {
    "productDetailId": 1,
    "quantity": 2
  }
}

400 Bad Request (재고가 없는 상품)

{
  "error": "재고 부족",
  "status": 400
}
장바구니 상품 삭제
DELETE /api/v1/carts/users/{userId}/products/{productId}

Swager-장바구니삭제-Request

  • Request Header
{
  "Content-Type": "application/json"
}

Swagger-장바구니삭제-Response

  • Response Body

200 OK

{
  "message": "장바구니에서 상품을 삭제했습니다.",
  "userId": 12345,
  "cart": {
    "productDetailId": 2,
    "quantity": 1
  }
}

404 Not Found (사용자 정보 없음)

{
  "error": "사용자 없음",
  "status": 404
}

404 Not Found (상품 정보 없음)

{
  "error": "상품 없음",
  "status": 404
}
장바구니 조회
GET /api/v1/carts/users/{userId}

Swagger-장바구니조회-Request

  • Request Header
{
  "Content-Type": "application/json"
}

Swagger-장바구니조회-Response

  • Response Body

200 OK

{
  "userId": 12345,
  "carts": [
    {
      "productDetailId": 1,
      "quantity": 2
    },
    {
      "productDetailId": 2,
      "quantity": 1
    }
  ],
}

404 Not Found (장바구니 정보 없음)

{
  "error": "장바구니 없음",
  "status": 404
}