Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/main/java/com/avab/avab/converter/FlowConverter.java
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ public static FlowScrapDTO toFlowScrapDTO(Boolean isScraped) {
return FlowScrapDTO.builder().isScraped(isScraped).build();
}

public static FlowScrap toFlowFavorite(Flow flow, User user) {
public static FlowScrap toFlowScrap(Flow flow, User user) {
return FlowScrap.builder().flow(flow).user(user).build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ private static RecreationPreviewDTO toRecreationPreviewDTO(Recreation recreation

public static WayDTO toWayDTO(RecreationWay recreationWay) {
return WayDTO.builder()
.contents(recreationWay.getContents())
.content(recreationWay.getContent())
.imageUrl(recreationWay.getImageUrl())
.seq(recreationWay.getSeq())
.build();
Expand Down Expand Up @@ -244,7 +244,7 @@ public static RecreationReview toRecreationReview(
return RecreationReview.builder()
.recreation(recreation)
.author(user)
.contents(request.getContents())
.content(request.getContent())
.stars(request.getStars())
.build();
}
Expand Down Expand Up @@ -283,7 +283,7 @@ public static RecreationReviewDTO toRecreationReviewDTO(RecreationReview review,
.build())
.createdAt(review.getCreatedAt())
.updatedAt(review.getUpdatedAt())
.contents(review.getContents())
.content(review.getContent())
.goodCount(review.getGoodCount())
.badCount(review.getBadCount())
.recommendation(
Expand Down Expand Up @@ -419,7 +419,7 @@ private static RecreationWay toRecreationWay(
CreateRecreationWayDTO request, String wayImageUrl, Recreation recreation) {
return RecreationWay.builder()
.recreation(recreation)
.contents(request.getContents())
.content(request.getContent())
.seq(request.getSeq())
.imageUrl(wayImageUrl)
.build();
Expand Down
16 changes: 12 additions & 4 deletions src/main/java/com/avab/avab/domain/Flow.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,21 +48,29 @@ public class Flow extends BaseEntity {

private Integer participants;

private Long viewCount;
@ColumnDefault("0")
@Builder.Default
private Long viewCount = 0L;

@ColumnDefault("0")
@Column(name = "view_count_last_7_days")
private Long viewCountLast7Days;
@Builder.Default
private Long viewCountLast7Days = 0L;

@Column(length = 100)
private String title;

private Long scrapCount;
@ColumnDefault("0")
@Builder.Default
private Long scrapCount = 0L;

@Column(length = 300)
private String imageUrl;

@Column private LocalDateTime deletedAt;
@Column
@ColumnDefault("null")
@Builder.Default
private LocalDateTime deletedAt = null;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "author_id")
Expand Down
19 changes: 14 additions & 5 deletions src/main/java/com/avab/avab/domain/Recreation.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ public class Recreation extends BaseEntity {
@Column(length = 300)
private String imageUrl;

private Float totalStars;
@ColumnDefault("0")
@Builder.Default
private Float totalStars = 0.0f;

@Column(length = 300)
private String summary;
Expand All @@ -61,19 +63,26 @@ public class Recreation extends BaseEntity {

private Integer playTime;

private Long viewCount;
@ColumnDefault("0")
@Builder.Default
private Long viewCount = 0L;

private Long favoriteCount;
@ColumnDefault("0")
@Builder.Default
private Long favoriteCount = 0L;

@ColumnDefault("0")
@Column(name = "view_count_last_7_days")
private Long viewCountLast7Days;
@Builder.Default
private Long viewCountLast7Days = 0L;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "author_id")
private User author;

private LocalDateTime deletedAt;
@ColumnDefault("null")
@Builder.Default
private LocalDateTime deletedAt = null;

@Builder.Default
@OneToMany(mappedBy = "recreation", cascade = CascadeType.ALL)
Expand Down
15 changes: 11 additions & 4 deletions src/main/java/com/avab/avab/domain/RecreationReview.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import jakarta.persistence.ManyToOne;
import jakarta.persistence.OneToMany;

import org.hibernate.annotations.ColumnDefault;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;

Expand Down Expand Up @@ -43,13 +44,19 @@ public class RecreationReview extends BaseEntity {
private Integer stars;

@Column(length = 500)
private String contents;
private String content;

private Integer goodCount;
@ColumnDefault("0")
@Builder.Default
private Integer goodCount = 0;

private Integer badCount;
@ColumnDefault("0")
@Builder.Default
private Integer badCount = 0;

private LocalDateTime deletedAt;
@ColumnDefault("null")
@Builder.Default
private LocalDateTime deletedAt = null;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "recreation_id")
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/avab/avab/domain/RecreationWay.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class RecreationWay {
private Long id;

@Column(length = 300)
private String contents;
private String content;

@Column(length = 300)
private String imageUrl;
Expand Down
18 changes: 13 additions & 5 deletions src/main/java/com/avab/avab/domain/Report.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;

import org.hibernate.annotations.ColumnDefault;

import com.avab.avab.domain.common.BaseEntity;
import com.avab.avab.domain.enums.ReportReason;
import com.avab.avab.domain.enums.ReportType;
Expand Down Expand Up @@ -42,26 +44,32 @@ public class Report extends BaseEntity {

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "target_user_id")
private User targetUser;
@Builder.Default
private User targetUser = null;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "target_recreation_id")
private Recreation targetRecreation;
@Builder.Default
private Recreation targetRecreation = null;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "target_recreation_review_id")
private RecreationReview targetRecreationReview;
@Builder.Default
private RecreationReview targetRecreationReview = null;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "target_flow_id")
private Flow targetFlow;
@Builder.Default
private Flow targetFlow = null;

@Enumerated(EnumType.STRING)
@Column(columnDefinition = "VARCHAR(20)")
private ReportReason reason;

@Column(length = 300)
private String extraReason;
@ColumnDefault("null")
@Builder.Default
private String extraReason = null;

public Boolean isReporter(User user) {
return this.reporter.equals(user);
Expand Down
36 changes: 24 additions & 12 deletions src/main/java/com/avab/avab/domain/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,15 @@
import java.util.ArrayList;
import java.util.List;

import jakarta.persistence.*;
import jakarta.persistence.CascadeType;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.EnumType;
import jakarta.persistence.Enumerated;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.OneToMany;

import org.hibernate.annotations.ColumnDefault;
import org.hibernate.annotations.DynamicInsert;
Expand All @@ -18,7 +26,12 @@
import com.avab.avab.domain.mapping.RecreationFavorite;
import com.avab.avab.domain.mapping.RecreationReviewRecommendation;

import lombok.*;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

@Entity
@Builder
Expand Down Expand Up @@ -51,15 +64,19 @@ public class User extends BaseEntity {

@Enumerated(EnumType.STRING)
@Column(columnDefinition = "VARCHAR(10)")
private UserStatus userStatus;
private UserStatus userStatus = UserStatus.ENABLED;

@ColumnDefault("null")
private LocalDate deletedTime;
@Builder.Default
private LocalDate deletedAt = null;

@ColumnDefault("0")
private Integer reportCount;
@Builder.Default
private Integer reportCount = 0;

private LocalDateTime disabledAt;
@ColumnDefault("null")
@Builder.Default
private LocalDateTime disabledAt = null;

@OneToMany(mappedBy = "author", cascade = CascadeType.ALL)
private List<Recreation> recreationList = new ArrayList<>();
Expand All @@ -84,7 +101,7 @@ public class User extends BaseEntity {
private List<Report> reportList = new ArrayList<>();

public void deleteUser() {
this.deletedTime = LocalDate.now();
this.deletedAt = LocalDate.now();
this.userStatus = UserStatus.DELETED;
}

Expand All @@ -102,11 +119,6 @@ public void enableUser() {
this.userStatus = UserStatus.ENABLED;
}

public void restoreUser() {
this.deletedTime = null;
this.userStatus = UserStatus.ENABLED;
}

public Boolean isDisabled() {
return this.userStatus == UserStatus.DISABLED;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public static class PostRecreationReviewDTO {

@Size(max = 500, message = "리뷰는 300자 이하여야 합니다.")
@NotEmpty(message = "리뷰 내용은 필수입니다.")
private String contents;
private String content;
}

@Getter
Expand Down Expand Up @@ -87,7 +87,7 @@ public static class CreateRecreationWayDTO {

@NotBlank(message = "방법 내용은 비워둘 수 없습니다.")
@Size(max = 300, message = "방법 내용은 300자를 넘을 수 없습니다.")
String contents;
String content;

@Schema(description = "방법 순서, 0부터 시작")
Integer seq;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public static class DescriptionDTO {
@AllArgsConstructor(access = AccessLevel.PROTECTED)
public static class WayDTO {

String contents;
String content;
String imageUrl;
Integer seq;
}
Expand Down Expand Up @@ -117,7 +117,7 @@ public static class RecreationReviewDTO {
Integer stars;
LocalDateTime createdAt;
LocalDateTime updatedAt;
String contents;
String content;
Integer goodCount;
Integer badCount;

Expand Down Expand Up @@ -160,6 +160,7 @@ public static class RecreationCreatedDTO {
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@AllArgsConstructor(access = AccessLevel.PROTECTED)
public static class RecreationFlowDTO {

Long id;
Boolean isMasked;
MaskedReason maskedReason;
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/com/avab/avab/repository/UserRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,5 @@ public interface UserRepository extends JpaRepository<User, Long> {

Optional<User> findByEmail(String email);

List<User> findByUserStatusAndDeletedTimeLessThanEqual(
UserStatus userStatus, LocalDate threshold);
List<User> findByUserStatusAndDeletedAtBefore(UserStatus userStatus, LocalDate threshold);
}
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ public Boolean toggleScrapeFlow(User user, Long flowId) {
return false;
}

FlowScrap favorite = FlowConverter.toFlowFavorite(flow, user);
FlowScrap favorite = FlowConverter.toFlowScrap(flow, user);
flowScrapRepository.save(favorite);
flowRepository.incrementScrapCountById(flow.getId());

Expand Down
5 changes: 2 additions & 3 deletions src/main/java/com/avab/avab/service/impl/UserServiceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,7 @@ public Page<Flow> getMyFlows(User user, Integer page) {
@Transactional
public void hardDeleteOldUser(LocalDate threshold) {
List<User> oldUsers =
userRepository.findByUserStatusAndDeletedTimeLessThanEqual(
UserStatus.DELETED, threshold);
userRepository.findByUserStatusAndDeletedAtBefore(UserStatus.DELETED, threshold);
userRepository.deleteAll(oldUsers);
}

Expand All @@ -106,7 +105,7 @@ public User restoreUserDeletion(String restoreToken) {
throw new UserException(ErrorStatus.USER_NOT_DELETED);
}

user.restoreUser();
user.enableUser();
return user;
}
}