๐Ÿช kakaotech campus

์นดํ…Œ์ผ | [STEP2 clone coding] 1์ฃผ์ฐจ ๊ณผ์ œ - (2)

c0zi 2023. 6. 29. 12:57

๊ณผ์ œ๋ช…

1. ์š”๊ตฌ์‚ฌํ•ญ๋ถ„์„ / API์š”์ฒญ ๋ฐ ์‘๋‹ต ์‹œ๋‚˜๋ฆฌ์˜ค ๋ถ„์„
2. ์š”๊ตฌ์‚ฌํ•ญ ์ถ”๊ฐ€ ๋ฐ˜์˜ ๋ฐ ํ…Œ์ด๋ธ” ์„ค๊ณ„๋„

 

๊ณผ์ œ ์„ค๋ช… 

 

1. ์š”๊ตฌ์‚ฌํ•ญ ์‹œ๋‚˜๋ฆฌ์˜ค๋ฅผ ๋ณด๊ณ  ๋ถ€์กฑํ•ด ๋ณด์ด๋Š” ๊ธฐ๋Šฅ์„ ํ•˜๋‚˜ ์ด์ƒ ์ฒดํฌํ•˜์—ฌ README์— ๋‚ด์šฉ์„ ์ž‘์„ฑํ•˜์‹œ์˜ค.

 

2. ์ œ์‹œ๋œ ํ™”๋ฉด์„ค๊ณ„๋ฅผ ๋ณด๊ณ  ํ•ด๋‹น ํ™”๋ฉด์„ค๊ณ„์™€ ๋ฐฐํฌ๋œ ๊ธฐ์กด ์„œ๋ฒ„์˜ API์ฃผ์†Œ๋ฅผ ๋งค์นญํ•˜์—ฌ README์— ๋‚ด์šฉ์„ ์ž‘์„ฑํ•˜์‹œ์˜ค. (์นด์นด์˜ค ํ™”๋ฉด์„ค๊ณ„ ์‹œ๋‚˜๋ฆฌ์˜ค๊ฐ€ ์žˆ์Œ)

 

3. ๋ฐฐํฌ๋œ ์„œ๋ฒ„์— ๋ชจ๋“  API๋ฅผ POSTMAN์œผ๋กœ ์š”์ฒญํ•ด๋ณธ ๋’ค ์‘๋‹ต๋˜๋Š” ๋ฐ์ดํ„ฐ๋ฅผ ํ™•์ธํ•˜๊ณ  ๋ถ€์กฑํ•œ ๋ฐ์ดํ„ฐ๊ฐ€ ๋ฌด์—‡์ธ์ง€ ์ฒดํฌํ•˜์—ฌ README์— ๋‚ด์šฉ์„ ์ž‘์„ฑํ•˜์‹œ์˜ค.

 

WEB | API ์•Œ์•„๋ณด๊ธฐ

00. API ? 1) API : ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ์†Œํ”„ํŠธ์›จ์–ด๋ฅผ ๋นŒ๋“œํ•˜๊ณ  ํ†ตํ•ฉํ•˜๊ธฐ ์œ„ํ•œ ์ •์˜ ๋ฐ ํ”„๋กœํ† ์ฝœ ์„ธํŠธ์ธ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ํ”„๋กœ๊ทธ๋ž˜๋ฐ ์ธํ„ฐํŽ˜์ด์Šค(Application Programming Interface) - ํ”„๋กœ๊ทธ๋žจ๋“ค์ด ์„œ๋กœ ์ƒํ˜ธ์ž‘์šฉํ•˜๋Š”

codingdialee.tistory.com

 

4. ํ…Œ์ด๋ธ” ์„ค๊ณ„๋ฅผ ํ•˜์—ฌ README์— ER-Diagram์„ ์ถ”๊ฐ€ํ•˜์—ฌ ์ œ์ถœํ•˜์‹œ์˜ค. 

 


2. ์š”๊ตฌ์‚ฌํ•ญ ์ถ”๊ฐ€ ๋ฐ˜์˜ ๋ฐ ํ…Œ์ด๋ธ” ์„ค๊ณ„๋„


