delete short url

This commit is contained in:
kenneth
2023-12-25 17:31:07 +08:00
parent c1f4731669
commit ae060a2a37
10 changed files with 132 additions and 12 deletions

View File

@@ -17,6 +17,7 @@ type Querier interface {
GetUserByName(ctx context.Context, username string) (*User, error)
ListUrlByUser(ctx context.Context, userID string) ([]*UserRelateUrl, error)
ListUsers(ctx context.Context, arg *ListUsersParams) ([]*User, error)
UpdateStatus(ctx context.Context, arg *UpdateStatusParams) (*UserRelateUrl, error)
UpdateUser(ctx context.Context, arg *UpdateUserParams) (*User, error)
}

View File

@@ -6,6 +6,12 @@ INSERT INTO user_relate_url (
)
RETURNING *;
-- name: UpdateStatus :one
UPDATE user_relate_url
SET status = $2
WHERE short_url = $1
RETURNING *;
-- name: ListUrlByUser :many
SELECT *
FROM user_relate_url

View File

@@ -83,3 +83,30 @@ func (q *Queries) ListUrlByUser(ctx context.Context, userID string) ([]*UserRela
}
return items, nil
}
const updateStatus = `-- name: UpdateStatus :one
UPDATE user_relate_url
SET status = $2
WHERE short_url = $1
RETURNING id, user_id, short_url, origin_url, status, expire_at, created_at
`
type UpdateStatusParams struct {
ShortUrl string `json:"short_url"`
Status int32 `json:"status"`
}
func (q *Queries) UpdateStatus(ctx context.Context, arg *UpdateStatusParams) (*UserRelateUrl, error) {
row := q.db.QueryRowContext(ctx, updateStatus, arg.ShortUrl, arg.Status)
var i UserRelateUrl
err := row.Scan(
&i.ID,
&i.UserID,
&i.ShortUrl,
&i.OriginUrl,
&i.Status,
&i.ExpireAt,
&i.CreatedAt,
)
return &i, err
}