蓝眼网盘定制版
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

73 lines
1.8 KiB

package rest
8 years ago
import (
"github.com/eyebluecn/tank/code/core"
"github.com/eyebluecn/tank/code/tool/result"
5 years ago
"github.com/eyebluecn/tank/code/tool/uuid"
8 years ago
"time"
)
type DownloadTokenDao struct {
BaseDao
}
//find by uuid. if not found return nil.
8 years ago
func (this *DownloadTokenDao) FindByUuid(uuid string) *DownloadToken {
var entity = &DownloadToken{}
db := core.CONTEXT.GetDB().Where("uuid = ?", uuid).First(entity)
8 years ago
if db.Error != nil {
if db.Error.Error() == result.DB_ERROR_NOT_FOUND {
return nil
} else {
panic(db.Error)
}
8 years ago
}
return entity
8 years ago
}
//find by uuid. if not found panic NotFound error
8 years ago
func (this *DownloadTokenDao) CheckByUuid(uuid string) *DownloadToken {
entity := this.FindByUuid(uuid)
if entity == nil {
panic(result.NotFound("not found record with uuid = %s", uuid))
}
return entity
8 years ago
}
func (this *DownloadTokenDao) Create(downloadToken *DownloadToken) *DownloadToken {
timeUUID, _ := uuid.NewV4()
downloadToken.Uuid = string(timeUUID.String())
downloadToken.CreateTime = time.Now()
downloadToken.UpdateTime = time.Now()
downloadToken.Sort = time.Now().UnixNano() / 1e6
db := core.CONTEXT.GetDB().Create(downloadToken)
8 years ago
this.PanicError(db.Error)
return downloadToken
}
func (this *DownloadTokenDao) Save(downloadToken *DownloadToken) *DownloadToken {
downloadToken.UpdateTime = time.Now()
db := core.CONTEXT.GetDB().Save(downloadToken)
8 years ago
this.PanicError(db.Error)
return downloadToken
}
func (this *DownloadTokenDao) DeleteByUserUuid(userUuid string) {
db := core.CONTEXT.GetDB().Where("user_uuid = ?", userUuid).Delete(DownloadToken{})
this.PanicError(db.Error)
}
func (this *DownloadTokenDao) Cleanup() {
this.logger.Info("[DownloadTokenDao] clean up. Delete all DownloadToken")
db := core.CONTEXT.GetDB().Where("uuid is not null").Delete(DownloadToken{})
this.PanicError(db.Error)
}