03) ๋ฐฐํฌ๋œ ์„œ๋ฒ„์— ๋ชจ๋“  API๋ฅผ POSTMAN์œผ๋กœ ์š”์ฒญํ•ด๋ณธ ๋’ค ์‘๋‹ต๋˜๋Š” ๋ฐ์ดํ„ฐ๋ฅผ ํ™•์ธํ•˜๊ณ  ๋ถ€์กฑํ•œ ๋ฐ์ดํ„ฐ๊ฐ€ ๋ฌด์—‡์ธ์ง€ ์ฒดํฌํ•˜์—ฌ README์— ๋‚ด์šฉ์„ ์ž‘์„ฑํ•˜์‹œ์˜ค.

 

1. ์ „์ฒด ์ƒํ’ˆ ๋ชฉ๋ก ์กฐํšŒ

  • API : http://localhost:8080/products
  • Response body
{
    "success": true,
    "response": [
        {
            "id": 1,
            "productName": "๊ธฐ๋ณธ์— ์Šฌ๋ผ์ด๋”ฉ ์ง€ํผ๋ฐฑ ํฌ๋ฆฌ์Šค๋งˆ์Šค/ํ”Œ๋ผ์›Œ์—๋””์…˜ ์—๋””์…˜ ์™ธ ์ฃผ๋ฐฉ์šฉํ’ˆ ํŠน๊ฐ€์ „",
            "description": "",
            "image": "/images/1.jpg",
            "price": 1000
        },
        {
            "id": 2,
            "productName": "[ํ™ฉ๊ธˆ์•ฝ๋‹จ๋ฐค ๊ณจ๋“œ]2022๋…„์‚ฐ ํ–‡๋ฐค ์นผ์ง‘๋ฐค700g์™ธ/๊ตฐ๋ฐค์šฉ/์ƒ์œจ",
            "description": "",
            "image": "/images/2.jpg",
            "price": 2000
        },
        {
            "id": 3,
            "productName": "์‚ผ์„ฑ์ „์ž JBL JR310 ์™ธ ์–ด๋ฆฐ์ด์šฉ/์„ฑ์ธ์šฉ ํ—ค๋“œ์…‹ 3์ข…!",
            "description": "",
            "image": "/images/3.jpg",
            "price": 30000
        },
        {
            "id": 4,
            "productName": "๋ฐ”๋ฅธ ๋ˆ„๋ฃฝ์ง€๋ง› ๋ฐœํšจํšจ์†Œ 2๋ฐ•์Šค ์—ญ๊ฐ€์ˆ˜์น˜๋ณด์žฅ / ์™ธ 7์ข…",
            "description": "",
            "image": "/images/4.jpg",
            "price": 4000
        },
        {
            "id": 5,
            "productName": "[๋”์ฃผ] ์ปทํŒ…๋ง๋ž‘์žฅ์กฑ, ์ˆ๋‹ค๋ฆฌ 100g/300g ์™ธ ์ฃผ์ „๋ถ€๋ฆฌ ๋ชจ์Œ /์ค‘๋…์„ฑ ์ตœ๊ณ /๋งˆ๋ฅธ์•ˆ์ฃผ",
            "description": "",
            "image": "/images/5.jpg",
            "price": 5000
        },
        {
            "id": 6,
            "productName": "๊ตณ์ง€์•Š๋Š” ์•™๊ธˆ์ ˆํŽธ 1,050g 2ํŒฉ ์™ธ ์šฐ๋ฆฌ์Œ€๋–ก ๋ชจ์Œ์ „",
            "description": "",
            "image": "/images/6.jpg",
            "price": 15900
        },
        {
            "id": 7,
            "productName": "eoe ์ด๋„ˆ๋”œ๋ฆฌํ‹ฐ 30ํฌ, ์˜ค๋ Œ์ง€๋ง› ๊ณ  ์‹์ด์„ฌ์œ  ๋ณด์ถฉ์ œ",
            "description": "",
            "image": "/images/7.jpg",
            "price": 26800
        },
        {
            "id": 8,
            "productName": "์ œ๋‚˜๋ฒจ PDRN ํฌ๋ฆผ 2๊ฐœ. ํ”ผ๋ถ€๋ณด์Šต/์ง„์ • ์ผ€์–ด",
            "description": "",
            "image": "/images/8.jpg",
            "price": 25900
        },
        {
            "id": 9,
            "productName": "ํ”Œ๋ ˆ์ด์Šคํ…Œ์ด์…˜ VR2 ํ˜ธ๋ผ์ด์ฆŒ ๋ฒˆ๋“ค. ์ƒ์ƒํ•œ ๋ชฐ์ž…๊ฐ",
            "description": "",
            "image": "/images/9.jpg",
            "price": 797000
        }
    ],
    "error": null
}
  • ์ถ”๊ฐ€ํ• ๋งŒํ•œ ๋ฐ์ดํ„ฐ
    > ๊ฐ•์˜์—์„œ ์–ธ๊ธ‰ํ•˜์‹  ๊ฒƒ๊ณผ ๊ฐ™์ด ๋ณ„์  ๊ธฐ๋Šฅ์„ ์ถ”๊ฐ€ํ•œ๋‹ค๋ฉด, ๋ณ„์  ๋ฐ์ดํ„ฐ๋ฅผ ์ถ”๊ฐ€ํ•ด์•ผ ํ•  ๊ฒƒ ๊ฐ™๋‹ค.

 

