From b45a79bfb62419e4cf728875db5ea1c573e71e4b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrej=20Rama=C5=A1euski?= <andrej@x2.cz> Date: Sat, 13 Nov 2021 17:43:14 +0100 Subject: [PATCH] Existence objednavky a detail objednavky --- .gitlab-ci.yml | 2 +- lib/CF2022/Controller/Orders.pm | 49 +++++++++++++++++++++++++++++++++ openapi.yaml | 48 ++++++++++++++++++++++++++++++++ 3 files changed, 98 insertions(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index ce5f551..64e8cd7 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -2,7 +2,7 @@ image: docker:20.10.9 variables: DOCKER_TLS_CERTDIR: "/certs" - IMAGE_VER: 0.7.0 + IMAGE_VER: 0.8.0 services: - docker:20.10.9-dind diff --git a/lib/CF2022/Controller/Orders.pm b/lib/CF2022/Controller/Orders.pm index 4d1778e..477fd38 100644 --- a/lib/CF2022/Controller/Orders.pm +++ b/lib/CF2022/Controller/Orders.pm @@ -157,4 +157,53 @@ sub create ($c ) { ); } +sub exists ($c ) { + $c->openapi->valid_input or return; + + my $key = $c->param('key'); + + my $field = ( $key =~ /\@/ ) ? 'email' : 'sso_uuid'; + + my $exists = $c->schema->resultset('Order')->search({ + deleted => undef, + $field => $key, + })->count; + + $c->render( + status => 200, + openapi => { exists => $exists }, + ); +} + +sub get ($c ) { + $c->openapi->valid_input or return; + + $c->oauth_token($c->tx->req->content->headers->header('X-Token')); + + my $claims = $c->oauth_claims; + return $c->error(403, 'Invalid token') if ! $claims; + + my $order = $c->schema->resultset('Order')->search({ + deleted => undef, + sso_uuid => $claims->{sub}, + })->first; + + return $c->error(404, 'NOT FOUND') if ! $order; + + # datas z pretixu + + $c->app->log->error($order->api . $order->order_id); + my $ua = Mojo::UserAgent->new; + my $rc = $ua->get( $order->api . $order->order_id . '/', + { Authorization => 'Token ' . $c->config->{pretix_token} }, + )->result; + + return $c->error(400, $rc->body) if ! $rc->is_success; + + $c->render( + status => 200, + openapi => { order => $rc->json }, + ); +} + 1; diff --git a/openapi.yaml b/openapi.yaml index 89e82ae..234e727 100644 --- a/openapi.yaml +++ b/openapi.yaml @@ -162,3 +162,51 @@ paths: url: type: string description: Tickets url + + /orders/exists: + get: + x-mojo-to: orders#exists + tags: + - order + summary: "Existence objednavky" + operationId: checkOrder + parameters: + - name: key + in: query + required: true + example: andrej.ramaseuski@pirati.cz + description: "Email nebo SSO UUID" + schema: + type: string + responses: + 200: + description: Stav + content: + application/json: + schema: + type: object + properties: + exists: + type: boolean + + /orders/detail: + get: + x-mojo-to: orders#get + tags: + - order + summary: "Objednavka" + operationId: getOrder + parameters: + - name: "X-Token" + in: header + required: true + description: "SSO Token" + schema: + type: string + responses: + 200: + description: Objednavka + content: + application/json: + schema: + type: object -- GitLab