[UMC] 2rd Lecture

์ตœ๋™๊ทผยท2023๋…„ 4์›” 12์ผ
0

UMC

๋ชฉ๋ก ๋ณด๊ธฐ
2/3
post-custom-banner

๐ŸŒฑ ๊ฒŒ์‹œ๊ธ€ API ์™„์„ฑ

[1] ๊ฒŒ์‹œ๊ธ€ ๋“ฑ๋ก(POST)

@PostMapping("/board/create/{boardId}") // http://localhost:8080/board/create/:boardId?key1=value1&key2=value2
    public String createBoard(
            @PathVariable int boardId, // ๊ฒฝ๋กœ ๋ณ€์ˆ˜
            @RequestParam String title, // ์ฟผ๋ฆฌ ์ŠคํŠธ๋ง
            @RequestParam String content // ์ฟผ๋ฆฌ ์ŠคํŠธ๋ง
    ) {
        Board board = new Board(boardId, title, content); // ์ž๋ฐ” new
        boardList.add(board);

        return "์ •์ƒ์ ์œผ๋กœ POSTING ๋˜์—ˆ์Šต๋‹ˆ๋‹ค!"; // String
    }

[2] ๊ฒŒ์‹œ๊ธ€ ์กฐํšŒ(GET)

@GetMapping("/board/get")
    public List<Board> getBoard() {
        log.info("์ •์ƒ์ ์œผ๋กœ get ๋˜์—ˆ์Šต๋‹ˆ๋‹ค.");
        return this.boardList;
    }
    // Json ํ˜•์‹ (๋ฐ์ดํ„ฐ ํ˜•์‹)

[3] ๊ฒŒ์‹œ๊ธ€ ์ˆ˜์ •(PUT)

 @PutMapping("/board/update/{boardId}")
    public String updateBoard(
            @PathVariable(name = "boardId") int id,
            @RequestParam String title, // ์ˆ˜์ •ํ•˜๊ณ ์ž ํ•˜๋Š” ์ œ๋ชฉ
            @RequestParam String content // ์ˆ˜์ •ํ•˜๊ณ ์ž ํ•˜๋Š” ๋‚ด์šฉ

    ) {


        for (int i = 0; i < this.boardList.size(); i++) { // 0 , 1

            if (boardList.get(i).getBoardId() == id) {
                boardList.get(i).setTitle(title);
                boardList.get(i).setContent(content);

                log.info("์ƒˆ๋กœ์šด ์ œ๋ชฉ๊ณผ ๋‚ด์šฉ : " + title + " " + content);
                return "์ •์ƒ์ ์œผ๋กœ ์ˆ˜์ •์™„๋ฃŒ๋˜์—ˆ์Šต๋‹ˆ๋‹ค.";
            }
        }

        log.error("์š”์ฒญํ•œ ๊ฒŒ์‹œ๊ธ€ ์•„์ด๋””๊ฐ€ ์กด์žฌํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค.");
        return "์š”์ฒญํ•œ ๊ฒŒ์‹œ๊ธ€ ์•„์ด๋””๊ฐ€ ์กด์žฌํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค.";
    }

[4] ๊ฒŒ์‹œ๊ธ€ ์‚ญ์ œ(DELETE)

๐ŸŒฑ RDBMS

[1] RDBMS ํŠน์ง•

๊ด€๊ณ„ํ˜• ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค์˜ ํŠน์ง•์€ ๋‹ค์Œ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค.

  1. ๋ฐ์ดํ„ฐ์˜ ๋ถ„๋ฅ˜, ์ •๋ ฌ, ํƒ์ƒ‰ ์†๋„๊ฐ€ ๋น ๋ฆ…๋‹ˆ๋‹ค.

  2. ์˜ค๋žซ๋™์•ˆ ์‚ฌ์šฉ๋œ ๋งŒํผ ์‹ ๋ขฐ์„ฑ์ด ๋†’๊ณ , ์–ด๋–ค ์ƒํ™ฉ์—์„œ๋„ ๋ฐ์ดํ„ฐ์˜ ๋ฌด๊ฒฐ์„ฑ์„ ๋ณด์žฅํ•ด ์ค๋‹ˆ๋‹ค.

  3. ๊ธฐ์กด์— ์ž‘์„ฑ๋œ ์Šคํ‚ค๋งˆ๋ฅผ ์ˆ˜์ •ํ•˜๊ธฐ๊ฐ€ ์–ด๋ ต์Šต๋‹ˆ๋‹ค.

  4. ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค์˜ ๋ถ€ํ•˜๋ฅผ ๋ถ„์„ํ•˜๋Š” ๊ฒƒ์ด ์–ด๋ ต์Šต๋‹ˆ๋‹ค.

