提交 bb151fb5 authored 作者: Whispa's avatar Whispa

commit

上级 0049994e
...@@ -294,6 +294,7 @@ public class OrderController extends Controller { ...@@ -294,6 +294,7 @@ public class OrderController extends Controller {
System.out.println(orderId); System.out.println(orderId);
repository.save(order); repository.save(order);
return new Result(); return new Result();
} }
......
...@@ -60,9 +60,11 @@ public class PostController { ...@@ -60,9 +60,11 @@ public class PostController {
@GetMapping("/listPosts") @GetMapping("/listPosts")
public List<Post> postList(@RequestParam(value = "userId", required = false) String id, @RequestParam(value = "pageNo") Integer pageNo, @RequestParam(value = "pageSize") Integer pageSize) { public List<Post> postList(@RequestParam(value = "userId", required = false) String id, @RequestParam(value = "pageNo") Integer pageNo, @RequestParam(value = "pageSize") Integer pageSize) {
//Optional<User> byId = userRepository.findById(id);
//if( !byId.isPresent() ) return new ArrayList<>(); Optional<TbCfUserInfo> byId = id == null ? Optional.empty() : userRepository.findById(id);
List<Post> postList = repository.findAllByOrderByCreateDateDesc(PageRequest.of(pageNo, pageSize)).toList(); List<Post> postList;
PageRequest of = PageRequest.of(pageNo, pageSize);
postList = byId.map(tbCfUserInfo -> repository.findAllByOrderByIdDesc(tbCfUserInfo, of).toList()).orElseGet(() -> repository.findAllByOrderByCreateDateDesc(of).toList());
return id == null ? postList : postList(postList, id); return id == null ? postList : postList(postList, id);
} }
......
...@@ -12,8 +12,8 @@ import org.springframework.data.repository.query.Param; ...@@ -12,8 +12,8 @@ import org.springframework.data.repository.query.Param;
public interface PostRepository extends PagingAndSortingRepository<Post, String> { public interface PostRepository extends PagingAndSortingRepository<Post, String> {
Page<Post> findAllByUserInfoUserIdOrderByCreateDateDesc(String tUser_userId, Pageable pageable); Page<Post> findAllByUserInfoUserIdOrderByCreateDateDesc(String tUser_userId, Pageable pageable);
Page<Post> findAllByDescriptionContainingOrTitleContainingOrUserInfoNickContaining(String query, String query1, String query2, Pageable pageable); Page<Post> findAllByDescriptionContainingOrTitleContainingOrUserInfoNickContaining(String query, String query1, String query2, Pageable pageable);
//@Query(value = "select a from #{#entityName} a WHERE EXISTS(SELECT f.follower FROM Following f WHERE f.follower=:me and f.followed=a.user)") @Query(value = "select a from #{#entityName} a WHERE EXISTS(SELECT f.follower FROM Following f WHERE f.followerInfo=:me and f.followedInfo=a.userInfo)")
//Page<Post> findAllByOrderByIdDesc(@Param("me") User user, Pageable pageable); Page<Post> findAllByOrderByIdDesc(@Param("me") TbCfUserInfo user, Pageable pageable);
@Query(value = "select a from #{#entityName} a WHERE a IN (SELECT x.post FROM PostLike x WHERE x.userInfo=:me) order by a.createDate desc") @Query(value = "select a from #{#entityName} a WHERE a IN (SELECT x.post FROM PostLike x WHERE x.userInfo=:me) order by a.createDate desc")
Page<Post> findAllByOrderByCreateDateDesc(@Param("me") TbCfUserInfo user, Pageable pageable); Page<Post> findAllByOrderByCreateDateDesc(@Param("me") TbCfUserInfo user, Pageable pageable);
@Query(value = "select a from #{#entityName} a WHERE a IN (SELECT x.post FROM PostHashtag x WHERE x.hashtag=:tag) order by a.createDate desc") @Query(value = "select a from #{#entityName} a WHERE a IN (SELECT x.post FROM PostHashtag x WHERE x.hashtag=:tag) order by a.createDate desc")
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论