Skip to content

coding-Benny/web-framework

Repository files navigation

web-framework

Web Framework 1

๊ณผ์ œ 1

๊ณผ์ œ 2

Medium Article ์ฝ๊ณ  ๋ฌธ์ œ์— ๋‹ตํ•˜๊ธฐ(์ด๋ก )

๊ณผ์ œ 3

์š”๊ตฌ ์‚ฌํ•ญ
  1. ์ง€๊ธˆ๊นŒ์ง€ ์ˆ˜๊ฐ•ํ•œ ๊ต๊ณผ๋ชฉ์„ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค์— ์ €์žฅ
  2. ์›น ํŽ˜์ด์ง€ ์ ‘์† ์‹œ ์ธ์ฆ ์œ ๋ฌด๋ฅผ ์ฒดํฌ
    • ์ธ์ฆ๋˜์—ˆ์œผ๋ฉด ๋ฉ”์ธ ํŽ˜์ด์ง€๋กœ ์ด๋™
    • ๋ฏธ์ธ์ฆ์‹œ ์ž์ฒด์ ์œผ๋กœ ์ž‘์„ฑํ•œ ๋กœ๊ทธ์ธ ํผ์„ ์ถœ๋ ฅํ•˜๊ณ  ์ž…๋ ฅ๋œ ์‚ฌ์šฉ์ž ๊ณ„์ • ์ •๋ณด๋Š” DB์— ์ €์žฅ
  3. ๋ฉ”์ธ ํŽ˜์ด์ง€์—๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์€ ๋ฉ”๋‰ด๊ฐ€ ์žˆ์Œ
    • ํ•™๋…„/ํ•™๊ธฐ๋ณ„ ์ด์ˆ˜ ํ•™์  ์กฐํšŒ
    • ๋…„๋„ํ•™๊ธฐ์ทจ๋“ ํ•™์ ์ƒ์„ธ๋ณด๊ธฐ
      ............
      2020118๋งํฌ
      2020218๋งํฌ
      ์ด๊ณ„94
      ์ƒ์„ธ๋ณด๊ธฐ ๋งํฌ ํด๋ฆญ ์‹œ ํ•™๊ธฐ๋ณ„ ์ˆ˜๊ฐ• ๋‚ด์—ญ ์ถœ๋ ฅ
      ๋…„๋„ํ•™๊ธฐ๊ต๊ณผ๋ชฉ๋ช…๊ต๊ณผ๊ตฌ๋ถ„๋‹ด๋‹น๊ต์ˆ˜ํ•™์ 
      20201์ •๋ณด๋ณด์•ˆ์ „์„ ๊น€๋‚จ์œค3
      20201์šด์˜์ฒด์ œ์ „์„ ํ™ฉ๊ธฐํƒœ3
      ..................
    • ์ˆ˜๊ฐ• ์‹ ์ฒญํ•˜๊ธฐ
    • 2021๋…„ 1ํ•™๊ธฐ์— ์‹ ์ฒญํ•  ์˜ˆ์ƒ ๊ต๊ณผ๋ชฉ์„ ์›น ํผ์„ ํ†ตํ•ด ์ž…๋ ฅ ๋ฐ›๊ณ  ํ•ด๋‹น ๋ฐ์ดํ„ฐ์— ๋Œ€ํ•œ ๊ฒ€์ฆ ์ž‘์—…์„ ์‹ค์‹œํ•œ ํ›„(์˜ค๋ฅ˜์‹œ ์žฌ์ž…๋ ฅ ์š”์ฒญ) DB์— ์ €์žฅ
    • ์ˆ˜๊ฐ• ์‹ ์ฒญ ์กฐํšŒ
    • ๋…„๋„ํ•™๊ธฐ๊ต๊ณผ๋ชฉ๋ช…๊ต๊ณผ๊ตฌ๋ถ„๋‹ด๋‹น๊ต์ˆ˜ํ•™์ 
      20211๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค์ „์„ ๊น€์˜์›…3
      20211์•ˆ๋“œ๋กœ์ด๋“œ์ „์ง€ํ—ˆ์ค€์˜3
      ..................
