Initial Commit
This commit is contained in:
13
graph/model/models_auth.go
Normal file
13
graph/model/models_auth.go
Normal file
@@ -0,0 +1,13 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/lestrrat-go/jwx/jwt"
|
||||
)
|
||||
|
||||
type AuthContext struct {
|
||||
AccessToken *jwt.Token
|
||||
AuthResponse *http.ResponseWriter
|
||||
AuthRequest *http.Request
|
||||
}
|
||||
36
graph/model/models_db.go
Normal file
36
graph/model/models_db.go
Normal file
@@ -0,0 +1,36 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"github.com/google/uuid"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
func (u *User) BeforeCreate(tx *gorm.DB) (err error) {
|
||||
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
|
||||
}
|
||||
|
||||
func (m *MediaItem) BeforeCreate(tx *gorm.DB) (err error) {
|
||||
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
|
||||
}
|
||||
|
||||
func (d *Device) BeforeCreate(tx *gorm.DB) (err error) {
|
||||
newID := uuid.New().String()
|
||||
d.ID = newID
|
||||
return
|
||||
}
|
||||
465
graph/model/models_gen.go
Normal file
465
graph/model/models_gen.go
Normal file
@@ -0,0 +1,465 @@
|
||||
// Code generated by github.com/99designs/gqlgen, DO NOT EDIT.
|
||||
|
||||
package model
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/99designs/gqlgen/graphql"
|
||||
)
|
||||
|
||||
type Album struct {
|
||||
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"`
|
||||
UserID string `json:"userID" gorm:"not null"`
|
||||
}
|
||||
|
||||
type AlbumFilter struct {
|
||||
ID *IDFilter `json:"id" `
|
||||
CreatedAt *TimeFilter `json:"createdAt" `
|
||||
UpdatedAt *TimeFilter `json:"updatedAt" `
|
||||
Name *StringFilter `json:"name" `
|
||||
}
|
||||
|
||||
type AlbumResponse struct {
|
||||
Data []*Album `json:"data" `
|
||||
Page *PageResponse `json:"page" `
|
||||
}
|
||||
|
||||
type AuthResponse struct {
|
||||
Result AuthResult `json:"result" `
|
||||
Device *Device `json:"device" `
|
||||
Error *string `json:"error" `
|
||||
}
|
||||
|
||||
type AuthTypeFilter struct {
|
||||
EqualTo *AuthType `json:"equalTo" `
|
||||
NotEqualTo *AuthType `json:"notEqualTo" `
|
||||
}
|
||||
|
||||
type BooleanFilter struct {
|
||||
EqualTo *bool `json:"equalTo" `
|
||||
NotEqualTo *bool `json:"notEqualTo" `
|
||||
}
|
||||
|
||||
type Device struct {
|
||||
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"`
|
||||
RefreshKey *string `json:"refreshKey" `
|
||||
UserID string `json:"userID" gorm:"not null"`
|
||||
}
|
||||
|
||||
type DeviceFilter struct {
|
||||
ID *IDFilter `json:"id" `
|
||||
CreatedAt *TimeFilter `json:"createdAt" `
|
||||
UpdatedAt *TimeFilter `json:"updatedAt" `
|
||||
Name *StringFilter `json:"name" `
|
||||
Type *DeviceTypeFilter `json:"type" `
|
||||
}
|
||||
|
||||
type DeviceResponse struct {
|
||||
Data []*Device `json:"data" `
|
||||
Page *PageResponse `json:"page" `
|
||||
}
|
||||
|
||||
type DeviceTypeFilter struct {
|
||||
EqualTo *DeviceType `json:"equalTo" `
|
||||
NotEqualTo *DeviceType `json:"notEqualTo" `
|
||||
}
|
||||
|
||||
type FloatFilter struct {
|
||||
EqualTo *float64 `json:"equalTo" `
|
||||
NotEqualTo *float64 `json:"notEqualTo" `
|
||||
LessThan *float64 `json:"lessThan" `
|
||||
LessThanOrEqualTo *float64 `json:"lessThanOrEqualTo" `
|
||||
GreaterThan *float64 `json:"greaterThan" `
|
||||
GreaterThanOrEqualTo *float64 `json:"greaterThanOrEqualTo" `
|
||||
}
|
||||
|
||||
type IDFilter struct {
|
||||
EqualTo *string `json:"equalTo" `
|
||||
NotEqualTo *string `json:"notEqualTo" `
|
||||
}
|
||||
|
||||
type IntFilter struct {
|
||||
EqualTo *int `json:"equalTo" `
|
||||
NotEqualTo *int `json:"notEqualTo" `
|
||||
LessThan *int `json:"lessThan" `
|
||||
LessThanOrEqualTo *int `json:"lessThanOrEqualTo" `
|
||||
GreaterThan *int `json:"greaterThan" `
|
||||
GreaterThanOrEqualTo *int `json:"greaterThanOrEqualTo" `
|
||||
}
|
||||
|
||||
type MediaItem struct {
|
||||
ID string `json:"id" gorm:"primaryKey;not null"`
|
||||
CreatedAt *time.Time `json:"createdAt" `
|
||||
UpdatedAt *time.Time `json:"updatedAt" `
|
||||
ExifDate *time.Time `json:"exifDate" `
|
||||
Latitude *float64 `json:"latitude" gorm:"precision:5"`
|
||||
Longitude *float64 `json:"longitude" gorm:"precision:5"`
|
||||
IsVideo bool `json:"isVideo" gorm:"default:false;not null"`
|
||||
FileName string `json:"fileName" gorm:"not null"`
|
||||
OrigName string `json:"origName" gorm:"not null"`
|
||||
Tags []*Tag `json:"tags" gorm:"many2many:media_tags;foreignKey:ID,UserID;References:ID"`
|
||||
Albums []*Album `json:"albums" gorm:"many2many:media_albums;foreignKey:ID,UserID;Refrences:ID"`
|
||||
UserID string `json:"userID" gorm:"not null"`
|
||||
}
|
||||
|
||||
type MediaItemFilter struct {
|
||||
ID *IDFilter `json:"id" `
|
||||
CreatedAt *TimeFilter `json:"createdAt" `
|
||||
UpdatedAt *TimeFilter `json:"updatedAt" `
|
||||
ExifDate *TimeFilter `json:"exifDate" `
|
||||
Latitude *FloatFilter `json:"latitude" `
|
||||
Longitude *FloatFilter `json:"longitude" `
|
||||
IsVideo *BooleanFilter `json:"isVideo" `
|
||||
OrigName *StringFilter `json:"origName" `
|
||||
Tags *TagFilter `json:"tags" `
|
||||
Albums *AlbumFilter `json:"albums" `
|
||||
}
|
||||
|
||||
type MediaItemResponse struct {
|
||||
Data []*MediaItem `json:"data" `
|
||||
Page *PageResponse `json:"page" `
|
||||
}
|
||||
|
||||
type NewAlbum struct {
|
||||
Name string `json:"name" `
|
||||
}
|
||||
|
||||
type NewMediaItem struct {
|
||||
File graphql.Upload `json:"file" `
|
||||
Tags []string `json:"tags" `
|
||||
Albums []string `json:"albums" `
|
||||
}
|
||||
|
||||
type NewTag struct {
|
||||
Name string `json:"name" `
|
||||
}
|
||||
|
||||
type NewUser struct {
|
||||
Email string `json:"email" `
|
||||
Username string `json:"username" `
|
||||
FirstName *string `json:"firstName" `
|
||||
LastName *string `json:"lastName" `
|
||||
Role Role `json:"role" `
|
||||
AuthType AuthType `json:"authType" `
|
||||
Password *string `json:"password" `
|
||||
}
|
||||
|
||||
type Order struct {
|
||||
By *string `json:"by" `
|
||||
Direction *OrderDirection `json:"direction" `
|
||||
}
|
||||
|
||||
type Page struct {
|
||||
Size *int `json:"size" `
|
||||
Page *int `json:"page" `
|
||||
}
|
||||
|
||||
type PageResponse struct {
|
||||
Size int `json:"size" `
|
||||
Page int `json:"page" `
|
||||
Total int `json:"total" `
|
||||
}
|
||||
|
||||
type RoleFilter struct {
|
||||
EqualTo *Role `json:"equalTo" `
|
||||
NotEqualTo *Role `json:"notEqualTo" `
|
||||
}
|
||||
|
||||
type StringFilter struct {
|
||||
EqualTo *string `json:"equalTo" `
|
||||
NotEqualTo *string `json:"notEqualTo" `
|
||||
StartsWith *string `json:"startsWith" `
|
||||
NotStartsWith *string `json:"notStartsWith" `
|
||||
EndsWith *string `json:"endsWith" `
|
||||
NotEndsWith *string `json:"notEndsWith" `
|
||||
Contains *string `json:"contains" `
|
||||
NotContains *string `json:"notContains" `
|
||||
}
|
||||
|
||||
type Tag struct {
|
||||
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"`
|
||||
UserID string `json:"userID" gorm:"not null"`
|
||||
}
|
||||
|
||||
type TagFilter struct {
|
||||
ID *IDFilter `json:"id" `
|
||||
CreatedAt *TimeFilter `json:"createdAt" `
|
||||
UpdatedAt *TimeFilter `json:"updatedAt" `
|
||||
Name *StringFilter `json:"name" `
|
||||
}
|
||||
|
||||
type TagResponse struct {
|
||||
Data []*Tag `json:"data" `
|
||||
Page *PageResponse `json:"page" `
|
||||
}
|
||||
|
||||
type TimeFilter struct {
|
||||
EqualTo *time.Time `json:"equalTo" `
|
||||
NotEqualTo *time.Time `json:"notEqualTo" `
|
||||
LessThan *time.Time `json:"lessThan" `
|
||||
LessThanOrEqualTo *time.Time `json:"lessThanOrEqualTo" `
|
||||
GreaterThan *time.Time `json:"greaterThan" `
|
||||
GreaterThanOrEqualTo *time.Time `json:"greaterThanOrEqualTo" `
|
||||
}
|
||||
|
||||
type User struct {
|
||||
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"`
|
||||
Username string `json:"username" gorm:"not null;unique"`
|
||||
FirstName *string `json:"firstName" `
|
||||
LastName *string `json:"lastName" `
|
||||
Role Role `json:"role" gorm:"default:User;not null"`
|
||||
AuthType AuthType `json:"authType" gorm:"default:Local;not null"`
|
||||
Password *string `json:"password" `
|
||||
Devices []*Device `json:"devices" gorm:"foreignKey:UserID"`
|
||||
MediaItems []*MediaItem `json:"mediaItems" gorm:"foreignKey:UserID"`
|
||||
}
|
||||
|
||||
type UserFilter struct {
|
||||
ID *IDFilter `json:"id" `
|
||||
CreatedAt *TimeFilter `json:"createdAt" `
|
||||
UpdatedAt *TimeFilter `json:"updatedAt" `
|
||||
Username *StringFilter `json:"username" `
|
||||
FirstName *StringFilter `json:"firstName" `
|
||||
LastName *StringFilter `json:"lastName" `
|
||||
Role *RoleFilter `json:"role" `
|
||||
AuthType *AuthTypeFilter `json:"authType" `
|
||||
}
|
||||
|
||||
type UserResponse struct {
|
||||
Data []*User `json:"data" `
|
||||
Page *PageResponse `json:"page" `
|
||||
}
|
||||
|
||||
type AuthResult string
|
||||
|
||||
const (
|
||||
AuthResultSuccess AuthResult = "Success"
|
||||
AuthResultFailure AuthResult = "Failure"
|
||||
)
|
||||
|
||||
var AllAuthResult = []AuthResult{
|
||||
AuthResultSuccess,
|
||||
AuthResultFailure,
|
||||
}
|
||||
|
||||
func (e AuthResult) IsValid() bool {
|
||||
switch e {
|
||||
case AuthResultSuccess, AuthResultFailure:
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (e AuthResult) String() string {
|
||||
return string(e)
|
||||
}
|
||||
|
||||
func (e *AuthResult) UnmarshalGQL(v interface{}) error {
|
||||
str, ok := v.(string)
|
||||
if !ok {
|
||||
return fmt.Errorf("enums must be strings")
|
||||
}
|
||||
|
||||
*e = AuthResult(str)
|
||||
if !e.IsValid() {
|
||||
return fmt.Errorf("%s is not a valid AuthResult", str)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (e AuthResult) MarshalGQL(w io.Writer) {
|
||||
fmt.Fprint(w, strconv.Quote(e.String()))
|
||||
}
|
||||
|
||||
type AuthType string
|
||||
|
||||
const (
|
||||
AuthTypeLocal AuthType = "Local"
|
||||
AuthTypeLdap AuthType = "LDAP"
|
||||
)
|
||||
|
||||
var AllAuthType = []AuthType{
|
||||
AuthTypeLocal,
|
||||
AuthTypeLdap,
|
||||
}
|
||||
|
||||
func (e AuthType) IsValid() bool {
|
||||
switch e {
|
||||
case AuthTypeLocal, AuthTypeLdap:
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (e AuthType) String() string {
|
||||
return string(e)
|
||||
}
|
||||
|
||||
func (e *AuthType) UnmarshalGQL(v interface{}) error {
|
||||
str, ok := v.(string)
|
||||
if !ok {
|
||||
return fmt.Errorf("enums must be strings")
|
||||
}
|
||||
|
||||
*e = AuthType(str)
|
||||
if !e.IsValid() {
|
||||
return fmt.Errorf("%s is not a valid AuthType", str)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (e AuthType) MarshalGQL(w io.Writer) {
|
||||
fmt.Fprint(w, strconv.Quote(e.String()))
|
||||
}
|
||||
|
||||
type DeviceType string
|
||||
|
||||
const (
|
||||
DeviceTypeIOs DeviceType = "iOS"
|
||||
DeviceTypeAndroid DeviceType = "Android"
|
||||
DeviceTypeChrome DeviceType = "Chrome"
|
||||
DeviceTypeFirefox DeviceType = "Firefox"
|
||||
DeviceTypeInternetExplorer DeviceType = "InternetExplorer"
|
||||
DeviceTypeEdge DeviceType = "Edge"
|
||||
DeviceTypeSafari DeviceType = "Safari"
|
||||
DeviceTypeUnknown DeviceType = "Unknown"
|
||||
)
|
||||
|
||||
var AllDeviceType = []DeviceType{
|
||||
DeviceTypeIOs,
|
||||
DeviceTypeAndroid,
|
||||
DeviceTypeChrome,
|
||||
DeviceTypeFirefox,
|
||||
DeviceTypeInternetExplorer,
|
||||
DeviceTypeEdge,
|
||||
DeviceTypeSafari,
|
||||
DeviceTypeUnknown,
|
||||
}
|
||||
|
||||
func (e DeviceType) IsValid() bool {
|
||||
switch e {
|
||||
case DeviceTypeIOs, DeviceTypeAndroid, DeviceTypeChrome, DeviceTypeFirefox, DeviceTypeInternetExplorer, DeviceTypeEdge, DeviceTypeSafari, DeviceTypeUnknown:
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (e DeviceType) String() string {
|
||||
return string(e)
|
||||
}
|
||||
|
||||
func (e *DeviceType) UnmarshalGQL(v interface{}) error {
|
||||
str, ok := v.(string)
|
||||
if !ok {
|
||||
return fmt.Errorf("enums must be strings")
|
||||
}
|
||||
|
||||
*e = DeviceType(str)
|
||||
if !e.IsValid() {
|
||||
return fmt.Errorf("%s is not a valid DeviceType", str)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (e DeviceType) MarshalGQL(w io.Writer) {
|
||||
fmt.Fprint(w, strconv.Quote(e.String()))
|
||||
}
|
||||
|
||||
type OrderDirection string
|
||||
|
||||
const (
|
||||
OrderDirectionAsc OrderDirection = "ASC"
|
||||
OrderDirectionDesc OrderDirection = "DESC"
|
||||
)
|
||||
|
||||
var AllOrderDirection = []OrderDirection{
|
||||
OrderDirectionAsc,
|
||||
OrderDirectionDesc,
|
||||
}
|
||||
|
||||
func (e OrderDirection) IsValid() bool {
|
||||
switch e {
|
||||
case OrderDirectionAsc, OrderDirectionDesc:
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (e OrderDirection) String() string {
|
||||
return string(e)
|
||||
}
|
||||
|
||||
func (e *OrderDirection) UnmarshalGQL(v interface{}) error {
|
||||
str, ok := v.(string)
|
||||
if !ok {
|
||||
return fmt.Errorf("enums must be strings")
|
||||
}
|
||||
|
||||
*e = OrderDirection(str)
|
||||
if !e.IsValid() {
|
||||
return fmt.Errorf("%s is not a valid OrderDirection", str)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (e OrderDirection) MarshalGQL(w io.Writer) {
|
||||
fmt.Fprint(w, strconv.Quote(e.String()))
|
||||
}
|
||||
|
||||
type Role string
|
||||
|
||||
const (
|
||||
RoleAdmin Role = "Admin"
|
||||
RoleUser Role = "User"
|
||||
)
|
||||
|
||||
var AllRole = []Role{
|
||||
RoleAdmin,
|
||||
RoleUser,
|
||||
}
|
||||
|
||||
func (e Role) IsValid() bool {
|
||||
switch e {
|
||||
case RoleAdmin, RoleUser:
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (e Role) String() string {
|
||||
return string(e)
|
||||
}
|
||||
|
||||
func (e *Role) UnmarshalGQL(v interface{}) error {
|
||||
str, ok := v.(string)
|
||||
if !ok {
|
||||
return fmt.Errorf("enums must be strings")
|
||||
}
|
||||
|
||||
*e = Role(str)
|
||||
if !e.IsValid() {
|
||||
return fmt.Errorf("%s is not a valid Role", str)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (e Role) MarshalGQL(w io.Writer) {
|
||||
fmt.Fprint(w, strconv.Quote(e.String()))
|
||||
}
|
||||
Reference in New Issue
Block a user