-
Notifications
You must be signed in to change notification settings - Fork 0
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
bngsh
committed
Sep 14, 2023
1 parent
77a6638
commit f18fcd3
Showing
9 changed files
with
251 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package com.whyranoid.walkie.domain; | ||
|
||
import lombok.AccessLevel; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.ToString; | ||
|
||
import javax.persistence.Column; | ||
import javax.persistence.Entity; | ||
import javax.persistence.FetchType; | ||
import javax.persistence.GeneratedValue; | ||
import javax.persistence.GenerationType; | ||
import javax.persistence.Id; | ||
import javax.persistence.JoinColumn; | ||
import javax.persistence.ManyToOne; | ||
import javax.persistence.OneToOne; | ||
|
||
@Entity | ||
@Getter | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
@ToString | ||
public class PostLike { | ||
|
||
@Id | ||
@Column(name = "post_like_id") | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
private Long postLikeId; | ||
|
||
@OneToOne(fetch = FetchType.LAZY) | ||
@JoinColumn(name = "liker") | ||
private Walkie liker; | ||
|
||
@ManyToOne(fetch = FetchType.LAZY) | ||
@JoinColumn(name = "post") | ||
private Post post; | ||
|
||
@Builder | ||
public PostLike(Long postLikeId, Walkie liker, Post post) { | ||
this.postLikeId = postLikeId; | ||
this.liker = liker; | ||
this.post = post; | ||
} | ||
} |
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,41 @@ | ||
package com.whyranoid.walkie.dto; | ||
|
||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import lombok.AccessLevel; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Getter | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
public class PostDto { | ||
|
||
@Schema(description = "[응답] 워키 아이디", example = "3") | ||
private Long viewerId; | ||
|
||
@Schema(description = "[응답] 작성자 아이디", example = "2") | ||
private Long posterId; | ||
|
||
@Schema(description = "[응답] 게시글 pk", example = "26343") | ||
private Long postId; | ||
|
||
@Schema(description = "[응답] 좋아요 여부", example = "true") | ||
private Boolean liked; | ||
|
||
@Schema(description = "[응답] 좋아요 개수", example = "36") | ||
private Integer likeCount; | ||
|
||
@Schema(description = "[응답] 사진파일 URI", example = "") | ||
private String photo; | ||
|
||
@Schema(description = "[응답] 게시글 내용", example = "오운완.") | ||
private String content; | ||
|
||
@Schema(description = "[응답] 게시 시각", example = "2023-09-09 09:09:09") | ||
private String date; | ||
|
||
@Schema(description = "[응답] 글씨색 설정", example = "0") | ||
private Integer colorMode; | ||
|
||
@Schema(description = "[응답] 기록 데이터", example = "") | ||
private String historyContent; | ||
} |
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,45 @@ | ||
package com.whyranoid.walkie.dto; | ||
|
||
import com.querydsl.core.annotations.QueryProjection; | ||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import lombok.AccessLevel; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
import java.util.List; | ||
|
||
@Getter | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
public class PostLikeDto { | ||
|
||
@Schema(description = "요청 필수 파라미터 - 좋아요 누른 유저의 워키 아이디", requiredMode = Schema.RequiredMode.REQUIRED, example = "3") | ||
private Long likerId; | ||
|
||
@Schema(description = "요청 필수 파라미터 - 좋아요 받은 글의 포스트 아이디", requiredMode = Schema.RequiredMode.REQUIRED, example = "6521") | ||
private Long postId; | ||
|
||
@Schema(description = "응답 파라미터 - 좋아요 누른 유저 수", example = "62") | ||
private Long likerCount; | ||
|
||
@Schema(description = "응답 파라미터 - 좋아요 누른 유저들의 프로필") | ||
private List<WalkieDto> likerProfiles; | ||
|
||
@QueryProjection | ||
public PostLikeDto(Long likerId, Long postId) { | ||
this.likerId = likerId; | ||
this.postId = postId; | ||
} | ||
|
||
@Builder | ||
public PostLikeDto(Long likerId, Long postId, Long likerCount, List<WalkieDto> likerProfiles) { | ||
this.likerId = likerId; | ||
this.postId = postId; | ||
this.likerCount = likerCount; | ||
this.likerProfiles = likerProfiles; | ||
} | ||
|
||
public void setLikerCount(Long likerCount) { | ||
this.likerCount = likerCount; | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
src/main/java/com/whyranoid/walkie/repository/PostLikeRepository.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,14 @@ | ||
package com.whyranoid.walkie.repository; | ||
|
||
import com.whyranoid.walkie.domain.Post; | ||
import com.whyranoid.walkie.domain.PostLike; | ||
import com.whyranoid.walkie.domain.Walkie; | ||
import com.whyranoid.walkie.repository.querydsl.PostLikeRepositoryCustom; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
import java.util.List; | ||
|
||
public interface PostLikeRepository extends JpaRepository<PostLike, Long>, PostLikeRepositoryCustom { | ||
|
||
List<PostLike> findByPostAndLiker(Post post, Walkie liker); | ||
} |
11 changes: 11 additions & 0 deletions
11
src/main/java/com/whyranoid/walkie/repository/PostRepository.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,11 @@ | ||
package com.whyranoid.walkie.repository; | ||
|
||
import com.whyranoid.walkie.domain.Post; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
import java.util.Optional; | ||
|
||
public interface PostRepository extends JpaRepository<Post, Long> { | ||
|
||
Optional<Post> findByPostId(Long postId); | ||
} |
8 changes: 8 additions & 0 deletions
8
src/main/java/com/whyranoid/walkie/repository/querydsl/PostLikeRepositoryCustom.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,8 @@ | ||
package com.whyranoid.walkie.repository.querydsl; | ||
|
||
public interface PostLikeRepositoryCustom { | ||
|
||
Long findPostLikeCount(Long postId); | ||
|
||
// PostLikeDto findPostLikePeople(Long postId); | ||
} |
39 changes: 39 additions & 0 deletions
39
src/main/java/com/whyranoid/walkie/repository/querydsl/PostLikeRepositoryImpl.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,39 @@ | ||
package com.whyranoid.walkie.repository.querydsl; | ||
|
||
import com.querydsl.jpa.impl.JPAQueryFactory; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
import static com.whyranoid.walkie.domain.QPostLike.postLike; | ||
|
||
@RequiredArgsConstructor | ||
public class PostLikeRepositoryImpl implements PostLikeRepositoryCustom { | ||
|
||
private final JPAQueryFactory queryFactory; | ||
|
||
@Override | ||
public Long findPostLikeCount(Long postId) { | ||
return queryFactory | ||
.select(postLike) | ||
.from(postLike) | ||
.where(postLike.post.postId.eq(postId) | ||
.and(postLike.liker.isNotNull())) | ||
.stream().count(); | ||
} | ||
|
||
// @Override | ||
// public PostLikeDto findPostLikePeople(Long postId) { | ||
// return PostLikeDto.builder() | ||
// .postId(postId) | ||
// .likerCount(findPostLikeCount(postId)) | ||
// .likerProfiles(findLikerList(postId)) | ||
// .build(); | ||
// } | ||
// | ||
// public List<WalkieDto> findLikerList(Long postId) { | ||
// return queryFactory | ||
// .select(new QWalkieDto(postLike.liker)) | ||
// .from(postLike) | ||
// .where(postLike.post.postId.eq(postId)) | ||
// .fetch(); | ||
// } | ||
} |
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