From 27bafbdd899e05670949646f1ec99f59a6501297 Mon Sep 17 00:00:00 2001 From: Aaron Bieber Date: Sat, 24 Dec 2022 05:50:23 -0700 Subject: [PATCH] Don't require ownerID to get icons --- data/queries.sql.go | 12 +++--------- flake.nix | 2 +- handlers.go | 21 ++++++++++++--------- queries.sql | 3 +-- 4 files changed, 17 insertions(+), 21 deletions(-) diff --git a/data/queries.sql.go b/data/queries.sql.go index 4f40cd4..67568e8 100644 --- a/data/queries.sql.go +++ b/data/queries.sql.go @@ -482,17 +482,11 @@ func (q *Queries) GetAllWatchItemsByOwner(ctx context.Context, ownerID int64) ([ const getIconByLinkID = `-- name: GetIconByLinkID :one select owner_id, link_id, created_at, content_type, data from icons -where owner_id = ? - and link_id = ? +where link_id = ? ` -type GetIconByLinkIDParams struct { - OwnerID int64 `json:"owner_id"` - LinkID int64 `json:"link_id"` -} - -func (q *Queries) GetIconByLinkID(ctx context.Context, arg GetIconByLinkIDParams) (Icon, error) { - row := q.db.QueryRowContext(ctx, getIconByLinkID, arg.OwnerID, arg.LinkID) +func (q *Queries) GetIconByLinkID(ctx context.Context, linkID int64) (Icon, error) { + row := q.db.QueryRowContext(ctx, getIconByLinkID, linkID) var i Icon err := row.Scan( &i.OwnerID, diff --git a/flake.nix b/flake.nix index 62dc2b3..8da0a2f 100644 --- a/flake.nix +++ b/flake.nix @@ -19,7 +19,7 @@ in { gostart = pkgs.buildGoModule { pname = "gostart"; - version = "v0.1.6"; + version = "v0.1.7"; src = ./.; vendorSha256 = diff --git a/handlers.go b/handlers.go index 9c61b04..e9ef22e 100644 --- a/handlers.go +++ b/handlers.go @@ -54,11 +54,13 @@ func IconCacher(next http.Handler) http.Handler { func iconGET(w http.ResponseWriter, r *http.Request) { ctx := r.Context() - ownerID, ok := ctx.Value(ownerKey).(int64) - if !ok { - http.Error(w, http.StatusText(http.StatusUnprocessableEntity), http.StatusUnprocessableEntity) - return - } + /* + ownerID, ok := ctx.Value(ownerKey).(int64) + if !ok { + http.Error(w, http.StatusText(http.StatusUnprocessableEntity), http.StatusUnprocessableEntity) + return + } + */ linkID, err := strconv.Atoi(chi.URLParam(r, "linkID")) if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) @@ -71,10 +73,11 @@ func iconGET(w http.ResponseWriter, r *http.Request) { return } - icon, err := app.queries.GetIconByLinkID(ctx, data.GetIconByLinkIDParams{ - LinkID: int64(linkID), - OwnerID: ownerID, - }) + icon, err := app.queries.GetIconByLinkID(ctx, int64(linkID)) + if err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } if err != nil { size := 24 diff --git a/queries.sql b/queries.sql index 1249e36..d8b4d22 100644 --- a/queries.sql +++ b/queries.sql @@ -59,8 +59,7 @@ where owner_id = ?; -- name: GetIconByLinkID :one select * from icons -where owner_id = ? - and link_id = ?; +where link_id = ?; -- name: AddIcon :exec insert