์‹คํ–‰ ๊ฒฐ๊ณผ
  • ๋กœ๊ทธ์ธ
  • ๋ฉ”์ธ ํŽ˜์ด์ง€
  • ํ•™๋…„/ํ•™๊ธฐ๋ณ„ ์ด์ˆ˜ ์ด ํ•™์ 
  • 2020-1 ์ˆ˜๊ฐ• ๋‚ด์—ญ
  • 2021-1 ์ˆ˜๊ฐ•์‹ ์ฒญ ํผ
  • ์ˆ˜๊ฐ•์‹ ์ฒญ ์™„๋ฃŒ
  • 2021-1 ์ˆ˜๊ฐ• ์‹ ์ฒญ ๋‚ด์—ญ

Web Framework 2

๊ณผ์ œ 1

์š”๊ตฌ ์‚ฌํ•ญ ๊ธฐ๋ณธ ์†Œ์Šค๋ฅผ ์ˆ˜์ •ํ•˜์—ฌ Product์™€ Category๋ฅผ ๊ด€๋ฆฌํ•˜๋Š” REST API๋ฅผ ๊ตฌํ˜„ํ•˜๊ธฐ
์‹คํ–‰ ๊ฒฐ๊ณผ
  • Product์™€ Category ์ •๋ณด๋ฅผ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค์— ์‚ฝ์ž…
    $ cd eCommerce/src/main/resources
    $ mysql -u root -p
    $ use eCommerce;
    $ source data.sql;
  • Postman์œผ๋กœ ์ „์ฒด ์‹คํ–‰ ๊ฒฐ๊ณผ๋ฅผ ํ™•์ธํ•˜์‹ค ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค :)

    Run in Postman

    ์Šคํฌ๋ฆฐ์ƒท
    1. ๋ชจ๋“  product ์กฐํšŒํ•˜๊ธฐ: GET http://localhost:8080/ecommerce/api/products
      View all products
    2. ํŠน์ • product ์กฐํšŒํ•˜๊ธฐ: GET http://localhost:8080/ecommerce/api/products/{id}
      View product
    3. product ์ƒ์„ฑํ•˜๊ธฐ: POST http://localhost:8080/ecommerce/api/products
      Create product
    4. product ์ˆ˜์ •ํ•˜๊ธฐ: PUT http://localhost:8080/ecommerce/api/products/{id}
      Update product
    5. product ์‚ญ์ œํ•˜๊ธฐ: DELETE http://localhost:8080/ecommerce/api/products/{id}
      Remove product
    6. ๋ชจ๋“  category ์กฐํšŒํ•˜๊ธฐ: GET http://localhost:8080/ecommerce/api/categories
      View all categories
    7. ํŠน์ • category ์กฐํšŒํ•˜๊ธฐ: GET http://localhost:8080/ecommerce/api/categories/{id}
      View category
    8. category ์ƒ์„ฑํ•˜๊ธฐ: POST http://localhost:8080/ecommerce/api/categories
      Create category
    9. category ์ˆ˜์ •ํ•˜๊ธฐ: PUT http://localhost:8080/ecommerce/api/categories/{id}
      Update category
    10. category ์‚ญ์ œํ•˜๊ธฐ: DELETE http://localhost:8080/ecommerce/api/categories/{id}
      Remove category
    11. ๋ถ€๋ชจ ์นดํ…Œ๊ณ ๋ฆฌ์— ์†ํ•œ ์ž์‹ ์นดํ…Œ๊ณ ๋ฆฌ ์กฐํšŒํ•˜๊ธฐ: GET http://localhost:8080/ecommerce/api/categories/{parent_id}/subcategories
      View child categories
    12. ๋ถ€๋ชจ ์นดํ…Œ๊ณ ๋ฆฌ์™€ ์ž์‹ ์นดํ…Œ๊ณ ๋ฆฌ ์—ฐ๊ฒฐํ•˜๊ธฐ
      1. ์„œ๋ธŒ ์นดํ…Œ๊ณ ๋ฆฌ ์ƒ์„ฑํ•˜๊ธฐ: POST http://localhost:8080/ecommerce/api/categories
        Create subcategory
      2. ์—ฐ๊ฒฐํ•˜๊ธฐ: POST http://localhost:8080/ecommerce/api/categories/{parent_id}/subcategories/{child_id}
        Connect parent and child category
    13. ๋ถ€๋ชจ ์นดํ…Œ๊ณ ๋ฆฌ์— ์†ํ•œ ์ž์‹ ์นดํ…Œ๊ณ ๋ฆฌ ์ œ๊ฑฐํ•˜๊ธฐ: DELETE http://localhost:8080/ecommerce/api/categories/{parent_id}/subcategories
      Remove child from parent category
    14. ์นดํ…Œ๊ณ ๋ฆฌ์— ์†ํ•œ ๋ชจ๋“  product ์กฐํšŒํ•˜๊ธฐ: GET http://localhost:8080/ecommerce/api/categories/{id}/products
      View all products belongs category
    15. product๋ฅผ ์นดํ…Œ๊ณ ๋ฆฌ์— ๋„ฃ๊ธฐ
      1. product ์ƒ์„ฑํ•˜๊ธฐ: POST http://localhost:8080/ecommerce/api/products
        Create product
      2. ์นดํ…Œ๊ณ ๋ฆฌ์— ๋„ฃ๊ธฐ: POST http://localhost:8080/ecommerce/api/categories/{category_id}/products/{product_id}
        Put product into category
    16. product๋ฅผ ์นดํ…Œ๊ณ ๋ฆฌ์—์„œ ์ œ๊ฑฐํ•˜๊ธฐ: DELETE http://localhost:8080/ecommerce/api/categories/{category_id}/products/{product_id}
      Delete product from category

