update: pan

This commit is contained in:
Kerwin
2025-07-11 10:01:48 +08:00
parent 45c6e9fec4
commit f7fb4e6f14
15 changed files with 185 additions and 545 deletions

View File

@@ -91,14 +91,11 @@ func ToTagResponseList(tags []entity.Tag) []dto.TagResponse {
// ToPanResponse 将Pan实体转换为PanResponse
func ToPanResponse(pan *entity.Pan) dto.PanResponse {
return dto.PanResponse{
ID: pan.ID,
Name: pan.Name,
Key: pan.Key,
Ck: pan.Ck,
IsValid: pan.IsValid,
Space: pan.Space,
LeftSpace: pan.LeftSpace,
Remark: pan.Remark,
ID: pan.ID,
Name: pan.Name,
Key: pan.Key,
Icon: pan.Icon,
Remark: pan.Remark,
}
}
@@ -114,12 +111,14 @@ func ToPanResponseList(pans []entity.Pan) []dto.PanResponse {
// ToCksResponse 将Cks实体转换为CksResponse
func ToCksResponse(cks *entity.Cks) dto.CksResponse {
return dto.CksResponse{
ID: cks.ID,
PanID: cks.PanID,
T: cks.T,
Idx: cks.Idx,
Ck: cks.Ck,
Remark: cks.Remark,
ID: cks.ID,
PanID: cks.PanID,
Idx: cks.Idx,
Ck: cks.Ck,
IsValid: cks.IsValid,
Space: cks.Space,
LeftSpace: cks.LeftSpace,
Remark: cks.Remark,
}
}

View File

@@ -2,19 +2,24 @@ package dto
// CreatePanRequest 创建平台请求
type CreatePanRequest struct {
Name string `json:"name" binding:"required"`
Key int `json:"key"`
Ck string `json:"ck"`
IsValid bool `json:"is_valid"`
Space int64 `json:"space"`
LeftSpace int64 `json:"left_space"`
Remark string `json:"remark"`
Name string `json:"name" binding:"required"`
Key int `json:"key"`
Icon string `json:"icon"`
Remark string `json:"remark"`
}
// UpdatePanRequest 更新平台请求
type UpdatePanRequest struct {
Name string `json:"name"`
Key int `json:"key"`
Name string `json:"name"`
Key int `json:"key"`
Icon string `json:"icon"`
Remark string `json:"remark"`
}
// CreateCksRequest 创建cookie请求
type CreateCksRequest struct {
PanID uint `json:"pan_id" binding:"required"`
Idx int `json:"idx"`
Ck string `json:"ck"`
IsValid bool `json:"is_valid"`
Space int64 `json:"space"`
@@ -22,22 +27,15 @@ type UpdatePanRequest struct {
Remark string `json:"remark"`
}
// CreateCksRequest 创建cookie请求
type CreateCksRequest struct {
PanID uint `json:"pan_id" binding:"required"`
T string `json:"t"`
Idx int `json:"idx"`
Ck string `json:"ck"`
Remark string `json:"remark"`
}
// UpdateCksRequest 更新cookie请求
type UpdateCksRequest struct {
PanID uint `json:"pan_id"`
T string `json:"t"`
Idx int `json:"idx"`
Ck string `json:"ck"`
Remark string `json:"remark"`
PanID uint `json:"pan_id"`
Idx int `json:"idx"`
Ck string `json:"ck"`
IsValid bool `json:"is_valid"`
Space int64 `json:"space"`
LeftSpace int64 `json:"left_space"`
Remark string `json:"remark"`
}
// CreateResourceRequest 创建资源请求

View File

@@ -46,9 +46,18 @@ type TagResponse struct {
// PanResponse 平台响应
type PanResponse struct {
ID uint `json:"id"`
Name string `json:"name"`
Key int `json:"key"`
Icon string `json:"icon"`
Remark string `json:"remark"`
}
// CksResponse Cookie响应
type CksResponse struct {
ID uint `json:"id"`
Name string `json:"name"`
Key int `json:"key"`
PanID uint `json:"pan_id"`
Idx int `json:"idx"`
Ck string `json:"ck"`
IsValid bool `json:"is_valid"`
Space int64 `json:"space"`
@@ -56,16 +65,6 @@ type PanResponse struct {
Remark string `json:"remark"`
}
// CksResponse Cookie响应
type CksResponse struct {
ID uint `json:"id"`
PanID uint `json:"pan_id"`
T string `json:"t"`
Idx int `json:"idx"`
Ck string `json:"ck"`
Remark string `json:"remark"`
}
// ReadyResourceResponse 待处理资源响应
type ReadyResourceResponse struct {
ID uint `json:"id"`

View File

@@ -10,9 +10,11 @@ import (
type Cks struct {
ID uint `json:"id" gorm:"primaryKey;autoIncrement"`
PanID uint `json:"pan_id" gorm:"not null;comment:平台ID"`
T string `json:"t" gorm:"size:64;comment:cookie类型"`
Idx int `json:"idx" gorm:"comment:索引"`
Ck string `json:"ck" gorm:"type:text;comment:cookie"`
IsValid bool `json:"is_valid" gorm:"default:true;comment:是否有效"`
Space int64 `json:"space" gorm:"default:0;comment:总空间"`
LeftSpace int64 `json:"left_space" gorm:"default:0;comment:剩余空间"`
Remark string `json:"remark" gorm:"size:64;not null;comment:备注"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`

View File

@@ -11,10 +11,7 @@ type Pan struct {
ID uint `json:"id" gorm:"primaryKey;autoIncrement"`
Name string `json:"name" gorm:"size:64;comment:平台名称"`
Key int `json:"key" gorm:"comment:平台标识"`
Ck string `json:"ck" gorm:"type:text;comment:cookie"`
IsValid bool `json:"is_valid" gorm:"default:true;comment:是否有效"`
Space int64 `json:"space" gorm:"default:0;comment:总空间"`
LeftSpace int64 `json:"left_space" gorm:"default:0;comment:剩余空间"`
Icon string `json:"icon" gorm:"size:128;comment:图标文字"`
Remark string `json:"remark" gorm:"size:64;not null;comment:备注"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`

View File

@@ -10,7 +10,8 @@ import (
type CksRepository interface {
BaseRepository[entity.Cks]
FindByPanID(panID uint) ([]entity.Cks, error)
FindByPanIDAndType(panID uint, ckType string) ([]entity.Cks, error)
FindByIsValid(isValid bool) ([]entity.Cks, error)
UpdateSpace(id uint, space, leftSpace int64) error
DeleteByPanID(panID uint) error
}
@@ -33,13 +34,22 @@ func (r *CksRepositoryImpl) FindByPanID(panID uint) ([]entity.Cks, error) {
return cks, err
}
// FindByPanIDAndType 根据PanID和类型查找
func (r *CksRepositoryImpl) FindByPanIDAndType(panID uint, ckType string) ([]entity.Cks, error) {
// FindByIsValid 根据有效性查找
func (r *CksRepositoryImpl) FindByIsValid(isValid bool) ([]entity.Cks, error) {
var cks []entity.Cks
err := r.db.Where("pan_id = ? AND t = ?", panID, ckType).Find(&cks).Error
err := r.db.Where("is_valid = ?", isValid).Find(&cks).Error
return cks, err
}
// UpdateSpace 更新空间信息
func (r *CksRepositoryImpl) UpdateSpace(id uint, space, leftSpace int64) error {
return r.db.Model(&entity.Cks{}).Where("id = ?", id).
Updates(map[string]interface{}{
"space": space,
"left_space": leftSpace,
}).Error
}
// DeleteByPanID 根据PanID删除
func (r *CksRepositoryImpl) DeleteByPanID(panID uint) error {
return r.db.Where("pan_id = ?", panID).Delete(&entity.Cks{}).Error

View File

@@ -9,9 +9,7 @@ import (
// PanRepository Pan的Repository接口
type PanRepository interface {
BaseRepository[entity.Pan]
FindByIsValid(isValid bool) ([]entity.Pan, error)
FindWithCks() ([]entity.Pan, error)
UpdateSpace(id uint, space, leftSpace int64) error
}
// PanRepositoryImpl Pan的Repository实现
@@ -26,25 +24,9 @@ func NewPanRepository(db *gorm.DB) PanRepository {
}
}
// FindByIsValid 根据有效性查找
func (r *PanRepositoryImpl) FindByIsValid(isValid bool) ([]entity.Pan, error) {
var pans []entity.Pan
err := r.db.Where("is_valid = ?", isValid).Find(&pans).Error
return pans, err
}
// FindWithCks 查找包含Cks的Pan
func (r *PanRepositoryImpl) FindWithCks() ([]entity.Pan, error) {
var pans []entity.Pan
err := r.db.Preload("Cks").Find(&pans).Error
return pans, err
}
// UpdateSpace 更新空间信息
func (r *PanRepositoryImpl) UpdateSpace(id uint, space, leftSpace int64) error {
return r.db.Model(&entity.Pan{}).Where("id = ?", id).
Updates(map[string]interface{}{
"space": space,
"left_space": leftSpace,
}).Error
}