diff --git a/models/upload.model.go b/models/upload.model.go index 8ecf179..3949701 100644 --- a/models/upload.model.go +++ b/models/upload.model.go @@ -7,7 +7,7 @@ import ( type Upload struct { ID string `gorm:"type:text;primary_key;default:generate_uid(16)"` UploadId string `gorm:"type:text"` - UserId string `gorm:"type:bigint"` + UserId int64 `gorm:"type:bigint"` Name string `gorm:"type:text"` PartNo int `gorm:"type:integer"` TotalParts int `gorm:"type:integer"` diff --git a/services/upload.service.go b/services/upload.service.go index 26c6f85..6a18ce4 100644 --- a/services/upload.service.go +++ b/services/upload.service.go @@ -63,11 +63,15 @@ func (us *UploadService) UploadFile(c *gin.Context) (*schemas.UploadPartOut, *ty return nil, &types.AppError{Error: errors.New("filename missing"), Code: http.StatusBadRequest} } + userId, session := getUserAuth(c) + uploadId := c.Param("id") var uploadPart []models.Upload - us.Db.Model(&models.Upload{}).Where("upload_id = ?", uploadId).Where("part_no = ?", uploadQuery.PartNo).Find(&uploadPart) + us.Db.Model(&models.Upload{}).Where("upload_id = ?", uploadId).Where("part_no = ?", uploadQuery.PartNo). + Where("user_id = ?", userId). + Find(&uploadPart) if len(uploadPart) == 1 { out := mapper.MapUploadSchema(&uploadPart[0]) @@ -82,8 +86,6 @@ func (us *UploadService) UploadFile(c *gin.Context) (*schemas.UploadPartOut, *ty var msgId int - userId, session := getUserAuth(c) - tokens, err := GetBotsToken(c, userId) if err != nil { @@ -166,6 +168,7 @@ func (us *UploadService) UploadFile(c *gin.Context) (*schemas.UploadPartOut, *ty Size: fileSize, PartNo: uploadQuery.PartNo, TotalParts: uploadQuery.TotalParts, + UserId: userId, } if err := us.Db.Create(partUpload).Error; err != nil {