67 lines
2.1 KiB
Go
67 lines
2.1 KiB
Go
package dto
|
|
|
|
import (
|
|
"errors"
|
|
|
|
"github.com/Caknoooo/go-gin-clean-starter/database/entities"
|
|
pkgdto "github.com/Caknoooo/go-gin-clean-starter/pkg/dto"
|
|
)
|
|
|
|
const (
|
|
MESSAGE_FAILED_CREATE_CATEGORY = "failed create category"
|
|
MESSAGE_SUCCESS_CREATE_CATEGORY = "success create category"
|
|
MESSAGE_FAILED_GET_CATEGORY = "failed get category"
|
|
MESSAGE_SUCCESS_GET_CATEGORY = "success get category"
|
|
MESSAGE_FAILED_UPDATE_CATEGORY = "failed update category"
|
|
MESSAGE_SUCCESS_UPDATE_CATEGORY = "success update category"
|
|
MESSAGE_FAILED_DELETE_CATEGORY = "failed delete category"
|
|
MESSAGE_SUCCESS_DELETE_CATEGORY = "success delete category"
|
|
MESSAGE_FAILED_GET_DATA_FROM_BODY = "failed get data from body"
|
|
)
|
|
|
|
var (
|
|
ErrCreateCategory = errors.New("failed to create category")
|
|
ErrGetCategoryById = errors.New("failed to get category by id")
|
|
ErrUpdateCategory = errors.New("failed to update category")
|
|
ErrDeleteCategory = errors.New("failed to delete category")
|
|
)
|
|
|
|
type CategoryCreateRequest struct {
|
|
Name string `json:"name" binding:"required"`
|
|
SearchKey string `json:"search_key" binding:"required"`
|
|
Description string `json:"description"`
|
|
IsActive bool `json:"is_active"`
|
|
ClientID string `json:"client_id" binding:"required"`
|
|
}
|
|
|
|
type CategoryUpdateRequest struct {
|
|
Name string `json:"name"`
|
|
SearchKey string `json:"search_key"`
|
|
Description string `json:"description"`
|
|
IsActive bool `json:"is_active"`
|
|
ClientID string `json:"client_id"`
|
|
}
|
|
|
|
type CategoryResponse struct {
|
|
ID string `json:"id"`
|
|
Name string `json:"name"`
|
|
SearchKey string `json:"search_key"`
|
|
Description string `json:"description"`
|
|
IsActive bool `json:"is_active"`
|
|
Client pkgdto.IdNameResponse `json:"client"`
|
|
}
|
|
|
|
func ToCategoryResponse(e entities.MCategoryEntity) CategoryResponse {
|
|
return CategoryResponse{
|
|
ID: e.ID.String(),
|
|
Name: e.Name,
|
|
SearchKey: e.SearchKey,
|
|
Description: e.Description,
|
|
IsActive: e.IsActive,
|
|
Client: pkgdto.IdNameResponse{
|
|
ID: e.Client.ID.String(),
|
|
Name: e.Client.Name,
|
|
},
|
|
}
|
|
}
|