mirror of
https://codeberg.org/shroff/phylum.git
synced 2026-01-06 03:31:02 -06:00
[server][core] Bookmark delete
This commit is contained in:
@@ -72,9 +72,8 @@ func handleBookmarksRemoveRoute(c *gin.Context) {
|
||||
id := uuid.MustParse(idStr)
|
||||
|
||||
u := auth.GetUser(c)
|
||||
b, err := user.CreateManager(c.Request.Context()).RemoveBookmark(u, id)
|
||||
if err != nil {
|
||||
if err := user.CreateManager(c.Request.Context()).RemoveBookmark(u, id); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
c.JSON(200, b)
|
||||
c.JSON(200, gin.H{})
|
||||
}
|
||||
|
||||
@@ -57,7 +57,7 @@ func setupBookmarksRemoveCommand() *cobra.Command {
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
if _, err := user.CreateManager(context.Background()).RemoveBookmark(common.User(cmd), r.ID()); err != nil {
|
||||
if err := user.CreateManager(context.Background()).RemoveBookmark(common.User(cmd), r.ID()); err != nil {
|
||||
fmt.Println("unable to remove bookmark: " + err.Error())
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
@@ -59,31 +59,6 @@ func (q *Queries) AddBookmark(ctx context.Context, arg AddBookmarkParams) (Bookm
|
||||
return i, err
|
||||
}
|
||||
|
||||
const deleteBookmark = `-- name: DeleteBookmark :one
|
||||
DELETE FROM bookmarks WHERE username = $1::TEXT AND resource_id = $2::UUID
|
||||
RETURNING username, resource_id, name, dir, created, modified, deleted
|
||||
`
|
||||
|
||||
type DeleteBookmarkParams struct {
|
||||
Username string
|
||||
ResourceID uuid.UUID
|
||||
}
|
||||
|
||||
func (q *Queries) DeleteBookmark(ctx context.Context, arg DeleteBookmarkParams) (Bookmark, error) {
|
||||
row := q.db.QueryRow(ctx, deleteBookmark, arg.Username, arg.ResourceID)
|
||||
var i Bookmark
|
||||
err := row.Scan(
|
||||
&i.Username,
|
||||
&i.ResourceID,
|
||||
&i.Name,
|
||||
&i.Dir,
|
||||
&i.Created,
|
||||
&i.Modified,
|
||||
&i.Deleted,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const listBookmarks = `-- name: ListBookmarks :many
|
||||
SELECT username, resource_id, name, dir, created, modified, deleted FROM bookmarks b WHERE username = $1::TEXT AND modified > $2::TIMESTAMP
|
||||
`
|
||||
|
||||
@@ -1,45 +0,0 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.26.0
|
||||
// source: publink.sql
|
||||
|
||||
package db
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
)
|
||||
|
||||
const createPublink = `-- name: CreatePublink :exec
|
||||
INSERT INTO publinks(name, created_by, root, password_hash, expires, max_accesses) VALUES(
|
||||
$1::text,
|
||||
$2::text,
|
||||
$3::uuid,
|
||||
$4::text,
|
||||
$5::timestamp,
|
||||
$6::int
|
||||
)
|
||||
`
|
||||
|
||||
type CreatePublinkParams struct {
|
||||
Name string
|
||||
CreatedBy string
|
||||
Root uuid.UUID
|
||||
PasswordHash string
|
||||
Expires pgtype.Timestamp
|
||||
MaxAccesses int32
|
||||
}
|
||||
|
||||
func (q *Queries) CreatePublink(ctx context.Context, arg CreatePublinkParams) error {
|
||||
_, err := q.db.Exec(ctx, createPublink,
|
||||
arg.Name,
|
||||
arg.CreatedBy,
|
||||
arg.Root,
|
||||
arg.PasswordHash,
|
||||
arg.Expires,
|
||||
arg.MaxAccesses,
|
||||
)
|
||||
return err
|
||||
}
|
||||
@@ -6,7 +6,6 @@ import (
|
||||
"github.com/google/uuid"
|
||||
"github.com/jackc/pgx/v5"
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
"github.com/shroff/phylum/server/internal/core/db"
|
||||
"github.com/shroff/phylum/server/internal/core/util/crypt"
|
||||
)
|
||||
|
||||
@@ -65,14 +64,11 @@ func (r Resource) CreatePublink(name, password string, duration time.Duration, a
|
||||
}
|
||||
}
|
||||
|
||||
return r.f.db.CreatePublink(r.f.ctx, db.CreatePublinkParams{
|
||||
Name: name,
|
||||
CreatedBy: r.f.username,
|
||||
Root: r.ID(),
|
||||
PasswordHash: passwordHash,
|
||||
Expires: expires,
|
||||
MaxAccesses: int32(accesses),
|
||||
})
|
||||
const q = `INSERT INTO publinks(name, created_by, root, password_hash, expires, max_accesses) VALUES
|
||||
($1::text, $2::text, $3::uuid, $4::text, $5::timestamp, $6::int)`
|
||||
|
||||
_, err := r.f.db.Exec(r.f.ctx, q, name, r.f.username, r.ID(), passwordHash, expires, accesses)
|
||||
return err
|
||||
}
|
||||
|
||||
func (r Resource) ListPublinks() ([]Publink, error) {
|
||||
|
||||
@@ -36,14 +36,10 @@ func (m manager) AddBookmark(u User, resource fs.Resource, name string) (Bookmar
|
||||
}
|
||||
}
|
||||
|
||||
func (m manager) RemoveBookmark(u User, id uuid.UUID) (Bookmark, error) {
|
||||
if b, err := m.db.Queries.DeleteBookmark(m.ctx, db.DeleteBookmarkParams{Username: u.Username, ResourceID: id}); err != nil {
|
||||
return Bookmark{}, err
|
||||
} else {
|
||||
r := bookmarkFromDb(b)
|
||||
r.Deleted = true
|
||||
return r, nil
|
||||
}
|
||||
func (m manager) RemoveBookmark(u User, id uuid.UUID) error {
|
||||
const q = "DELETE FROM bookmarks WHERE username = $1::TEXT AND resource_id = $2::UUID"
|
||||
_, err := m.db.Exec(m.ctx, q, u.Username, id)
|
||||
return err
|
||||
}
|
||||
|
||||
func (m manager) ListBookmarks(u User, since *time.Time) ([]Bookmark, error) {
|
||||
|
||||
@@ -44,7 +44,7 @@ type Manager interface {
|
||||
|
||||
// bookmarks.go
|
||||
AddBookmark(u User, resource fs.Resource, name string) (Bookmark, error)
|
||||
RemoveBookmark(u User, id uuid.UUID) (Bookmark, error)
|
||||
RemoveBookmark(u User, id uuid.UUID) error
|
||||
ListBookmarks(u User, since *time.Time) ([]Bookmark, error)
|
||||
|
||||
// shared.go
|
||||
|
||||
@@ -17,9 +17,5 @@ SET
|
||||
name = @name::TEXT
|
||||
RETURNING *;
|
||||
|
||||
-- name: DeleteBookmark :one
|
||||
DELETE FROM bookmarks WHERE username = @username::TEXT AND resource_id = @resource_id::UUID
|
||||
RETURNING *;
|
||||
|
||||
-- name: ListBookmarks :many
|
||||
SELECT * FROM bookmarks b WHERE username = @username::TEXT AND modified > @since::TIMESTAMP;
|
||||
|
||||
@@ -1,9 +0,0 @@
|
||||
-- name: CreatePublink :exec
|
||||
INSERT INTO publinks(name, created_by, root, password_hash, expires, max_accesses) VALUES(
|
||||
@name::text,
|
||||
@created_by::text,
|
||||
@root::uuid,
|
||||
@password_hash::text,
|
||||
sqlc.narg('expires')::timestamp,
|
||||
@max_accesses::int
|
||||
);
|
||||
Reference in New Issue
Block a user