Skip to content

Commit

Permalink
Merge pull request SWYP-3-Reading-everywhere#114 from dltjdgh0428/dev
Browse files Browse the repository at this point in the history
refatoring: 상위 5개 태그를 가져오는 핀목록 Page->List
  • Loading branch information
dltjdgh0428 authored Mar 25, 2024
2 parents 6b9fc43 + 1bce4ed commit 4d6fbcd
Show file tree
Hide file tree
Showing 23 changed files with 169 additions and 86 deletions.
8 changes: 3 additions & 5 deletions src/main/java/com/book_everywhere/auth/entity/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@
import com.book_everywhere.tag.entity.Tagged;
import com.book_everywhere.pin.entity.Visit;
import jakarta.persistence.*;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.*;
import org.hibernate.annotations.CreationTimestamp;

import java.sql.Timestamp;
Expand All @@ -16,13 +13,14 @@

@Builder
@AllArgsConstructor
@NoArgsConstructor
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@Entity
@Getter
@Table(name = "users")
public class User {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "user_id")
private Long id;

@Builder.Default
Expand Down
8 changes: 3 additions & 5 deletions src/main/java/com/book_everywhere/book/entity/Book.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@
import com.book_everywhere.review.entity.Review;
import com.book_everywhere.auth.entity.User;
import jakarta.persistence.*;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.*;
import org.hibernate.annotations.CreationTimestamp;

import java.sql.Timestamp;
Expand All @@ -15,12 +12,13 @@

@Builder
@AllArgsConstructor
@NoArgsConstructor
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@Getter
@Entity
public class Book {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "book_id")
private Long id;

@Builder.Default
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import org.springframework.stereotype.Repository;

import java.util.List;
@Repository

