refactor: standardize response types across controllers

- Updated multiple controller methods to return VoidResponse instead of generic Response[any].
- Consolidated error handling to utilize GetErrorVoidResponse for consistent error responses.
- Enhanced parameter handling in export and file management functions for improved clarity and maintainability.
- Refactored health check and login/logout methods to align with new response structure.
- Improved overall consistency in response formatting across various endpoints.
This commit is contained in:
Marvin Zhang
2025-03-16 22:25:13 +08:00
parent 700c263cfe
commit 43d1c7692b
16 changed files with 175 additions and 135 deletions

View File

@@ -263,6 +263,12 @@ type ListResponse[T any] struct {
Error string `json:"error"`
}
type VoidResponse struct {
Status string `json:"status"`
Message string `json:"message"`
Error string `json:"error"`
}
func GetDataResponse[T any](model T) (res *Response[T], err error) {
return &Response[T]{
Status: constants.HttpResponseStatusOk,
@@ -280,6 +286,13 @@ func GetListResponse[T any](models []T, total int) (res *ListResponse[T], err er
}, nil
}
func GetVoidResponse() (res *VoidResponse, err error) {
return &VoidResponse{
Status: constants.HttpResponseStatusOk,
Message: constants.HttpResponseMessageSuccess,
}, nil
}
func GetErrorResponse[T any](err error) (res *Response[T], err2 error) {
return &Response[T]{
Status: constants.HttpResponseStatusOk,
@@ -288,6 +301,14 @@ func GetErrorResponse[T any](err error) (res *Response[T], err2 error) {
}, err
}
func GetErrorVoidResponse(err error) (res *VoidResponse, err2 error) {
return &VoidResponse{
Status: constants.HttpResponseStatusOk,
Message: constants.HttpResponseMessageError,
Error: err.Error(),
}, err
}
func GetErrorListResponse[T any](err error) (res *ListResponse[T], err2 error) {
return &ListResponse[T]{
Status: constants.HttpResponseStatusOk,