Skip to content

Commit

Permalink
feat: table adjustments due to the addition of future notifications, …
Browse files Browse the repository at this point in the history
…pins, etc
  • Loading branch information
taegyun1995 committed Aug 16, 2023
1 parent a736299 commit f77d0bd
Show file tree
Hide file tree
Showing 11 changed files with 115 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import lombok.NoArgsConstructor;
import project.linkarchive.backend.advice.entityBase.CreatedEntity;
import project.linkarchive.backend.link.domain.Link;
import project.linkarchive.backend.pin.enums.PinStatus;
import project.linkarchive.backend.user.domain.User;

import javax.persistence.*;
Expand All @@ -20,6 +21,9 @@ public class Bookmark extends CreatedEntity {
@Column(name = "book_mark_id")
private Long id;

@Enumerated(EnumType.STRING)
private PinStatus pinStatus;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "user_id")
private User user;
Expand All @@ -29,14 +33,16 @@ public class Bookmark extends CreatedEntity {
private Link link;

@Builder
public Bookmark(Long id, User user, Link link) {
public Bookmark(Long id, PinStatus pinStatus, User user, Link link) {
this.id = id;
this.pinStatus = pinStatus.UNFIXED;
this.user = user;
this.link = link;
}

public static Bookmark create(User user, Link link) {
return Bookmark.builder()
.pinStatus(PinStatus.UNFIXED)
.user(user)
.link(link)
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import project.linkarchive.backend.isLinkRead.domain.IsLinkRead;
import project.linkarchive.backend.link.enums.LinkStatus;
import project.linkarchive.backend.link.request.CreateLinkRequest;
import project.linkarchive.backend.pin.enums.PinStatus;
import project.linkarchive.backend.user.domain.User;

import javax.persistence.*;
Expand All @@ -18,6 +19,7 @@
import static project.linkarchive.backend.advice.data.DataConstants.BOOKMARK_DEFAULT_COUNT;
import static project.linkarchive.backend.link.enums.LinkStatus.ACTIVE;
import static project.linkarchive.backend.link.enums.LinkStatus.TRASH;
import static project.linkarchive.backend.pin.enums.PinStatus.UNFIXED;

@Entity
@Getter
Expand All @@ -41,6 +43,9 @@ public class Link extends TimeEntity {
@Enumerated(EnumType.STRING)
private LinkStatus linkStatus;

@Enumerated(EnumType.STRING)
private PinStatus pinStatus;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "user_id")
private User user;
Expand All @@ -55,14 +60,15 @@ public class Link extends TimeEntity {
private List<IsLinkRead> isLinkReadList = new ArrayList<>();

@Builder
public Link(Long id, String url, String title, String description, String thumbnail, int bookmarkCount, LinkStatus linkStatus, User user) {
public Link(Long id, String url, String title, String description, String thumbnail, int bookmarkCount, LinkStatus linkStatus, PinStatus pinStatus, User user) {
this.id = id;
this.url = url;
this.title = title;
this.description = description;
this.thumbnail = thumbnail;
this.bookmarkCount = bookmarkCount;
this.linkStatus = linkStatus.ACTIVE;
this.pinStatus = pinStatus.UNFIXED;
this.user = user;
}

Expand All @@ -74,6 +80,7 @@ public static Link create(CreateLinkRequest request, User user) {
.thumbnail(request.getThumbnail())
.bookmarkCount(BOOKMARK_DEFAULT_COUNT)
.linkStatus(ACTIVE)
.pinStatus(UNFIXED)
.user(user)
.build();
}
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package project.linkarchive.backend.notification.domain;


import lombok.AccessLevel;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import project.linkarchive.backend.advice.entityBase.CreatedEntity;
import project.linkarchive.backend.notification.enums.NotificationRead;
import project.linkarchive.backend.notification.enums.NotificationType;
import project.linkarchive.backend.user.domain.User;

import javax.persistence.*;

@Getter
@Entity
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class Notification extends CreatedEntity {

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

@Enumerated(EnumType.STRING)
private NotificationType notificationType;

@Enumerated(EnumType.STRING)
private NotificationRead notificationRead;

private Long relationshipId;
private Long bookmarkId;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "user_id")
private User user;

@Builder
public Notification(Long id, NotificationType notificationType, NotificationRead notificationRead, Long relationshipId, Long bookmarkId, User user) {
this.id = id;
this.notificationType = notificationType;
this.notificationRead = notificationRead;
this.relationshipId = relationshipId;
this.bookmarkId = bookmarkId;
this.user = user;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package project.linkarchive.backend.notification.enums;

public enum NotificationPreference {

ALLOWED, DISALLOWED, MUTE

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package project.linkarchive.backend.notification.enums;

public enum NotificationRead {

READ, UNREAD

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package project.linkarchive.backend.notification.enums;

public enum NotificationType {

BOOKMARK, RELATIONSHIP

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package project.linkarchive.backend.pin;
package project.linkarchive.backend.pin.domain;

import lombok.AccessLevel;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import project.linkarchive.backend.advice.entityBase.TimeEntity;
Expand All @@ -10,17 +11,19 @@
import javax.persistence.GenerationType;
import javax.persistence.Id;

@NoArgsConstructor(access = AccessLevel.PROTECTED)
@Entity
@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class Pin extends TimeEntity {

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

private int linkCount;
private int bookmarkCount;

@Builder
public Pin(Long id, int linkCount, int bookmarkCount) {
this.id = id;
this.linkCount = linkCount;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package project.linkarchive.backend.pin.enums;

public enum PinStatus {

FIXED, UNFIXED

}
26 changes: 19 additions & 7 deletions src/main/java/project/linkarchive/backend/user/domain/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import project.linkarchive.backend.bookmark.domain.Bookmark;
import project.linkarchive.backend.hashtag.domain.UserHashtag;
import project.linkarchive.backend.isLinkRead.domain.IsLinkRead;
import project.linkarchive.backend.notification.domain.Notification;
import project.linkarchive.backend.notification.enums.NotificationPreference;
import project.linkarchive.backend.profileImage.domain.ProfileImage;
import project.linkarchive.backend.user.request.UpdateNicknameRequest;
import project.linkarchive.backend.user.request.UpdateProfileRequest;
Expand All @@ -31,10 +33,11 @@ public class User extends TimeEntity {
@Column(name = "user_id")
private Long id;

private String socialId;

@Enumerated(EnumType.STRING)
private AuthProvider authProvider;

private String socialId;
private String email;
private String nickname;
private String introduce;
Expand All @@ -43,6 +46,9 @@ public class User extends TimeEntity {
private int linkCount;
private int bookmarkCount;

@Enumerated(EnumType.STRING)
private NotificationPreference notificationPreference;

@OneToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
@JoinColumn(name = "profile_image_id")
private ProfileImage profileImage;
Expand All @@ -56,47 +62,53 @@ public class User extends TimeEntity {
@OneToMany(mappedBy = "user", cascade = CascadeType.ALL)
private List<IsLinkRead> isLinkReadList = new ArrayList<>();

@OneToMany(mappedBy = "user", cascade = CascadeType.ALL)
private List<Notification> notificationList = new ArrayList<>();

@Builder
public User(Long id, AuthProvider authProvider, String socialId, String email, String nickname, String introduce, int followerCount, int followingCount, int linkCount, int bookmarkCount, ProfileImage profileImage) {
public User(Long id, String socialId, AuthProvider authProvider, String email, String nickname, String introduce, int followerCount, int followingCount, int linkCount, int bookmarkCount, NotificationPreference notificationPreference, ProfileImage profileImage) {
this.id = id;
this.authProvider = authProvider;
this.socialId = socialId;
this.authProvider = authProvider;
this.email = email;
this.nickname = nickname;
this.introduce = introduce;
this.followerCount = followerCount;
this.followingCount = followingCount;
this.linkCount = linkCount;
this.bookmarkCount = bookmarkCount;
this.notificationPreference = notificationPreference;
this.profileImage = profileImage;
}

public static User localCreate(ProfileImage profileImage) {
return User.builder()
.authProvider(AuthProvider.LOCAL)
.socialId(SOCIAL_LOGIN)
.nickname(EMPTY)
.authProvider(AuthProvider.LOCAL)
.email(LOCAL_EMAIL)
.nickname(EMPTY)
.introduce(EMPTY)
.followerCount(DEFAULT_COUNT)
.followingCount(DEFAULT_COUNT)
.linkCount(DEFAULT_COUNT)
.bookmarkCount(DEFAULT_COUNT)
.notificationPreference(NotificationPreference.ALLOWED)
.profileImage(profileImage)
.build();
}

public static User create(AuthProvider authProvider, KakaoProfile kakaoProfile, ProfileImage profileImage) {
return User.builder()
.authProvider(authProvider)
.socialId(kakaoProfile.getId())
.nickname(EMPTY)
.authProvider(authProvider)
.email(kakaoProfile.getKakaoAccount().getEmail())
.nickname(EMPTY)
.introduce(EMPTY)
.followerCount(DEFAULT_COUNT)
.followingCount(DEFAULT_COUNT)
.linkCount(DEFAULT_COUNT)
.bookmarkCount(DEFAULT_COUNT)
.notificationPreference(NotificationPreference.ALLOWED)
.profileImage(profileImage)
.build();
}
Expand Down

0 comments on commit f77d0bd

Please sign in to comment.