Skip to content

Commit

Permalink
Merge pull request #181 from THEGOODs-repo/feature/10
Browse files Browse the repository at this point in the history
โœจ ํ”ผ๋“œ, ๋Œ“๊ธ€, ์ข‹์•„์š” api ๊ตฌํ˜„
  • Loading branch information
yxhwxn authored May 6, 2024
2 parents 9f72ba6 + 55f4213 commit 0fbe0b8
Show file tree
Hide file tree
Showing 17 changed files with 432 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ public enum ErrorStatus implements BaseErrorCode {
POST_SELF_FOLLOW(HttpStatus.BAD_REQUEST, "POST4001", "์ž์‹ ์„ ํŒ”๋กœ์šฐ ํ–ˆ์Šต๋‹ˆ๋‹ค."),
POST_ALREADY_FOLLOW(HttpStatus.BAD_REQUEST, "POST4002", "์ด๋ฏธ ํŒ”๋กœ์šฐ ํ–ˆ์Šต๋‹ˆ๋‹ค."),
POST_FOLLOW_NOT_FOUND(HttpStatus.BAD_REQUEST, "POST4003", "ํ•ด๋‹น ํŒ”๋กœ์šฐ๋ฅผ ์ฐพ์„์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค."),
POST_NOT_FOUND(HttpStatus.BAD_REQUEST, "POST4004", "ํฌ์ŠคํŠธ๋ฅผ ์ฐพ์„์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค."),
POST_COMMENT_NOT_FOUND(HttpStatus.BAD_REQUEST,"POST4005", "ํ•ด๋‹น ๋Œ“๊ธ€์„ ์ฐพ์„ ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค."),
POST_COMMENT_NOT_UPDATE(HttpStatus.BAD_REQUEST, "POST4006", "ํ•ด๋‹น ๋Œ“๊ธ€์„ ์ˆ˜์ •ํ•  ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค."),


//Category
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,17 @@ public enum SuccessStatus implements BaseCode {

//POST
POST_FOLLOW_SUCCESS(HttpStatus.OK, "POST2001", "ํŒ”๋กœ์šฐ ์„ฑ๊ณต์ž…๋‹ˆ๋‹ค."),
POST_DELETE_FOLLOW_SUCCESS(HttpStatus.OK, "POST2002", "ํŒ”๋กœ์šฐ ์ทจ์†Œ ์„ฑ๊ณต์ž…๋‹ˆ๋‹ค.")
POST_DELETE_FOLLOW_SUCCESS(HttpStatus.OK, "POST2002", "ํŒ”๋กœ์šฐ ์ทจ์†Œ ์„ฑ๊ณต์ž…๋‹ˆ๋‹ค."),
POST_UPLOAD_SUCCESS(HttpStatus.OK, "POST2003", "ํฌ์ŠคํŠธ ์—…๋กœ๋“œ ์„ฑ๊ณต์ž…๋‹ˆ๋‹ค."),
POST_UPDATE_SUCCESS(HttpStatus.OK, "POST2004", "ํฌ์ŠคํŠธ ์—…๋ฐ์ดํŠธ ์„ฑ๊ณต์ž…๋‹ˆ๋‹ค."),
POST_DELETE_SUCCESS(HttpStatus.OK, "POST2005", "ํฌ์ŠคํŠธ ์‚ญ์ œ ์„ฑ๊ณต์ž…๋‹ˆ๋‹ค."),
POST_LIKE_SUCCESS(HttpStatus.OK, "POST2006", "ํฌ์ŠคํŠธ ์ข‹์•„์š” ์„ฑ๊ณต์ž…๋‹ˆ๋‹ค."),
POST_DELETE_LIKE_SUCCESS(HttpStatus.OK, "POST2007", "ํฌ์ŠคํŠธ ์ข‹์•„์š” ์ทจ์†Œ ์„ฑ๊ณต์ž…๋‹ˆ๋‹ค."),
POST_COMMENT_SUCCESS(HttpStatus.OK, "POST2008", "ํฌ์ŠคํŠธ ๋Œ“๊ธ€ ๋‹ฌ๊ธฐ ์„ฑ๊ณต์ž…๋‹ˆ๋‹ค."),
POST_DELETE_COMMENT_SUCCESS(HttpStatus.OK,"POST2009", "ํฌ์ŠคํŠธ ๋Œ“๊ธ€ ์‚ญ์ œ ์„ฑ๊ณต์ž…๋‹ˆ๋‹ค."),
POST_UPDATE_COMMENT_SUCCESS(HttpStatus.OK, "POST2010", "ํฌ์ŠคํŠธ ๋Œ“๊ธ€ ์ˆ˜์ • ์„ฑ๊ณต์ž…๋‹ˆ๋‹ค."),
POST_COMMENT_LIKE_SUCCESS(HttpStatus.OK, "POST2011", "ํฌ์ŠคํŠธ ๋Œ“๊ธ€ ์ข‹์•„์š” ์„ฑ๊ณต์ž…๋‹ˆ๋‹ค."),
POST_DELETE_COMMENT_LIKE_SUCCESS(HttpStatus.OK,"POST2012", "ํฌ์ŠคํŠธ ๋Œ“๊ธ€ ์ข‹์•„์š” ์ทจ์†Œ ์„ฑ๊ณต์ž…๋‹ˆ๋‹ค.")
;

private final HttpStatus httpStatus;
Expand Down
46 changes: 46 additions & 0 deletions src/main/java/com/umc/TheGoods/converter/post/PostConverter.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
package com.umc.TheGoods.converter.post;


import com.umc.TheGoods.domain.community.Comment;
import com.umc.TheGoods.domain.community.Post;
import com.umc.TheGoods.domain.images.PostImg;
import com.umc.TheGoods.domain.mapping.comment.CommentLike;
import com.umc.TheGoods.domain.mapping.post.PostLike;
import com.umc.TheGoods.domain.member.Follow;
import com.umc.TheGoods.domain.member.Member;

Expand All @@ -11,4 +17,44 @@ public static Follow toFollow(Member follower, Member following){
.following(following)
.build();
}

public static Post toPost(Member member, String content){

return Post.builder()
.content(content)
.member(member)
.build();
}

public static PostImg toPostImg(String url, Post post){

return PostImg.builder()
.post(post)
.url(url)
.build();
}

public static PostLike toPostLike(Member member, Post post){

return PostLike.builder()
.member(member)
.post(post)
.build();
}

public static Comment toComment(Member member, Post post, String comment){

return Comment.builder()
.content(comment)
.post(post)
.member(member)
.build();
}

public static CommentLike toCommentLike(Member member, Comment comment){
return CommentLike.builder()
.comment(comment)
.member(member)
.build();
}
}
17 changes: 14 additions & 3 deletions src/main/java/com/umc/TheGoods/domain/community/Comment.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
import com.umc.TheGoods.domain.mapping.comment.CommentLike;
import com.umc.TheGoods.domain.mapping.comment.CommentMention;
import com.umc.TheGoods.domain.member.Member;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.*;
import org.hibernate.annotations.ColumnDefault;
import org.hibernate.annotations.DynamicInsert;

import javax.persistence.*;
import java.util.ArrayList;
Expand All @@ -15,6 +15,9 @@
@Entity
@Table(name = "comment")
@Getter
@Builder
@DynamicInsert
@AllArgsConstructor
@NoArgsConstructor(access = AccessLevel.PROTECTED) // ์ƒ์„ฑ ๋กœ์ง ๊ทœ์ •
public class Comment extends BaseDateTimeEntity {

Expand All @@ -31,6 +34,10 @@ public class Comment extends BaseDateTimeEntity {
@JoinColumn(name = "post_id")
private Post post;

@ColumnDefault("0")
@Column(nullable = false)
private Integer likesCount;

/**
* ๋Œ€๋Œ“๊ธ€ ๊ด€๋ จ
* parentComment: ๋ถ€๋ชจ ๋Œ“๊ธ€์„ ์ฐธ์กฐํ•˜๋Š” ํ•„๋“œ
Expand Down Expand Up @@ -60,4 +67,8 @@ public void setContent(String newContent) {
public void removeCommentLike(Long id) {
this.commentLikeList.removeIf((like) -> like.getId() == id);
}

public void updateParent(Comment comment) {
this.parentComment = comment;
}
}
21 changes: 18 additions & 3 deletions src/main/java/com/umc/TheGoods/domain/community/Post.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
import com.umc.TheGoods.domain.images.PostImg;
import com.umc.TheGoods.domain.mapping.post.PostLike;
import com.umc.TheGoods.domain.member.Member;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.*;
import org.hibernate.annotations.ColumnDefault;
import org.hibernate.annotations.DynamicInsert;

import javax.persistence.*;
import java.util.ArrayList;
Expand All @@ -15,6 +15,9 @@
@Entity
@Table(name = "post")
@Getter
@Builder
@DynamicInsert
@AllArgsConstructor
@NoArgsConstructor(access = AccessLevel.PROTECTED) // ์ƒ์„ฑ ๋กœ์ง ๊ทœ์ •
public class Post extends BaseDateTimeEntity {

Expand All @@ -38,4 +41,16 @@ public class Post extends BaseDateTimeEntity {

@OneToMany(mappedBy = "post", cascade = CascadeType.ALL)
private List<PostImg> postImgList = new ArrayList<>();

@ColumnDefault("0")
@Column(nullable = false)
private Long viewCount;

@ColumnDefault("0")
@Column(nullable = false)
private Integer likesCount;

public void updatePost(String content){
this.content = content;
}
}
14 changes: 11 additions & 3 deletions src/main/java/com/umc/TheGoods/domain/images/PostImg.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
package com.umc.TheGoods.domain.images;

import com.umc.TheGoods.domain.community.Post;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.NoArgsConstructor;
import com.umc.TheGoods.domain.item.Item;
import lombok.*;

import javax.persistence.*;

@Entity
@Table(name = "post_img")
@Getter
@Builder
@AllArgsConstructor
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class PostImg {

Expand All @@ -24,4 +25,11 @@ public class PostImg {

@Column(columnDefinition = "TEXT", nullable = false)
private String url;

public void setPost(Post post){
if(this.post != null)
post.getPostImgList().remove(this);
this.post = post;
post.getPostImgList().add(this);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

import com.umc.TheGoods.domain.community.Comment;
import com.umc.TheGoods.domain.member.Member;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.*;

import javax.persistence.*;

@Entity
@Table(name = "comment_like")
@Getter
@Builder
@AllArgsConstructor
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class CommentLike {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
import com.umc.TheGoods.domain.common.BaseDateTimeEntity;
import com.umc.TheGoods.domain.community.Post;
import com.umc.TheGoods.domain.member.Member;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.*;

import javax.persistence.*;

@Entity
@Table(name = "post_like")
@Getter
@Builder
@AllArgsConstructor
@NoArgsConstructor(access = AccessLevel.PROTECTED) // ์ƒ์„ฑ ๋กœ์ง ๊ทœ์ •
public class PostLike extends BaseDateTimeEntity {

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.umc.TheGoods.repository.post;


import com.umc.TheGoods.domain.mapping.comment.CommentLike;
import org.springframework.data.jpa.repository.JpaRepository;

import java.util.Optional;

public interface CommentLikeRepository extends JpaRepository<CommentLike, Long> {

Optional<CommentLike> findByMember_IdAndComment_Id(Long memberId, Long commentId);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.umc.TheGoods.repository.post;

import com.umc.TheGoods.domain.community.Comment;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

public interface CommentRepository extends JpaRepository<Comment, Long> {
@Modifying(clearAutomatically = true)
@Query("update Comment c SET c.content= :comment WHERE c.id= :commentId")
void updateComment(Long commentId, String comment);

@Modifying(clearAutomatically = true)
@Query("UPDATE Comment c SET c.likesCount = c.likesCount +1 WHERE c.id= :commentId")
void updateLikeCount(Long commentId);

@Modifying(clearAutomatically = true)
@Query("UPDATE Comment c SET c.likesCount = c.likesCount -1 WHERE c.id= :commentId")
void updateUnlikeCount(Long commentId);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.umc.TheGoods.repository.post;

import com.umc.TheGoods.domain.images.PostImg;
import org.springframework.data.jpa.repository.JpaRepository;

import java.util.List;

public interface PostImgRepository extends JpaRepository<PostImg, Long> {
List<PostImg> findByPostId(Long postId);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.umc.TheGoods.repository.post;


import com.umc.TheGoods.domain.mapping.post.PostLike;
import org.springframework.data.jpa.repository.JpaRepository;

import java.util.Optional;

public interface PostLikeRepository extends JpaRepository<PostLike, Long> {

Optional<PostLike> findByMember_IdAndPost_Id(Long memberId, Long postId);
}
12 changes: 12 additions & 0 deletions src/main/java/com/umc/TheGoods/repository/post/PostRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,19 @@

import com.umc.TheGoods.domain.community.Post;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

public interface PostRepository extends JpaRepository<Post, Long> {
//Page<Post> getPostsOrderByLikes(Pageable pageable);

@Modifying(clearAutomatically = true)
@Query("UPDATE Post p SET p.likesCount = p.likesCount +1 WHERE p.id= :postId")
void updateLikeCount(Long postId);

@Modifying(clearAutomatically = true)
@Query("update Post p SET p.likesCount = p.likesCount -1 WHERE p.id= :postId")
void updateUnlikeCount(Long postId);


}
Original file line number Diff line number Diff line change
@@ -1,11 +1,31 @@
package com.umc.TheGoods.service.PostService;

import com.umc.TheGoods.domain.member.Member;
import com.umc.TheGoods.web.dto.post.PostRequestDto;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

public interface PostCommandService {

void follow(Long followingId, Member follower);

void deleteFollow(Long followingId, Long followerId);

void registerPost(Member member, String content, List<MultipartFile> multipartFileList);

void updatePost(Member member, Long postId, String content, List<MultipartFile> multipartFileList);

void deletePost(Member member, Long postId);

void likePost(Member member, Long postId);


void uploadComment(Member member, Long postId, PostRequestDto.CommentDTO request);

void updateComment(Member member, Long postId, Long commentId, PostRequestDto.UpdateCommentDTO request);

void likeComment(Member member, Long commentId);


}
Loading

0 comments on commit 0fbe0b8

Please sign in to comment.