Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: endpoints changes #26

Merged
merged 14 commits into from
Jun 14, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions docs/spec/components/schemas/Event.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ allOf:
- status
- created_at
- updated_at
- has_expiration
- meta
properties:
status:
Expand All @@ -24,6 +25,9 @@ allOf:
type: integer
description: Unix timestamp of the event status change
example: 1706531218
has_expiration:
type: boolean
description: Whether this event may become expired.
meta:
$ref: '#/components/schemas/EventMeta'
points_amount:
Expand Down
18 changes: 17 additions & 1 deletion docs/spec/components/schemas/EventStaticMeta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ required:
- description
- short_description
- frequency
- no_auto_open
- flag
properties:
name:
type: string
Expand Down Expand Up @@ -53,3 +53,19 @@ properties:
type: string
description: Event logo
example: https://logo.com/some_logo.svg
flag:
type: string
description: |
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.
enum:
- active
- not_started
- expired
- disabled
12 changes: 12 additions & 0 deletions docs/spec/components/schemas/EventType.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
allOf:
- $ref: '#/components/schemas/EventTypeKey'
- type: object
description: Event type configuration and metadata
required:
- attributes
properties:
attributes:
# helps to both display good doc and generate convenient model
type: object
format: EventStaticMeta
$ref: '#/components/schemas/EventStaticMeta'
12 changes: 12 additions & 0 deletions docs/spec/components/schemas/EventTypeKey.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
type: object
required:
- id
- type
properties:
id:
type: string
description: Event type unique code name
example: passport_scan
type:
type: string
enum: [ event_type ]
Original file line number Diff line number Diff line change
Expand Up @@ -40,51 +40,3 @@ get:
$ref: '#/components/responses/invalidAuth'
500:
$ref: '#/components/responses/internalError'

patch:
tags:
- Points balance
summary: Activate points balance
description: |
Activate inactive balance. Balance is inactive when referred_by field is null.
nullifier in query must match with id in request body
operationId: activatePointsBalance
parameters:
- $ref: '#/components/parameters/pathNullifier'
requestBody:
content:
application/vnd.api+json:
schema:
type: object
required:
- data
properties:
data:
$ref: '#/components/schemas/CreateBalance'

responses:
200:
description: Success
content:
application/vnd.api+json:
schema:
type: object
required:
- data
properties:
data:
$ref: '#/components/schemas/Balance'
400:
$ref: '#/components/responses/invalidParameter'
401:
$ref: '#/components/responses/invalidAuth'
404:
$ref: '#/components/responses/notFound'
409:
description: Balance already activated
content:
application/vnd.api+json:
schema:
$ref: '#/components/schemas/Errors'
500:
$ref: '#/components/responses/internalError'
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
get:
tags:
- Events
summary: List event types
description: |
Returns public configuration of all event types.
Basically, it is event static metadata (model `EventStaticMeta`)
for each event type in the system.
operationId: getEventTypes
parameters:
- in: query
name: 'filter[name]'
description: Filter by type name. Possible values should be hard-coded in the client.
required: false
schema:
type: array
items:
type: string
example: "passport_scan"
- in: query
name: 'filter[flag]'
description: Filter by configuration flags. Values are disjunctive (OR).
required: false
schema:
type: array
items:
type: string
enum:
- active
- not_started
- expired
- disabled
responses:
200:
description: Success
content:
application/vnd.api+json:
schema:
type: object
required:
- data
properties:
data:
type: array
items:
$ref: '#/components/schemas/EventType'
500:
$ref: '#/components/responses/internalError'
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,13 @@ get:
type: array
items:
type: string
example: "create_org"
example: "passport_scan"
- in: query
name: 'filter[has_expiration]'
description: Filter events by type which has or hasn't expiration.
required: false
schema:
type: boolean
- in: query
name: count
description: Count total number of events for a single user, applying filters.
Expand Down
3 changes: 1 addition & 2 deletions internal/cli/workers.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"github.com/rarimo/rarime-points-svc/internal/service/workers/expirywatch"
"github.com/rarimo/rarime-points-svc/internal/service/workers/nooneisforgotten"
"github.com/rarimo/rarime-points-svc/internal/service/workers/reopener"
"github.com/rarimo/rarime-points-svc/internal/service/workers/sbtcheck"
)

// runServices manages service's dependencies and runs them in the correct order
Expand Down Expand Up @@ -40,7 +39,7 @@ func runServices(ctx context.Context, cfg config.Config, wg *sync.WaitGroup) {
// fulfilled, then both services do not overlap each other
<-reopenerSig
run(func() { nooneisforgotten.Run(cfg, noOneIsForgottenSig) })
run(func() { sbtcheck.Run(ctx, cfg) })
//run(func() { sbtcheck.Run(ctx, cfg) }) // see deprecation notice

// service depends on all the workers for good UX, except sbtcheck, as it has
// long catchup period and users are fine to wait
Expand Down
36 changes: 36 additions & 0 deletions internal/data/evtypes/filters.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ import (
"time"
)

// Filter functions work in the following way:
//
// 1. For FilterBy* functions, the config is only added when it matches the filter:
// FilterByName(name1, name2) will only return events with name1 or name2
//
// 2. For other Filter* functions, the configs matching the filter are excluded:
// FilterExpired eliminates all expired events (instead of including only them)

type filter func(EventConfig) bool

func FilterExpired(ev EventConfig) bool {
Expand All @@ -28,6 +36,34 @@ func FilterByFrequency(f Frequency) func(EventConfig) bool {
}
}

func FilterByNames(names ...string) func(EventConfig) bool {
return func(ev EventConfig) bool {
if len(names) == 0 {
return false
}
for _, name := range names {
if ev.Name == name {
return false
}
}
return true
}
}

func FilterByFlags(flags ...string) func(EventConfig) bool {
return func(ev EventConfig) bool {
if len(flags) == 0 {
return false
}
for _, flag := range flags {
if ev.Flag() == flag {
return false
}
}
return true
}
}

func isFiltered(ev EventConfig, filters ...filter) bool {
for _, f := range filters {
if f(ev) {
Expand Down
20 changes: 18 additions & 2 deletions internal/data/evtypes/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@ const (
)

const (
PassportRewardAge = "age"
PassportRewardNationality = "nationality"
FlagActive = "active"
FlagNotStarted = "not_started"
FlagExpired = "expired"
FlagDisabled = "disabled"
)

type EventConfig struct {
Expand All @@ -50,6 +52,19 @@ type EventConfig struct {
Logo *url.URL `fig:"logo"`
}

func (e EventConfig) Flag() string {
switch {
case e.Disabled:
return FlagDisabled
case FilterNotStarted(e):
return FlagNotStarted
case FilterExpired(e):
return FlagExpired
default:
return FlagActive
}
}

func (e EventConfig) Resource() resources.EventStaticMeta {
safeConv := func(u *url.URL) *string {
if u == nil {
Expand All @@ -70,6 +85,7 @@ func (e EventConfig) Resource() resources.EventStaticMeta {
ExpiresAt: e.ExpiresAt,
ActionUrl: safeConv(e.ActionURL),
Logo: safeConv(e.Logo),
Flag: e.Flag(),
}
}

Expand Down
100 changes: 0 additions & 100 deletions internal/service/handlers/activate_balance.go

This file was deleted.

Loading
Loading