๊ณผ์ œ 2

์š”๊ตฌ ์‚ฌํ•ญ ์ œ๊ณต๋œ ๊ธฐ๋ณธ ์†Œ์Šค๋ฅผ ๊ธฐ๋ฐ˜์œผ๋กœ Spring Boot 2.4.5์—์„œ ๋‹ค์Œ์„ ์ˆ˜ํ–‰ํ•˜๊ธฐ
  1. README.md์˜ 6๋ฒˆ ํ•ญ๋ชฉ์— ๋”ฐ๋ผ Postman์„ ์‚ฌ์šฉํ•˜์—ฌ Request๋ฅผ ๋ณด๋‚ด๊ณ  Response๋ฅผ ๋ณด์ด๊ธฐ
  2. Charlie ๊ณ„์ •(๊ถŒํ•œ์€ admin, ํŒจ์Šค์›Œ๋“œ๋Š” charliepw)์„ data.sql์— ์ €์žฅํ•˜๊ธฐ
    • ํŒจ์Šค์›Œ๋“œ๋Š” BCryptPasswordEncoder๋ฅผ ์ด์šฉํ•˜์—ฌ ํ•ด์‰ฌ๊ฐ’์„ ์ €์žฅ
    • GET /api/products๋ฅผ ํ˜ธ์ถœํ–ˆ์„ ๋•Œ ๋กœ๊ทธ์ธ ํ™”๋ฉด์ด ๋ณด์ผ ์ˆ˜ ์žˆ๋„๋ก ์ฝ”๋“œ๋ฅผ ์ˆ˜์ •ํ•˜๊ณ  ๋ธŒ๋ผ์šฐ์ €์—์„œ ๋กœ๊ทธ์ธ์ด ์„ฑ๊ณต์ ์œผ๋กœ ์ด๋ฃจ์–ด์ง์„ ๋ณด์ด๊ธฐ
  3. GET /api/categories/1 ์š”์ฒญ์„ ๋ณด๋‚ด๊ณ  ์‘๋‹ต ๋ฉ”์‹œ์ง€(hypermedia)๋ฅผ ๋ณด์ธ ๋‹ค์Œ, ์ด์™€ ๊ด€๋ จ๋œ ํ”„๋กœ๊ทธ๋žจ ์†Œ์Šค๋ฅผ ์ง€์ ํ•˜๊ณ  ์„ค๋ช…ํ•˜๊ธฐ
  4. Category์—์„œ ํŠน์ • Product๋ฅผ ์ œ๊ฑฐํ•˜๋Š” ์ฝ”๋“œ ์ž‘์„ฑํ•˜๊ณ  ๊ฒฐ๊ณผ ๋ณด์ด๊ธฐ
    • ์‘๋‹ต ์ƒํƒœ ์ฝ”๋“œ(status code)๋Š” 204 No Content.๋กœ ์„ค์ •
