Coder Social home page Coder Social logo

community's Introduction

πŸ“Œ Community

REST API Community Project

μ œμž‘ κΈ°κ°„ & μ°Έμ—¬ 인원

πŸ“‹ 2022λ…„ 11μ›” 8일 ~ ν˜„μž¬κΉŒμ§€ μ—…λ°μ΄νŠΈ 쀑

  • 개인 ν”„λ‘œμ νŠΈ

개발 ν•„μˆ˜μš”κ±΄

κ²Œμ‹œλ¬Ό

  • κ²Œμ‹œλ¬Όμ„ 등둝/μˆ˜μ •/μ‚­μ œ κ°€λŠ₯
  • μΉ΄ν…Œκ³ λ¦¬λ₯Ό ν™œμš© κ°€λŠ₯

μ‚¬μš©μžλ³„ κ²Œμ‹œλ¬Ό

  • λŒ“κΈ€/λŒ€λŒ“κΈ€ ν™œμš© κ°€λŠ₯
  • μ²¨λΆ€νŒŒμΌμ„ 등둝/μˆ˜μ •/μ‚­μ œ κ°€λŠ₯
  • μ’‹μ•„μš”, 즐겨찾기 ν™œμš© κ°€λŠ₯

μ‚¬μš©μž

  • μ‚¬μš©μž μžμ‹ μ˜ 정보 관리가λŠ₯

메세지

  • 메세지 등둝/μˆ˜μ •/μ‚­μ œ κ°€λŠ₯
  • 받은 메세지, 보낸 메세지 관리 κ°€λŠ₯

μ‹ κ³ 

  • μ‚¬μš©μž, κ²Œμ‹œλ¬Όμ„ μ‹ κ³  κ°€λŠ₯

κ΄€λ¦¬μž

  • μ‹ κ³ λœ μ‚¬μš©μž, κ²Œμ‹œλ¬Όμ„ 관리 κ°€λŠ₯
  • μΉ΄ν…Œκ³ λ¦¬ 관리 κ°€λŠ₯

Tech Stacks

  • Spring Boot Framework

  • MySQL

  • Swagger Open API 3.0


Project Sturucture

community
β”œβ”€β”€ advice
β”œβ”€β”€ config
β”‚   β”œβ”€β”€ auth
β”‚   β”œβ”€β”€ constant
β”‚   β”œβ”€β”€ jwt
β”‚   β”œβ”€β”€ redis
β”‚   └──  security
β”œβ”€β”€ controller
β”œβ”€β”€ dto
β”œβ”€β”€ entity
β”œβ”€β”€ exceptions
β”‚   └── type
β”œβ”€β”€ repository
β”œβ”€β”€ response 
└── service

Components

  • advice

  • config

  • controller

  • dto

  • entity

  • exceptions

  • repository

  • response

  • service

ERD 섀계

ERD_real

API

Auth

  • νšŒμ›κ°€μž… (POST /sign-up)
  • 둜그인 (POST /sign-in)
  • 토큰 μž¬λ°œκΈ‰ (POST /reissue)

Board

  • κ²Œμ‹œλ¬Ό μž‘μ„± (POST /boards)
  • 전체 κ²Œμ‹œλ¬Ό 쑰회 (GET /boards/all/{categoryid})
  • 단건 κ²Œμ‹œλ¬Ό 쑰회 (GET /boards/{id})
  • κ²Œμ‹œλ¬Ό μˆ˜μ • (PUT /boards/{id})
  • κ²Œμ‹œλ¬Ό μ‚­μ œ (DELETE /boards/{id})
  • κ²Œμ‹œλ¬Ό 검색 (GET /boards/search?page={})
  • κ²Œμ‹œλ¬Ό μ’‹μ•„μš”/μ·¨μ†Œ (POST /boards/{id})
  • κ²Œμ‹œλ¬Ό 즐겨찾기/μ·¨μ†Œ (POST /boards/{id}/favorites)
  • μΆ”μ²œκΈ€ 쑰회 (GET /boards/best)

Member

  • 전체 νšŒμ› 쑰회 (GET /members)
  • 개인 νšŒμ› 쑰회 (GET /members/{id})
  • νšŒμ› 정보 μˆ˜μ • (PUT /members)
  • 전체 νšŒμ› μ‚­μ œ (DELETE /members)

Comment

  • λŒ“κΈ€ μž‘μ„± (POST /comments)
  • λŒ“κΈ€ 쑰회 (GET /comments)
  • λŒ“κΈ€ μ‚­μ œ (DELETE /comments/{id})

Message

  • 메세지 μž‘μ„± (POST /messages)
  • 받은 메세지 μ „λΆ€ 확인 (GET /messages/receiver)
  • 받은 메세지 단건 확인 (GET /messages/receiver/{id})
  • 보낸 메세지 μ „λΆ€ 확인 (GET /messages/sender)
  • 보낸 메세지 단건 확인 (GET /messages/sender/{id})
  • 받은 메세지 μ‚­μ œ (DELETE /messages/receiver/{id})
  • 보낸 메세지 μ‚­μ œ (DELETE /messages/sender/{id})

