Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[20210124] Spring Swagger, 게시글 좋아요 기능 로직, MySQL Boolean type #20

Open
JuHyun419 opened this issue Jan 24, 2021 · 0 comments

Comments

@JuHyun419
Copy link
Owner

Spring Swagger

  • dependency 추가
    <dependency>
      <groupId>io.springfox</groupId>
      <artifactId>springfox-swagger2</artifactId>
      <version>2.9.2</version>
    </dependency>

    <dependency>
      <groupId>io.springfox</groupId>
      <artifactId>springfox-swagger-ui</artifactId>
      <version>2.9.2</version>
    </dependency>
  • Config 파일 생성
    • ApiInfo, Docket 등을 리턴하는 함수 생성
  • 문서화 할 Controller, Dto, Request 등에 어노테이션 추가
  • Controller
    • @Api, @ApiOperation, @ApiImplicitParam, @ApiParam 등
  • Dto, Request
    • @ApiModelProperty 등

좋아요 기능 간단한 로직(한 사용자당 좋아요 한 번 클릭 가능, 중복 X)

  • User <-> Post <-> Like
  • userId(PK), postId(PK) 로 Like 테이블 조회
    • 데이터가 존재하면 ? 좋아요를 이미 누름 => 좋아요 취소
    • 데이터가 없으면 ? 좋아요를 안누른 상태 => 좋아요(check)

좋아요 기능


MySQL Boolean Type

  • MySQL에선 Boolean 테입을 포함하지 않고, 대신 TINYINT 타입을 제공함(값은 0 or 1)
  • 0 => false, 1 => true
mysql> CREATE TABLE student (  
    studentid INT PRIMARY KEY AUTO_INCREMENT,  
    name VARCHAR(40) NOT NULL,  
    age VARCHAR(3),  
    check BOOLEAN  
);  
  • 위 pass의 Type을 확인해보면 tinyint(1) 로 나옴
mysql> INSERT INTO student(name, check) VALUES('Peter',true), ('John',false);  

위와 같이 데이터를 INSERT 할 시, Peter의 check 값은 1이고, John의 check 값은 0

References

https://onecutwook.tistory.com/23

https://www.javatpoint.com/mysql-boolean#:~:text=MySQL%20does%20not%20contain%20built,to%200%20and%201%20value.

@JuHyun419 JuHyun419 changed the title [20210123] Spring Swagger, 게시글 좋아요 기능 로직, MySQL Boolean type [20210124] Spring Swagger, 게시글 좋아요 기능 로직, MySQL Boolean type Jan 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant