You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
43 lines
896 B
Go
43 lines
896 B
Go
package column
|
|
|
|
import "cls/internal/domain/column"
|
|
|
|
// ToDto 将领域对象转换为DTO
|
|
func ToDto(col *column.Column) *ColumnDto {
|
|
if col == nil {
|
|
return nil
|
|
}
|
|
return &ColumnDto{
|
|
ID: col.ID,
|
|
Title: col.Title,
|
|
Brief: col.Brief,
|
|
Cover: col.Cover,
|
|
AuthorID: col.AuthorID,
|
|
Status: col.Status,
|
|
ArticleNum: col.ArticleNum,
|
|
CreatedAt: col.CreatedAt,
|
|
}
|
|
}
|
|
|
|
// ToDtoList 将领域对象列表转换为DTO列表
|
|
func ToDtoList(cols []*column.Column) []*ColumnDto {
|
|
if cols == nil {
|
|
return nil
|
|
}
|
|
dtos := make([]*ColumnDto, len(cols))
|
|
for i, col := range cols {
|
|
dtos[i] = ToDto(col)
|
|
}
|
|
return dtos
|
|
}
|
|
|
|
// ToListResp 转换为列表响应
|
|
func ToListResp(total int64, page, pageSize int, cols []*column.Column) *ColumnListResp {
|
|
return &ColumnListResp{
|
|
Total: total,
|
|
List: ToDtoList(cols),
|
|
Page: page,
|
|
PageSize: pageSize,
|
|
}
|
|
}
|