๐ŸŒฑ NO-SQL DBMS

[1] RDBMS ํ•œ๊ณ„

๋งŽ์€ ๋ฐ์ดํ„ฐ๋Ÿ‰๊ณผ ๋ฐ์ดํ„ฐ ์ฒ˜๋ฆฌ๋Ÿ‰์ด ๊ณ„์†์ ์œผ๋กœ ์ฆ๊ฐ€ํ•œ๋‹ค๋ฉด RDBMS๋Š” ์•„๋ž˜์™€ ๊ฐ™์€ ๋ฌธ์ œ์ ์„ ๋งŒ๋‚œ๋‹ค.

์Šคํ‚ค๋งˆ ๋ฌธ์ œ : ๋น…๋ฐ์ดํ„ฐ๋ฅผ RDB์˜ ์Šคํ‚ค๋งˆ์— ๋งž์ถฐ ๋ณ€๊ฒฝํ•ด์„œ ๋„ฃ์œผ๋ ค๋ฉด ๋งค์šฐ ๊ธด ์‹œ๊ฐ„์˜ down time์ด ๋ฐœ์ƒ
์Šค์ผ€์ผ์—…์˜ ํ•œ๊ณ„ : RDBMS๋Š” ์• ์ดˆ๋ถ€ํ„ฐ ์Šค์ผ€์ผ ์•„์›ƒ์„ ์—ผ๋‘์— ๋‘๊ณ  ์„ค๊ณ„๋˜์ง€ ์•Š์•˜๋‹ค. ๊ด€๊ณ„ ๋ชจ๋ธ๊ณผ ํŠธ๋žœ์žญ์…˜์˜ ์—ฐ์‚ฐ, ์ผ๊ด€์„ฑ, ์†์„ฑ์„ ์œ ์ง€ํ•˜๋ฉด์„œ ๋ถ„์‚ฐํ™˜๊ฒฝ(์Šค์ผ€์ผ์•„์›ƒ)์—์„œ RDBMS๋ฅผ ์กฐ์ž‘ํ•˜๋Š” ๊ฒƒ์€ ์–ด๋ ต๋‹ค.

[2] No-SQL DBMS ํŠน์ง•

  1. ๊ฑฐ๋Œ€ํ•œ Map์œผ๋กœ์„œ key-value ํ˜•์‹์„ ์ง€์›ํ•œ๋‹ค.
  2. RDBMS๊ฐ€ ๋ฐ์ดํ„ฐ์˜ ๊ด€๊ณ„๋ฅผ Foreign Key ๋“ฑ์œผ๋กœ ์ •์˜ํ•˜๊ณ  Join ๋“ฑ ๊ด€๊ณ„ํ˜• ์—ฐ์ƒ์„ ํ•˜์ง€๋งŒ NoSQL์€ ๊ด€๊ณ„๋ฅผ ์ •์˜ํ•˜์ง€ ์•Š๋Š”๋‹ค.
  3. ๋Œ€์šฉ๋Ÿ‰ ๋ฐ์ดํ„ฐ ์ €์žฅ์„ ํ•œ๋‹ค.
  4. ๋ถ„์‚ฐํ˜• ๊ตฌ์กฐ๋ฅผ ํ†ตํ•ด ์—ฌ๋Ÿฌ๋Œ€์˜ ์„œ๋ฒ„์— ๋ถ„์‚ฐํ•˜์—ฌ ์ €์žฅํ•˜๊ณ  ์ƒํ˜ธ๋ณต์ œํ•˜์—ฌ ๋ฐ์ดํ„ฐ ์œ ์‹ค์ด๋‚˜ ์„œ๋น„์Šค ์ค‘์ง€์— ๋Œ€๋น„ํ•œ๋‹ค.
    Schema-less
  5. ์ฝ๊ธฐ ์ž‘์—…๋ณด๋‹ค ์“ฐ๊ธฐ ์ž‘์—…์ด ๋” ๋น ๋ฅด๋ฉฐ, ์ผ๋ฐ˜์ ์œผ๋กœ RDBMS์— ๋น„ํ•˜์—ฌ ์“ฐ๊ธฐ์™€ ์ฝ๊ธฐ ์„ฑ๋Šฅ์ด ๋น ๋ฅด๋‹ค.

