mirror of
https://github.com/sbondCo/Watcharr.git
synced 2026-08-07 07:14:44 +00:00
Content and relations
This commit is contained in:
+4
-3
@@ -19,9 +19,10 @@ import (
|
||||
type User struct {
|
||||
bun.BaseModel `bun:"table:users"`
|
||||
|
||||
ID int `bun:"id,pk,autoincrement" json:"id"`
|
||||
Username string `bun:"username,notnull,unique" json:"username" binding:"required"`
|
||||
Password string `bun:"password,notnull" json:"password" binding:"required"`
|
||||
ID int `bun:"id,pk,autoincrement" json:"id"`
|
||||
Username string `bun:"username,notnull,unique" json:"username" binding:"required"`
|
||||
Password string `bun:"password,notnull" json:"password" binding:"required"`
|
||||
Lists []*List `bun:"rel:has-many,join:id=user_id"`
|
||||
}
|
||||
|
||||
type AuthResponse struct {
|
||||
|
||||
+10
-4
@@ -8,24 +8,30 @@ import (
|
||||
)
|
||||
|
||||
type Content struct {
|
||||
bun.BaseModel `bun:"table:content"`
|
||||
|
||||
ID int `bun:"id,pk,autoincrement" json:"id"`
|
||||
Type string `json:"-"`
|
||||
Name string `json:"name"`
|
||||
}
|
||||
|
||||
type List struct {
|
||||
bun.BaseModel `bun:"table:lists"`
|
||||
|
||||
ID int `bun:"id,pk,autoincrement" json:"id"`
|
||||
ImdbID int `bun:"imdb_id" json:"imdbId"`
|
||||
ID int `bun:"id,pk,autoincrement" json:"id"`
|
||||
Watched bool `bun:"watched" json:"watched"`
|
||||
UserID int `bun:"user_id" json:"-"`
|
||||
ContentID int
|
||||
Content *Content `bun:"rel:belongs-to,join:content_id=id" json:"content"`
|
||||
}
|
||||
|
||||
func getContent(db *bun.DB) List {
|
||||
ctx := context.TODO()
|
||||
list := new(List)
|
||||
err := db.NewSelect().Model(list).Where("id = ?", 1).Scan(ctx)
|
||||
err := db.NewSelect().Model(list).Relation("Content").Where("user_id = ?", 8).Scan(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
fmt.Println(list.ID)
|
||||
fmt.Println(list.ImdbID)
|
||||
return *list
|
||||
}
|
||||
|
||||
@@ -34,6 +34,7 @@ func main() {
|
||||
|
||||
// Create tables if they don't exist
|
||||
db.NewCreateTable().Model((*User)(nil)).IfNotExists().Exec(context.TODO())
|
||||
db.NewCreateTable().Model((*Content)(nil)).IfNotExists().Exec(context.TODO())
|
||||
db.NewCreateTable().Model((*List)(nil)).IfNotExists().Exec(context.TODO())
|
||||
|
||||
gin := gin.Default()
|
||||
|
||||
Reference in New Issue
Block a user