add some endpoints

This commit is contained in:
sentriz
2019-04-01 13:53:21 +01:00
parent b7c398f1eb
commit f5aa05abc3
18 changed files with 455 additions and 267 deletions

35
db/base.go Normal file
View File

@@ -0,0 +1,35 @@
package db
import (
"time"
"github.com/jinzhu/gorm"
"github.com/twinj/uuid"
)
type CrudBase struct {
CreatedAt time.Time
UpdatedAt time.Time
DeletedAt *time.Time `sql:"index"`
}
type IDBase struct {
ID uint `gorm:"primary_key"`
}
// Base is the base model with an auto incrementing primary key
type Base struct {
IDBase
CrudBase
}
// BaseWithUUID is the base model with an UUIDv4 primary key
type BaseWithUUID struct {
IDBase
CrudBase
}
// BeforeCreate is called by GORM to set the UUID primary key
func (b *BaseWithUUID) BeforeCreate(scope *gorm.Scope) error {
return scope.SetColumn("ID", uuid.NewV4().String())
}

52
db/model.go Normal file
View File

@@ -0,0 +1,52 @@
package db
// Album represents the albums table
type Album struct {
Base
Artist Artist
ArtistID uint
Title string `gorm:"not null;index"`
Tracks []Track
}
// Artist represents the artists table
type Artist struct {
Base
Albums []Album
Name string `gorm:"not null;unique_index"`
}
// Track represents the tracks table
type Track struct {
Base
Album Album
AlbumID uint
Artist Artist
ArtistID uint
Bitrate uint
Codec string
DiscNumber uint
Duration uint
Title string
TotalDiscs uint
TotalTracks uint
TrackNumber uint
Year uint
Path string `gorm:"not null;unique_index"`
}
// Cover represents the covers table
type Cover struct {
Base
Album Album
AlbumID uint
Image []byte
Path string `gorm:"not null;unique_index"`
}
// User represents the users table
type User struct {
IDBase
Username string `gorm:"not null;unique_index"`
Password string
}