You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
website/database/database.go

92 lines
2.2 KiB
Go

package database
import "time"
// Tools
type DBMigrate interface {
Migrate(migrationDir string) error
}
// Entities
type DBDispense interface {
CreateDispensa(template Dispensa) (string, error)
GetDispensa(id string) (Dispensa, error)
AllDispense() ([]Dispensa, error)
UpdateDispensa(d Dispensa) error
DeleteDispensa(id string) error
}
type DBUpload interface {
CreateUpload(template UploadedContent) (string, error)
DeleteUpload(id UploadedContent) (UploadedContent, error)
}
type DBHashApprovals interface {
CreateApprovedHash(a HashApproval) error
GetApprovedHash(hash string) (HashApproval, error)
AllApprovedHash(a HashApproval) error
}
type DBHashRejections interface {
CreateRejectedHash(a HashRejection) error
GetRejectedHash(hash string) (HashRejection, error)
AllRejectedHash(a HashRejection) error
}
// Relations
type DBTags interface {
SetTags(dispensaId string, tag []string) error
GetTags(dispensaId string) ([]string, error)
}
type DBOwners interface {
CreateOwner(owner, owned string) error
GetOwner(ownedId string) (string, error)
}
type DBAuthors interface {
CreateAuthor(userId, dispensaId string) error
GetAuthorId(dispensaId string) (string, error)
GetUserDispenseIds(user string) ([]string, error)
}
type DBCreationTimes interface {
CreateCreationTime(entityId string, createdAt time.Time) error
GetCreationTime(entityId string) (time.Time, error)
}
type DBOther interface {
// AllDispenseOfUser ritorna tutte le dispense di un certo utente
AllDispenseOfUser(username string) ([]Dispensa, error)
// AllLatestsApprovedDispenseUploads ritorna una lista contenente tutte le dispense con almeno un upload approvato e ritorna la coppia della (dispensa, upload più recente)
AllLatestsApprovedDispenseUploads() ([]struct {
Dispensa
UploadedContent
}, error)
// AllDispenseWithState ...
AllDispenseWithState(username string) ([]struct {
Dispensa
State string
}, error)
}
// DB main "interface group" for interacting with the database, with this technique we can test each "table" api of the DB in isolation.
type DB struct {
DBMigrate
DBDispense
DBUpload
DBHashApprovals
DBHashRejections
DBTags
DBOwners
DBAuthors
DBCreationTimes
DBOther
}