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 }