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

Pridana prace s konfigem

parent 6b5f3228
No related branches found
No related tags found
No related merge requests found
Pipeline #1872 passed
...@@ -3,7 +3,7 @@ image: docker:19.03.1 ...@@ -3,7 +3,7 @@ image: docker:19.03.1
variables: variables:
DOCKER_TLS_CERTDIR: "/certs" DOCKER_TLS_CERTDIR: "/certs"
IMAGE_TAG: $CI_REGISTRY_IMAGE IMAGE_TAG: $CI_REGISTRY_IMAGE
IMAGE_VER: 0.5.1 IMAGE_VER: 0.6.0
services: services:
- docker:19.03.1-dind - docker:19.03.1-dind
......
package CF::Controller::Config;
use Mojo::Base 'Mojolicious::Controller';
use Mojo::Pg::PubSub;
use feature 'signatures';
no warnings qw{ experimental::signatures };
sub entries {
my $c = shift->openapi->valid_input or return;
my $entries = $c->schema->resultset('ConfigEntry')->search();
my @entries = ();
ENTRY:
while ( my $entry = $entries->next ) {
push @entries, $c->spec_filter( {
$entry->get_columns,
}, 'ConfigEntry');
}
$c->render(openapi => \@entries );
}
sub update ($c) {
$c->openapi->valid_input or return;
my $entry = $c->schema->resultset('ConfigEntry')->find( $c->stash->{id} );
return $c->error(404, 'Config entry not found') if ! $entry;
return $c->error(403, 'Config entry protected') if $entry->is_readonly;
my $update = $c->prepare_update_data( $entry, $c->req->json );
my $pubsub = Mojo::Pg::PubSub->new(pg => $c->pg);
my $guard = $c->schema->txn_scope_guard;
$entry->update( $update );
$pubsub->json('notify')->notify( notify => {
event => 'config_entry_changed',
payload => {
id => $entry->id,
%{ $update },
}
});
$guard->commit;
$c->render(status => 204, text => '');
}
1;
package CF::Schema::Result::ConfigEntry;
use strict;
use warnings;
use base 'DBIx::Class::Core';
our $VERSION = 1;
__PACKAGE__->table('config');
__PACKAGE__->add_columns(
qw(
id
is_readonly
value
default
description
),
);
__PACKAGE__->set_primary_key('id');
1;
...@@ -44,6 +44,17 @@ components: ...@@ -44,6 +44,17 @@ components:
default: 100 default: 100
minimum: 1 minimum: 1
schemas: schemas:
ConfigEntry:
type: object
properties:
id:
type: string
readOnly: true
is_readonly:
type: boolean
readOnly: true
value:
type: string
ProgramScheduleEntry: ProgramScheduleEntry:
type: object type: object
properties: properties:
...@@ -155,6 +166,40 @@ components: ...@@ -155,6 +166,40 @@ components:
$ref: '#/components/schemas/PostHistoryItem' $ref: '#/components/schemas/PostHistoryItem'
paths: paths:
/config:
get:
x-mojo-to: config#entries
tags:
- config
summary: "Konfigurace systemu"
operationId: getConfig
responses:
200:
description: Konfigurace systemu
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/ConfigEntry'
/config/{id}:
put:
x-mojo-to: config#update
security:
- Bearer: ['chairman']
tags:
- config
summary: "Upravit polozku konfigu"
operationId: updateConfigEntry
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/ConfigEntry'
responses:
204:
description: Program entry updated
/program: /program:
get: get:
x-mojo-to: program#entries x-mojo-to: program#entries
......
create table "config" (
"id" varchar(64),
"is_readonly" bool not null default false,
"value" text,
"default" text,
"description" text,
primary key("id")
);
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment