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: admin panel #3

Merged
merged 12 commits into from
Jul 5, 2024
33 changes: 0 additions & 33 deletions .github/workflows/actions_branch.yaml

This file was deleted.

12 changes: 12 additions & 0 deletions docs/spec/components/schemas/EventStaticMeta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -10,6 +12,8 @@ required:
- short_description
- frequency
- flag
- auto_claim
- disabled
properties:
name:
type: string
Expand Down Expand Up @@ -64,11 +68,19 @@ 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
- expired
- disabled
auto_claim:
type: boolean
description: Whether the event is automatically claimed on fulfillment, or requires manual claim
disabled:
type: boolean
description: Whether the event is disabled in the system. Disabled events can only be retrieved.
qr_code_value:
type: string
description: Base64-encoded QR code. Must match the code provided in event type.
Expand Down
15 changes: 0 additions & 15 deletions docs/spec/components/schemas/JoinProgram.yaml

This file was deleted.

13 changes: 0 additions & 13 deletions docs/spec/components/schemas/JoinProgramKey.yaml

This file was deleted.

6 changes: 0 additions & 6 deletions docs/spec/components/schemas/VerifyPassport.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,12 @@ allOf:
attributes:
required:
- anonymous_id
- country
type: object
properties:
anonymous_id:
type: string
description: Unique identifier of the passport.
example: "2bd3a2532096fee10a45a40e444a11b4d00a707f3459376087747de05996fbf5"
country:
type: string
description: |
ISO 3166-1 alpha-3 country code, must match the one provided in `proof`.
example: "UKR"
proof:
type: object
format: types.ZKProof
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
get:
tags:
- Events
- Event types
summary: List event types
description: |
Returns public configuration of all event types.
Expand Down Expand Up @@ -56,3 +56,38 @@ get:
$ref: '#/components/schemas/EventType'
500:
$ref: '#/components/responses/internalError'

post:
tags:
- Event types
summary: Create event type
description: |
Creates a new event type. Requires **admin** role in JWT.
The type must not be present in the system.
operationId: createEventType
requestBody:
required: true
content:
application/vnd.api+json:
schema:
type: object
required:
- data
properties:
data:
$ref: '#/components/schemas/EventType'
responses:
204:
description: No content
400:
$ref: '#/components/responses/invalidParameter'
401:
$ref: '#/components/responses/invalidAuth'
409:
description: Event type already exists
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,69 @@
get:
tags:
- Event types
summary: Get event type
description: Returns public configuration of event type by its unique name
operationId: getEventType
responses:
200:
description: Success
content:
application/vnd.api+json:
schema:
type: object
required:
- data
properties:
data:
type: array
items:
$ref: '#/components/schemas/EventType'
404:
$ref: '#/components/responses/notFound'
500:
$ref: '#/components/responses/internalError'

patch:
tags:
- Event types
summary: Update event type
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
content:
application/vnd.api+json:
schema:
type: object
required:
- data
properties:
data:
$ref: '#/components/schemas/EventType'
responses:
200:
description: Success
content:
application/vnd.api+json:
schema:
type: object
required:
- data
properties:
data:
type: array
items:
$ref: '#/components/schemas/EventType'
400:
$ref: '#/components/responses/invalidParameter'
401:
$ref: '#/components/responses/invalidAuth'
404:
$ref: '#/components/responses/notFound'
500:
$ref: '#/components/responses/internalError'
5 changes: 5 additions & 0 deletions generate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ function parseArgs {

function generate {
(cd docs && npm run build)
if [[ ! -d "${GENERATED}" ]]; then
mkdir -p "${GENERATED}"
else
rm -rf "${GENERATED}"/*
fi
docker run --rm -v "${OPENAPI_DIR}":/openapi -v "${GENERATED}":/generated "${GENERATOR_IMAGE}" \
generate -pkg "${PACKAGE_NAME}" --raw-formats-as-types --meta-for-lists
goimports -w ${GENERATED}
Expand Down
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,12 @@ require (
github.com/go-co-op/gocron/v2 v2.2.2
github.com/go-ozzo/ozzo-validation/v4 v4.3.0
github.com/google/jsonapi v1.0.0
github.com/google/uuid v1.6.0
github.com/iden3/go-rapidsnark/types v0.0.3
github.com/labstack/gommon v0.4.0
github.com/rarimo/decentralized-auth-svc v0.0.0-20240522134350-2694eafa9509
github.com/rarimo/geo-auth-svc v0.2.0
github.com/rarimo/saver-grpc-lib v1.0.0
github.com/rarimo/zkverifier-kit v1.0.0
github.com/rubenv/sql-migrate v1.6.1
github.com/stretchr/testify v1.9.0
gitlab.com/distributed_lab/ape v1.7.1
gitlab.com/distributed_lab/figure/v3 v3.1.4
gitlab.com/distributed_lab/kit v1.11.3
Expand Down Expand Up @@ -83,6 +81,7 @@ require (
github.com/golang/protobuf v1.5.3 // indirect
github.com/golang/snappy v0.0.5-0.20220116011046-fa5810519dcb // indirect
github.com/google/btree v1.1.2 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/gorilla/websocket v1.5.0 // indirect
github.com/grpc-ecosystem/go-grpc-middleware v1.3.0 // indirect
github.com/grpc-ecosystem/grpc-gateway v1.16.0 // indirect
Expand Down Expand Up @@ -136,6 +135,7 @@ require (
github.com/spf13/cobra v1.7.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/spf13/viper v1.18.2 // indirect
github.com/stretchr/testify v1.9.0 // indirect
github.com/subosito/gotenv v1.6.0 // indirect
github.com/supranational/blst v0.3.11 // indirect
github.com/syndtr/goleveldb v1.0.1-0.20220721030215-126854af5e6d // indirect
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2114,8 +2114,8 @@ github.com/rarimo/broadcaster-svc v1.0.2 h1:ExQcjjWCRP5+POLDlZHrTD1ffUsBH+Dgv5FA
github.com/rarimo/broadcaster-svc v1.0.2/go.mod h1:lYIHy+X4IqQt4eBdtMN/V352H3EV0/gO8G+32SFwUWI=
github.com/rarimo/cosmos-sdk v0.46.7 h1:jU2PiWzc+19SF02cXM0O0puKPeH1C6Q6t2lzJ9s1ejc=
github.com/rarimo/cosmos-sdk v0.46.7/go.mod h1:fqKqz39U5IlEFb4nbQ72951myztsDzFKKDtffYJ63nk=
github.com/rarimo/decentralized-auth-svc v0.0.0-20240522134350-2694eafa9509 h1:U3gu/Z61tVIVEVoWL1YdwiNzkaXlkgd7cSeEslVfsLI=
github.com/rarimo/decentralized-auth-svc v0.0.0-20240522134350-2694eafa9509/go.mod h1:V9XSqZSBN/YmLdI6PW6GL2xNeJ94IXAnhcuvyQfVBL8=
github.com/rarimo/geo-auth-svc v0.2.0 h1:yQvcIBNx+Tc1jJdtpWDfyLc0HogU+okA08HEZ55wv5U=
github.com/rarimo/geo-auth-svc v0.2.0/go.mod h1:SB4bo1xHYDAsBaQGX2+FoEgD3xxqYmcgr4XTTjy4/OM=
github.com/rarimo/saver-grpc-lib v1.0.0 h1:MGUVjYg7unmodYczVsLqlqZNkT4CIgKqdo6aQtL1qdE=
github.com/rarimo/saver-grpc-lib v1.0.0/go.mod h1:DpugWK5B7Hi0bdC3MPe/9FD2zCxaRwsyykdwxtF1Zgg=
github.com/rarimo/zkverifier-kit v1.0.0 h1:zMW85hyDP3Uk6p9Dk9U4TBzOf0Pry+RNlWpli1tUZ1Q=
Expand Down
25 changes: 20 additions & 5 deletions internal/assets/migrations/001_initial.sql
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,12 @@ CREATE TABLE IF NOT EXISTS referrals

CREATE INDEX IF NOT EXISTS referrals_nullifier_index ON referrals (nullifier);

DROP TYPE IF EXISTS event_status;
CREATE TYPE event_status AS ENUM ('open', 'fulfilled', 'claimed');

CREATE TABLE IF NOT EXISTS events
(
id uuid PRIMARY KEY NOT NULL default gen_random_uuid(),
nullifier TEXT NOT NULL REFERENCES balances (nullifier),
type text NOT NULL,
status event_status NOT NULL,
status text NOT NULL,
created_at integer NOT NULL default EXTRACT('EPOCH' FROM NOW()),
updated_at integer NOT NULL default EXTRACT('EPOCH' FROM NOW()),
meta jsonb,
Expand All @@ -60,10 +57,28 @@ CREATE TRIGGER set_updated_at
FOR EACH ROW
EXECUTE FUNCTION trigger_set_updated_at();

CREATE TABLE IF NOT EXISTS event_types
(
name text PRIMARY KEY NOT NULL,
short_description text NOT NULL,
description text NOT NULL,
reward integer NOT NULL,
title text NOT NULL,
frequency text NOT NULL,
starts_at timestamp,
expires_at timestamp,
no_auto_open BOOLEAN NOT NULL DEFAULT FALSE,
auto_claim BOOLEAN NOT NULL DEFAULT FALSE,
disabled BOOLEAN NOT NULL DEFAULT FALSE,
action_url text,
logo text,
qr_code_value text
);

-- +migrate Down
DROP TABLE IF EXISTS event_types;
DROP TABLE IF EXISTS events;
DROP TABLE IF EXISTS referrals;
DROP TABLE IF EXISTS balances;

DROP TYPE IF EXISTS event_status;
DROP FUNCTION IF EXISTS trigger_set_updated_at();
8 changes: 7 additions & 1 deletion internal/cli/workers.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"sync"

"github.com/rarimo/geo-points-svc/internal/config"
"github.com/rarimo/geo-points-svc/internal/data/evtypes"
"github.com/rarimo/geo-points-svc/internal/service"
"github.com/rarimo/geo-points-svc/internal/service/workers/expirywatch"
"github.com/rarimo/geo-points-svc/internal/service/workers/nooneisforgotten"
Expand All @@ -17,6 +18,7 @@ func runServices(ctx context.Context, cfg config.Config, wg *sync.WaitGroup) {
var (
reopenerSig = make(chan struct{})
expiryWatchSig = make(chan struct{})
evTypesSig = make(chan struct{})
noOneIsForgottenSig = make(chan struct{})
)

Expand All @@ -28,7 +30,11 @@ func runServices(ctx context.Context, cfg config.Config, wg *sync.WaitGroup) {
}()
}

// these services can safely run in parallel and don't have dependencies
// all services depend on event types
run(func() { evtypes.Init(ctx, cfg, evTypesSig) })
<-evTypesSig

// these services can safely run in parallel and depend only on event types
run(func() { reopener.Run(ctx, cfg, reopenerSig) })
run(func() { expirywatch.Run(ctx, cfg, expiryWatchSig) })

Expand Down
Loading
Loading