Last change
on this file since 2207 was 2077, checked in by Bruno Cornec, 8 years ago |
First attempt to add a Mojolicious web app with swagger providing a RESTful API for pb
|
File size:
968 bytes
|
Rev | Line | |
---|
[2077] | 1 | package ProjectBuilder::Model::Confs;
|
---|
| 2 | use Mojo::Base -base;
|
---|
| 3 | use ProjectBuilder::Conf;
|
---|
| 4 | use Data::Dumper;
|
---|
| 5 |
|
---|
| 6 | sub add {
|
---|
| 7 | my ($self, $conf) = @_;
|
---|
| 8 | my $sql = 'insert into confs (title, body) values (?, ?) returning id';
|
---|
| 9 | #return $self->pg->db->query($sql, $conf->{title}, $conf->{body})->hash->{id};
|
---|
| 10 | }
|
---|
| 11 |
|
---|
| 12 | sub all { #shift->pg->db->query('select * from confs')->hashes->to_array
|
---|
| 13 | my @confs;
|
---|
| 14 | my $i = 0;
|
---|
| 15 | foreach my $k (pb_conf_get_all()) {
|
---|
| 16 | my ($v) = pb_conf_get($k);
|
---|
| 17 | $confs[$i] = { id => $k,
|
---|
| 18 | body => $v->{"pb"},
|
---|
| 19 | };
|
---|
| 20 | $i++;
|
---|
| 21 | }
|
---|
| 22 | #print "PARAMS: ".Dumper(@confs)."\n";
|
---|
| 23 | return(\@confs);
|
---|
| 24 | }
|
---|
| 25 |
|
---|
| 26 | sub find {
|
---|
| 27 | my ($self, $id) = @_;
|
---|
| 28 | #return $self->pg->db->query('select * from confs where id = ?', $id)->hash;
|
---|
| 29 | }
|
---|
| 30 |
|
---|
| 31 | sub remove { #shift->pg->db->query('delete from confs where id = ?', shift)
|
---|
| 32 | }
|
---|
| 33 |
|
---|
| 34 | sub save {
|
---|
| 35 | my ($self, $id, $conf) = @_;
|
---|
| 36 | my $sql = 'update confs set title = ?, body = ? where id = ?';
|
---|
| 37 | #$self->pg->db->query($sql, $conf->{title}, $conf->{body}, $id);
|
---|
| 38 | }
|
---|
| 39 |
|
---|
| 40 | 1;
|
---|
Note:
See
TracBrowser
for help on using the repository browser.