Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Better implementation of Bookmarks, using its own table
- Loading branch information
Showing
17 changed files
with
362 additions
and
186 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package migration | ||
|
||
import ( | ||
"database/sql" | ||
|
||
"github.com/pressly/goose" | ||
) | ||
|
||
func init() { | ||
goose.AddMigration(upCreateBookmarkTable, downCreateBookmarkTable) | ||
} | ||
|
||
func upCreateBookmarkTable(tx *sql.Tx) error { | ||
_, err := tx.Exec(` | ||
create table bookmark | ||
( | ||
user_id varchar(255) not null | ||
references user | ||
on update cascade on delete cascade, | ||
item_id varchar(255) not null, | ||
item_type varchar(255) not null, | ||
comment varchar(255), | ||
position integer, | ||
changed_by varchar(255), | ||
created_at datetime, | ||
updated_at datetime, | ||
constraint bookmark_pk | ||
unique (user_id, item_id, item_type) | ||
); | ||
create table playqueue_dg_tmp | ||
( | ||
id varchar(255) not null, | ||
user_id varchar(255) not null | ||
references user | ||
on update cascade on delete cascade, | ||
current varchar(255), | ||
position real, | ||
changed_by varchar(255), | ||
items varchar(255), | ||
created_at datetime, | ||
updated_at datetime | ||
); | ||
drop table playqueue; | ||
alter table playqueue_dg_tmp rename to playqueue; | ||
`) | ||
|
||
return err | ||
} | ||
|
||
func downCreateBookmarkTable(tx *sql.Tx) error { | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package model | ||
|
||
import "time" | ||
|
||
type Bookmarkable struct { | ||
BookmarkPosition int64 `json:"bookmarkPosition"` | ||
} | ||
|
||
type BookmarkableRepository interface { | ||
AddBookmark(id, comment string, position int64) error | ||
DeleteBookmark(id string) error | ||
GetBookmarks() (Bookmarks, error) | ||
} | ||
|
||
type Bookmark struct { | ||
Item MediaFile `json:"item"` | ||
Comment string `json:"comment"` | ||
Position int64 `json:"position"` | ||
ChangedBy string `json:"changed_by"` | ||
CreatedAt time.Time `json:"createdAt"` | ||
UpdatedAt time.Time `json:"updatedAt"` | ||
} | ||
|
||
type Bookmarks []Bookmark | ||
|
||
// While I can't find a better way to make these fields optional in the models, I keep this list here | ||
// to be used in other packages | ||
var BookmarkFields = []string{"bookmarkPosition"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.