Skip to content

Commit

Permalink
Code style improvements for PR #5
Browse files Browse the repository at this point in the history
  • Loading branch information
violog committed Jul 24, 2024
1 parent a54fa99 commit b636427
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 19 deletions.
2 changes: 1 addition & 1 deletion docs/spec/paths/integrations@forms-svc@[email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ post:
401:
$ref: '#/components/responses/invalidAuth'
403:
description: "Empty form absent for user, but already exists processed or accepted forms"
description: "Empty form absent for user, but processed or accepted one exists"
content:
application/vnd.api+json:
schema:
Expand Down
1 change: 0 additions & 1 deletion internal/data/forms.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ type FormStatus struct {
type FormsQ interface {
New() FormsQ
Insert(*Form) (*FormStatus, error)
UpdateStatus(status string) error

Update(map[string]interface{}) error

Expand Down
8 changes: 0 additions & 8 deletions internal/data/pg/forms.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,6 @@ func (q *formsQ) Insert(form *data.Form) (*data.FormStatus, error) {
return &res, nil
}

func (q *formsQ) UpdateStatus(status string) error {
if err := q.db.Exec(q.updater.Set("status", status)); err != nil {
return fmt.Errorf("update forms status: %w", err)
}

return nil
}

func (q *formsQ) Update(fields map[string]any) error {
if err := q.db.Exec(q.updater.SetMap(fields)); err != nil {
return fmt.Errorf("update forms: %w", err)
Expand Down
2 changes: 1 addition & 1 deletion internal/service/handlers/submit_form.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func SubmitForm(w http.ResponseWriter, r *http.Request) {
}

if lastForm.Status != data.CreatedStatus {
Log(r).Debugf("User last form don't have created status")
Log(r).Debugf("User last form must have %s status, got %s", data.CreatedStatus, lastForm.Status)
ape.RenderErr(w, problems.Forbidden())
return
}
Expand Down
5 changes: 4 additions & 1 deletion internal/service/workers/formsender/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,10 @@ func Run(ctx context.Context, cfg config.Config) {
ids[i] = v.ID
}

if err = db.FormsQ().FilterByID(ids...).UpdateStatus(data.ProcessedStatus); err != nil {
err = db.FormsQ().FilterByID(ids...).Update(map[string]any{
data.ColStatus: data.ProcessedStatus,
})
if err != nil {
return fmt.Errorf("failed to update form status: %w", err)
}

Expand Down
14 changes: 7 additions & 7 deletions internal/storage/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
)

func (s *Storage) GetImageBase64(object *url.URL) (*string, error) {
spacesURL, err := ParseDOSpacesURL(object)
spacesURL, err := parseDOSpacesURL(object)
if err != nil {
return nil, fmt.Errorf("failed to parse url [%s]: %w", object.String(), err)
}
Expand All @@ -38,7 +38,7 @@ func (s *Storage) GetImageBase64(object *url.URL) (*string, error) {
}

func (s *Storage) ValidateImage(object *url.URL, id string) error {
spacesURL, err := ParseDOSpacesURL(object)
spacesURL, err := parseDOSpacesURL(object)
if err != nil {
return fmt.Errorf("failed to parse url [%s]: %w", object.String(), err)
}
Expand Down Expand Up @@ -91,7 +91,7 @@ func (s *Storage) GeneratePutURL(fileName, contentType string, contentLength int
return signedURL, key, nil
}

func ParseDOSpacesURL(object *url.URL) (*SpacesURL, error) {
func parseDOSpacesURL(object *url.URL) (*SpacesURL, error) {
spacesURL := &SpacesURL{
URL: object,
}
Expand All @@ -110,10 +110,10 @@ func ParseDOSpacesURL(object *url.URL) (*SpacesURL, error) {
}

func IsBadRequestError(err error) bool {
if errors.Is(err, ErrImageTooLarge) &&
errors.Is(err, ErrIncorrectImageType) &&
errors.Is(err, ErrURLRegexp) &&
errors.Is(err, ErrInvalidBucket) &&
if errors.Is(err, ErrImageTooLarge) ||
errors.Is(err, ErrIncorrectImageType) ||
errors.Is(err, ErrURLRegexp) ||
errors.Is(err, ErrInvalidBucket) ||
errors.Is(err, ErrInvalidKey) {
return true
}
Expand Down

0 comments on commit b636427

Please sign in to comment.