Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Matúš Valko
Online Gaming Management System
Commits
653fc890
Commit
653fc890
authored
May 24, 2022
by
Marek Kadlečík
Browse files
Set up 404 status when nonexistent player is requested
parent
91861072
Changes
2
Hide whitespace changes
Inline
Side-by-side
gaming-rest/src/main/java/cz/muni/fi/pa165/rest/controllers/PlayerController.java
View file @
653fc890
...
...
@@ -4,6 +4,7 @@ import cz.muni.fi.pa165.dto.PlayerDTO;
import
cz.muni.fi.pa165.facade.PlayerFacade
;
import
cz.muni.fi.pa165.rest.RootUris
;
import
cz.muni.fi.pa165.rest.exception.ResourceAlreadyExistsException
;
import
cz.muni.fi.pa165.rest.exception.ResourceNotFoundException
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.http.MediaType
;
import
org.springframework.web.bind.annotation.PathVariable
;
...
...
@@ -23,7 +24,12 @@ public class PlayerController {
@RequestMapping
(
value
=
"/{uuid}"
,
method
=
RequestMethod
.
GET
,
produces
=
MediaType
.
APPLICATION_JSON_VALUE
)
public
final
PlayerDTO
findById
(
@PathVariable
(
"uuid"
)
String
uuid
)
{
return
playerFacade
.
getPlayerById
(
uuid
);
var
playerDTO
=
playerFacade
.
getPlayerById
(
uuid
);
if
(
playerDTO
!=
null
)
{
return
playerDTO
;
}
else
{
throw
new
ResourceNotFoundException
();
}
}
@RequestMapping
(
method
=
RequestMethod
.
GET
,
produces
=
MediaType
.
APPLICATION_JSON_VALUE
)
...
...
gaming-rest/src/main/java/cz/muni/fi/pa165/rest/exception/ResourceNotFoundException.java
0 → 100644
View file @
653fc890
package
cz.muni.fi.pa165.rest.exception
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.web.bind.annotation.ResponseStatus
;
/**
* @author Marek Kadlečík
*/
@ResponseStatus
(
value
=
HttpStatus
.
NOT_FOUND
,
reason
=
"The requested player was not found"
)
public
class
ResourceNotFoundException
extends
RuntimeException
{
public
ResourceNotFoundException
()
{
super
(
HttpStatus
.
NOT_FOUND
.
getReasonPhrase
());
}
}
\ No newline at end of file
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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