Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
wellbeing-dough committed Oct 5, 2023
2 parents d2b0662 + a9426c6 commit 819690d
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 108 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@

public interface UserRepositoryCustom {

Slice<FindPostResponseByAll> findMyPost(Long userId, Pageable pageable);
// Slice<FindPostResponseByAll> findMyPost(Long userId, Pageable pageable);

}
Original file line number Diff line number Diff line change
@@ -1,52 +1,52 @@
package kr.co.studyhubinu.studyhubserver.user.repository;


import com.querydsl.core.types.Projections;
import com.querydsl.jpa.impl.JPAQuery;
import com.querydsl.jpa.impl.JPAQueryFactory;
import kr.co.studyhubinu.studyhubserver.study.domain.QStudyPostEntity;
import kr.co.studyhubinu.studyhubserver.study.dto.response.FindPostResponseByAll;
import kr.co.studyhubinu.studyhubserver.userstudy.domain.QUserPostEntity;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Slice;
import org.springframework.data.domain.SliceImpl;
import org.springframework.stereotype.Repository;

import java.util.List;

import static kr.co.studyhubinu.studyhubserver.study.domain.QStudyPostEntity.studyPostEntity;
import static kr.co.studyhubinu.studyhubserver.userstudy.domain.QUserPostEntity.*;

@Repository
@RequiredArgsConstructor
public class UserRepositoryImpl implements UserRepositoryCustom {

private final JPAQueryFactory jpaQueryFactory;

@Override
public Slice<FindPostResponseByAll> findMyPost(Long userId, Pageable pageable) {
QStudyPostEntity post = studyPostEntity;
QUserPostEntity userPost = userPostEntity;

JPAQuery<FindPostResponseByAll> studyPostDto = jpaQueryFactory
.select(Projections.constructor(FindPostResponseByAll.class,
post.id, post.major, post.title, post.content, post.studyPerson, post.studyPerson, post.close))
.from(post)
.where(userPost.id.eq(userId), post.id.eq(userPost.id))
.orderBy(post.createdDate.desc())
.offset(pageable.getOffset())
.limit(pageable.getPageSize() + 1);

return toSlice(pageable, studyPostDto.fetch());

}

public static <T> Slice<T> toSlice(final Pageable pageable, final List<T> items) {
if (items.size() > pageable.getPageSize()) {
items.remove(items.size()-1);
return new SliceImpl<>(items, pageable, true);
}
return new SliceImpl<>(items, pageable, false);
}
}
//package kr.co.studyhubinu.studyhubserver.user.repository;
//
//
//import com.querydsl.core.types.Projections;
//import com.querydsl.jpa.impl.JPAQuery;
//import com.querydsl.jpa.impl.JPAQueryFactory;
//import kr.co.studyhubinu.studyhubserver.study.domain.QStudyPostEntity;
//import kr.co.studyhubinu.studyhubserver.study.dto.response.FindPostResponseByAll;
//import kr.co.studyhubinu.studyhubserver.userstudy.domain.QUserPostEntity;
//import lombok.RequiredArgsConstructor;
//import org.springframework.data.domain.Pageable;
//import org.springframework.data.domain.Slice;
//import org.springframework.data.domain.SliceImpl;
//import org.springframework.stereotype.Repository;
//
//import java.util.List;
//
//import static kr.co.studyhubinu.studyhubserver.study.domain.QStudyPostEntity.studyPostEntity;
//import static kr.co.studyhubinu.studyhubserver.userstudy.domain.QUserPostEntity.*;
//
//@Repository
//@RequiredArgsConstructor
//public class UserRepositoryImpl implements UserRepositoryCustom {
//
// private final JPAQueryFactory jpaQueryFactory;
//
// @Override
// public Slice<FindPostResponseByAll> findMyPost(Long userId, Pageable pageable) {
// QStudyPostEntity post = studyPostEntity;
// QUserPostEntity userPost = userPostEntity;
//
// JPAQuery<FindPostResponseByAll> studyPostDto = jpaQueryFactory
// .select(Projections.constructor(FindPostResponseByAll.class,
// post.id, post.major, post.title, post.content, post.studyPerson, post.studyPerson, post.close))
// .from(post)
// .where(userPost.id.eq(userId), post.id.eq(userPost.id))
// .orderBy(post.createdDate.desc())
// .offset(pageable.getOffset())
// .limit(pageable.getPageSize() + 1);
//
// return toSlice(pageable, studyPostDto.fetch());
//
// }
//
// public static <T> Slice<T> toSlice(final Pageable pageable, final List<T> items) {
// if (items.size() > pageable.getPageSize()) {
// items.remove(items.size()-1);
// return new SliceImpl<>(items, pageable, true);
// }
// return new SliceImpl<>(items, pageable, false);
// }
//}
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ public void updatePassword(UpdatePasswordInfo info) {
}

public Slice<FindPostResponseByAll> findUserPost(Long userId, Pageable pageable) {
return userRepository.findMyPost(userId, pageable);
// return userRepository.findMyPost(userId, pageable);
return null;
}
}
1 change: 1 addition & 0 deletions src/main/resources/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ DROP TABLE if EXISTS post;
DROP TABLE if EXISTS study;
DROP TABLE if EXISTS alarm;
DROP TABLE if EXISTS bookmark;
DROP TABLE if EXISTS user_study;

CREATE TABLE users
(
Expand Down

0 comments on commit 819690d

Please sign in to comment.