Skip to content

Commit

Permalink
feat: completing get collection
Browse files Browse the repository at this point in the history
  • Loading branch information
anamikak005 committed Dec 15, 2024
1 parent 824f682 commit 20d9e63
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ maek
api_server
main
mysql_data
.DS_Store
.DS_Store
*.local.*
4 changes: 2 additions & 2 deletions domains/notes/find.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,10 +162,10 @@ func FindNoteByUuid(ctx context.Context, nuuid string, workspaceId uint64) (*Not
return &note, nil
}

func FindCollectionByID(ctx context.Context, id uint64, withNotes bool) (*Collection, error) {
func FindCollectionByID(ctx context.Context, wid uint64, id uint64, withNotes bool) (*Collection, error) {
var collection Collection
if err := db.WithOrmerCtx(ctx, func(ctx context.Context, ormer orm.Ormer) error {
err := ormer.QueryTable("collection").Filter("id", id).RelatedSel("CreatedBy", "UpdatedBy").One(&collection)
err := ormer.QueryTable("collection").Filter("workspace_id", wid).Filter("id", id).RelatedSel("CreatedBy", "UpdatedBy").One(&collection)
if err != nil {
return err
}
Expand Down
16 changes: 16 additions & 0 deletions routers/collections/get.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package collections

import (
"github.com/karngyan/maek/domains/notes"
"github.com/karngyan/maek/routers/models"
"net/http"
"strconv"

"github.com/karngyan/maek/routers/base"
Expand All @@ -25,4 +28,17 @@ func Get(ctx *base.WebContext) {
return
}

rctx := ctx.Request.Context()
c, err := notes.FindCollectionByID(rctx, wid, cid, true)
if err != nil {
base.NotFound(ctx, err)
return
}

uiC := models.ModelForCollection(c)

base.Respond(ctx, map[string]any{
"collection": uiC,
}, http.StatusOK)

}

0 comments on commit 20d9e63

Please sign in to comment.