Skip to content

Commit

Permalink
Merge branch 'main' of github.com:basenana/friday into fix/param
Browse files Browse the repository at this point in the history
  • Loading branch information
zwwhdls committed Dec 9, 2024
2 parents ff0aa05 + 3fdbfb3 commit d038ba1
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 5 deletions.
53 changes: 49 additions & 4 deletions api/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"github.com/gin-gonic/gin"

"github.com/basenana/friday/pkg/models/doc"
"github.com/basenana/friday/pkg/utils"
)

func (s *HttpServer) store() gin.HandlerFunc {
Expand Down Expand Up @@ -145,13 +146,57 @@ func (s *HttpServer) filter() gin.HandlerFunc {
Source: c.Query("source"),
WebUrl: c.Query("webUrl"),
ParentID: c.Query("parentID"),
UnRead: unread,
Mark: mark,
Search: c.Query("search"),
HitsPerPage: int64(pageSize),
Page: int64(page),
Sort: sort,
Desc: desc,
Sort: c.DefaultQuery("sort", "createdAt"),
Desc: c.DefaultQuery("desc", "false") == "true",
}
createAtStart := c.Query("createAtStart")
if createAtStart != "" {
createAtStartTimestamp, err := strconv.Atoi(createAtStart)
if err != nil {
c.String(400, fmt.Sprintf("invalid createAtStart: %s", c.Query("page")))
return
}
docQuery.CreatedAtStart = utils.ToPtr(int64(createAtStartTimestamp))
}
createAtEnd := c.Query("createAtEnd")
if createAtEnd != "" {
createAtEndTimestamp, err := strconv.Atoi(createAtEnd)
if err != nil {
c.String(400, fmt.Sprintf("invalid createAtEnd: %s", c.Query("page")))
return
}
docQuery.ChangedAtEnd = utils.ToPtr(int64(createAtEndTimestamp))
}
updatedAtStart := c.Query("updatedAtStart")
if updatedAtStart != "" {
updatedAtStartTimestamp, err := strconv.Atoi(updatedAtStart)
if err != nil {
c.String(400, fmt.Sprintf("invalid updatedAtStart: %s", c.Query("page")))
return
}
docQuery.ChangedAtStart = utils.ToPtr(int64(updatedAtStartTimestamp))
}
updatedAtEnd := c.Query("updatedAtEnd")
if updatedAtEnd != "" {
updatedAtEndTimestamp, err := strconv.Atoi(updatedAtEnd)
if err != nil {
c.String(400, fmt.Sprintf("invalid updatedAtEnd: %s", c.Query("page")))
return
}
docQuery.ChangedAtEnd = utils.ToPtr(int64(updatedAtEndTimestamp))
}
fuzzyName := c.Query("fuzzyName")
if fuzzyName != "" {
docQuery.FuzzyName = &fuzzyName
}
if c.Query("unread") != "" {
docQuery.UnRead = utils.ToPtr(c.Query("unread") == "true")
}
if c.Query("mark") != "" {
docQuery.Mark = utils.ToPtr(c.Query("mark") == "true")
}
docs, err := s.chain.Search(c, docQuery.ToQuery(), docQuery.GetAttrQueries())
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion pkg/models/doc/document.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
var (
DocFilterableAttrs = []string{"namespace", "id", "entryId", "kind", "name", "source", "webUrl", "createdAt", "updatedAt"}
DocAttrFilterableAttrs = []string{"namespace", "entryId", "key", "id", "kind", "value"}
DocSortAttrs = []string{"createdAt", "updatedAt"}
DocSortAttrs = []string{"createdAt", "updatedAt", "name"}
)

type DocPtrInterface interface {
Expand Down
21 changes: 21 additions & 0 deletions pkg/utils/util.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
Copyright 2024 Friday Author.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package utils

func ToPtr[T any](t T) *T {
return &t
}

0 comments on commit d038ba1

Please sign in to comment.