Skip to content
Snippets Groups Projects
Verified Commit d2335c65 authored by Andrej Ramašeuski's avatar Andrej Ramašeuski
Browse files

Dokonceny zakladni CRUD pro Events

parent e98cd361
No related branches found
No related tags found
No related merge requests found
Pipeline #3061 passed
...@@ -2,7 +2,7 @@ image: docker:19.03.12 ...@@ -2,7 +2,7 @@ image: docker:19.03.12
variables: variables:
DOCKER_TLS_CERTDIR: "/certs" DOCKER_TLS_CERTDIR: "/certs"
IMAGE_VER: 2.0.0 IMAGE_VER: 2.1.0
services: services:
- docker:19.03.12-dind - docker:19.03.12-dind
......
...@@ -30,8 +30,10 @@ sub create ($c) { ...@@ -30,8 +30,10 @@ sub create ($c) {
sub get ($c) { sub get ($c) {
$c->openapi->valid_input or return; $c->openapi->valid_input or return;
my $event = $c->schema->resultset('Event')->find($c->stash->{id}); my $event = $c->schema->resultset('Event')->find({
return $c->error(404, 'Event not found') if ! $event; id => $c->stash->{id},
});
return $c->error(404, 'Event not found') if ! $event || $event->deleted;
my $formatted = $event->format(); my $formatted = $event->format();
$formatted->{acl} = []; $formatted->{acl} = [];
...@@ -49,7 +51,7 @@ sub get ($c) { ...@@ -49,7 +51,7 @@ sub get ($c) {
return $c->error(404, 'Event not found'); return $c->error(404, 'Event not found');
} }
$c->render(openapi => $c->spec_filter($formatted, 'Event')); $c->render(json => $c->spec_filter($formatted, 'Event')); # BUG: error if openpi
} }
sub list ($c) { sub list ($c) {
...@@ -98,14 +100,11 @@ sub update ($c) { ...@@ -98,14 +100,11 @@ sub update ($c) {
return $c->error(404, 'Event not found') if ! $event; return $c->error(404, 'Event not found') if ! $event;
my $update = $c->prepare_update_data( $event, $c->req->json ); my $update = $c->prepare_update_data( $event, $c->req->json );
my $guard = $c->schema->txn_scope_guard;
$event->update({
%{ $update },
changed => \'now()',
});
my $guard = $c->schema->txn_scope_guard;
$event->update({ %{ $update }, });
$guard->commit; $guard->commit;
$c->render(status => 204, text => ''); $c->render(status => 204, text => '');
} }
...@@ -117,8 +116,9 @@ sub delete ($c) { ...@@ -117,8 +116,9 @@ sub delete ($c) {
my $guard = $c->schema->txn_scope_guard; my $guard = $c->schema->txn_scope_guard;
$event->update({ deleted => \'now()', }); $event->update({ deleted => \'now()', });
$guard->commit; $guard->commit;
$c->render(status => 204, text => ''); $c->render(status => 204, text => '');
} }
1; 1;
package CF::Schema::ResultSet::Event;
use strict;
use warnings;
use base 'DBIx::Class::ResultSet';
use constant PROTECTED_FIELDS => [qw(
id
uuid
owner_id
deleted
)];
1;
...@@ -401,6 +401,8 @@ paths: ...@@ -401,6 +401,8 @@ paths:
required: false required: false
schema: schema:
type: boolean type: boolean
default: false
example: true
- name: sort - name: sort
description: "Razeni" description: "Razeni"
in: query in: query
...@@ -431,7 +433,7 @@ paths: ...@@ -431,7 +433,7 @@ paths:
get: get:
x-mojo-to: events#get x-mojo-to: events#get
security: security:
- Bearer: ['optional'] - Bearer: ['optional', '*']
tags: tags:
- events - events
summary: "Detail udalosti" summary: "Detail udalosti"
...@@ -440,6 +442,7 @@ paths: ...@@ -440,6 +442,7 @@ paths:
- name: id - name: id
in: path in: path
required: true required: true
example: 100345
description: "ID" description: "ID"
schema: schema:
type: integer type: integer
...@@ -462,6 +465,7 @@ paths: ...@@ -462,6 +465,7 @@ paths:
- name: id - name: id
in: path in: path
required: true required: true
example: 100345
description: "ID" description: "ID"
schema: schema:
type: integer type: integer
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment