Use query params too for page adding handler

This commit is contained in:
2023-03-28 19:40:09 +03:00
parent 9dafdf6abf
commit be8f5e019c
10 changed files with 339 additions and 19 deletions

View File

@@ -98,11 +98,7 @@ func FormatFromRest(format []openapi.Format) []entity.Format {
switch {
case len(format) == 0 || (len(format) == 1 && format[0] == openapi.FormatAll):
formats = []entity.Format{
entity.FormatHeaders,
entity.FormatPDF,
entity.FormatSingleFile,
}
formats = entity.AllFormats
default:
formats = make([]entity.Format, len(format))

View File

@@ -41,8 +41,26 @@ func (s *Service) GetPage(ctx context.Context, params openapi.GetPageParams) (op
return &restPage, nil
}
func (s *Service) AddPage(ctx context.Context, req openapi.OptAddPageReq) (*openapi.Page, error) {
page := entity.NewPage(req.Value.URL, req.Value.Description.Value, FormatFromRest(req.Value.Formats)...)
func (s *Service) AddPage(ctx context.Context, req openapi.OptAddPageReq, params openapi.AddPageParams) (*openapi.Page, error) {
url := params.URL.Or(req.Value.URL)
description := params.Description.Or(req.Value.Description.Value)
formats := req.Value.Formats
if len(formats) == 0 {
formats = params.Formats
}
if len(formats) == 0 {
formats = []openapi.Format{"all"}
}
switch {
case req.Value.URL != "":
url = req.Value.URL
case params.URL.IsSet():
url = params.URL.Value
}
page := entity.NewPage(url, description, FormatFromRest(formats)...)
page.Status = entity.StatusProcessing