Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
D
DAAExample
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Santiago Gómez Vilar
DAAExample
Commits
f0ea308b
Commit
f0ea308b
authored
Mar 08, 2019
by
Santi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Complete pets dato an repository
parent
bdd498fc
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
98 additions
and
4 deletions
+98
-4
PetsResource.java
src/main/java/es/uvigo/esei/daa/rest/PetsResource.java
+98
-4
No files found.
src/main/java/es/uvigo/esei/daa/rest/PetsResource.java
View file @
f0ea308b
...
@@ -4,10 +4,7 @@ import es.uvigo.esei.daa.dao.DAOException;
...
@@ -4,10 +4,7 @@ import es.uvigo.esei.daa.dao.DAOException;
import
es.uvigo.esei.daa.dao.PetsDAO
;
import
es.uvigo.esei.daa.dao.PetsDAO
;
import
es.uvigo.esei.daa.entities.Pet
;
import
es.uvigo.esei.daa.entities.Pet
;
import
javax.ws.rs.GET
;
import
javax.ws.rs.*
;
import
javax.ws.rs.Path
;
import
javax.ws.rs.PathParam
;
import
javax.ws.rs.Produces
;
import
javax.ws.rs.core.MediaType
;
import
javax.ws.rs.core.MediaType
;
import
javax.ws.rs.core.Response
;
import
javax.ws.rs.core.Response
;
import
java.util.logging.Level
;
import
java.util.logging.Level
;
...
@@ -63,4 +60,101 @@ public class PetsResource {
...
@@ -63,4 +60,101 @@ public class PetsResource {
.
build
();
.
build
();
}
}
}
}
@DELETE
@Path
(
"/{id}"
)
public
Response
delete
(
@PathParam
(
"id"
)
int
id
)
{
try
{
this
.
dao
.
delete
(
id
);
return
Response
.
ok
(
id
).
build
();
}
catch
(
IllegalArgumentException
iae
)
{
LOG
.
log
(
Level
.
FINE
,
"Invalid pet id in delete method"
,
iae
);
return
Response
.
status
(
Response
.
Status
.
BAD_REQUEST
)
.
entity
(
iae
.
getMessage
())
.
build
();
}
catch
(
DAOException
e
)
{
LOG
.
log
(
Level
.
SEVERE
,
"Error deleting a pet"
,
e
);
return
Response
.
serverError
()
.
entity
(
e
.
getMessage
())
.
build
();
}
}
@GET
public
Response
list
()
{
try
{
return
Response
.
ok
(
this
.
dao
.
list
()).
build
();
}
catch
(
DAOException
e
)
{
LOG
.
log
(
Level
.
SEVERE
,
"Error listing pets"
,
e
);
return
Response
.
serverError
().
entity
(
e
.
getMessage
()).
build
();
}
}
@PUT
@Path
(
"/{id}"
)
public
Response
modify
(
@PathParam
(
"id"
)
int
id
,
@FormParam
(
"name"
)
String
name
,
@FormParam
(
"owner"
)
int
owner
)
{
try
{
final
Pet
modifiedPet
=
new
Pet
(
id
,
owner
,
name
);
this
.
dao
.
modify
(
modifiedPet
);
return
Response
.
ok
(
modifiedPet
).
build
();
}
catch
(
NullPointerException
npe
)
{
final
String
message
=
String
.
format
(
"Invalid data for pet (name: %s, owner: %s)"
,
name
,
owner
);
LOG
.
log
(
Level
.
FINE
,
message
);
return
Response
.
status
(
Response
.
Status
.
BAD_REQUEST
)
.
entity
(
message
)
.
build
();
}
catch
(
IllegalArgumentException
iae
)
{
LOG
.
log
(
Level
.
FINE
,
"Invalid pet id in modify method"
,
iae
);
return
Response
.
status
(
Response
.
Status
.
BAD_REQUEST
)
.
entity
(
iae
.
getMessage
())
.
build
();
}
catch
(
DAOException
e
)
{
LOG
.
log
(
Level
.
SEVERE
,
"Error modifying a pet"
,
e
);
return
Response
.
serverError
()
.
entity
(
e
.
getMessage
())
.
build
();
}
}
@POST
public
Response
add
(
@FormParam
(
"name"
)
String
name
,
@FormParam
(
"owner"
)
int
owner
)
{
try
{
final
Pet
newPet
=
this
.
dao
.
add
(
name
,
owner
);
return
Response
.
ok
(
newPet
).
build
();
}
catch
(
IllegalArgumentException
iae
)
{
LOG
.
log
(
Level
.
FINE
,
"Invalid pet id in add method"
,
iae
);
return
Response
.
status
(
Response
.
Status
.
BAD_REQUEST
)
.
entity
(
iae
.
getMessage
())
.
build
();
}
catch
(
DAOException
e
)
{
LOG
.
log
(
Level
.
SEVERE
,
"Error adding a pet"
,
e
);
return
Response
.
serverError
()
.
entity
(
e
.
getMessage
())
.
build
();
}
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment