Skip to content

Commit

Permalink
Merge pull request #286 from Jinvic/feat/memo
Browse files Browse the repository at this point in the history
置顶memo筛选处理
  • Loading branch information
xuewenG authored Feb 20, 2025
2 parents a149397 + 217049c commit 6ef0256
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 30 deletions.
2 changes: 0 additions & 2 deletions backend/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ require (
github.com/aokoli/goutils v1.0.1 // indirect
github.com/aymerick/douceur v0.2.0 // indirect
github.com/gorilla/css v1.0.1 // indirect
github.com/hbollon/go-edlib v1.6.0 // indirect
github.com/huandu/xstrings v1.2.0 // indirect
github.com/imdario/mergo v0.3.6 // indirect
github.com/jaytaylor/html2text v0.0.0-20180606194806-57d518f124b0 // indirect
Expand All @@ -46,7 +45,6 @@ require (
)

require (
github.com/AfterShip/email-verifier v1.4.1
github.com/BurntSushi/toml v1.4.0 // indirect
github.com/KyleBanks/depth v1.2.1 // indirect
github.com/andybalholm/cascadia v1.3.2 // indirect
Expand Down
8 changes: 0 additions & 8 deletions backend/go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
github.com/AfterShip/email-verifier v1.4.1 h1:vDmnqq680siSLw8rtiAYaqgmqYeW+AUoMfEY1RjWK8k=
github.com/AfterShip/email-verifier v1.4.1/go.mod h1:AcFyA5b7X6L4l5dBuemWBSh8mq74nxkBTtoWgLOFrbw=
github.com/BurntSushi/toml v1.2.1/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ=
github.com/BurntSushi/toml v1.4.0 h1:kuoIxZQy2WRRk1pttg9asf+WVv6tWQuBNVmK8+nqPr0=
github.com/BurntSushi/toml v1.4.0/go.mod h1:ukJfTF/6rtPPRCnwkur4qwRxa8vTRFBF0uk2lLoLwho=
Expand Down Expand Up @@ -100,10 +98,6 @@ github.com/gorilla/css v1.0.1 h1:ntNaBIghp6JmvWnxbZKANoLyuXTPZ4cAMlo6RyhlbO8=
github.com/gorilla/css v1.0.1/go.mod h1:BvnYkspnSzMmwRK+b8/xgNPLiIuNZr6vbZBTPQ2A3b0=
github.com/gorilla/feeds v1.2.0 h1:O6pBiXJ5JHhPvqy53NsjKOThq+dNFm8+DFrxBEdzSCc=
github.com/gorilla/feeds v1.2.0/go.mod h1:WMib8uJP3BbY+X8Szd1rA5Pzhdfh+HCCAYT2z7Fza6Y=
github.com/h2non/parth v0.0.0-20190131123155-b4df798d6542 h1:2VTzZjLZBgl62/EtslCrtky5vbi9dd7HrQPQIx6wqiw=
github.com/h2non/parth v0.0.0-20190131123155-b4df798d6542/go.mod h1:Ow0tF8D4Kplbc8s8sSb3V2oUCygFHVp8gC3Dn6U4MNI=
github.com/hbollon/go-edlib v1.6.0 h1:ga7AwwVIvP8mHm9GsPueC0d71cfRU/52hmPJ7Tprv4E=
github.com/hbollon/go-edlib v1.6.0/go.mod h1:wnt6o6EIVEzUfgbUZY7BerzQ2uvzp354qmS2xaLkrhM=
github.com/huandu/xstrings v1.2.0 h1:yPeWdRnmynF7p+lLYz0H2tthW9lqhMJrQV/U7yy4wX0=
github.com/huandu/xstrings v1.2.0/go.mod h1:DvyZB1rfVYsBIigL8HwpZgxHwXozlTgGqn63UyNX5k4=
github.com/ilyakaznacheev/cleanenv v1.5.0 h1:0VNZXggJE2OYdXE87bfSSwGxeiGt9moSR2lOrsHHvr4=
Expand Down Expand Up @@ -258,8 +252,6 @@ gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
gopkg.in/h2non/gock.v1 v1.1.2 h1:jBbHXgGBK/AoPVfJh5x4r/WxIrElvbLel8TCZkkZJoY=
gopkg.in/h2non/gock.v1 v1.1.2/go.mod h1:n7UGz/ckNChHiK05rDoiC4MYSunEC/lyaUm2WWaDva0=
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
Expand Down
23 changes: 3 additions & 20 deletions backend/handler/memo.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,6 @@ func (m MemoHandler) ListMemos(c echo.Context) error {
var (
req vo.ListMemoReq
list []db.Memo
pinnedList []db.Memo
total int64
sysConfig db.SysConfig
sysConfigVO vo.FullSysConfigVO
Expand All @@ -171,27 +170,22 @@ func (m MemoHandler) ListMemos(c echo.Context) error {
m.base.db.First(&sysConfig)
_ = json.Unmarshal([]byte(sysConfig.Content), &sysConfigVO)
offset := (req.Page - 1) * req.Size
totalCondition := m.base.db.Table("Memo").Where("pinned = 0")

tx := m.base.db.Preload("User", func(x *gorm.DB) *gorm.DB {
return x.Select("username", "nickname", "slogan", "id", "avatarUrl", "coverUrl")
}).Where("pinned = 0")
})

if req.Start != nil {
tx = tx.Where("createdAt >= ?", req.Start)
totalCondition = totalCondition.Where("createdAt >= ?", req.Start)
}
if req.End != nil {
tx = tx.Where("createdAt <= ?", req.End)
totalCondition = totalCondition.Where("createdAt <= ?", req.End)
}
if req.ContentContains != "" {
tx = tx.Where("content like ?", "%"+req.ContentContains+"%")
totalCondition = totalCondition.Where("content like ?", "%"+req.ContentContains+"%")
}
if req.ShowType != nil && *req.ShowType >= 0 {
tx = tx.Where("showType=?", req.ShowType)
totalCondition = totalCondition.Where("showType=?", req.ShowType)
}
if currentUser == nil {
tx = tx.Where("showType = 1")
Expand All @@ -203,11 +197,9 @@ func (m MemoHandler) ListMemos(c echo.Context) error {
tags := strings.Split(req.Tag, ",")
for _, tag := range tags {
tx = tx.Where("tags like ?", fmt.Sprintf("%%%s,%%", tag))
totalCondition = totalCondition.Where("tags like ?", fmt.Sprintf("%%%s,%%", tag))
}
} else {
tx = tx.Where("tags like ?", fmt.Sprintf("%%%s,%%", req.Tag))
totalCondition = totalCondition.Where("tags like ?", fmt.Sprintf("%%%s,%%", req.Tag))
}
}
if req.Username != "" {
Expand All @@ -216,21 +208,12 @@ func (m MemoHandler) ListMemos(c echo.Context) error {
return FailRespWithMsg(c, Fail, "不存在的用户")
}
tx = tx.Where("userId = ?", target.Id)
totalCondition = totalCondition.Where("userId = ?", target.Id)
}
if req.UserId != nil {
tx = tx.Where("userId = ?", req.UserId)
totalCondition = totalCondition.Where("userId = ?", req.UserId)
}
tx.Order("createdAt desc").Limit(req.Size).Offset(offset).Find(&list)
totalCondition.Count(&total)

if req.Page == 1 {
m.base.db.Preload("User", func(x *gorm.DB) *gorm.DB {
return x.Select("username", "nickname", "slogan", "id", "avatarUrl", "coverUrl")
}).Where("pinned = 1").Find(&pinnedList)
list = append(pinnedList, list...)
}
tx.Order("pinned desc, createdAt desc").Limit(req.Size).Offset(offset).Find(&list)
tx.Count(&total)

for i, memo := range list {
var comments []db.Comment
Expand Down

0 comments on commit 6ef0256

Please sign in to comment.