Add the deleted time.

This commit is contained in:
lishuang 2020-07-12 17:46:17 +08:00
parent 82047f4504
commit 76e7359c69
4 changed files with 30 additions and 20 deletions

View File

@ -163,7 +163,7 @@ func (this *DavController) debug(writer http.ResponseWriter, request *http.Reque
func (this *DavController) Index(writer http.ResponseWriter, request *http.Request, subPath string) {
//when debugging. open it.
this.debug(writer, request, subPath)
//this.debug(writer, request, subPath)
user := this.CheckCurrentUser(writer, request)

View File

@ -200,7 +200,7 @@ func (this *DavService) HandlePropfind(writer http.ResponseWriter, request *http
matters = []*Matter{matter}
} else {
// len(matters) == 0 means empty directory
matters = this.matterDao.FindByPuuidAndUserUuid(matter.Uuid, user.Uuid, nil)
matters = this.matterDao.FindByPuuidAndUserUuidAndDeleted(matter.Uuid, user.Uuid, FALSE, nil)
//add this matter to head.
matters = append([]*Matter{matter}, matters...)
@ -373,7 +373,7 @@ func (this *DavService) HandleDelete(w http.ResponseWriter, r *http.Request, use
matter := this.matterDao.CheckWithRootByPath(subPath, user)
this.matterService.AtomicDelete(r, matter, user)
this.matterService.AtomicSoftDelete(r, matter, user)
}
//crate a directory

View File

@ -213,10 +213,19 @@ func (this *MatterDao) FindByUserUuidAndPuuidAndDirAndName(userUuid string, puui
}
func (this *MatterDao) FindByPuuidAndUserUuid(puuid string, userUuid string, sortArray []builder.OrderPair) []*Matter {
return this.FindByPuuidAndUserUuidAndDeleted(puuid, userUuid, "", sortArray)
}
func (this *MatterDao) FindByPuuidAndUserUuidAndDeleted(puuid string, userUuid string, deleted string, sortArray []builder.OrderPair) []*Matter {
var matters []*Matter
var wp = &builder.WherePair{}
wp = wp.And(&builder.WherePair{Query: "puuid = ? AND user_uuid = ?", Args: []interface{}{puuid, userUuid}})
if deleted == TRUE {
wp = wp.And(&builder.WherePair{Query: "deleted = 1", Args: []interface{}{}})
} else if deleted == FALSE {
wp = wp.And(&builder.WherePair{Query: "deleted = 0", Args: []interface{}{}})
}
if sortArray == nil {
@ -429,13 +438,13 @@ func (this *MatterDao) SoftDelete(matter *Matter) {
}
//soft delete from db.
db := core.CONTEXT.GetDB().Model(&Matter{}).Where("uuid = ?", matter.Uuid).Update(map[string]interface{}{"deleted": 1})
db := core.CONTEXT.GetDB().Model(&Matter{}).Where("uuid = ?", matter.Uuid).Update(map[string]interface{}{"deleted": 1, "delete_time": time.Now()})
this.PanicError(db.Error)
} else {
//soft delete from db.
db := core.CONTEXT.GetDB().Model(&Matter{}).Where("uuid = ?", matter.Uuid).Update(map[string]interface{}{"deleted": 1})
db := core.CONTEXT.GetDB().Model(&Matter{}).Where("uuid = ?", matter.Uuid).Update(map[string]interface{}{"deleted": 1, "delete_time": time.Now()})
this.PanicError(db.Error)
//no need to delete its image cache.

View File

@ -31,21 +31,22 @@ const (
*/
type Matter struct {
Base
Puuid string `json:"puuid" gorm:"type:char(36);index:idx_puuid"`
UserUuid string `json:"userUuid" gorm:"type:char(36);index:idx_uu"`
Username string `json:"username" gorm:"type:varchar(45) not null"`
Dir bool `json:"dir" gorm:"type:tinyint(1) not null;default:0"`
Name string `json:"name" gorm:"type:varchar(255) not null"`
Md5 string `json:"md5" gorm:"type:varchar(45)"`
Size int64 `json:"size" gorm:"type:bigint(20) not null;default:0"`
Privacy bool `json:"privacy" gorm:"type:tinyint(1) not null;default:0"`
Path string `json:"path" gorm:"type:varchar(1024)"`
Times int64 `json:"times" gorm:"type:bigint(20) not null;default:0"`
Parent *Matter `json:"parent" gorm:"-"`
Children []*Matter `json:"-" gorm:"-"`
Prop string `json:"prop" gorm:"type:varchar(1024) not null;default:'{}'"`
VisitTime time.Time `json:"visitTime" gorm:"type:timestamp not null;default:'2018-01-01 00:00:00'"`
Deleted bool `json:"deleted" gorm:"type:tinyint(1) not null;default:0"`
Puuid string `json:"puuid" gorm:"type:char(36);index:idx_puuid"`
UserUuid string `json:"userUuid" gorm:"type:char(36);index:idx_uu"`
Username string `json:"username" gorm:"type:varchar(45) not null"`
Dir bool `json:"dir" gorm:"type:tinyint(1) not null;default:0"`
Name string `json:"name" gorm:"type:varchar(255) not null"`
Md5 string `json:"md5" gorm:"type:varchar(45)"`
Size int64 `json:"size" gorm:"type:bigint(20) not null;default:0"`
Privacy bool `json:"privacy" gorm:"type:tinyint(1) not null;default:0"`
Path string `json:"path" gorm:"type:varchar(1024)"`
Times int64 `json:"times" gorm:"type:bigint(20) not null;default:0"`
Parent *Matter `json:"parent" gorm:"-"`
Children []*Matter `json:"-" gorm:"-"`
Prop string `json:"prop" gorm:"type:varchar(1024) not null;default:'{}'"`
VisitTime time.Time `json:"visitTime" gorm:"type:timestamp not null;default:'2018-01-01 00:00:00'"`
Deleted bool `json:"deleted" gorm:"type:tinyint(1) not null;default:0"`
DeleteTime time.Time `json:"deleteTime" gorm:"type:timestamp not null;default:'2018-01-01 00:00:00'"`
}
// set File's table name to be `profiles`