Skip to content

Commit

Permalink
컬럼 제약조건 및 DB 동기화를 위한 엔티티 클래스 수정 (#806)
Browse files Browse the repository at this point in the history
* feat: 소셜 로그인으로 가입한 회원인지 일반 로그인으로 가입한 회원인지 판단하는 Enum 추가

* feat: 일반 회원인 경우 STANDARD로 가입

* feat: 소셜 회원인 경우 SOCIAL로 가입

* feat: 이미 소셜 로그인으로 가입한 회원인 경우 특정 주소로 리다이렉트 하도록 구현

* chore: yml update

* style: sonarqube

* feat: 회원정보 조회 시 소셜로그인/일반가입 필드 추가

* chore: yml update

* feat: 리다이렉트 주소 변경

* refactor: 컬럼 제약조건 및 DB 동기화를 위한 엔티티 클래스 수정

* fix: Comment 엔티티에서 제거한 reportedCount로 인한 컴파일 에러 해결

* style: 사용되지 않는 import문 제거

* style: 사용되지 않는 변수 redirectUrl 제거

* chore: 사용되지 않는 환경변수 제거

---------

Co-authored-by: jschoi-96 <[email protected]>
  • Loading branch information
Hanjaemo and jschoi-96 authored Dec 16, 2024
1 parent 16df435 commit e64f8ad
Show file tree
Hide file tree
Showing 13 changed files with 123 additions and 57 deletions.
4 changes: 0 additions & 4 deletions src/main/java/balancetalk/bookmark/domain/GameBookmark.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@
import balancetalk.game.domain.GameSet;
import balancetalk.global.common.BaseTimeEntity;
import balancetalk.member.domain.Member;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.EnumType;
import jakarta.persistence.Enumerated;
import jakarta.persistence.FetchType;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
Expand All @@ -29,7 +26,6 @@ public class GameBookmark extends BaseTimeEntity {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id")
private Long id;

@ManyToOne(fetch = FetchType.LAZY)
Expand Down
17 changes: 13 additions & 4 deletions src/main/java/balancetalk/bookmark/domain/TalkPickBookmark.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,29 @@
import balancetalk.global.common.BaseTimeEntity;
import balancetalk.member.domain.Member;
import balancetalk.talkpick.domain.TalkPick;
import jakarta.persistence.*;
import jakarta.persistence.Entity;
import jakarta.persistence.FetchType;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import jakarta.validation.constraints.NotNull;
import lombok.*;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Entity
@Builder
@Getter
@AllArgsConstructor(access = AccessLevel.PRIVATE)
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class TalkPickBookmark extends BaseTimeEntity {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id")
private Long id;

@ManyToOne(fetch = FetchType.LAZY)
Expand Down Expand Up @@ -44,5 +54,4 @@ public void activate() {
public void deactivate() {
this.active = false;
}

}
44 changes: 21 additions & 23 deletions src/main/java/balancetalk/comment/domain/Comment.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,30 @@
import balancetalk.member.domain.Member;
import balancetalk.talkpick.domain.TalkPick;
import balancetalk.talkpick.domain.ViewStatus;
import jakarta.persistence.*;
import jakarta.persistence.CascadeType;
import jakarta.persistence.Embedded;
import jakarta.persistence.Entity;
import jakarta.persistence.EnumType;
import jakarta.persistence.Enumerated;
import jakarta.persistence.FetchType;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.OneToMany;
import jakarta.persistence.Transient;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Size;
import lombok.*;
import org.springframework.lang.Nullable;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Entity
@Builder
Expand All @@ -23,8 +37,6 @@
@AllArgsConstructor(access = AccessLevel.PRIVATE)
public class Comment extends BaseTimeEntity {

private static final int MIN_COUNT_FOR_BLIND = 5;

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
Expand All @@ -34,12 +46,11 @@ public class Comment extends BaseTimeEntity {
private String content;

@Enumerated(value = EnumType.STRING)
@NotNull
private ViewStatus viewStatus;

private Boolean isBest;

@NotNull
private int reportedCount;
private Boolean isBest;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "member_id")
Expand All @@ -49,7 +60,6 @@ public class Comment extends BaseTimeEntity {
@JoinColumn(name = "talk_pick_id")
private TalkPick talkPick;

@Nullable
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "parent_id")
private Comment parent;
Expand All @@ -60,6 +70,7 @@ public class Comment extends BaseTimeEntity {
@Transient
private Boolean isNotifiedForFirstReply = false;

@NotNull
private LocalDateTime editedAt;

private boolean isEdited;
Expand All @@ -77,19 +88,6 @@ public void setIsBest(boolean isBest) {
this.isBest = isBest;
}

public boolean isBlind() {
return this.viewStatus.equals(ViewStatus.BLIND);
}

public void incrementReportCount() {
this.reportedCount++;

if (this.reportedCount == MIN_COUNT_FOR_BLIND) {
this.content = "신고된 댓글입니다.";
this.viewStatus = ViewStatus.BLIND;
}
}

public void setIsNotifiedForFirstReplyTrue() {
this.isNotifiedForFirstReply = true;
}
Expand Down
8 changes: 1 addition & 7 deletions src/main/java/balancetalk/comment/dto/CommentDto.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,12 @@
import balancetalk.vote.domain.VoteOption;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.v3.oas.annotations.media.Schema;
import java.time.LocalDateTime;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.time.LocalDateTime;

public class CommentDto {
@Data
@Builder
Expand All @@ -32,7 +31,6 @@ public Comment toEntity(Member member, TalkPick talkPick) {
.talkPick(talkPick)
.isBest(false)
.viewStatus(ViewStatus.NORMAL)
.reportedCount(0)
.isNotifiedForFirstReply(false)
.editedAt(LocalDateTime.now())
.isEdited(false)
Expand All @@ -46,7 +44,6 @@ public Comment toEntity(Member member, TalkPick talkPick, Comment parent) {
.talkPick(talkPick)
.isBest(false)
.viewStatus(ViewStatus.NORMAL)
.reportedCount(0)
.parent(parent)
.isEdited(false)
.build();
Expand Down Expand Up @@ -128,7 +125,6 @@ public static LatestCommentResponse fromEntity(Comment comment, VoteOption voteO
.likesCount(likesCount)
.myLike(myLike)
.replyCount(comment.getReplies() == null ? 0 : comment.getReplies().size())
.reportedCount(comment.getReportedCount())
.isEdited(comment.isEdited())
.createdAt(comment.getCreatedAt())
.lastModifiedAt(comment.getLastModifiedAt())
Expand Down Expand Up @@ -202,7 +198,6 @@ public static BestCommentResponse fromEntity(Comment comment, VoteOption voteOpt
.likesCount(likesCount)
.myLike(myLike)
.replyCount(comment.getReplies() == null ? 0 : comment.getReplies().size())
.reportedCount(comment.getReportedCount())
.isBest(comment.getIsBest())
.isEdited(comment.isEdited())
.createdAt(comment.getCreatedAt())
Expand Down Expand Up @@ -278,7 +273,6 @@ public static CommentReplyResponse fromEntity(Comment comment, VoteOption voteOp
.myLike(myLike)
.parentId(comment.getParent() == null ? null : comment.getParent().getId())
.replyCount(comment.getReplies() == null ? 0 : comment.getReplies().size())
.reportedCount(comment.getReportedCount())
.isEdited(comment.isEdited())
.createdAt(comment.getCreatedAt())
.lastModifiedAt(comment.getLastModifiedAt())
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/balancetalk/file/domain/File.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Positive;
import jakarta.validation.constraints.Size;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Builder;
Expand All @@ -32,12 +33,15 @@ public class File extends BaseTimeEntity {
private Long resourceId;

@Enumerated(value = EnumType.STRING)
@NotNull
private FileType fileType;

@NotBlank
@Size(max = 50)
private String uploadName;

@NotBlank
@Size(max = 100)
private String storedName;

@NotBlank
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/balancetalk/game/domain/GameOption.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package balancetalk.game.domain;

import balancetalk.global.common.BaseTimeEntity;
import balancetalk.vote.domain.GameVote;
import balancetalk.vote.domain.VoteOption;
import jakarta.persistence.Column;
Expand Down Expand Up @@ -30,7 +31,7 @@
@Builder
@AllArgsConstructor(access = AccessLevel.PRIVATE)
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class GameOption {
public class GameOption extends BaseTimeEntity {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import java.io.IOException;
import lombok.RequiredArgsConstructor;
import org.springframework.security.core.Authentication;
import org.springframework.security.web.authentication.SimpleUrlAuthenticationSuccessHandler;
import org.springframework.stereotype.Component;
import java.io.IOException;

@Component
@RequiredArgsConstructor
Expand Down
19 changes: 17 additions & 2 deletions src/main/java/balancetalk/like/domain/Like.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,22 @@

import balancetalk.global.common.BaseTimeEntity;
import balancetalk.member.domain.Member;
import jakarta.persistence.*;
import jakarta.persistence.Entity;
import jakarta.persistence.EnumType;
import jakarta.persistence.Enumerated;
import jakarta.persistence.FetchType;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.Table;
import jakarta.validation.constraints.NotNull;
import lombok.*;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Entity
@Builder
Expand All @@ -19,6 +32,7 @@ public class Like extends BaseTimeEntity {
private Long id;

@Enumerated(value = EnumType.STRING)
@NotNull
private LikeType likeType;

@ManyToOne(fetch = FetchType.LAZY)
Expand All @@ -28,6 +42,7 @@ public class Like extends BaseTimeEntity {
@NotNull
private Long resourceId;

@NotNull
private Boolean active = true;

public void activate() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
package balancetalk.report.application;

import static balancetalk.global.exception.ErrorCode.ALREADY_REPORTED_COMMENT;
import static balancetalk.global.exception.ErrorCode.NOT_FOUND_COMMENT;
import static balancetalk.global.exception.ErrorCode.NOT_FOUND_COMMENT_AT_THAT_TALK_PICK;
import static balancetalk.global.exception.ErrorCode.REPORT_MY_COMMENT;

import balancetalk.comment.domain.Comment;
import balancetalk.comment.domain.CommentRepository;
import balancetalk.global.exception.BalanceTalkException;
Expand All @@ -14,8 +19,6 @@
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import static balancetalk.global.exception.ErrorCode.*;

@Service
@Transactional
@RequiredArgsConstructor
Expand Down Expand Up @@ -48,7 +51,6 @@ public void createCommentReport(@Valid CreateReportRequest createReportRequest,
Report report = createReportRequest.toEntity(reporter, reported, resourceId, comment.getContent());

reportRepository.save(report);
comment.incrementReportCount();
}

private Comment validateCommentOnTalkPick(Long resourceId, Long talkPickId) {
Expand Down
23 changes: 19 additions & 4 deletions src/main/java/balancetalk/talkpick/domain/TalkPick.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,31 @@
import balancetalk.member.domain.Member;
import balancetalk.vote.domain.TalkPickVote;
import balancetalk.vote.domain.VoteOption;
import jakarta.persistence.*;
import jakarta.persistence.CascadeType;
import jakarta.persistence.Column;
import jakarta.persistence.Embedded;
import jakarta.persistence.Entity;
import jakarta.persistence.EnumType;
import jakarta.persistence.Enumerated;
import jakarta.persistence.FetchType;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.OneToMany;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.PositiveOrZero;
import jakarta.validation.constraints.Size;
import lombok.*;
import org.hibernate.annotations.ColumnDefault;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.ColumnDefault;

@Entity
@Getter
Expand Down
18 changes: 14 additions & 4 deletions src/main/java/balancetalk/talkpick/domain/TempTalkPick.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,27 @@
package balancetalk.talkpick.domain;

import balancetalk.global.common.BaseTimeEntity;
import balancetalk.member.domain.Member;
import jakarta.persistence.*;
import jakarta.validation.constraints.NotBlank;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.OneToOne;
import jakarta.validation.constraints.Size;
import lombok.*;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Entity
@Getter
@Builder
@AllArgsConstructor(access = AccessLevel.PRIVATE)
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class TempTalkPick {
public class TempTalkPick extends BaseTimeEntity {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
Expand Down
Loading

0 comments on commit e64f8ad

Please sign in to comment.