2. ๊ฐœ๋ณ„ ์ƒํ’ˆ ์ƒ์„ธ ์กฐํšŒ

  • API : http://localhost:8080/products/1
  • Response Body
{
    "success": true,
    "response": {
        "id": 1,
        "productName": "๊ธฐ๋ณธ์— ์Šฌ๋ผ์ด๋”ฉ ์ง€ํผ๋ฐฑ ํฌ๋ฆฌ์Šค๋งˆ์Šค/ํ”Œ๋ผ์›Œ์—๋””์…˜ ์—๋””์…˜ ์™ธ ์ฃผ๋ฐฉ์šฉํ’ˆ ํŠน๊ฐ€์ „",
        "description": "",
        "image": "/images/1.jpg",
        "price": 1000,
        "starCount": 5,
        "options": [
            {
                "id": 1,
                "optionName": "01. ์Šฌ๋ผ์ด๋”ฉ ์ง€ํผ๋ฐฑ ํฌ๋ฆฌ์Šค๋งˆ์Šค์—๋””์…˜ 4์ข…",
                "price": 10000
            },
            {
                "id": 2,
                "optionName": "02. ์Šฌ๋ผ์ด๋”ฉ ์ง€ํผ๋ฐฑ ํ”Œ๋ผ์›Œ์—๋””์…˜ 5์ข…",
                "price": 10900
            },
            {
                "id": 3,
                "optionName": "๊ณ ๋ฌด์žฅ๊ฐ‘ ๋ฒ ์ด์ง€ S(์†Œํ˜•) 6ํŒฉ",
                "price": 9900
            },
            {
                "id": 4,
                "optionName": "๋ฝ‘์•„์“ฐ๋Š” ํ‚ค์นœํƒ€์˜ฌ 130๋งค 12ํŒฉ",
                "price": 16900
            },
            {
                "id": 5,
                "optionName": "2๊ฒน ์‹๋นต์ˆ˜์„ธ๋ฏธ 6๋งค",
                "price": 8900
            }
        ]
    },
    "error": null
}
  • ์ถ”๊ฐ€ํ• ๋งŒํ•œ ๋ฐ์ดํ„ฐ
    - ์ œํ’ˆ ์ƒ์„ธ ์ •๋ณด ์„ค๋ช… ๋ฐ์ดํ„ฐ
    - ๋ณ„์  or ๋ฆฌ๋ทฐ ๋ฐ์ดํ„ฐ
    - ๋ฐฐ์†ก๋น„

 

3. ์ด๋ฉ”์ผ ์ค‘๋ณต ์ฒดํฌ

  • API : http://localhost:8080/check
  • Response body
{
    "success": false,
    "response": null,
    "error": {
        "message": "์ด๋ฉ”์ผ ํ˜•์‹์œผ๋กœ ์ž‘์„ฑํ•ด์ฃผ์„ธ์š”:email",
        "status": 400
    }
}
  • ์ถ”๊ฐ€ ๋ฐ์ดํ„ฐ x

