···
"github.com/Azure/go-autorest/autorest/to"
"github.com/bluesky-social/indigo/atproto/data"
8
+
"github.com/bluesky-social/indigo/atproto/syntax"
"github.com/haileyok/cocoon/internal/helpers"
"github.com/haileyok/cocoon/models"
"github.com/labstack/echo/v4"
14
+
type ComAtprotoRepoListRecordsRequest struct {
15
+
Repo string `query:"repo" validate:"required"`
16
+
Collection string `query:"collection" validate:"required,atproto-nsid"`
17
+
Limit int64 `query:"limit"`
18
+
Cursor string `query:"cursor"`
19
+
Reverse bool `query:"reverse"`
type ComAtprotoRepoListRecordsResponse struct {
Cursor *string `json:"cursor,omitempty"`
···
func (s *Server) handleListRecords(e echo.Context) error {
41
-
did := e.QueryParam("repo")
42
-
collection := e.QueryParam("collection")
43
-
cursor := e.QueryParam("cursor")
44
-
reverse := e.QueryParam("reverse")
49
+
var req ComAtprotoRepoListRecordsRequest
50
+
if err := e.Bind(&req); err != nil {
51
+
s.logger.Error("could not bind list records request", "error", err)
52
+
return helpers.ServerError(e, nil)
55
+
if err := e.Validate(req); err != nil {
56
+
return helpers.InputError(e, nil)
61
+
} else if req.Limit > 100 {
limit, err := getLimitFromContext(e, 50)
return helpers.InputError(e, nil)
···
54
-
if strings.ToLower(reverse) == "true" {
59
-
params := []any{did, collection}
61
-
params = append(params, cursor)
80
+
if _, err := syntax.ParseDID(did); err != nil {
81
+
actor, err := s.getActorByHandle(req.Repo)
83
+
return helpers.InputError(e, to.StringPtr("RepoNotFound"))
88
+
params := []any{did, req.Collection}
89
+
if req.Cursor != "" {
90
+
params = append(params, req.Cursor)
cursorquery = "AND created_at " + dir + " ?"
params = append(params, limit)