fixing list result, if not found return empty array
This commit is contained in:
@@ -15,7 +15,10 @@ type BaseResponse[T any] struct {
|
||||
}
|
||||
|
||||
type BaseResponsePaginate[T any] struct {
|
||||
BaseResponse[T]
|
||||
Success bool `json:"success"`
|
||||
Code int `json:"code"`
|
||||
Message string `json:"message"`
|
||||
Data []T `json:"data" swaggertype:"array"`
|
||||
Paginate PaginationInfo
|
||||
}
|
||||
|
||||
@@ -28,14 +31,16 @@ func ToBaseResponse[T any](data T, isSuccess bool, code int, message string) Bas
|
||||
}
|
||||
}
|
||||
|
||||
func ToBaseResponsePaginate[T any](data T, paginate PaginationInfo, isSuccess bool, code int, message string) BaseResponsePaginate[T] {
|
||||
func ToBaseResponsePaginate[T any](data []T, paginate PaginationInfo, isSuccess bool, code int, message string) BaseResponsePaginate[T] {
|
||||
if len(data) == 0 {
|
||||
data = make([]T, 0)
|
||||
}
|
||||
|
||||
return BaseResponsePaginate[T]{
|
||||
BaseResponse: BaseResponse[T]{
|
||||
Success: true,
|
||||
Code: 200,
|
||||
Message: message,
|
||||
Data: data,
|
||||
},
|
||||
Paginate: paginate,
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user