-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[FEAT] 홈 API 구현 #34
[FEAT] 홈 API 구현 #34
Changes from 3 commits
48dba37
e4b5108
820a0b3
cbe830f
1d70eae
3e9dfed
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package org.sopt.lequuServer; | ||
|
||
import jakarta.annotation.PostConstruct; | ||
import jakarta.persistence.EntityManager; | ||
import lombok.RequiredArgsConstructor; | ||
import org.sopt.lequuServer.domain.book.model.Book; | ||
import org.sopt.lequuServer.domain.member.model.Member; | ||
import org.sopt.lequuServer.domain.member.model.SocialPlatform; | ||
import org.sopt.lequuServer.domain.note.model.Note; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@Component | ||
@RequiredArgsConstructor | ||
public class InitDb { | ||
private final InitService initService; | ||
|
||
@PostConstruct | ||
public void init() { | ||
initService.dbInit(); | ||
} | ||
|
||
@Component | ||
@Transactional | ||
@RequiredArgsConstructor | ||
static class InitService { | ||
|
||
private final EntityManager em; | ||
|
||
@Transactional | ||
public void dbInit() { | ||
Member member = Member.builder() | ||
.socialPlatform(SocialPlatform.KAKAO) | ||
.socialId("dwq4d1sa68xx1qw61") | ||
.build(); | ||
em.persist(member); | ||
|
||
for (int i = 0; i < 7; i++) { | ||
Book book = Book.builder() | ||
.uuid("dwq65d19asx6qw1c") | ||
.favoriteName(String.valueOf(i)) | ||
.favoriteImage("dqw84dsaac9q9") | ||
.title(String.valueOf(i)) | ||
.description("test") | ||
.backgroundColor(11) | ||
.member(member) | ||
.isPopular(true) | ||
.build(); | ||
em.persist(book); | ||
} | ||
|
||
Book book1 = Book.builder() | ||
.uuid("dwq65d19asx6qw1c") | ||
.favoriteName("test") | ||
.favoriteImage("dqw84dsaac9q9") | ||
.title("test") | ||
.description("test") | ||
.backgroundColor(11) | ||
.member(member) | ||
.isPopular(true) | ||
.build(); | ||
em.persist(book1); | ||
|
||
for (int i = 0; i < 7; i++) { | ||
Note note = Note.builder() | ||
.content(String.valueOf(i)) | ||
.background("back") | ||
.textColor(i) | ||
.member(member) | ||
.book(book1) | ||
.build(); | ||
em.persist(note); | ||
} | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,6 +38,8 @@ public class Book extends BaseTimeEntity { | |
|
||
private int backgroundColor; | ||
|
||
private boolean isPopular; | ||
|
||
@ManyToOne(fetch = FetchType.LAZY) | ||
@JoinColumn(name = "member_id") | ||
private Member member; | ||
|
@@ -57,18 +59,19 @@ public void addPostedSticker(PostedSticker postedSticker) { | |
} | ||
|
||
@Builder | ||
public Book(String uuid, String favoriteName, String favoriteImage, String title, String description, int backgroundColor, Member member) { | ||
public Book(String uuid, String favoriteName, String favoriteImage, String title, String description, int backgroundColor, Member member, boolean isPopular) { | ||
this.uuid = uuid; | ||
this.favoriteName = favoriteName; | ||
this.favoriteImage = favoriteImage; | ||
this.title = title; | ||
this.description = description; | ||
this.backgroundColor = backgroundColor; | ||
this.member = member; | ||
this.isPopular = isPopular; | ||
} | ||
|
||
public static Book of(String uuid, String favoriteName, String favoriteImage, String title, String description, int backgroundColor, Member member) { | ||
return new Book(uuid, favoriteName, favoriteImage, title, description, backgroundColor, member); | ||
public static Book of(String uuid, String favoriteName, String favoriteImage, String title, String description, int backgroundColor, Member member, boolean isPopular) { | ||
return new Book(uuid, favoriteName, favoriteImage, title, description, backgroundColor, member, isPopular); | ||
Comment on lines
+62
to
+74
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 필드 추가 확인했습니당~ |
||
} | ||
|
||
// TODO S3 테스트용, 추후 삭제 | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,13 @@ | ||
package org.sopt.lequuServer.domain.book.repository; | ||
|
||
import java.util.List; | ||
import org.sopt.lequuServer.domain.book.model.Book; | ||
import org.springframework.data.domain.PageRequest; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.data.jpa.repository.Query; | ||
import org.springframework.data.repository.query.Param; | ||
|
||
public interface BookRepository extends JpaRepository<Book, Long> { | ||
@Query(value = "select b from Book b where b.isPopular = :isPopular") | ||
List<Book> getAllByPopular(@Param("isPopular") Boolean isPopular, PageRequest pageRequest); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 와우 Paging 쓰는거 처음보는데, 신기하군뇨~~ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [P3] 혹시 여기 Book 뒤에 띄어쓰기 한번 더 들어간거 같은데 수정해주실 수 있나요~? |
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package org.sopt.lequuServer.domain.book.service; | ||
|
||
import java.util.List; | ||
import lombok.RequiredArgsConstructor; | ||
import org.sopt.lequuServer.domain.book.model.Book; | ||
import org.sopt.lequuServer.domain.book.repository.BookRepository; | ||
import org.springframework.data.domain.PageRequest; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class BookService { | ||
|
||
private final BookRepository bookRepository; | ||
|
||
public List<Book> getPopularBook() { | ||
return bookRepository.getAllByPopular(true, PageRequest.of(0, 6)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 오호 PageRequest에 대해 새롭게 알고갑니다 !!!! 😁 |
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package org.sopt.lequuServer.domain.common.dto.response; | ||
|
||
import org.sopt.lequuServer.domain.book.model.Book; | ||
|
||
public record PopularBookResponseDto( | ||
Long bookId, | ||
String bookUuid, | ||
String favoriteName, | ||
String favoriteImage | ||
) { | ||
public static PopularBookResponseDto of(Book book) { | ||
return new PopularBookResponseDto(book.getId(), book.getUuid(), book.getFavoriteName(), | ||
book.getFavoriteImage()); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,7 +10,8 @@ | |
@Getter | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
@Table(name = "note") | ||
public class Note extends BaseTimeEntity { | ||
public class | ||
Note extends BaseTimeEntity { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [P2] 여기 불필요한 엔터가 들어간 것 같아요! 수정 부탁드림당~ |
||
|
||
@Id | ||
@Column(name = "note_id") | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
InitDb 만드는거 귀찮은 작업인데,,, 맛있게 쓰겠습니다,,,