4. ํšŒ์›๊ฐ€์ž…

  • API : http://localhost:8080/join
  • ํšŒ์›๊ฐ€์ž… ์„ฑ๊ณต ์‹œ Response body
{
"success": true,
"response": null,
"error": null
}
  • ํšŒ์›๊ฐ€์ž… ์‹คํŒจ ์‹œ Response body
{
    "success": false,
    "response": null,
    "error": {
        "message": "8์—์„œ 20์ž ์ด๋‚ด์—ฌ์•ผ ํ•ฉ๋‹ˆ๋‹ค.:password",
        "status": 400
    }
}
  • ์ถ”๊ฐ€ ๋ฐ์ดํ„ฐ x

 

5. ๋กœ๊ทธ์ธ

  • API : http://localhost:8080/login
  • Response body
{
	"success": true,
	"response": null,
	"error": null
}
  • ์ถ”๊ฐ€ ๋ฐ์ดํ„ฐ x

 

6. ์žฅ๋ฐ”๊ตฌ๋‹ˆ ๋‹ด๊ธฐ

  • API : http://localhost:8080/carts/add
  • Response body
{
	"success": true,
	"response": null,
	"error": null
}
  • ๋ฐฐ์†ก๋น„๊ฐ€ ์žˆ๋‹ค๋ฉด ๋ฐฐ์†ก๋น„ ๋ฐ์ดํ„ฐ ?

 

7. ์žฅ๋ฐ”๊ตฌ๋‹ˆ ์กฐํšŒ

  • API : http://localhost:8080/carts
  • Response body
{
	"success": true,
	"response": {
		"products": [
			{
				"id": 1,
				"productName": "๊ธฐ๋ณธ์— ์Šฌ๋ผ์ด๋”ฉ ์ง€ํผ๋ฐฑ ํฌ๋ฆฌ์Šค๋งˆ์Šค/ํ”Œ๋ผ์›Œ์—๋””์…˜ ์—๋””์…˜
์™ธ ์ฃผ๋ฐฉ์šฉํ’ˆ ํŠน๊ฐ€์ „",
				"carts": [
					{
						"id": 4,
						"option": {
							"id": 1,
							"optionName": "01. ์Šฌ๋ผ์ด๋”ฉ ์ง€ํผ๋ฐฑ ํฌ๋ฆฌ์Šค๋งˆ์Šค์—๋””์…˜ 
4์ข…",
							"price": 10000
						},
						"quantity": 5,
						"price": 50000
					},
					{
						"id": 5,
						"option": {
							"id": 2,
							"optionName": "02. ์Šฌ๋ผ์ด๋”ฉ ์ง€ํผ๋ฐฑ ํ”Œ๋ผ์›Œ์—๋””์…˜ 5์ข…",
							"price": 10900
						},
						"quantity": 5,
						"price": 54500
					}
				]
			}
		],
		"totalPrice": 104500
	},
	"error": null
}
  • ์žฅ๋ฐ”๊ตฌ๋‹ˆ ์˜ต์…˜ ์‚ญ์ œ ๊ธฐ๋Šฅ
  • ์ตœ๊ทผ ๋ณธ ์ƒํ’ˆ ๋ฐ์ดํ„ฐ or ์—ฐ๊ด€์žˆ๋Š” ์ƒํ’ˆ ๋ฐ์ดํ„ฐ

 

