update PrintJob model and add Invoice
This commit is contained in:
82
repositories/printJobRepository.go
Normal file
82
repositories/printJobRepository.go
Normal file
@@ -0,0 +1,82 @@
|
||||
package repositories
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
|
||||
"gorm.io/gorm"
|
||||
|
||||
"git.dynamicdiscord.de/kalipso/zineshop/models"
|
||||
)
|
||||
|
||||
type PrintJobRepository interface {
|
||||
Create(models.PrintJob) (models.PrintJob, error)
|
||||
GetAll() ([]models.PrintJob, error)
|
||||
GetById(string) (models.PrintJob, error)
|
||||
//GetByShopItemId(string) (models.PrintJob, error)
|
||||
Update(models.PrintJob) (models.PrintJob, error)
|
||||
DeleteById(string) error
|
||||
}
|
||||
|
||||
type GORMPrintJobRepository struct {
|
||||
DB *gorm.DB
|
||||
}
|
||||
|
||||
func NewGORMPrintJobRepository(db *gorm.DB) PrintJobRepository {
|
||||
return &GORMPrintJobRepository{
|
||||
DB: db,
|
||||
}
|
||||
}
|
||||
|
||||
func (t *GORMPrintJobRepository) Create(tag models.PrintJob) (models.PrintJob, error) {
|
||||
result := t.DB.Create(&tag)
|
||||
|
||||
if result.Error != nil {
|
||||
return models.PrintJob{}, result.Error
|
||||
}
|
||||
|
||||
return tag, nil
|
||||
}
|
||||
|
||||
func (t *GORMPrintJobRepository) GetAll() ([]models.PrintJob, error) {
|
||||
var tags []models.PrintJob
|
||||
result := t.DB.Find(&tags)
|
||||
|
||||
return tags, result.Error
|
||||
}
|
||||
|
||||
func (t *GORMPrintJobRepository) GetById(id string) (models.PrintJob, error) {
|
||||
tagId, err := strconv.Atoi(id)
|
||||
|
||||
if err != nil {
|
||||
return models.PrintJob{}, err
|
||||
}
|
||||
|
||||
var tag models.PrintJob
|
||||
result := t.DB.First(&tag, uint(tagId))
|
||||
|
||||
if result.Error != nil {
|
||||
return models.PrintJob{}, result.Error
|
||||
}
|
||||
|
||||
return tag, nil
|
||||
}
|
||||
|
||||
func (t *GORMPrintJobRepository) Update(tag models.PrintJob) (models.PrintJob, error) {
|
||||
result := t.DB.Save(&tag)
|
||||
if result.Error != nil {
|
||||
return models.PrintJob{}, result.Error
|
||||
}
|
||||
|
||||
return tag, nil
|
||||
}
|
||||
|
||||
func (t *GORMPrintJobRepository) DeleteById(id string) error {
|
||||
tagId, err := strconv.Atoi(id)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
result := t.DB.Delete(&models.PrintJob{}, tagId)
|
||||
return result.Error
|
||||
}
|
||||
@@ -17,6 +17,7 @@ var (
|
||||
Tokens RegisterTokenRepository
|
||||
ConfigOptions ConfigRepository
|
||||
Papers PaperRepository
|
||||
PrintJobs PrintJobRepository
|
||||
)
|
||||
|
||||
func InitRepositories() {
|
||||
@@ -33,6 +34,8 @@ func InitRepositories() {
|
||||
&models.Order{},
|
||||
&models.Config{},
|
||||
&models.Paper{},
|
||||
&models.PrintJob{},
|
||||
&models.Invoice{},
|
||||
&models.RegisterToken{})
|
||||
|
||||
if err != nil {
|
||||
@@ -47,4 +50,5 @@ func InitRepositories() {
|
||||
Tokens = NewGORMRegisterTokenRepository(db)
|
||||
ConfigOptions = NewGORMConfigRepository(db)
|
||||
Papers = NewGORMPaperRepository(db)
|
||||
PrintJobs = NewGORMPrintJobRepository(db)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user