๐ŸŒฑ ERD

Entity Relationship Diagram
๊ฐœ์ฒด-๊ด€๊ณ„ ๋ชจ๋ธ. ํ…Œ์ด๋ธ”๊ฐ„์˜ ๊ด€๊ณ„๋ฅผ ์„ค๋ช…ํ•ด์ฃผ๋Š” ๋‹ค์ด์–ด๊ทธ๋žจ์ด๋ผ๊ณ  ๋ณผ ์ˆ˜ ์žˆ์œผ๋ฉฐ, ์ด๋ฅผ ํ†ตํ•ด ํ”„๋กœ์ ํŠธ์—์„œ ์‚ฌ์šฉ๋˜๋Š” DB์˜ ๊ตฌ์กฐ๋ฅผ ํ•œ๋ˆˆ์— ํŒŒ์•…ํ•  ์ˆ˜ ์žˆ๋‹ค.
์ฆ‰, API๋ฅผ ํšจ์œจ์ ์œผ๋กœ ๋ฝ‘์•„๋‚ด๊ธฐ ์œ„ํ•œ ๋ชจ๋ธ ๊ตฌ์กฐ๋„๋ผ๊ณ  ์ƒ๊ฐํ•˜๋ฉด ๋œ๋‹ค.

[1] Entity(๊ฐœ์ฒด)

Attribute๋Š” Entity๋ฅผ ๊ตฌ์„ฑํ•˜๊ณ  ์žˆ๋Š” ๊ตฌ์„ฑ ์š”์†Œ์ด๋‹ค.
๋ฐ์ดํ„ฐ ํƒ€์ž…์„ ๋ฐ˜๋“œ์‹œ ๊ฐ™์ด ๋ช…์‹œํ•ด์ค˜์•ผ ํ•œ๋‹ค.

[3] Relation(๊ด€๊ณ„)

Entity๊ฐ„์˜ ๊ด€๊ณ„๋ฅผ ์˜๋ฏธํ•œ๋‹ค.
๋‘ Entity๊ฐ„์— ์„ ์„ ๊ธ‹๊ณ , ๊ด€๊ณ„ ๋ช…์นญ์„ ๊ธฐ๋กํ•˜๊ฒŒ ๋œ๋‹ค.

[4] Cardinality(๊ด€๊ณ„ ํ˜•ํƒœ)

ex)

Student - Course

Customer - Order

Employee - Department

๊นŒ๋งˆ๊ท€ ํ‘œ๊ธฐ๋ฒ•์ด๋ž€(Crow Notation)?

๐ŸŒฑ ERD ๋ฅผ ์„ค๊ณ„ํ•ด๋ด…์‹œ๋‹ค

ํ•œ๋ช…์˜ ํšŒ์›(Member)์€ ์—ฌ๋Ÿฌ๊ฐœ์˜ ๊ฒŒ์‹œํŒ(Posting)์„ ๊ฐ€์ง€๊ฑฐ๋‚˜ ๊ฐ€์ง€์ง€ ์•Š์„ ์ˆ˜ ์žˆ๋‹ค.
ํ•˜๋‚˜์˜ ๊ฒŒ์‹œํŒ(Board)๋Š” ์—†๊ฑฐ๋‚˜ ์—ฌ๋Ÿฌ๊ฐœ์˜ ์ข‹์•„์š”(Like)๋ฅผ ๊ฐ€์ง€๋ฉฐ ์—†๊ฑฐ๋‚˜ ์—ฌ๋Ÿฌ๊ฐœ์˜ ๋Œ“๊ธ€(Comment) ๋ฅผ ๊ฐ€์ง„๋‹ค.

[1] ๊ฒŒ์‹œํŒ(POSTING)

[2] ํšŒ์›(USER)

[3] ์ข‹์•„์š”(LIKE)

[4] ๋Œ“๊ธ€(Comment)

profile
๋น„์ฆˆ๋‹ˆ์Šค๊ฐ€์น˜๋ฅผ์ถ”๊ตฌํ•˜๋Š”๊ฐœ๋ฐœ์ž
post-custom-banner

0๊ฐœ์˜ ๋Œ“๊ธ€