-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
user 이름
committed
Mar 12, 2024
1 parent
1dcf26e
commit c3b89f0
Showing
23 changed files
with
587 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
src/main/java/com/yello/server/domain/user/dto/request/UserPostCommentUpdateRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package com.yello.server.domain.user.dto.request; | ||
|
||
import jakarta.annotation.Nullable; | ||
|
||
public record UserPostCommentUpdateRequest( | ||
@Nullable Long id, | ||
Long postId, | ||
String userName, | ||
String yelloId, | ||
String status, | ||
String title, | ||
String subtitle, | ||
String content | ||
) { | ||
|
||
} |
13 changes: 13 additions & 0 deletions
13
src/main/java/com/yello/server/domain/user/dto/response/UserPostCommentResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.yello.server.domain.user.dto.response; | ||
|
||
import java.util.List; | ||
import lombok.Builder; | ||
|
||
@Builder | ||
public record UserPostCommentResponse( | ||
Long pageCount, | ||
Long totalCount, | ||
List<UserPostCommentVO> postCommentList | ||
) { | ||
|
||
} |
40 changes: 40 additions & 0 deletions
40
src/main/java/com/yello/server/domain/user/dto/response/UserPostCommentVO.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package com.yello.server.domain.user.dto.response; | ||
|
||
import com.yello.server.domain.user.entity.User; | ||
import com.yello.server.domain.user.entity.UserPost; | ||
import com.yello.server.domain.user.entity.UserPostComment; | ||
import lombok.Builder; | ||
|
||
@Builder | ||
public record UserPostCommentVO( | ||
Long id, | ||
Long userPostId, | ||
Long userId, | ||
String status, | ||
String userName, | ||
String yelloId, | ||
String title, | ||
String subtitle, | ||
String content, | ||
String createdAt, | ||
String updatedAt | ||
) { | ||
|
||
public static UserPostCommentVO of(UserPostComment userPostComment) { | ||
UserPost userPost = userPostComment.getUserPost(); | ||
User user = userPostComment.getUser(); | ||
return UserPostCommentVO.builder() | ||
.id(userPostComment.getId()) | ||
.userPostId(userPost == null ? null : userPost.getId()) | ||
.userId(user == null ? null : user.getId()) | ||
.status(userPostComment.getStatus().getInitial()) | ||
.userName(userPostComment.getUserName()) | ||
.yelloId(userPostComment.getYelloId()) | ||
.title(userPostComment.getTitle()) | ||
.subtitle(userPostComment.getSubtitle()) | ||
.content(userPostComment.getContent()) | ||
.createdAt(String.valueOf(userPostComment.getCreatedAt())) | ||
.updatedAt(String.valueOf(userPostComment.getUpdatedAt())) | ||
.build(); | ||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
src/main/java/com/yello/server/domain/user/entity/UserPost.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package com.yello.server.domain.user.entity; | ||
|
||
import com.yello.server.global.common.dto.AuditingTimeEntity; | ||
import jakarta.persistence.Column; | ||
import jakarta.persistence.Convert; | ||
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 lombok.AccessLevel; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import org.hibernate.annotations.OnDelete; | ||
import org.hibernate.annotations.OnDeleteAction; | ||
|
||
@Getter | ||
@Entity | ||
@Builder | ||
@AllArgsConstructor | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
public class UserPost extends AuditingTimeEntity { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
private Long id; | ||
|
||
@ManyToOne(fetch = FetchType.LAZY) | ||
@OnDelete(action = OnDeleteAction.SET_NULL) | ||
@JoinColumn(name = "userId", nullable = true) | ||
private User user; | ||
|
||
@Column(nullable = false) | ||
@Convert(converter = UserPostStatusConverter.class) | ||
private UserPostStatus status; | ||
|
||
@Column | ||
private String userName; | ||
|
||
@Column | ||
private String yelloId; | ||
|
||
@Column | ||
private String title; | ||
|
||
@Column | ||
private String subtitle; | ||
|
||
@Column(columnDefinition = "MEDIUMTEXT") | ||
private String content; | ||
|
||
} |
73 changes: 73 additions & 0 deletions
73
src/main/java/com/yello/server/domain/user/entity/UserPostComment.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package com.yello.server.domain.user.entity; | ||
|
||
import com.yello.server.domain.user.dto.request.UserPostCommentUpdateRequest; | ||
import com.yello.server.global.common.dto.AuditingTimeEntity; | ||
import jakarta.persistence.Column; | ||
import jakarta.persistence.Convert; | ||
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 lombok.AccessLevel; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import org.hibernate.annotations.OnDelete; | ||
import org.hibernate.annotations.OnDeleteAction; | ||
|
||
@Getter | ||
@Entity | ||
@Builder | ||
@AllArgsConstructor | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
public class UserPostComment extends AuditingTimeEntity { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
private Long id; | ||
|
||
@ManyToOne(fetch = FetchType.LAZY) | ||
@OnDelete(action = OnDeleteAction.RESTRICT) | ||
@JoinColumn(name = "userPostId", nullable = false) | ||
private UserPost userPost; | ||
|
||
@ManyToOne(fetch = FetchType.LAZY) | ||
@OnDelete(action = OnDeleteAction.SET_NULL) | ||
@JoinColumn(name = "userId", nullable = true) | ||
private User user; | ||
|
||
@Column(nullable = false) | ||
@Convert(converter = UserPostCommentStatusConverter.class) | ||
private UserPostCommentStatus status; | ||
|
||
@Column | ||
private String userName; | ||
|
||
@Column | ||
private String yelloId; | ||
|
||
@Column | ||
private String title; | ||
|
||
@Column | ||
private String subtitle; | ||
|
||
@Column(columnDefinition = "TEXT") | ||
private String content; | ||
|
||
public void update(UserPostCommentUpdateRequest request, UserPost userPost, User user, | ||
UserPostCommentStatus status) { | ||
this.userPost = userPost; | ||
this.user = user; | ||
this.status = status; | ||
this.userName = request.userName(); | ||
this.yelloId = request.yelloId(); | ||
this.title = request.title(); | ||
this.subtitle = request.subtitle(); | ||
this.content = request.content(); | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
src/main/java/com/yello/server/domain/user/entity/UserPostCommentStatus.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package com.yello.server.domain.user.entity; | ||
|
||
import static com.yello.server.global.common.ErrorCode.ENUM_BAD_REQUEST_EXCEPTION; | ||
|
||
import com.yello.server.global.exception.EnumIllegalArgumentException; | ||
import java.util.Arrays; | ||
import lombok.Getter; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@Getter | ||
@RequiredArgsConstructor | ||
public enum UserPostCommentStatus { | ||
ACTIVE("ACTIVE"), | ||
INACTIVE("INACTIVE"); | ||
|
||
private final String initial; | ||
|
||
public static UserPostCommentStatus fromCode(String dbData) { | ||
return Arrays.stream(UserPostCommentStatus.values()) | ||
.filter(v -> v.getInitial().equals(dbData)) | ||
.findAny() | ||
.orElseThrow(() -> new EnumIllegalArgumentException(ENUM_BAD_REQUEST_EXCEPTION)); | ||
} | ||
|
||
public static UserPostCommentStatus fromName(String name) { | ||
return Arrays.stream(UserPostCommentStatus.values()) | ||
.filter(v -> v.name().equals(name)) | ||
.findAny() | ||
.orElseThrow(() -> new EnumIllegalArgumentException(ENUM_BAD_REQUEST_EXCEPTION)); | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
src/main/java/com/yello/server/domain/user/entity/UserPostCommentStatusConverter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package com.yello.server.domain.user.entity; | ||
|
||
import jakarta.persistence.AttributeConverter; | ||
import lombok.extern.slf4j.Slf4j; | ||
|
||
@Slf4j | ||
public class UserPostCommentStatusConverter implements AttributeConverter<UserPostCommentStatus, String> { | ||
|
||
@Override | ||
public String convertToDatabaseColumn(UserPostCommentStatus userData) { | ||
if (userData == null) { | ||
return null; | ||
} | ||
return userData.name(); | ||
} | ||
|
||
@Override | ||
public UserPostCommentStatus convertToEntityAttribute(String dbData) { | ||
if (dbData == null) { | ||
return null; | ||
} | ||
|
||
return UserPostCommentStatus.fromName(dbData); | ||
} | ||
} |
Oops, something went wrong.