39 lines
910 B
Go
39 lines
910 B
Go
package utils
|
|
|
|
import (
|
|
"alfred/model/common"
|
|
)
|
|
|
|
func ErrorResponse(err error, code int, metadata interface{}) common.Response {
|
|
return common.Response{
|
|
Error: &common.Error{
|
|
Message: err.Error(),
|
|
Metadata: metadata,
|
|
},
|
|
Status: code,
|
|
}
|
|
}
|
|
|
|
func SuccessResponse(data interface{}, code int) common.Response {
|
|
return common.Response{
|
|
Data: data,
|
|
Status: code,
|
|
}
|
|
}
|
|
|
|
func AddErrorToResponse(err error, code int, metadata interface{}, response []common.Response) []common.Response {
|
|
return append(response, ErrorResponse(err, code, metadata))
|
|
}
|
|
|
|
func AddDataToResponse(data interface{}, code int, response []common.Response) []common.Response {
|
|
return append(response, SuccessResponse(data, code))
|
|
}
|
|
|
|
func SuccessPaginatedResponse(data interface{}, page common.Page, code int) common.PaginatedResponse {
|
|
return common.PaginatedResponse{
|
|
Data: data,
|
|
Page: page,
|
|
Status: code,
|
|
}
|
|
}
|