diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 486f5707cc6826f1b95c9e67a4d377a19ea34f79..1363ff6bb0b7f3f58db95b1b380d2a735b57468b 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.2.0 + IMAGE_VER: 0.3.0 services: - docker:20.10.9-dind diff --git a/lib/CF2022/Controller/Lists.pm b/lib/CF2022/Controller/Lists.pm deleted file mode 100644 index bd9c587edf883c91e48461be5c77246806aa9b4c..0000000000000000000000000000000000000000 --- a/lib/CF2022/Controller/Lists.pm +++ /dev/null @@ -1,68 +0,0 @@ -package CF2022::Controller::Lists; -use Mojo::Base 'Mojolicious::Controller'; -use Mojo::UserAgent; - -sub options { - my $c = shift->openapi->valid_input or return; - - my $args = $c->validation->output; - - my @options = (); - - my $url = sprintf ('%s/organizers/%s/events/%s/', - $c->config->{pretix_api}, - $c->config->{pretix_organizer}, - $c->config->{pretix_event}, - ); - - if ( $args->{type} eq 'products' ) { - $url .= 'items/'; - } - if ( $args->{type} eq 'variations' ) { - $url .= 'items/' . $args->{product_id} . '/variations/'; - } - elsif ( $args->{type} eq 'questions' ) { - $url .= 'questions/'; - } - - my $ua = Mojo::UserAgent->new; - - my $records = $ua->get( $url, { - Authorization => 'Token ' . $c->config->{pretix_token} - } )->result->json; - - RECORD: - foreach my $record ( @{ $records->{results} } ) { - if ( $args->{type} eq 'products' ) { - next RECORD if ! $record->{active}; - next RECORD if $args->{category_id} && $record->{category} != $args->{category_id}; - push @options, { - value => $record->{id}, - label => $record->{name}{en}, - price => $record->{default_price} + 0, - }; - } - elsif ( $args->{type} eq 'questions' ) { - next RECORD if $record->{hidden}; - push @options, { - value => $record->{id}, - label => $record->{question}{en}, - price => 0, - }; - } - elsif ( $args->{type} eq 'variations' ) { - next RECORD if $record->{hidden}; - push @options, { - value => $record->{id}, - label => $record->{value}{en}, - price => $record->{price} + 0, - }; - } - } - - - - $c->render(openapi => \@options); -} - -1; diff --git a/lib/CF2022/Controller/Products.pm b/lib/CF2022/Controller/Products.pm new file mode 100644 index 0000000000000000000000000000000000000000..644303cd276589eb292eb9e57e5eacc39ed681fd --- /dev/null +++ b/lib/CF2022/Controller/Products.pm @@ -0,0 +1,45 @@ +package CF2022::Controller::Products; +use Mojo::Base 'Mojolicious::Controller'; +use Mojo::UserAgent; + +sub list { + my $c = shift->openapi->valid_input or return; + + my $url = sprintf ('%s/organizers/%s/events/%s/items/', + $c->config->{pretix_api}, + $c->config->{pretix_organizer}, + $c->config->{pretix_event}, + ); + + my $ua = Mojo::UserAgent->new; + + my $records = $ua->get( $url, { + Authorization => 'Token ' . $c->config->{pretix_token} + } )->result->json; + + my @options = (); + + RECORD: + foreach my $record ( @{ $records->{results} } ) { + next RECORD if ! $record->{active}; + + push @options, { + id => $record->{id}, + name => $record->{name}{en}, + price => $record->{default_price} + 0, + free_price => $record->{free_price}, + category_id => $record->{category}, + variations => [ + map {{ + id => $_->{id}, + value => $_->{value}{en}, + price => $_->{price} + 0 + }} @{ $record->{variations} } + ], + }; + } + + $c->render(openapi => \@options); +} + +1; diff --git a/lib/CF2022/Controller/Questions.pm b/lib/CF2022/Controller/Questions.pm new file mode 100644 index 0000000000000000000000000000000000000000..62c801d87a12017b27c578ce7b15c47ab7973004 --- /dev/null +++ b/lib/CF2022/Controller/Questions.pm @@ -0,0 +1,36 @@ +package CF2022::Controller::Questions; +use Mojo::Base 'Mojolicious::Controller'; +use Mojo::UserAgent; + +sub list { + my $c = shift->openapi->valid_input or return; + + my $url = sprintf ('%s/organizers/%s/events/%s/questions/', + $c->config->{pretix_api}, + $c->config->{pretix_organizer}, + $c->config->{pretix_event}, + ); + + my $ua = Mojo::UserAgent->new; + + my $records = $ua->get( $url, { + Authorization => 'Token ' . $c->config->{pretix_token} + } )->result->json; + + my @options = (); + + RECORD: + foreach my $record ( @{ $records->{results} } ) { + next RECORD if $record->{hidden}; + push @options, { + id => $record->{id}, + question => $record->{question}{en}, + help => $record->{help_text}{en} // '', + }; + } + + $c->render(openapi => \@options); +} + +1; + diff --git a/openapi.yaml b/openapi.yaml index b11b1d6a50410bdba6b11f3433158c218bc2c8b7..63611e5af01a77a13eb493108750b375b1a4589e 100644 --- a/openapi.yaml +++ b/openapi.yaml @@ -22,69 +22,94 @@ servers: components: schemas: - Response: + Question: type: object properties: - request_id: + id: + type: integer + question: type: string + help: + type: string + Response: + type: object + properties: + question_id: + type: integer response: type: string - Product: + Variation: type: object properties: id: - type: integer - variation: type: integer + value: + type: string price: type: integer - Option: + Product: type: object properties: - value: + id: + type: integer + category_id: + type: integer + name: type: string - label: + description: type: string + variations: + type: array + items: + $ref: '#/components/schemas/Variation' + price: + type: integer + free_price: + type: boolean + ProductOrder: + type: object + properties: + id: + type: integer + variation: + type: integer price: type: integer paths: - /options/{type}/: + /questions: + get: + x-mojo-to: questions#list + tags: + - options + summary: "Questions" + operationId: getQuestions + responses: + 200: + description: Questions list + content: + application/json: + schema: + type: array + items: + $ref: '#/components/schemas/Question' + /products: get: - x-mojo-to: lists#options + x-mojo-to: products#list tags: - options - summary: "Options" - operationId: getOptions - parameters: - - name: type - in: path - description: List ID - required: true - schema: - type: string - enum: ['products', 'variations', 'questions'] - - name: product_id - in: query - description: Product ID for variations - required: false - schema: - type: integer - - name: category_id - in: query - description: Category ID for variations - required: false - schema: - type: integer + summary: "Products" + operationId: getProducts responses: 200: - description: Options list + description: Products list content: application/json: schema: type: array items: - $ref: '#/components/schemas/Option' + $ref: '#/components/schemas/Product' + /orders: post: @@ -116,7 +141,7 @@ paths: products: type: array items: - $ref: '#/components/schemas/Product' + $ref: '#/components/schemas/ProductOrder' responses: type: array items: