Skip to content
This repository has been archived by the owner on Oct 27, 2021. It is now read-only.

Commit

Permalink
Fix posts sorting
Browse files Browse the repository at this point in the history
  • Loading branch information
rb-de0 committed Oct 6, 2020
1 parent 323f0c9 commit 96d298f
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Sources/App/Controllers/Public/PostController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ final class PostController {

func index(request: Request) throws -> EventLoopFuture<View> {
return Post.query(on: request.db).publicAll().noStaticAll().withRelated()
.sort(\.$createdAt, .descending)
.paginate(for: request)
.flatMapThrowing { page -> PageResponse<Post.Public> in
let posts = try page.items.map { try $0.formPublic() }
Expand All @@ -44,6 +45,7 @@ final class PostController {
.unwrap(or: Abort(.notFound))
.flatMap { tag -> EventLoopFuture<View> in
tag.$posts.query(on: request.db).publicAll().noStaticAll().withRelated()
.sort(\.$createdAt, .descending)
.paginate(for: request)
.flatMapThrowing { page -> PageResponse<Post.Public> in
let posts = try page.items.map { try $0.formPublic() }
Expand All @@ -70,6 +72,7 @@ final class PostController {
.unwrap(or: Abort(.notFound))
.flatMap { category -> EventLoopFuture<View> in
category.$posts.query(on: request.db).publicAll().noStaticAll().withRelated()
.sort(\.$createdAt, .descending)
.paginate(for: request)
.flatMapThrowing { page -> PageResponse<Post.Public> in
let posts = try page.items.map { try $0.formPublic() }
Expand All @@ -90,6 +93,7 @@ final class PostController {

func indexNoCategory(request: Request) throws -> EventLoopFuture<View> {
return Post.query(on: request.db).publicAll().noCategoryAll().withRelated()
.sort(\.$createdAt, .descending)
.paginate(for: request)
.flatMapThrowing { page -> PageResponse<Post.Public> in
let posts = try page.items.map { try $0.formPublic() }
Expand Down

0 comments on commit 96d298f

Please sign in to comment.