refactor: remove default time tracking in file model

This commit is contained in:
Bhunter 2025-01-08 10:01:52 +01:00
parent 74bae5fdc2
commit 126a2c4af3
3 changed files with 9 additions and 17 deletions

View file

@ -21,6 +21,6 @@ type File struct {
ParentID sql.NullString `gorm:"type:uuid;index"` ParentID sql.NullString `gorm:"type:uuid;index"`
Parts datatypes.JSONSlice[api.Part] `gorm:"type:jsonb"` Parts datatypes.JSONSlice[api.Part] `gorm:"type:jsonb"`
ChannelID *int64 `gorm:"type:bigint"` ChannelID *int64 `gorm:"type:bigint"`
CreatedAt time.Time `gorm:"default:timezone('utc'::text, now())"` CreatedAt time.Time `gorm:"autoCreateTime:false"`
UpdatedAt time.Time `gorm:"default:timezone('utc'::text, now())"` UpdatedAt time.Time `gorm:"autoUpdateTime:false"`
} }

View file

@ -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"`
}

View file

@ -12,6 +12,7 @@ import (
"net/http" "net/http"
"strconv" "strconv"
"strings" "strings"
"time"
"github.com/google/uuid" "github.com/google/uuid"
"github.com/gotd/td/telegram" "github.com/gotd/td/telegram"
@ -492,6 +493,8 @@ func (a *apiService) FilesUpdate(ctx context.Context, req *api.FileUpdate, param
} }
if req.UpdatedAt.IsSet() { if req.UpdatedAt.IsSet() {
updateDb.UpdatedAt = req.UpdatedAt.Value 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 { 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, Valid: true,
} }
} }
updatePayload.UpdatedAt = req.UpdatedAt
err := a.db.Transaction(func(tx *gorm.DB) error { err := a.db.Transaction(func(tx *gorm.DB) error {
if err := tx.Where("id = ?", params.ID).First(&file).Error; err != nil { if err := tx.Where("id = ?", params.ID).First(&file).Error; err != nil {
return err return err
} }
if err := tx.Model(models.File{}).Where("id = ?", params.ID).Updates(updatePayload). if err := tx.Model(models.File{}).Where("id = ?", params.ID).Updates(updatePayload).Error; err != nil {
Update("updated_at", req.UpdatedAt).Error; err != nil {
return err return err
} }
if req.UploadId.Value != "" { if req.UploadId.Value != "" {