You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
43 lines
1.2 KiB
43 lines
1.2 KiB
package template
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"fmt"
|
|
"net/http"
|
|
|
|
"repository.basistech.ru/BASIS/dynamix-standard-go-sdk/internal/constants"
|
|
"repository.basistech.ru/BASIS/dynamix-standard-go-sdk/internal/validators"
|
|
"repository.basistech.ru/BASIS/dynamix-standard-go-sdk/pkg/template/models"
|
|
"repository.basistech.ru/BASIS/dynamix-standard-go-sdk/pkg/template/requests"
|
|
)
|
|
|
|
// Get return information about specified template
|
|
func (t Template) Get(ctx context.Context, req requests.GetTemplateRequest) (*models.RecordTemplateResponse, error) {
|
|
res, err := t.GetRaw(ctx, req)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
list := models.RecordTemplateResponse{}
|
|
|
|
err = json.Unmarshal(res, &list)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return &list, nil
|
|
}
|
|
|
|
// GetRaw return information about specified template an array of bytes
|
|
func (t Template) GetRaw(ctx context.Context, req requests.GetTemplateRequest) ([]byte, error) {
|
|
|
|
if err := validators.ValidateRequest(req); err != nil {
|
|
return nil, validators.ValidationErrors(validators.GetErrors(err))
|
|
}
|
|
|
|
url := constants.APIv0 + "/template/" + fmt.Sprint(req.TemplateID)
|
|
|
|
res, err := t.client.ApiCall(ctx, http.MethodGet, url, req)
|
|
return res, err
|
|
}
|