From 20d9e6318951807be561b41949748da0c86ee9be Mon Sep 17 00:00:00 2001 From: Anamika <43814685+anamikak005@users.noreply.github.com> Date: Sun, 15 Dec 2024 22:16:15 +0530 Subject: [PATCH] feat: completing get collection --- .gitignore | 3 ++- domains/notes/find.go | 4 ++-- routers/collections/get.go | 16 ++++++++++++++++ 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 6bf1aa2..02c7e7f 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,5 @@ maek api_server main mysql_data -.DS_Store \ No newline at end of file +.DS_Store +*.local.* \ No newline at end of file diff --git a/domains/notes/find.go b/domains/notes/find.go index ea756a1..a4982b8 100644 --- a/domains/notes/find.go +++ b/domains/notes/find.go @@ -162,10 +162,10 @@ func FindNoteByUuid(ctx context.Context, nuuid string, workspaceId uint64) (*Not return ¬e, 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 } diff --git a/routers/collections/get.go b/routers/collections/get.go index d7a2936..cb0ac3d 100644 --- a/routers/collections/get.go +++ b/routers/collections/get.go @@ -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" @@ -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) + }