feat(tag): draft for inline editing
Some checks failed
Build and Push Docker Image / Build-And-Push-Docker-Image (push) Failing after 1m15s
Some checks failed
Build and Push Docker Image / Build-And-Push-Docker-Image (push) Failing after 1m15s
This commit is contained in:
@@ -15,6 +15,7 @@ type Db interface {
|
||||
delete(ctx context.Context, userId uuid.UUID, id uuid.UUID) error
|
||||
get(ctx context.Context, userId uuid.UUID, id uuid.UUID) (*Tag, error)
|
||||
getAll(ctx context.Context, userId uuid.UUID) ([]Tag, error)
|
||||
find(ctx context.Context, userId uuid.UUID, search string) ([]Tag, error)
|
||||
}
|
||||
|
||||
type DbSqlite struct {
|
||||
@@ -73,7 +74,7 @@ func (db DbSqlite) delete(ctx context.Context, userId uuid.UUID, id uuid.UUID) e
|
||||
|
||||
func (db DbSqlite) get(ctx context.Context, userId uuid.UUID, id uuid.UUID) (*Tag, error) {
|
||||
var tag Tag
|
||||
err := db.db.Get(&tag, "SELECT * FROM tag WHERE id = ? AND user_id = ?", id, userId)
|
||||
err := db.db.GetContext(ctx, &tag, "SELECT * FROM tag WHERE id = ? AND user_id = ?", id, userId)
|
||||
|
||||
if err != nil {
|
||||
slog.ErrorContext(ctx, "Could not get tag", "err", err)
|
||||
@@ -85,7 +86,7 @@ func (db DbSqlite) get(ctx context.Context, userId uuid.UUID, id uuid.UUID) (*Ta
|
||||
|
||||
func (db DbSqlite) getAll(ctx context.Context, userId uuid.UUID) ([]Tag, error) {
|
||||
var tags []Tag
|
||||
err := db.db.Select(&tags, "SELECT * FROM tag WHERE user_id = ?", userId)
|
||||
err := db.db.SelectContext(ctx, &tags, "SELECT * FROM tag WHERE user_id = ?", userId)
|
||||
|
||||
if err != nil {
|
||||
slog.ErrorContext(ctx, "Could not GetAll tag", "err", err)
|
||||
@@ -94,3 +95,17 @@ func (db DbSqlite) getAll(ctx context.Context, userId uuid.UUID) ([]Tag, error)
|
||||
|
||||
return tags, nil
|
||||
}
|
||||
|
||||
func (db DbSqlite) find(ctx context.Context, userId uuid.UUID, search string) ([]Tag, error) {
|
||||
var tags []Tag
|
||||
err := db.db.SelectContext(ctx, &tags, "SELECT * FROM tag WHERE user_id = ? AND name LIKE ?", userId, "%"+search+"%")
|
||||
|
||||
slog.InfoContext(ctx, "find", "len", len(tags), "search", search)
|
||||
|
||||
if err != nil {
|
||||
slog.ErrorContext(ctx, "Could not find tag", "err", err)
|
||||
return nil, core.ErrInternal
|
||||
}
|
||||
|
||||
return tags, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user