From 554f77dddf092200b5cf278b05c94c26691383df Mon Sep 17 00:00:00 2001 From: violog <51th.apprent1ce.f0rce@gmail.com> Date: Fri, 5 Jul 2024 11:51:53 +0300 Subject: [PATCH] Notice having JSON:API non-compliance in docs --- .../components/schemas/EventStaticMeta.yaml | 4 ++ ...ints-svc@v1@public@event_types@{name}.yaml | 3 ++ .../service/requests/create_event_type.go | 1 + resources/model_event_static_meta.go | 4 +- resources/model_passport_event_state.go | 43 ------------------- .../model_passport_event_state_attributes.go | 10 ----- 6 files changed, 10 insertions(+), 55 deletions(-) delete mode 100644 resources/model_passport_event_state.go delete mode 100644 resources/model_passport_event_state_attributes.go diff --git a/docs/spec/components/schemas/EventStaticMeta.yaml b/docs/spec/components/schemas/EventStaticMeta.yaml index bdb3255..c59c727 100644 --- a/docs/spec/components/schemas/EventStaticMeta.yaml +++ b/docs/spec/components/schemas/EventStaticMeta.yaml @@ -2,6 +2,8 @@ type: object description: | Primary event metadata in plain JSON. This is a template to be filled by `dynamic` when it's present. + + This structure is also reused as request body to event type creation and update. required: - name - reward @@ -66,6 +68,8 @@ properties: If event is disabled, it doesn't matter if it's expired or not started: it has `disabled` flag. + + Do not specify this field on creation: this structure is reused for request body too. enum: - active - not_started diff --git a/docs/spec/paths/integrations@geo-points-svc@v1@public@event_types@{name}.yaml b/docs/spec/paths/integrations@geo-points-svc@v1@public@event_types@{name}.yaml index fa5f7e1..ab20afd 100644 --- a/docs/spec/paths/integrations@geo-points-svc@v1@public@event_types@{name}.yaml +++ b/docs/spec/paths/integrations@geo-points-svc@v1@public@event_types@{name}.yaml @@ -30,6 +30,9 @@ patch: description: | Update an existing event type. Requires **admin** role in JWT. **All attributes** are updated, ensure to pass every existing field too. + Although this is not JSON:API compliant, it is much easier to work with + in Go, because differentiating between `{}` and `{"field": null}` + requires custom unmarshalling implementation. operationId: updateEventType requestBody: required: true diff --git a/internal/service/requests/create_event_type.go b/internal/service/requests/create_event_type.go index b723515..8ba56bf 100644 --- a/internal/service/requests/create_event_type.go +++ b/internal/service/requests/create_event_type.go @@ -26,6 +26,7 @@ func NewCreateEventType(r *http.Request) (req resources.EventTypeResponse, err e "data/attributes/frequency": val.Validate(attr.Frequency, val.Required, val.In(models.Unlimited)), "data/attributes/logo": val.Validate(attr.Logo, is.URL), "data/attributes/name": val.Validate(attr.Name, val.Required, val.In(req.Data.ID)), + "data/attributes/flag": val.Validate(attr.Flag, val.Empty), "data/attributes/qr_code_value": val.Validate(attr.QrCodeValue, val.Required), "data/attributes/reward": val.Validate(attr.Reward, val.Required, val.Min(1)), "data/attributes/short_description": val.Validate(attr.ShortDescription, val.Required), diff --git a/resources/model_event_static_meta.go b/resources/model_event_static_meta.go index 9869a4d..cb8f77d 100644 --- a/resources/model_event_static_meta.go +++ b/resources/model_event_static_meta.go @@ -6,7 +6,7 @@ package resources import "time" -// Primary event metadata in plain JSON. This is a template to be filled by `dynamic` when it's present. +// Primary event metadata in plain JSON. This is a template to be filled by `dynamic` when it's present. This structure is also reused as request body to event type creation and update. type EventStaticMeta struct { // Page where you can fulfill the event ActionUrl *string `json:"action_url,omitempty"` @@ -17,7 +17,7 @@ type EventStaticMeta struct { Disabled bool `json:"disabled"` // General event expiration date (UTC RFC3339) ExpiresAt *time.Time `json:"expires_at,omitempty"` - // Event configuration flag: - active: Events can be opened, fulfilled, claimed - not_started: Event are not available yet, see `starts_at` - expired: Event is not available, as it has already expired, see `expires_at` - disabled: Event is disabled in the system If event is disabled, it doesn't matter if it's expired or not started: it has `disabled` flag. + // Event configuration flag: - active: Events can be opened, fulfilled, claimed - not_started: Event are not available yet, see `starts_at` - expired: Event is not available, as it has already expired, see `expires_at` - disabled: Event is disabled in the system If event is disabled, it doesn't matter if it's expired or not started: it has `disabled` flag. Do not specify this field on creation: this structure is reused for request body too. Flag string `json:"flag"` // Event frequency, which means how often you can fulfill certain task and claim the reward. Frequency string `json:"frequency"` diff --git a/resources/model_passport_event_state.go b/resources/model_passport_event_state.go deleted file mode 100644 index 79dd9f4..0000000 --- a/resources/model_passport_event_state.go +++ /dev/null @@ -1,43 +0,0 @@ -/* - * GENERATED. Do not modify. Your changes might be overwritten! - */ - -package resources - -import "encoding/json" - -type PassportEventState struct { - Key - Attributes PassportEventStateAttributes `json:"attributes"` -} -type PassportEventStateResponse struct { - Data PassportEventState `json:"data"` - Included Included `json:"included"` -} - -type PassportEventStateListResponse struct { - Data []PassportEventState `json:"data"` - Included Included `json:"included"` - Links *Links `json:"links"` - Meta json.RawMessage `json:"meta,omitempty"` -} - -func (r *PassportEventStateListResponse) PutMeta(v interface{}) (err error) { - r.Meta, err = json.Marshal(v) - return err -} - -func (r *PassportEventStateListResponse) GetMeta(out interface{}) error { - return json.Unmarshal(r.Meta, out) -} - -// MustPassportEventState - returns PassportEventState from include collection. -// if entry with specified key does not exist - returns nil -// if entry with specified key exists but type or ID mismatches - panics -func (c *Included) MustPassportEventState(key Key) *PassportEventState { - var passportEventState PassportEventState - if c.tryFindEntry(key, &passportEventState) { - return &passportEventState - } - return nil -} diff --git a/resources/model_passport_event_state_attributes.go b/resources/model_passport_event_state_attributes.go deleted file mode 100644 index 1d3107c..0000000 --- a/resources/model_passport_event_state_attributes.go +++ /dev/null @@ -1,10 +0,0 @@ -/* - * GENERATED. Do not modify. Your changes might be overwritten! - */ - -package resources - -type PassportEventStateAttributes struct { - // If passport scan event was automatically claimed - Claimed bool `json:"claimed"` -}