Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add name col/field to bookmarks api endpoints #144

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions db/data.sql
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ CREATE TABLE public.bookmarks (
identifier character varying,
date_value timestamp without time zone,
id_value integer,
name character varying,
created_at timestamp without time zone NOT NULL,
updated_at timestamp without time zone NOT NULL
);
Expand Down
2 changes: 2 additions & 0 deletions internal/bookmarks/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ func (m *Manager) Submit(w http.ResponseWriter, r *http.Request) {
ServiceID: bookmark.ServiceID,
ResourceID: bookmark.ResourceID,
UserID: bookmark.UserID,
Name: bookmark.Name,
}

err = m.DbClient.SubmitBookmark(dbBookmark)
Expand Down Expand Up @@ -130,6 +131,7 @@ func (m *Manager) Update(w http.ResponseWriter, r *http.Request) {
ServiceID: bookmark.ServiceID,
ResourceID: bookmark.ResourceID,
UserID: bookmark.UserID,
Name: bookmark.Name,
}

err = m.DbClient.UpdateBookmark(dbBookmark)
Expand Down
2 changes: 2 additions & 0 deletions internal/bookmarks/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ type Bookmark struct {
ServiceID *int `json:"service_id"`
ResourceID *int `json:"resource_id"`
UserID *int `json:"user_id"`
Name string `json:"name"`
}

type Bookmarks struct {
Expand All @@ -23,6 +24,7 @@ func FromDBType(dbBookmark *db.Bookmark) *Bookmark {
ResourceID: dbBookmark.ResourceID,
UserID: dbBookmark.UserID,
FolderID: dbBookmark.FolderID,
Name: dbBookmark.Name,
}
return bookmark
}
Expand Down
23 changes: 11 additions & 12 deletions internal/db/bookmarks.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,26 @@ type Bookmark struct {
ServiceID *int
ResourceID *int
UserID *int
Name string
CreatedAt sql.NullTime
UpdatedAt sql.NullTime
}

const findBookmarksSql = `
SELECT id, "order", user_id, folder_id, service_id, resource_id from public.bookmarks`
SELECT id, "order", user_id, folder_id, service_id, resource_id, name from public.bookmarks`

const findBookmarksByUserIDSql = `
SELECT id, "order", user_id, folder_id, service_id, resource_id from public.bookmarks
WHERE user_id=$1`
SELECT id, "order", user_id, folder_id, service_id, resource_id, name from public.bookmarks WHERE user_id=$1`

const findBookmarksByIDSql = `
SELECT id, "order", user_id, folder_id, service_id, resource_id from public.bookmarks
WHERE id=$1`
SELECT id, "order", user_id, folder_id, service_id, resource_id, name from public.bookmarks WHERE id=$1`

const submitBookmark = `
INSERT INTO public.bookmarks ("order", user_id, folder_id, resource_id, service_id, created_at, updated_at)
VALUES ($1, $2, $3, $4, $5, now(), now())`
INSERT INTO public.bookmarks ("order", user_id, folder_id, resource_id, service_id, name, created_at, updated_at)
VALUES ($1, $2, $3, $4, $5, $6, now(), now())`

const updateBookmark = `
UPDATE public.bookmarks SET "order" = $2, user_id = $3, folder_id= $4, resource_id = $5, service_id = $6 where id = $1`
UPDATE public.bookmarks SET "order" = $2, user_id = $3, folder_id= $4, resource_id = $5, service_id = $6, name = $7 where id = $1`

const deleteBookmarkByIDSql = `
DELETE FROM public.bookmarks WHERE id = $1
Expand Down Expand Up @@ -77,7 +76,7 @@ func (m *Manager) SubmitBookmark(bookmark *Bookmark) error {
if err != nil {
return err
}
res, err := tx.Exec(submitBookmark, bookmark.Order, bookmark.UserID, bookmark.FolderID, bookmark.ResourceID, bookmark.ServiceID)
res, err := tx.Exec(submitBookmark, bookmark.Order, bookmark.UserID, bookmark.FolderID, bookmark.ResourceID, bookmark.ServiceID, bookmark.Name)
if err != nil {
return err
}
Expand All @@ -99,7 +98,7 @@ func (m *Manager) UpdateBookmark(bookmark *Bookmark) error {
if err != nil {
return err
}
res, err := tx.Exec(updateBookmark, bookmark.Id, bookmark.Order, bookmark.UserID, bookmark.FolderID, bookmark.ResourceID, bookmark.ServiceID)
res, err := tx.Exec(updateBookmark, bookmark.Id, bookmark.Order, bookmark.UserID, bookmark.FolderID, bookmark.ResourceID, bookmark.ServiceID, bookmark.Name)
if err != nil {
return err
}
Expand Down Expand Up @@ -140,7 +139,7 @@ func scanBookmarks(rows *sql.Rows) []*Bookmark {
var bookmarks []*Bookmark
for rows.Next() {
var bookmark Bookmark
err := rows.Scan(&bookmark.Id, &bookmark.Order, &bookmark.UserID, &bookmark.FolderID, &bookmark.ServiceID, &bookmark.ResourceID)
err := rows.Scan(&bookmark.Id, &bookmark.Order, &bookmark.UserID, &bookmark.FolderID, &bookmark.ServiceID, &bookmark.ResourceID, &bookmark.Name)
switch err {
case sql.ErrNoRows:
fmt.Println("No rows were returned!")
Expand All @@ -153,6 +152,6 @@ func scanBookmarks(rows *sql.Rows) []*Bookmark {

func scanBookmark(row *sql.Row) (*Bookmark, error) {
var bookmark Bookmark
err := row.Scan(&bookmark.Id, &bookmark.Order, &bookmark.UserID, &bookmark.FolderID, &bookmark.ServiceID, &bookmark.ResourceID)
err := row.Scan(&bookmark.Id, &bookmark.Order, &bookmark.UserID, &bookmark.FolderID, &bookmark.ServiceID, &bookmark.ResourceID, &bookmark.Name)
return &bookmark, err
}
Loading