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
variables:
DOCKER_TLS_CERTDIR: "/certs"
IMAGE_VER: 2.0.0
IMAGE_VER: 2.1.0
services:
- docker:19.03.12-dind
......
......@@ -30,8 +30,10 @@ sub create ($c) {
sub get ($c) {
$c->openapi->valid_input or return;
my $event = $c->schema->resultset('Event')->find($c->stash->{id});
return $c->error(404, 'Event not found') if ! $event;
my $event = $c->schema->resultset('Event')->find({
id => $c->stash->{id},
});
return $c->error(404, 'Event not found') if ! $event || $event->deleted;
my $formatted = $event->format();
$formatted->{acl} = [];
......@@ -49,7 +51,7 @@ sub get ($c) {
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) {
......@@ -98,14 +100,11 @@ sub update ($c) {
return $c->error(404, 'Event not found') if ! $event;
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;
$c->render(status => 204, text => '');
}
......@@ -117,8 +116,9 @@ sub delete ($c) {
my $guard = $c->schema->txn_scope_guard;
$event->update({ deleted => \'now()', });
$guard->commit;
$c->render(status => 204, text => '');
}
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:
required: false
schema:
type: boolean
default: false
example: true
- name: sort
description: "Razeni"
in: query
......@@ -431,7 +433,7 @@ paths:
get:
x-mojo-to: events#get
security:
- Bearer: ['optional']
- Bearer: ['optional', '*']
tags:
- events
summary: "Detail udalosti"
......@@ -440,6 +442,7 @@ paths:
- name: id
in: path
required: true
example: 100345
description: "ID"
schema:
type: integer
......@@ -462,6 +465,7 @@ paths:
- name: id
in: path
required: true
example: 100345
description: "ID"
schema:
type: integer
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment