-
Notifications
You must be signed in to change notification settings - Fork 25
/
package_group.go
59 lines (52 loc) · 1.59 KB
/
package_group.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package models
import (
"github.com/lib/pq"
"gorm.io/gorm"
)
const TableNamePackageGroup = "package_groups"
// RepositoryPackageGroup model for the gorm object of the database
// which represent a package group which belong to one
// repository.
type PackageGroup struct {
Base
ID string `json:"id" gorm:"not null"`
Name string `json:"name" gorm:"not null"`
Description string `json:"description"`
PackageList pq.StringArray `json:"packagelist" gorm:"type:text"`
HashValue string `json:"hashvalue"`
Repositories []Repository `gorm:"many2many:repositories_package_groups"`
}
// BeforeCreate hook performs validations and sets UUID of RepositoryPackageGroup
func (r *PackageGroup) BeforeCreate(tx *gorm.DB) (err error) {
if err := r.Base.BeforeCreate(tx); err != nil {
return err
}
if r.ID == "" {
return Error{Message: "ID cannot be empty", Validation: true}
}
if r.Name == "" {
return Error{Message: "Name cannot be empty", Validation: true}
}
return nil
}
// DeepCopy clone a RepositoryPackageGroup struct
func (in *PackageGroup) DeepCopy() *PackageGroup {
out := &PackageGroup{}
in.DeepCopyInto(out)
return out
}
func (in *PackageGroup) DeepCopyInto(out *PackageGroup) {
if in == nil || out == nil || in == out {
return
}
in.Base.DeepCopyInto(&out.Base)
out.ID = in.ID
out.Name = in.Name
out.Description = in.Description
out.PackageList = in.PackageList
out.HashValue = in.HashValue
out.Repositories = make([]Repository, len(in.Repositories))
for i, item := range in.Repositories {
item.DeepCopyInto(&out.Repositories[i])
}
}