์‹คํ–‰ ๊ฒฐ๊ณผ
  • Product์™€ Category ๋ฐ User ์ •๋ณด๋ฅผ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค์— ์‚ฝ์ž…
    $ cd ecommerce-springboot-rest/src/main/resources
    $ mysql -u root -p
    $ use ecommerce;
    $ source data.sql;
  • Postman์œผ๋กœ ์ „์ฒด ์‹คํ–‰ ๊ฒฐ๊ณผ๋ฅผ ํ™•์ธํ•˜์‹ค ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค :)

    Run in Postman

    ์Šคํฌ๋ฆฐ์ƒท

    1.Postman์œผ๋กœ Request & Response

    1. ๋ชจ๋“  product ์กฐํšŒํ•˜๊ธฐ: GET http://localhost:8080/api/products
    2. View all products

    3. ํŠน์ • product ์กฐํšŒํ•˜๊ธฐ: GET http://localhost:8080/api/products/{id}
    4. View product

    5. product ์ƒ์„ฑํ•˜๊ธฐ: POST http://localhost:8080/api/products
    6. Create product

    7. product ์ˆ˜์ •ํ•˜๊ธฐ: PUT http://localhost:8080/api/products/{id}
    8. Update product

    9. product ์‚ญ์ œํ•˜๊ธฐ: DELETE http://localhost:8080/api/products/{id}
    10. Remove product

    11. ๋ชจ๋“  category ์กฐํšŒํ•˜๊ธฐ: GET http://localhost:8080/api/categories
    12. View all categories

    13. ํŠน์ • category ์กฐํšŒํ•˜๊ธฐ: GET http://localhost:8080/api/categories/{id}
    14. View category

    15. category ์ƒ์„ฑํ•˜๊ธฐ: POST http://localhost:8080/api/categories
    16. Create category

    17. category ์ˆ˜์ •ํ•˜๊ธฐ: PUT http://localhost:8080/api/categories/{id}
    18. Update category

    19. category ์‚ญ์ œํ•˜๊ธฐ: DELETE http://localhost:8080/api/categories/{id}
    20. Remove category

    21. ๋ถ€๋ชจ ์นดํ…Œ๊ณ ๋ฆฌ์— ์†ํ•œ ์ž์‹ ์นดํ…Œ๊ณ ๋ฆฌ ์กฐํšŒํ•˜๊ธฐ: GET http://localhost:8080/api/categories/{parent_id}/subcategories
    22. View subcategories

    23. ๋ถ€๋ชจ ์นดํ…Œ๊ณ ๋ฆฌ์™€ ์ž์‹ ์นดํ…Œ๊ณ ๋ฆฌ ์—ฐ๊ฒฐํ•˜๊ธฐ
      1. ์„œ๋ธŒ ์นดํ…Œ๊ณ ๋ฆฌ ์ƒ์„ฑํ•˜๊ธฐ: POST http://localhost:8080/api/categories
      2. Create subcategory

      3. ์—ฐ๊ฒฐํ•˜๊ธฐ: POST http://localhost:8080/api/categories/{parent_id}/subcategories/{child_id}
      4. Connect parent and child category

    24. ์—ฐ๊ฒฐํ•˜๊ธฐ: POST http://localhost:8080/api/categories/{parent_id}/subcategories/{child_id}
    25. Connect parent and child category

    26. ๋ถ€๋ชจ ์นดํ…Œ๊ณ ๋ฆฌ์— ์†ํ•œ ์ž์‹ ์นดํ…Œ๊ณ ๋ฆฌ ์ œ๊ฑฐํ•˜๊ธฐ: DELETE http://localhost:8080/api/categories/{parent_id}/subcategories
    27. Remove child from parent category

    28. ์นดํ…Œ๊ณ ๋ฆฌ์— ์†ํ•œ ๋ชจ๋“  product ์กฐํšŒํ•˜๊ธฐ: GET http://localhost:8080/api/categories/{id}/products
    29. View all products belonging category

    30. product๋ฅผ ์นดํ…Œ๊ณ ๋ฆฌ์— ๋„ฃ๊ธฐ
      1. product ์ƒ์„ฑํ•˜๊ธฐ: POST http://localhost:8080/api/products
      2. Create product

      3. ์นดํ…Œ๊ณ ๋ฆฌ์— ๋„ฃ๊ธฐ: POST http://localhost:8080/api/categories/{category_id}/products/{product_id}
      4. Put product into category

    31. 2. Charlie์˜ ๊ณ„์ •์„ data.sql์— ์ €์žฅํ•˜๊ณ  ๋กœ๊ทธ์ธ ํ™•์ธ

      Charlie's login

      4. Category์—์„œ ํŠน์ • Product ์ œ๊ฑฐ

      Remove product from category