Skip to content

API Spec 분석 및 모델링

SR edited this page Sep 24, 2021 · 22 revisions

API 분석하기

기능 요구사항

  • 인증 토큰 불필요

    • 사용자 등록(Registration)
    • 사용자 로그인(Authentication)
  • 인증 토큰 필요

    • 현재 사용자 조회
    • 사용자 수정
    • 사용자 프로필 조회
    • 사용자 팔로우
    • 사용자 언팔로우
도메인 METHOD URI Prarameter Authentication RETURN
User POST /api/users/login email, password X UserResponse
User POST /api/users email, username, password X UserResponse
User GET /api/user - O UserResponse
User PUT /api/user email, username, password, image, bio O UserResponse
Profile GET /api/prifiles/:username username O/X ProfileResponse
Profile POST /api/prifiles/:username/follow username O ProfileResponse
Profile DELETE /api/prifiles/:username/follow username O ProfileResponse
Articles GET /api/articles/feed limit, offset O MultiArticlesResponse
Articles GET /api/articles tag, author, favorited, limit, offset X MultiArticlesResponse
Articles POST /api/articles article O SingleArticleResponse
Articles GET /api/articles/:slug slug X SingleArticleResponse
Articles PUT /api/articles/:slug slug, article O SingleArticleResponse
Articles DELETE /api/articles/:slug slug O -
Comments GET /api/articles/:slug/comments slug X MultipleCommentsResponse
Comments POST /api/articles/:slug/comments slug, comment O SingleCommentResponse
Comments POST /api/articles/:slug/comments/:id slug, id O -
Favorites POST /api/articles/:slug/favorite slug O SingleArticleResponse
Favorites DELETE /api/articles/:slug/favorite slug O SingleArticleResponse
Tag DELETE /api/tags - X TagResponse

모델링

  • 확인된 API Spec을 기준으로 TDD를 통해 Entity 설계
  • 설계된 Entity를 기준으로 POJO 테스트 코드 작성
  • @DataJpaTest를 통해 Jpa 테스트

User와 Profile 엔티티 간의 관계 구성

  • User와 Profile 엔티티는 일대일 관계

User와 Follow간의 관계 구성

  • Follow는 엔티티로 가져가느냐 User와의 관계로 정의하고 가느냐 엔티티 구성이 달라진다.

  • User 내에 Follow를 포함하는 방식으로 구성하느냐, User와 Follow 엔티티를 따로 구성하느냐 관련 로직의 위치가 달라진다.

User와 Article과의 관계 구성