-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathuploads.go
50 lines (41 loc) · 921 Bytes
/
uploads.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
package models
import (
"time"
"github.com/lib/pq"
"gorm.io/gorm"
)
type Upload struct {
UploadUUID string
CreatedAt time.Time
OrgID string
ChunkSize int64
Sha256 string
ChunkList pq.StringArray `gorm:"type:text[]"`
}
// BeforeCreate perform validations and sets UUID of Upload
func (t *Upload) BeforeCreate(tx *gorm.DB) error {
if err := t.validate(); err != nil {
return err
}
return nil
}
func (t *Upload) validate() error {
var err error
if t.UploadUUID == "" {
err = Error{Message: "Upload UUID cannot be blank.", Validation: true}
return err
}
if t.OrgID == "" {
err = Error{Message: "Org ID cannot be blank.", Validation: true}
return err
}
if t.ChunkSize == 0 {
err = Error{Message: "ChunkSize cannot be 0.", Validation: true}
return err
}
if t.Sha256 == "" {
err = Error{Message: "Sha256 cannot be blank.", Validation: true}
return err
}
return nil
}