Skip to content

Commit

Permalink
Merge pull request #26 from rarimo/feature/endpoints-changes
Browse files Browse the repository at this point in the history
Feature: endpoints changes
  • Loading branch information
violog authored Jun 14, 2024
2 parents 5ad6d35 + 7dbbca9 commit bea40cf
Show file tree
Hide file tree
Showing 34 changed files with 443 additions and 258 deletions.
22 changes: 8 additions & 14 deletions docs/spec/components/schemas/Balance.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ allOf:
type: object
required:
- amount
- is_disabled
- created_at
- updated_at
- level
Expand Down Expand Up @@ -38,22 +37,17 @@ allOf:
format: int
description: Rank of the user in the full leaderboard. Returned only for the single user.
example: 294
active_referral_codes:
referral_codes:
type: array
description: |
Referral codes which can be used to build a referral link and send it
to friends. Returned only for the single user.
example: ["zgsScguZ", "jerUsmac"]
items:
type: string
consumed_referral_codes:
type: array
description: Referral codes used by invited users. Returned only for the single user.
example: ["73k3bdYaFWM", "9csIL7dW65m"]
description: Referral codes. Returned only for the single user.
items:
type: string
$ref: '#/components/schemas/ReferralCode'
level:
type: integer
format: int
description: The level indicates user permissions and features
example: 2
example: 2
is_verified:
type: boolean
description: |
Whether the user has scanned passport. Returned only for the single user.
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 ]
30 changes: 30 additions & 0 deletions docs/spec/components/schemas/ReferralCode.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
type: object
required:
- id
- status
properties:
id:
type: string
description: Referral code itself, unique identifier
example: "bDSCcQB8Hhk"
status:
type: string
description: |
Status of the code, belonging to this user (referrer):
1. active: the code is not used yet by another user (referee)
2. banned: the referrer's country (known after scanning passport)
is not allowed to participate in the referral program
3. limited: the limit of reserved tokens in the referrer's country is reached
4. awaiting: the code is used by referee who has scanned passport, but the referrer hasn't yet
5. rewarded: the code is used, both referee and referrer have scanned passports
6. consumed: the code is used by referee who has not scanned passport yet
The list is sorted by priority. E.g. if the referee has scanned passport,
but referrer's country has limit reached, the status would be `limited`.
enum:
- active
- banned
- limited
- awaiting
- rewarded
- consumed
Original file line number Diff line number Diff line change
Expand Up @@ -20,48 +20,7 @@ get:
description: 'Specifies whether to return the referral codes'
required: false
schema:
type: booleand
example: true
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'
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'

type: boolean
responses:
200:
description: Success
Expand All @@ -78,13 +37,5 @@ patch:
$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
9 changes: 9 additions & 0 deletions internal/data/countries.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,15 @@ const (
ColWithdrawn = "withdrawn"
)

const (
StatusActive = "active"
StatusBanned = "banned"
StatusLimited = "limited"
StatusAwaiting = "awaiting"
StatusRewarded = "rewarded"
StatusConsumed = "consumed"
)

type CountriesQ interface {
New() CountriesQ
Insert(countries ...Country) error
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
Loading

0 comments on commit bea40cf

Please sign in to comment.