From ee62f3bef8a40adfe898d6300636faf751607441 Mon Sep 17 00:00:00 2001 From: LittleSheep Date: Fri, 26 Jul 2024 00:53:58 +0800 Subject: [PATCH] :sparkles: Better down vote author filter system --- go.mod | 6 +----- go.sum | 10 ---------- pkg/internal/server/api/recommendation_api.go | 15 ++++++++++----- 3 files changed, 11 insertions(+), 20 deletions(-) diff --git a/go.mod b/go.mod index ffd10a6..d0ed126 100644 --- a/go.mod +++ b/go.mod @@ -4,11 +4,8 @@ go 1.21.6 require ( git.solsynth.dev/hydrogen/dealer v0.0.0-20240716024524-cfb73fde1951 - git.solsynth.dev/hydrogen/paperclip v0.0.0-20240622051057-0f56dba45745 github.com/go-playground/validator/v10 v10.17.0 github.com/gofiber/fiber/v2 v2.52.4 - github.com/gofiber/template/html/v2 v2.1.1 - github.com/google/uuid v1.6.0 github.com/json-iterator/go v1.1.12 github.com/pemistahl/lingua-go v1.4.0 github.com/robfig/cron/v3 v3.0.1 @@ -31,8 +28,7 @@ require ( github.com/go-playground/locales v0.14.1 // indirect github.com/go-playground/universal-translator v0.18.1 // indirect github.com/go-sql-driver/mysql v1.7.1 // indirect - github.com/gofiber/template v1.8.3 // indirect - github.com/gofiber/utils v1.1.0 // indirect + github.com/google/uuid v1.6.0 // indirect github.com/hashicorp/consul/api v1.29.1 // indirect github.com/hashicorp/errwrap v1.1.0 // indirect github.com/hashicorp/go-cleanhttp v0.5.2 // indirect diff --git a/go.sum b/go.sum index fcade58..14f967f 100644 --- a/go.sum +++ b/go.sum @@ -1,9 +1,5 @@ -git.solsynth.dev/hydrogen/dealer v0.0.0-20240716024414-abba3b1c259d h1:cBDO9mJRz6BW3OXm14svCb+LtERp332nOmrfs6AKNQg= -git.solsynth.dev/hydrogen/dealer v0.0.0-20240716024414-abba3b1c259d/go.mod h1:eZwAwP7ahL7TO8GWBlYFYDdjlna+8zHYbDfNabnuUEU= git.solsynth.dev/hydrogen/dealer v0.0.0-20240716024524-cfb73fde1951 h1:RgZJK4PXhrjhUX75BclBCg2xfetMkswcMwMqfTBtryQ= git.solsynth.dev/hydrogen/dealer v0.0.0-20240716024524-cfb73fde1951/go.mod h1:eZwAwP7ahL7TO8GWBlYFYDdjlna+8zHYbDfNabnuUEU= -git.solsynth.dev/hydrogen/paperclip v0.0.0-20240622051057-0f56dba45745 h1:40BUsQMNXjqHyytkyF9py1HjTAWlRgO6R57YXUrHNy4= -git.solsynth.dev/hydrogen/paperclip v0.0.0-20240622051057-0f56dba45745/go.mod h1:FsQGSLTl0gvo+9Jmbot02S72suyF9tFTrzDj70Xhifo= github.com/DataDog/datadog-go v3.2.0+incompatible/go.mod h1:LButxg5PwREeZtORoXG3tL4fMGNddJ+vMq1mwgfaqoQ= github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= @@ -61,12 +57,6 @@ github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/me github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= github.com/gofiber/fiber/v2 v2.52.4 h1:P+T+4iK7VaqUsq2PALYEfBBo6bJZ4q3FP8cZ84EggTM= github.com/gofiber/fiber/v2 v2.52.4/go.mod h1:KEOE+cXMhXG0zHc9d8+E38hoX+ZN7bhOtgeF2oT6jrQ= -github.com/gofiber/template v1.8.3 h1:hzHdvMwMo/T2kouz2pPCA0zGiLCeMnoGsQZBTSYgZxc= -github.com/gofiber/template v1.8.3/go.mod h1:bs/2n0pSNPOkRa5VJ8zTIvedcI/lEYxzV3+YPXdBvq8= -github.com/gofiber/template/html/v2 v2.1.1 h1:QEy3O3EBkvwDthy5bXVGUseOyO6ldJoiDxlF4+MJiV8= -github.com/gofiber/template/html/v2 v2.1.1/go.mod h1:2G0GHHOUx70C1LDncoBpe4T6maQbNa4x1CVNFW0wju0= -github.com/gofiber/utils v1.1.0 h1:vdEBpn7AzIUJRhe+CiTOJdUcTg4Q9RK+pEa0KPbLdrM= -github.com/gofiber/utils v1.1.0/go.mod h1:poZpsnhBykfnY1Mc0KeEa6mSHrS3dV0+oBWyeQmb2e0= github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= github.com/golang-sql/civil v0.0.0-20220223132316-b832511892a9 h1:au07oEsX2xN0ktxqI+Sida1w446QrXBRJ0nee3SNZlA= github.com/golang-sql/civil v0.0.0-20220223132316-b832511892a9/go.mod h1:8vg3r2VgvsThLBIFL93Qb5yWzgyZWhEmBwUJWevAkK0= diff --git a/pkg/internal/server/api/recommendation_api.go b/pkg/internal/server/api/recommendation_api.go index 583567a..c45fdcd 100644 --- a/pkg/internal/server/api/recommendation_api.go +++ b/pkg/internal/server/api/recommendation_api.go @@ -12,10 +12,12 @@ func listRecommendationDefault(c *fiber.Ctx) error { take := c.QueryInt("take", 0) offset := c.QueryInt("offset", 0) realmId := c.QueryInt("realmId", 0) - maxDownVote := c.QueryInt("maxDownVote", 3) + maxDownVote := c.QueryInt("maxDownVote", 15) - tx := database.C.Joins("Author").Where("\"Author\".total_downvote <= ?", maxDownVote) - tx = services.FilterPostDraft(tx) + tx := services.FilterPostDraft(database.C) + if maxDownVote > 0 { + tx = tx.Joins("Author").Where("\"Author\".total_downvote - \"Author\".total_upvote <= ?", maxDownVote) + } if realmId > 0 { if realm, err := services.GetRealmWithExtID(uint(realmId)); err != nil { return fiber.NewError(fiber.StatusBadRequest, fmt.Sprintf("realm was not found: %v", err)) @@ -45,9 +47,12 @@ func listRecommendationShuffle(c *fiber.Ctx) error { take := c.QueryInt("take", 0) offset := c.QueryInt("offset", 0) realmId := c.QueryInt("realmId", 0) - maxDownVote := c.QueryInt("maxDownVote", 3) + maxDownVote := c.QueryInt("maxDownVote", 15) - tx := database.C.Joins("Author").Where("\"Author\".total_downvote <= ?", maxDownVote) + tx := services.FilterPostDraft(database.C) + if maxDownVote > 0 { + tx = tx.Joins("Author").Where("\"Author\".total_downvote - \"Author\".total_upvote <= ?", maxDownVote) + } tx = services.FilterPostDraft(tx) if realmId > 0 { if realm, err := services.GetRealmWithExtID(uint(realmId)); err != nil {