49 lines
1.4 KiB
Go
49 lines
1.4 KiB
Go
package response
|
|
|
|
import "centerBook/es"
|
|
|
|
// BookSearchResponse 图书搜索响应
|
|
type BookSearchResponse struct {
|
|
CurrentPage int `json:"current_page"`
|
|
Data []es.ESBookResponse `json:"data"`
|
|
PerPage int `json:"per_page"`
|
|
Total int `json:"total"`
|
|
}
|
|
|
|
// NewBookSearchResponse 创建图书搜索响应
|
|
func NewBookSearchResponse(page, pageSize, total int, data []es.ESBookResponse) *BookSearchResponse {
|
|
return &BookSearchResponse{
|
|
CurrentPage: page,
|
|
Data: data,
|
|
PerPage: pageSize,
|
|
Total: total,
|
|
}
|
|
}
|
|
|
|
// UpdateBookResponse 更新图书响应
|
|
type UpdateBookResponse struct {
|
|
Code int `json:"code"`
|
|
Message string `json:"message"`
|
|
ISBN string `json:"isbn"`
|
|
Updated int `json:"updated"`
|
|
FieldsUpdated int `json:"fields_updated"`
|
|
UpdatedFields []string `json:"updated_fields"`
|
|
}
|
|
|
|
// NewUpdateBookResponse 创建更新图书响应
|
|
func NewUpdateBookResponse(isbn string, updated int, fields map[string]interface{}) *UpdateBookResponse {
|
|
fieldsList := make([]string, 0, len(fields))
|
|
for k := range fields {
|
|
fieldsList = append(fieldsList, k)
|
|
}
|
|
|
|
return &UpdateBookResponse{
|
|
Code: 200,
|
|
Message: "success",
|
|
ISBN: isbn,
|
|
Updated: updated,
|
|
FieldsUpdated: len(fields),
|
|
UpdatedFields: fieldsList,
|
|
}
|
|
}
|