From 126a2c4af3deaec8c8ee44427981a7e12b98ad25 Mon Sep 17 00:00:00 2001 From: Bhunter <180028024+bhunter234@users.noreply.github.com> Date: Wed, 8 Jan 2025 10:01:52 +0100 Subject: [PATCH] refactor: remove default time tracking in file model --- pkg/models/file.go | 4 ++-- pkg/schemas/share.go | 13 ------------- pkg/services/file.go | 9 +++++++-- 3 files changed, 9 insertions(+), 17 deletions(-) delete mode 100644 pkg/schemas/share.go diff --git a/pkg/models/file.go b/pkg/models/file.go index 30126aa..fa0b44b 100644 --- a/pkg/models/file.go +++ b/pkg/models/file.go @@ -21,6 +21,6 @@ type File struct { ParentID sql.NullString `gorm:"type:uuid;index"` Parts datatypes.JSONSlice[api.Part] `gorm:"type:jsonb"` ChannelID *int64 `gorm:"type:bigint"` - CreatedAt time.Time `gorm:"default:timezone('utc'::text, now())"` - UpdatedAt time.Time `gorm:"default:timezone('utc'::text, now())"` + CreatedAt time.Time `gorm:"autoCreateTime:false"` + UpdatedAt time.Time `gorm:"autoUpdateTime:false"` } diff --git a/pkg/schemas/share.go b/pkg/schemas/share.go deleted file mode 100644 index a553cee..0000000 --- a/pkg/schemas/share.go +++ /dev/null @@ -1,13 +0,0 @@ -package schemas - -type ShareAccess struct { - Password string `json:"password" binding:"required"` -} - -type ShareFileQuery struct { - Path string `form:"path"` - Sort string `form:"sort"` - Order string `form:"order"` - Limit int `form:"limit"` - Page int `form:"page"` -} diff --git a/pkg/services/file.go b/pkg/services/file.go index f1b11b8..cea8189 100644 --- a/pkg/services/file.go +++ b/pkg/services/file.go @@ -12,6 +12,7 @@ import ( "net/http" "strconv" "strings" + "time" "github.com/google/uuid" "github.com/gotd/td/telegram" @@ -492,6 +493,8 @@ func (a *apiService) FilesUpdate(ctx context.Context, req *api.FileUpdate, param } if req.UpdatedAt.IsSet() { updateDb.UpdatedAt = req.UpdatedAt.Value + } else { + updateDb.UpdatedAt = time.Now().UTC() } if err := a.db.Model(&models.File{}).Where("id = ?", params.ID).Updates(updateDb).Error; err != nil { @@ -544,12 +547,14 @@ func (a *apiService) FilesUpdateParts(ctx context.Context, req *api.FilePartsUpd Valid: true, } } + + updatePayload.UpdatedAt = req.UpdatedAt + err := a.db.Transaction(func(tx *gorm.DB) error { if err := tx.Where("id = ?", params.ID).First(&file).Error; err != nil { return err } - if err := tx.Model(models.File{}).Where("id = ?", params.ID).Updates(updatePayload). - Update("updated_at", req.UpdatedAt).Error; err != nil { + if err := tx.Model(models.File{}).Where("id = ?", params.ID).Updates(updatePayload).Error; err != nil { return err } if req.UploadId.Value != "" {