Skip to content

Conversation

@Gyuhyeok99
Copy link
Contributor

관련 이슈

작업 내용

소식지 좋아요 엔티티를 추가하였습니다!

특이 사항

  @Column(name = "news_id")
   private long newsId;

   @Column(name = "site_user_id")
   private long siteUserId;

name을 명시해주지 않으니까

@UniqueConstraint(
                name = "uk_liked_news_site_user_id_news_id",
                columnNames = {"site_user_id", "news_id"}
        )

JPA가 이를 인식하지 못해 별도로 추가해주었습니다!

리뷰 요구사항 (선택)

혹시 로컬에서 이거 flyway validate 확인하는 법 알려주실 수 있나요?
우선 flyway 스크립트로 테이블 생성해보았을 땐 잘 작동하였습니다!

@coderabbitai
Copy link

coderabbitai bot commented Jun 30, 2025

Walkthrough

  1. 새로운 JPA 엔티티 클래스 추가

    • LikedNews라는 이름의 엔티티가 com.example.solidconnection.news.domain 패키지에 새롭게 생성되었습니다.
    • 이 클래스는 사용자가 좋아요를 누른 뉴스 항목을 기록하는 테이블을 모델링합니다.
    • @Entity@Table 어노테이션이 적용되어 있으며, site_user_idnews_id의 조합에 유니크 제약 조건이 설정되어 있습니다.
    • 필드는 자동 증가하는 기본키 id, 그리고 newsId, siteUserId로 구성되어 있습니다.
    • 롬복 어노테이션을 통해 getter, 전체 생성자, protected 접근제한의 기본 생성자가 자동 생성됩니다.
  2. 데이터베이스 마이그레이션 스크립트 추가

    • liked_news라는 이름의 새 테이블이 생성되는 SQL 마이그레이션 파일이 추가되었습니다.
    • 이 테이블은 BIGINT 타입의 자동 증가 PK id, NOT NULL 제약이 있는 news_idsite_user_id 컬럼을 포함합니다.
    • 동일 유저가 같은 뉴스에 중복 좋아요를 누를 수 없도록 유니크 제약 조건이 적용되어 있습니다.
    • news_idnews 테이블의 id와, site_user_idsite_user 테이블의 id와 각각 외래키로 연결되어 참조 무결성을 보장합니다.
✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (2)
src/main/resources/db/migration/V21__create_liked_news_table.sql (1)

1-9: 1) created_at 타임스탬프 & ON DELETE CASCADE 옵션이 누락되었습니다

  • 좋아요 시점을 기록할 컬럼이 없으면, 시간 별 통계나 “최근 내가 누른 좋아요” 같은 기능 구현이 곤란해집니다.
  • 두 FK 모두 부모가 삭제될 때 자식 레코드가 고아로 남습니다. ON DELETE CASCADE 로 정리 루틴을 DB에 맡기면 코드가 간결해집니다.
     site_user_id BIGINT NOT NULL,
+    created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
 ...
-    CONSTRAINT fk_liked_news_news_id FOREIGN KEY (news_id) REFERENCES news(id),
-    CONSTRAINT fk_liked_news_site_user_id FOREIGN KEY (site_user_id) REFERENCES site_user(id)
+    CONSTRAINT fk_liked_news_news_id
+        FOREIGN KEY (news_id) REFERENCES news(id) ON DELETE CASCADE,
+    CONSTRAINT fk_liked_news_site_user_id
+        FOREIGN KEY (site_user_id) REFERENCES site_user(id) ON DELETE CASCADE

필요하다면 Flyway 마이그레이션 스크립트 버전 업과 롤백 스크립트까지 같이 드릴 수 있어요!

src/main/java/com/example/solidconnection/news/domain/LikedNews.java (1)

17-18: 4) @AllArgsConstructor가 id까지 노출합니다
id 는 JPA에서 자동 생성되므로 외부 생성자에서 받지 않는 편이 안전합니다.

-@AllArgsConstructor
+@AllArgsConstructor(access = AccessLevel.PRIVATE)
+@Builder

그리고 정적 팩토리 of(News, SiteUser) 형태를 두면 테스트 작성도 편해집니다.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 45430c9 and 69e7fa2.

📒 Files selected for processing (2)
  • src/main/java/com/example/solidconnection/news/domain/LikedNews.java (1 hunks)
  • src/main/resources/db/migration/V21__create_liked_news_table.sql (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: build
🔇 Additional comments (1)
src/main/java/com/example/solidconnection/news/domain/LikedNews.java (1)

19-24: 2) 유니크 제약 설정 👍
JPA → DB → 엔티티 모두 일관성 있게 매핑되었습니다. 중복 좋아요 방지가 확실히 되겠네요!

Copy link
Member

@whqtker whqtker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

고생하셨습니다!

application-db.yml 의 dev 프로파일의 jpa, flyway 설정 복사하셔서 local 프로파일에 붙여넣으신 후, user, password 옵션 지우고 실행하시면 됩니다. (로컬 DB에서 테이블 다 drop하고 해야 합니다!)

