Wooo API!

This commit is contained in:
2021-02-04 05:16:13 -05:00
parent c39fe6ec24
commit 082f923482
18 changed files with 977 additions and 795 deletions

View File

@@ -1,12 +1,13 @@
package model
import (
"net/http"
"net/http"
"github.com/lestrrat-go/jwx/jwt"
)
type AuthContext struct {
AccessToken string
RefreshToken string
AuthResponse *http.ResponseWriter
AuthRequest *http.Request
AccessToken *jwt.Token
AuthResponse *http.ResponseWriter
AuthRequest *http.Request
}

View File

@@ -1,36 +1,36 @@
package model
import (
"gorm.io/gorm"
"github.com/google/uuid"
"github.com/google/uuid"
"gorm.io/gorm"
)
func (u *User) BeforeCreate(tx *gorm.DB) (err error) {
newID := uuid.New().String()
u.ID = &newID
return
newID := uuid.New().String()
u.ID = newID
return
}
func (a *Album) BeforeCreate(tx *gorm.DB) (err error) {
newID := uuid.New().String()
a.ID = &newID
return
newID := uuid.New().String()
a.ID = newID
return
}
func (m *MediaItem) BeforeCreate(tx *gorm.DB) (err error) {
newID := uuid.New().String()
m.ID = &newID
return
newID := uuid.New().String()
m.ID = newID
return
}
func (t *Tag) BeforeCreate(tx *gorm.DB) (err error) {
newID := uuid.New().String()
t.ID = &newID
return
newID := uuid.New().String()
t.ID = newID
return
}
func (d *Device) BeforeCreate(tx *gorm.DB) (err error) {
newID := uuid.New().String()
d.ID = &newID
return
newID := uuid.New().String()
d.ID = newID
return
}

View File

@@ -12,7 +12,7 @@ import (
)
type Album struct {
ID *string `json:"id" gorm:"primarykey;not null"`
ID string `json:"id" gorm:"primaryKey;not null"`
CreatedAt *time.Time `json:"createdAt" `
UpdatedAt *time.Time `json:"updatedAt" `
Name string `json:"name" gorm:"unique;not null"`
@@ -34,6 +34,7 @@ type AlbumResponse struct {
type AuthResponse struct {
Result AuthResult `json:"Result" `
Device *Device `json:"Device" `
Error *string `json:"Error" `
}
@@ -50,12 +51,13 @@ type BooleanFilter struct {
}
type Device struct {
ID *string `json:"id" gorm:"primarykey;not null"`
ID string `json:"id" gorm:"primaryKey;not null"`
CreatedAt *time.Time `json:"createdAt" `
UpdatedAt *time.Time `json:"updatedAt" `
Name string `json:"name" gorm:"not null"`
Type DeviceType `json:"type" gorm:"default:Unknown;not null"`
User *User `json:"user" gorm:"ForeignKey:ID;not null"`
UserID string `json:"userID" gorm:"not null"`
User *User `json:"user" gorm:"foreignKey:ID;references:UserID;not null"`
RefreshKey *string `json:"refreshKey" `
}
@@ -111,7 +113,7 @@ type IntFilter struct {
}
type MediaItem struct {
ID *string `json:"id" gorm:"primarykey;not null"`
ID string `json:"id" gorm:"primaryKey;not null"`
CreatedAt *time.Time `json:"createdAt" `
UpdatedAt *time.Time `json:"updatedAt" `
ExifDate *time.Time `json:"exifDate" `
@@ -122,7 +124,8 @@ type MediaItem struct {
OrigName string `json:"origName" gorm:"not null"`
Tags []*Tag `json:"tags" gorm:"many2many:media_tags"`
Albums []*Album `json:"albums" gorm:"many2many:media_albums"`
User *User `json:"user" gorm:"ForeignKey:ID;not null"`
UserID string `json:"userID" gorm:"not null"`
User *User `json:"user" gorm:"foreignKey:ID;references:UserID;not null"`
}
type MediaItemFilter struct {
@@ -206,7 +209,7 @@ type StringFilter struct {
}
type Tag struct {
ID *string `json:"id" gorm:"primarykey;not null"`
ID string `json:"id" gorm:"primaryKey;not null"`
CreatedAt *time.Time `json:"createdAt" `
UpdatedAt *time.Time `json:"updatedAt" `
Name string `json:"name" gorm:"unique;not null"`
@@ -236,7 +239,7 @@ type TimeFilter struct {
}
type User struct {
ID *string `json:"id" gorm:"primarykey;not null"`
ID string `json:"id" gorm:"primaryKey;not null"`
CreatedAt *time.Time `json:"createdAt" `
UpdatedAt *time.Time `json:"updatedAt" `
Email string `json:"email" gorm:"not null;unique"`