Add shared column to links

This commit is contained in:
Aaron Bieber 2022-12-21 19:21:40 -07:00
parent 98bc248ac0
commit 533432ca8b
4 changed files with 18 additions and 20 deletions

View File

@ -25,6 +25,7 @@ type Link struct {
Name string `json:"name"`
Clicked int64 `json:"clicked"`
LogoUrl string `json:"logo_url"`
Shared bool `json:"shared"`
}
type Owner struct {
@ -53,16 +54,6 @@ type PullRequestIgnore struct {
Repo string `json:"repo"`
}
type Todo struct {
OwnerID int64 `json:"owner_id"`
LinkID int64 `json:"link_id"`
CreatedAt time.Time `json:"created_at"`
CompletedAt sql.NullTime `json:"completed_at"`
Completed bool `json:"completed"`
Title string `json:"title"`
Body string `json:"body"`
}
type WatchItem struct {
ID int64 `json:"id"`
OwnerID int64 `json:"owner_id"`

View File

@ -34,8 +34,8 @@ func (q *Queries) AddIcon(ctx context.Context, arg AddIconParams) error {
}
const addLink = `-- name: AddLink :one
insert into links (owner_id, url, name, logo_url)
values (?, ?, ?, ?) returning id, owner_id, created_at, url, name, clicked, logo_url
insert into links (owner_id, url, name, logo_url, shared)
values (?, ?, ?, ?, ?) returning id, owner_id, created_at, url, name, clicked, logo_url, shared
`
type AddLinkParams struct {
@ -43,6 +43,7 @@ type AddLinkParams struct {
Url string `json:"url"`
Name string `json:"name"`
LogoUrl string `json:"logo_url"`
Shared bool `json:"shared"`
}
func (q *Queries) AddLink(ctx context.Context, arg AddLinkParams) (Link, error) {
@ -51,6 +52,7 @@ func (q *Queries) AddLink(ctx context.Context, arg AddLinkParams) (Link, error)
arg.Url,
arg.Name,
arg.LogoUrl,
arg.Shared,
)
var i Link
err := row.Scan(
@ -61,6 +63,7 @@ func (q *Queries) AddLink(ctx context.Context, arg AddLinkParams) (Link, error)
&i.Name,
&i.Clicked,
&i.LogoUrl,
&i.Shared,
)
return i, err
}
@ -257,7 +260,7 @@ func (q *Queries) GetAllIcons(ctx context.Context, ownerID int64) ([]Icon, error
}
const getAllLinks = `-- name: GetAllLinks :many
select id, owner_id, created_at, url, name, clicked, logo_url
select id, owner_id, created_at, url, name, clicked, logo_url, shared
from links
`
@ -278,6 +281,7 @@ func (q *Queries) GetAllLinks(ctx context.Context) ([]Link, error) {
&i.Name,
&i.Clicked,
&i.LogoUrl,
&i.Shared,
); err != nil {
return nil, err
}
@ -293,9 +297,9 @@ func (q *Queries) GetAllLinks(ctx context.Context) ([]Link, error) {
}
const getAllLinksForOwner = `-- name: GetAllLinksForOwner :many
select id, owner_id, created_at, url, name, clicked, logo_url
select id, owner_id, created_at, url, name, clicked, logo_url, shared
from links
where owner_id = ?
where owner_id = ? or shared = true
`
func (q *Queries) GetAllLinksForOwner(ctx context.Context, ownerID int64) ([]Link, error) {
@ -315,6 +319,7 @@ func (q *Queries) GetAllLinksForOwner(ctx context.Context, ownerID int64) ([]Lin
&i.Name,
&i.Clicked,
&i.LogoUrl,
&i.Shared,
); err != nil {
return nil, err
}
@ -497,7 +502,7 @@ func (q *Queries) GetIconByLinkID(ctx context.Context, arg GetIconByLinkIDParams
}
const getLinkByID = `-- name: GetLinkByID :one
select id, owner_id, created_at, url, name, clicked, logo_url from links where id = ?
select id, owner_id, created_at, url, name, clicked, logo_url, shared from links where id = ?
`
func (q *Queries) GetLinkByID(ctx context.Context, id int64) (Link, error) {
@ -511,6 +516,7 @@ func (q *Queries) GetLinkByID(ctx context.Context, id int64) (Link, error) {
&i.Name,
&i.Clicked,
&i.LogoUrl,
&i.Shared,
)
return i, err
}

View File

@ -29,15 +29,15 @@ where id = ?
-- name: GetAllLinksForOwner :many
select *
from links
where owner_id = ?;
where owner_id = ? or shared = true;
-- name: GetAllLinks :many
select *
from links;
-- name: AddLink :one
insert into links (owner_id, url, name, logo_url)
values (?, ?, ?, ?) returning *;
insert into links (owner_id, url, name, logo_url, shared)
values (?, ?, ?, ?, ?) returning *;
-- name: GetLinkByID :one
select * from links where id = ?;

View File

@ -31,7 +31,8 @@ create table links
url text not null unique,
name text not null,
clicked integer default 0 not null,
logo_url text not null
logo_url text not null,
shared bool default false not null
);
create table pull_requests
(