Category

  • μΉ΄ν…Œκ³ λ¦¬ 생성 (POST /categoryies)
  • μΉ΄ν…Œκ³ λ¦¬ 쑰회 (GET /categoryies)
  • μΉ΄ν…Œκ³ λ¦¬ μ‚­μ œ (DELETE /categoryies/{id})

Report

  • μœ μ € μ‹ κ³  (POST /reports/users)
  • κ²Œμ‹œλ¬Ό μ‹ κ³  (POST /reports/boards)

Admin

  • 정지 μœ μ € 관리 (GET /admin/manages/members)
  • μ‹ κ³ λœ μœ μ € 정지 ν•΄μ œ (POST /admin/manages/members/{id})
  • κ²Œμ‹œλ¬Ό 관리 (GET /admin/manages/boards)
  • μ‹ κ³ λœ κ²Œμ‹œλ¬Ό 관리 (POST /admin/manages/boards/{id})

핡심 νŠΈλŸ¬λΈ” μŠˆνŒ…

Authentication Refactoring

  • κΈ°μ‘΄μ—λŠ” Securityλ₯Ό Service에 μ˜μ‘΄ν•΄μ„œ μ²˜λ¦¬ν•˜λŠ” λ°©μ‹μœΌλ‘œ ν–ˆμ§€λ§Œ ServiceλŠ” 도메인에 λŒ€ν•œ λΉ„μ§€λ‹ˆμŠ€ 둜직이 λ“€μ–΄κ°€μ„œ Securityλ₯Ό μ˜μ‘΄ν•˜λŠ”κ±΄ 쒋지 μ•Šλ‹€κ³  μƒκ°ν•˜μ˜€μŠ΅λ‹ˆλ‹€.

  • 사전에 미리 μΈμ¦λ‘œμ§μ„ μˆ˜ν–‰ν•˜λ©΄ 쑰금 더 λΉ λ₯΄κ²Œ 인증 μ‹€νŒ¨ μ—λŸ¬λ₯Ό 내렀쀄 수 μžˆλ‹€ μƒκ°ν•˜κ²Œ λ˜μ—ˆμŠ΅λ‹ˆλ‹€. Controllerμ—μ„œ 인증에 ν•„μš”ν•œ 정보λ₯Ό 가지고, μ„œλΉ„μŠ€ λ©”μ†Œλ“œ νŒŒλΌλ―Έν„°λ‘œ 전달해쀄 κ²ƒμž…λ‹ˆλ‹€.

κΈ°μ‘΄ μ½”λ“œ
  
  /**
  * BoardController
  */
  @PostMapping("/boards")
    @ResponseStatus(HttpStatus.CREATED)
    public Response createBoard(@Valid @ModelAttribute BoardCreateRequest req,
                           @RequestParam(value = "category", defaultValue = "1") int categoryId) {
        return Response.success(boardService.createBoard(req, categoryId));
    }
  
  /**
  * BoardService
  */
  @Transactional
    public BoardCreateResponse createBoard(BoardCreateRequest req, int categoryId) {
        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
        Member meber = memberRepository.findByUsername(authentication.getName()).orElseThrow(MemberNotFoundException::new);
        List<Image> images = req.getImages().stream().map(i -> new Image(i.getOriginalFilename())).collect(toList());
        Category category = categoryRepository.findById(categoryId).orElseThrow(CategoryNotFoundException::new);
        Board board = boardRepository.save(new Board(req.getTitle(), req.getContent(), user, category, images));
  • λ˜ν•œ μ΄λŒ€λ‘œ λ¦¬νŒ©ν† λ§μ„ ν•˜λ‹€λ³΄λ‹ˆ λ„ˆλ¬΄ μ€‘μ²©λ˜λŠ” μ½”λ“œκ°€ μ™”λ‹€κ°”λ‹€ ν•˜λŠ”κ±° κ°™μ•„ 인증 & 인가 λ‘œμ§μ„ λ”°λ‘œ λ©”μ„œλ“œλ‘œ λΆ„λ¦¬ν•˜μ˜€μŠ΅λ‹ˆλ‹€.
κ°œμ„ λœ μ½”λ“œ
  
   /**
  * BoardController
  */
  @PostMapping("/boards")
    @ResponseStatus(HttpStatus.CREATED)
    public Response createBoard(@Valid @ModelAttribute BoardCreateRequest req,
                           @RequestParam(value = "category", defaultValue = "1") int categoryId) {
        Member member = getPrincipal();
        return Response.success(boardService.createBoard(req, categoryId, member));
    }
    private Member getPrincipal() {
        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
        Member member = memberRepository.findByUsername(authentication.getName())
                .orElseThrow(MemberNotFoundException::new);
        return member;
  
  
  /**
  * BoardService
  */
  @Override
    public BoardCreateResponse createBoard(BoardCreateRequest req, int categoryId, Member member) {
        List<Image> images = req.getImages().stream().
                map(i -> new Image(i.getOriginalFilename()))
                .collect(toList());
        Category category = categoryRepository.findById(categoryId).orElseThrow(CategoryNotFoundException::new);
        Board board = boardRepository.save(new Board(req.getTitle(), req.getContent(), member, category, images));
        uploadImages(board.getImages(), req.getImages());
        return new BoardCreateResponse(board.getId(), board.getTitle(), board.getContent());
    }
  

community's People

Contributors

hhwanseung avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.