-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfile.go
49 lines (39 loc) · 905 Bytes
/
file.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
package db
import (
"gorm.io/gorm"
"main/config"
"main/models"
)
type File struct {
db *gorm.DB
}
func NewFile(cfg *config.Config) (*File, error) {
db, err := NewDB(*cfg)
if err != nil {
return nil, err
}
return &File{
db: db,
}, nil
}
func (receiver File) Create(userID int, id, filename string) (models.File, error) {
file := models.File{
ID: id,
Filename: filename,
UserID: userID,
}
res := receiver.db.Create(&file)
if res.Error != nil {
return models.File{}, res.Error
}
return file, nil
}
func (receiver File) UpdateSalt(file models.File, salt string) error {
return receiver.db.Model(&file).Update("salt", salt).Error
}
func (receiver File) Delete(file models.File) error {
return receiver.db.Delete(&file).Error
}
func (receiver File) UpdateAccessedAt(file models.File) error {
return receiver.db.Model(&file).Update("accessed_at", "now()").Error
}