8. ์ฃผ๋ฌธํ•˜๊ธฐ - ์žฅ๋ฐ”๊ตฌ๋‹ˆ ์ˆ˜์ •

  • API : http://localhost:8080/carts/update
  • Response body
{
	"success": true,
	"response": {
		"carts": [
			{
				"cartId": 4,
				"optionId": 1,
				"optionName": "01. ์Šฌ๋ผ์ด๋”ฉ ์ง€ํผ๋ฐฑ ํฌ๋ฆฌ์Šค๋งˆ์Šค์—๋””์…˜ 4์ข…",
				"quantity": 10,
				"price": 100000
			},
			{
				"cartId": 5,
				"optionId": 2,
				"optionName": "02. ์Šฌ๋ผ์ด๋”ฉ ์ง€ํผ๋ฐฑ ํ”Œ๋ผ์›Œ์—๋””์…˜ 5์ข…",
				"quantity": 10,
				"price": 109000
			}
		],
		"totalPrice": 209000
	},
	"error": null
}
  • ์žฅ๋ฐ”๊ตฌ๋‹ˆ ์˜ต์…˜ ์‚ญ์ œ ๊ธฐ๋Šฅ
  • ์ตœ๊ทผ ๋ณธ ์ƒํ’ˆ ๋ฐ์ดํ„ฐ or ์—ฐ๊ด€์žˆ๋Š” ์ƒํ’ˆ ๋ฐ์ดํ„ฐ

 

9. ๊ฒฐ์ œํ•˜๊ธฐ - ์ฃผ๋ฌธ ์ธ์„œํŠธ

  • API : http://localhost:8080/orders/save
  • Response body
{
	"success": true,
	"response": {
		"id": 2,
		"products": [
			{
				"productName": "๊ธฐ๋ณธ์— ์Šฌ๋ผ์ด๋”ฉ ์ง€ํผ๋ฐฑ ํฌ๋ฆฌ์Šค๋งˆ์Šค/ํ”Œ๋ผ์›Œ์—๋””์…˜ ์—๋””์…˜
์™ธ ์ฃผ๋ฐฉ์šฉํ’ˆ ํŠน๊ฐ€์ „",
				"items": [
					{
						"id": 4,
						"optionName": "01. ์Šฌ๋ผ์ด๋”ฉ ์ง€ํผ๋ฐฑ ํฌ๋ฆฌ์Šค๋งˆ์Šค์—๋””์…˜ 4์ข…",
						"quantity": 10,
						"price": 100000
					},
					{
						"id": 5,
						"optionName": "02. ์Šฌ๋ผ์ด๋”ฉ ์ง€ํผ๋ฐฑ ํ”Œ๋ผ์›Œ์—๋””์…˜ 5์ข…",
						"quantity": 10,
						"price": 109000
					}
				]
			}
		],
		"totalPrice": 209000
	},
	"error": null
}
  • ๋ฐฐ์†ก๋น„ ์žˆ๋‹ค๋ฉด ๋ฐฐ์†ก๋น„ ํ•ฉ๊ณ„ ๋ฐ์ดํ„ฐ

 

10. ์ฃผ๋ฌธ ๊ฒฐ๊ณผ ํ™•์ธ

  • API : http://localhost:8080/orders/1
  • Response body
{
	"success": true,
	"response": {
		"id": 2,
		"products": [
			{
				"productName": "๊ธฐ๋ณธ์— ์Šฌ๋ผ์ด๋”ฉ ์ง€ํผ๋ฐฑ ํฌ๋ฆฌ์Šค๋งˆ์Šค/ํ”Œ๋ผ์›Œ์—๋””์…˜ ์—๋””์…˜
์™ธ ์ฃผ๋ฐฉ์šฉํ’ˆ ํŠน๊ฐ€์ „",
				"items": [
					{
						"id": 4,
						"optionName": "01. ์Šฌ๋ผ์ด๋”ฉ ์ง€ํผ๋ฐฑ ํฌ๋ฆฌ์Šค๋งˆ์Šค์—๋””์…˜ 4์ข…",
						"quantity": 10,
						"price": 100000
					},
					{
						"id": 5,
						"optionName": "02. ์Šฌ๋ผ์ด๋”ฉ ์ง€ํผ๋ฐฑ ํ”Œ๋ผ์›Œ์—๋””์…˜ 5์ข…",
						"quantity": 10,
						"price": 109000
					}
				]
			}
		],
		"totalPrice": 209000
	},
	"error": null
}
  • ์ฃผ๋ฌธ ๋ฒˆํ˜ธ ๋ฐ์ดํ„ฐ