2025-06-30T23:19:52.379+09:00  INFO 19204 --- [           main] o.f.core.internal.command.DbMigrate      : Migrating schema `solid_connection` to version "1 - init"
2025-06-30T23:19:55.533+09:00  INFO 19204 --- [           main] o.f.core.internal.command.DbMigrate      : Migrating schema `solid_connection` to version "2 - add gpa score and language test score"
2025-06-30T23:19:57.340+09:00  INFO 19204 --- [           main] o.f.core.internal.command.DbMigrate      : Migrating schema `solid_connection` to version "3 - add auth type column and unique key"
2025-06-30T23:19:57.643+09:00  INFO 19204 --- [           main] o.f.core.internal.command.DbMigrate      : Migrating schema `solid_connection` to version "4 - remove issue date columns"
2025-06-30T23:19:57.858+09:00  INFO 19204 --- [           main] o.f.core.internal.command.DbMigrate      : Migrating schema `solid_connection` to version "5 - add password column"
2025-06-30T23:19:57.995+09:00  INFO 19204 --- [           main] o.f.core.internal.command.DbMigrate      : Migrating schema `solid_connection` to version "6 - add admin to role enum"
2025-06-30T23:19:58.072+09:00  INFO 19204 --- [           main] o.f.core.internal.command.DbMigrate      : Migrating schema `solid_connection` to version "7 - expand details column length"
2025-06-30T23:19:58.140+09:00  INFO 19204 --- [           main] o.f.core.internal.command.DbMigrate      : Migrating schema `solid_connection` to version "8 - add two semester to semeter avaliable enum"
2025-06-30T23:19:58.286+09:00  INFO 19204 --- [           main] o.f.core.internal.command.DbMigrate      : Migrating schema `solid_connection` to version "9 - add etc to language test type enum"
2025-06-30T23:19:58.342+09:00  INFO 19204 --- [           main] o.f.core.internal.command.DbMigrate      : Migrating schema `solid_connection` to version "10 - change update count default value"
2025-06-30T23:19:58.387+09:00  INFO 19204 --- [           main] o.f.core.internal.command.DbMigrate      : Migrating schema `solid_connection` to version "11 - remove siteuser birth and gender"
2025-06-30T23:19:58.530+09:00  INFO 19204 --- [           main] o.f.core.internal.command.DbMigrate      : Migrating schema `solid_connection` to version "12 - create news"
2025-06-30T23:19:58.607+09:00  INFO 19204 --- [           main] o.f.core.internal.command.DbMigrate      : Migrating schema `solid_connection` to version "13 - add application index and delete manny to one mapping"
2025-06-30T23:19:58.803+09:00  INFO 19204 --- [           main] o.f.core.internal.command.DbMigrate      : Migrating schema `solid_connection` to version "14 - set unique constraint to nickname"
2025-06-30T23:19:58.890+09:00  INFO 19204 --- [           main] o.f.core.internal.command.DbMigrate      : Migrating schema `solid_connection` to version "15 - add unique constraint to liked university"
2025-06-30T23:19:58.958+09:00  INFO 19204 --- [           main] o.f.core.internal.command.DbMigrate      : Migrating schema `solid_connection` to version "16 - add unique constraint to intersted"
2025-06-30T23:19:59.050+09:00  INFO 19204 --- [           main] o.f.core.internal.command.DbMigrate      : Migrating schema `solid_connection` to version "21 - create liked news table"
2025-06-30T23:19:59.146+09:00  INFO 19204 --- [           main] o.f.core.internal.command.DbMigrate      : Successfully applied 17 migrations to schema `solid_connection`, now at version v21 (execution time 00:06.796s)

잘 생성됩니다 !

@Gyuhyeok99
Copy link
Contributor Author

application-db.yml 의 dev 프로파일의 jpa, flyway 설정 복사하셔서 local 프로파일에 붙여넣으신 후, user, password 옵션 지우고 실행하시면 됩니다. (로컬 DB에서 테이블 다 drop하고 해야 합니다!)

아하 감사합니다 ㅎㅎ

Copy link
Collaborator

@nayonsoso nayonsoso left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

name을 명시해주지 않으니까 JPA가 이를 인식하지 못해

이 부분에 대해 더 자세히 설명해주실 수 있나요? 😯

@Gyuhyeok99
Copy link
Contributor Author

Gyuhyeok99 commented Jul 1, 2025

name 명시를 안해주니까 아래와 같은 에러가 발생하더라구요! 혹시 모르니 지우고 다시 한 번 테스트 해보겠습니다!

Failed to initialize JPA EntityManagerFactory: Unable to create unique key constraint (site_user_id, newsId) on table 'liked_news' since the column 'site_user_id' was not found (specify the correct column name, which depends on the naming strategy, and may not be the same as the entity property name)

다시 지우고 해봤는데 같은 에러가 발생합니다!

Copy link
Contributor

@lsy1307 lsy1307 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

수고하셨어용!

@Gyuhyeok99 Gyuhyeok99 merged commit fe7aefc into solid-connection:develop Jul 2, 2025
2 checks passed
@Gyuhyeok99 Gyuhyeok99 deleted the feat/356-add-liked-news-entity branch July 10, 2025 07:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: 소식지 좋아요 엔티티 추가

4 participants