蓝眼网盘定制版
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.

61 lines
1.4 KiB

package rest
8 years ago
import (
"github.com/eyebluecn/tank/code/core"
"github.com/eyebluecn/tank/code/tool/result"
8 years ago
"github.com/nu7hatch/gouuid"
"time"
)
type UploadTokenDao struct {
BaseDao
}
//find by uuid. if not found return nil.
8 years ago
func (this *UploadTokenDao) FindByUuid(uuid string) *UploadToken {
var entity = &UploadToken{}
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
func (this *UploadTokenDao) CheckByUuid(uuid string) *UploadToken {
entity := this.FindByUuid(uuid)
if entity == nil {
panic(result.NotFound("not found record with uuid = %s", uuid))
}
return entity
8 years ago
}
//创建一个session并且持久化到数据库中。
func (this *UploadTokenDao) Create(uploadToken *UploadToken) *UploadToken {
timeUUID, _ := uuid.NewV4()
uploadToken.Uuid = string(timeUUID.String())
uploadToken.CreateTime = time.Now()
uploadToken.UpdateTime = time.Now()
uploadToken.Sort = time.Now().UnixNano() / 1e6
db := core.CONTEXT.GetDB().Create(uploadToken)
8 years ago
this.PanicError(db.Error)
return uploadToken
}
//修改一个uploadToken
func (this *UploadTokenDao) Save(uploadToken *UploadToken) *UploadToken {
uploadToken.UpdateTime = time.Now()
db := core.CONTEXT.GetDB().Save(uploadToken)
8 years ago
this.PanicError(db.Error)
return uploadToken
}