-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
209 lines (173 loc) · 8.65 KB
/
Copy pathindex.php
File metadata and controls
209 lines (173 loc) · 8.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
<?php
/**
* Created by PhpStorm.
* User: Eduardo_Chavez
* Date: 19/3/2017
* Time: 12:04 AM
*/
spl_autoload_register(function ($classname) {
require("include/" . $classname . ".php");
});
use \Psr\Http\Message\ServerRequestInterface as Request;
use \Psr\Http\Message\ResponseInterface as Response;
require 'vendor/autoload.php';
$config['displayErrorDetails'] = true;
$config['addContentLengthHeader'] = false;
$config['db']['host'] = "localhost";
$config['db']['user'] = "root";
$config['db']['pass'] = "";
$config['db']['dbname'] = "salvadoranRecords";
$app = new \Slim\App(["settings" => $config]);
$container = $app->getContainer();
$container['db'] = function ($c) {
$db = $c['settings']['db'];
$pdo = new PDO("mysql:host=" . $db['host'] . ";dbname=" . $db['dbname'],
$db['user'], $db['pass']);
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$pdo->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
return $pdo;
};
$app->get('/', function (Request $request, Response $response) {
readfile("webpage/index.html");
});
/**ARTISTAS**/
//LISTAR TODOS LOS ARTISTAS
$app->get('/artists', function (Request $request, Response $response) {
$sth = $this->db->prepare("SELECT * FROM Artist");
$sth->execute();
$artists = $sth->fetchAll();
return $this->response->withJson($artists);
});
//Obtener artista por ID
$app->get('/artist/[{id}]', function ($request, $response, $args) {
$sth = $this->db->prepare("SELECT * FROM Artist WHERE id=:id");
$sth->bindParam("id", $args['id']);
$sth->execute();
$artist = $sth->fetchObject();
return $this->response->withJson($artist);
});
//Obtener artistas por medio de nombre
$app->get('/artist/search/[{query}]', function ($request, $response, $args) {
$sth = $this->db->prepare("SELECT * FROM Artist WHERE UPPER(nombre) LIKE :query");
$query = "%" . $args['query'] . "%";
$sth->bindParam("query", $query);
$sth->execute();
$todos = $sth->fetchAll();
return $this->response->withJson($todos);
});
//POST para artista
$app->post('/newartist', function ($request, $response) {
$data = $request->getParsedBody();
$sql = "insert into Artist (nombre,miembros,trayectoria,genero,primersencillo)"
. " VALUES('$data[nombre]','$data[miembros]','$data[trayectoria]','$data[genero]','$data[primersencillo]')";
$exe = $this->db->query($sql);
echo("Artista agregado");
});
$app->delete('/artist/[{id}]', function ($request, $response, $args) {
$sth = $this->db->prepare("DELETE FROM Artist WHERE id=:id");
$sth->bindParam("id", $args['id']);
$sth->execute();
echo("Elemento eliminado");
});
$app->put('/artist/[{id}]', function ($request, $response, $args) {
$data = $request->getParsedBody();
$sql = "UPDATE Artist SET nombre='$data[nombre]', miembros = '$data[miembros]', trayectoria = '$data[trayectoria]',genero = '$data[genero]', primersencillo = '$data[primersencillo]' WHERE id=:id";
$sth = $this->db->prepare($sql);
$sth->bindParam("id", $args['id']);
$sth->execute();
echo("Artista actualizado");
});
/**CONCIERTOS **/
//Busqueda de conciertos por nombre de artista
$app->get('/concert/search/[{query}]', function ($request, $response, $args) {
$sth = $this->db->prepare("SELECT a.nombre as Artista, c.lugar as Lugar, c.asistencia as Asistencia, c.entrada as Entrada, c.ganancias as Ganacias, c.pago_artista as Pago_artista, c.fecha as Fecha,
c.representante as representante from Artist a INNER JOIN nextConcerts c ON a.id = c.id_artista WHERE UPPER(a.nombre) LIKE :query");
$query = "%" . $args['query'] . "%";
$sth->bindParam("query", $query);
$sth->execute();
$todos = $sth->fetchAll();
return $this->response->withJson($todos);
});
$app->get('/concerts', function (Request $request, Response $response) {
$sth = $this->db->prepare("SELECT c.id as identificador, a.nombre as Artista, c.lugar as Lugar, c.asistencia as Asistencia, c.entrada as Entrada, c.ganancias as Ganacias, c.pago_artista as Pago_artista, c.fecha as Fecha,
c.representante as representante from Artist a INNER JOIN nextConcerts c ON a.id = c.id_artista");
$sth->execute();
$concerts = $sth->fetchAll();
return $this->response->withJson($concerts);
});
$app->get('/concert/[{id}]', function ($request, $response, $args) {
$sth = $this->db->prepare("SELECT a.nombre as Artista, c.lugar as Lugar, c.asistencia as Asistencia, c.entrada as Entrada, c.ganancias as Ganacias, c.pago_artista as Pago_artista, c.fecha as Fecha,
c.representante as representante from Artist a INNER JOIN nextConcerts c ON a.id = c.id_artista WHERE c.id=:id");
$sth->bindParam("id", $args['id']);
$sth->execute();
$concerts = $sth->fetchObject();
return $this->response->withJson($concerts);
});
$app->post('/newconcert', function ($request, $response) {
$data = $request->getParsedBody();
$sql = "insert into nextConcerts(id_artista,lugar,asistencia,entrada,ganancias,pago_artista,fecha,representante)"
. " VALUES('$data[id_artista]','$data[lugar]','$data[asistencia]','$data[entrada]','$data[ganancias]','$data[pago_artista]','$data[fecha]','$data[representante]')";
$exe = $this->db->query($sql);
echo("Concierto agregado");
});
$app->delete('/concert/[{id}]', function ($request, $response, $args) {
$sth = $this->db->prepare("DELETE FROM nextConcerts WHERE id=:id");
$sth->bindParam("id", $args['id']);
$sth->execute();
echo("Elemento eliminado");
});
$app->put('/concert/[{id}]', function ($request, $response, $args) {
$data = $request->getParsedBody();
$sql = "UPDATE nextConcerts SET id_artista='$data[id_artista]', lugar = '$data[lugar]', asistencia = '$data[asistencia]', entrada = '$data[entrada]',ganancias = '$data[ganancias]', pago_artista = '$data[pago_artista]', fecha = '$data[fecha]', representante = '$data[representante]' WHERE id=:id";
$sth = $this->db->prepare($sql);
$sth->bindParam("id", $args['id']);
$sth->execute();
echo("Concierto actualizado");
});
/**DISCOGRAFIA**/
$app->get('/discography', function (Request $request, Response $response) {
$sth = $this->db->prepare("Select d.id as identificador, a.nombre as Artista, d.nombre as Disco, d.anio as Anio, d.ventas_copias as Ventas_copias, d.pistas as Pistas, d.colaboracion as Colaboracion, d.sencillo as Sencillo_principal
from discography d INNER JOIN artist a ON a.id = d.id_artista");
$sth->execute();
$artists = $sth->fetchAll();
return $this->response->withJson($artists);
});
$app->get('/disc/[{id}]', function ($request, $response, $args) {
$sth = $this->db->prepare("Select a.nombre as Artista, d.nombre as Disco, d.anio as Anio, d.ventas_copias as Ventas_copias, d.pistas as Pistas, d.colaboracion as Colaboracion, d.sencillo as Sencillo_principal
from discography d INNER JOIN artist a ON a.id = d.id_artista WHERE d.id=:id");
$sth->bindParam("id", $args['id']);
$sth->execute();
$concerts = $sth->fetchObject();
return $this->response->withJson($concerts);
});
$app->get('/disc/search/[{query}]', function ($request, $response, $args) {
$sth = $this->db->prepare("Select a.nombre as Artista, d.nombre as Disco, d.anio as Anio, d.ventas_copias as Ventas_copias, d.pistas as Pistas, d.colaboracion as Colaboracion, d.sencillo as Sencillo_principal
from discography d INNER JOIN artist a ON a.id = d.id_artista WHERE UPPER(a.nombre) LIKE :query");
$query = "%" . $args['query'] . "%";
$sth->bindParam("query", $query);
$sth->execute();
$todos = $sth->fetchAll();
return $this->response->withJson($todos);
});
$app->post('/newdisc', function ($request, $response) {
$data = $request->getParsedBody();
$sql = "insert into discography(id_artista,nombre,anio,ventas_copias,pistas,colaboracion,sencillo)"
. " VALUES('$data[id_artista]','$data[nombre]','$data[anio]','$data[ventas_copias]','$data[pistas]','$data[colaboracion]','$data[sencillo]')";
$exe = $this->db->query($sql);
echo("Disco agregado");
});
$app->delete('/disc/[{id}]', function ($request, $response, $args) {
$sth = $this->db->prepare("DELETE FROM Discography WHERE id=:id");
$sth->bindParam("id", $args['id']);
$sth->execute();
echo("Elemento eliminado");
});
$app->put('/disc/[{id}]', function ($request, $response, $args) {
$data = $request->getParsedBody();
$sql = "UPDATE discography SET id_artista='$data[id_artista]', nombre = '$data[nombre]', anio = '$data[anio]', ventas_copias= '$data[ventas_copias]', pistas = '$data[pistas]', colaboracion = '$data[colaboracion]', sencillo = '$data[sencillo]' WHERE id=:id";
$sth = $this->db->prepare($sql);
$sth->bindParam("id", $args['id']);
$sth->execute();
echo("Concierto actualizado");
});
$app->run();