public interface BookRepository extends JpaRepository<Book, Long> {

@Query("SELECT book FROM Book book JOIN book.reviews r WHERE r.user.socialId = :socialId")
Expand Down
8 changes: 3 additions & 5 deletions src/main/java/com/book_everywhere/pin/entity/Pin.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@
import com.book_everywhere.review.entity.Review;
import com.book_everywhere.tag.entity.Tagged;
import jakarta.persistence.*;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.*;
import org.hibernate.annotations.CreationTimestamp;

import java.sql.Timestamp;
Expand All @@ -15,12 +12,13 @@
@Getter
@Builder
@AllArgsConstructor
@NoArgsConstructor
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@Entity
public class Pin {

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

@Builder.Default
Expand Down
14 changes: 6 additions & 8 deletions src/main/java/com/book_everywhere/pin/entity/Visit.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,27 @@

import com.book_everywhere.auth.entity.User;
import jakarta.persistence.*;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.*;
import org.hibernate.annotations.CreationTimestamp;

import java.sql.Timestamp;

@Builder
@AllArgsConstructor
@NoArgsConstructor
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@Entity
@Getter
public class Visit {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "visit_id")
private Long id;
@ManyToOne
@JoinColumn(name = "userId")
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "user_id")
private User user;
@ManyToOne
@JoinColumn(name = "pinId")
@JoinColumn(name = "pin_id")
private Pin pin;

private boolean isPinPrivate;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

import java.util.List;

@Repository
public interface PinRepository extends JpaRepository<Pin, Long> {
// 유저 아이디를 넣으면 어디에 방믄했는지 모두 가져옴 -> 나만의 지도 기능
@Query("SELECT pin FROM Pin pin JOIN pin.visits visit WHERE visit.user.socialId = :socialId")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

import java.util.List;

@Repository
public interface VisitRepository extends JpaRepository<Visit, Long> {

//전체핀에서 몇명이 방문했는지 알려주는 쿼리
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,7 @@ public class PinServiceImpl implements PinService {
public List<PinWithTagCountRespDto> 핀의상위5개태그개수와함께조회() {
List<Pin> pins = pinRepository.findAll();
return pins.stream().map(pin -> {
PageRequest pageRequest = PageRequest.of(0, 5);
Page<Object[]> taggeds = taggedRepository.mCountByPinId(pin.getId(), pageRequest);
List<Object[]> taggeds = taggedRepository.mCountByPinId(pin.getId());
List<TagCountRespDto> tagCountRespDtos = taggeds.stream()
.map(tagged -> new TagCountRespDto(
(String) tagged[0],
Expand All @@ -96,8 +95,7 @@ public class PinServiceImpl implements PinService {
public List<PinWithTagCountRespDto> 공유또는개인핀의상위5개태그개수와함께조회(boolean pinIsPrivate) {
List<Pin> pins = pinRepository.mFindPinByIsPrivate(pinIsPrivate);
return pins.stream().map(pin -> {
PageRequest pageRequest = PageRequest.of(0, 5);
Page<Object[]> taggeds = taggedRepository.mCountByPinId(pin.getId(), pageRequest);
List<Object[]> taggeds = taggedRepository.mCountByPinId(pin.getId());
List<TagCountRespDto> tagCountRespDtos = taggeds.stream()
.map(tagged -> new TagCountRespDto(
(String) tagged[0],
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/com/book_everywhere/review/dto/ReviewDto.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package com.book_everywhere.review.dto;

import com.book_everywhere.pin.entity.Pin;
import com.book_everywhere.book.entity.Book;
import com.book_everywhere.review.entity.Review;
import lombok.AllArgsConstructor;
import lombok.Data;

Expand All @@ -16,4 +19,6 @@ public class ReviewDto {
private boolean isPrivate;
private Timestamp createdAt;
private Timestamp updatedAt;


}
16 changes: 16 additions & 0 deletions src/main/java/com/book_everywhere/review/dto/ReviewRespDto.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package com.book_everywhere.review.dto;

import com.book_everywhere.book.dto.BookRespDto;
import com.book_everywhere.book.entity.Book;
import com.book_everywhere.auth.entity.User;
import com.book_everywhere.pin.dto.PinRespDto;
import com.book_everywhere.pin.entity.Pin;
import com.book_everywhere.review.entity.Review;
import lombok.AllArgsConstructor;
import lombok.Data;

Expand All @@ -19,4 +23,16 @@ public class ReviewRespDto {
private BookRespDto bookRespDto;
private List<String> tags;
private String content;

public Review toEntity(Book book, Pin pin, User user){
return Review.builder()
.writer(writer)
.title(title)
.content(content)
.isPrivate(isPrivate)
.user(user)
.book(book)
.pin(pin)
.build();
}
}
20 changes: 9 additions & 11 deletions src/main/java/com/book_everywhere/review/entity/Review.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,36 +4,34 @@
import com.book_everywhere.book.entity.Book;
import com.book_everywhere.pin.entity.Pin;
import jakarta.persistence.*;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.*;
import org.hibernate.annotations.CreationTimestamp;
import org.hibernate.annotations.UpdateTimestamp;

import java.sql.Timestamp;

@Builder
@AllArgsConstructor
@NoArgsConstructor
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@Entity
@Getter
public class Review {

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

@ManyToOne
@JoinColumn(name = "bookId")
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "book_id")
private Book book;

@ManyToOne
@JoinColumn(name = "pinId")
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "pin_id")
private Pin pin;

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

@Column(nullable = false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

import java.util.List;

@Repository
public interface ReviewRepository extends JpaRepository<Review, Long> {

//공유 목록에서의 모든 독후감 조회
Expand Down
8 changes: 3 additions & 5 deletions src/main/java/com/book_everywhere/tag/entity/Category.java
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
package com.book_everywhere.tag.entity;

import jakarta.persistence.*;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.*;

import java.util.ArrayList;
import java.util.List;

@Entity
@AllArgsConstructor
@NoArgsConstructor
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@Builder
@Getter
public class Category {

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

@Builder.Default
Expand Down
12 changes: 5 additions & 7 deletions src/main/java/com/book_everywhere/tag/entity/Tag.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,28 @@
import com.book_everywhere.tag.entity.Category;
import com.book_everywhere.tag.entity.Tagged;
import jakarta.persistence.*;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.*;

import java.util.ArrayList;
import java.util.List;

@Getter
@Builder
@AllArgsConstructor
@NoArgsConstructor
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@Entity
public class Tag {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "tag_id")
private Long id;

@Builder.Default
@OneToMany(mappedBy = "tag",cascade = CascadeType.ALL)
private List<Tagged> tags = new ArrayList<>();

@ManyToOne
@JoinColumn(name = "categoryId")
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "category_id")
private Category category;

@Column(nullable = false, unique = true)
Expand Down
20 changes: 9 additions & 11 deletions src/main/java/com/book_everywhere/tag/entity/Tagged.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,32 @@
import com.book_everywhere.pin.entity.Pin;
import com.book_everywhere.auth.entity.User;
import jakarta.persistence.*;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.*;
import org.hibernate.annotations.CreationTimestamp;

import java.sql.Timestamp;

@Builder
@AllArgsConstructor
@NoArgsConstructor
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@Getter
@Entity
public class Tagged {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "tagged_id")
private Long id;

@ManyToOne
@JoinColumn(name = "pinId")
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "pin_id")
private Pin pin;

@ManyToOne
@JoinColumn(name = "tagId")
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "tag_id")
private Tag tag;

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

@CreationTimestamp
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

@Repository
public interface TagRepository extends JpaRepository<Tag, Long> {

// content를 통해 가져옴
Expand Down
Loading

0 comments on commit 4d6fbcd

Please sign in to comment.