Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Samuel Dudík
PA165 Winery Management System
Commits
cb57e13d
Commit
cb57e13d
authored
May 15, 2022
by
Ondřej Pavlica
Browse files
Merge branch 'feature/balga/rest' into 'main'
Rest controller See merge request
!39
parents
1c421be9
dfd60bbb
Pipeline
#139527
passed with stages
in 2 minutes and 13 seconds
Changes
3
Pipelines
1
Show whitespace changes
Inline
Side-by-side
winery/webapp/src/main/java/cz/muni/fi/pa165/winery/webapp/rest/controllers/GrapeRestController.java
0 → 100644
View file @
cb57e13d
package
cz.muni.fi.pa165.winery.webapp.rest.controllers
;
import
cz.muni.fi.pa165.winery.dto.wine.GrapeDto
;
import
cz.muni.fi.pa165.winery.services.wine.GrapeService
;
import
org.springframework.http.MediaType
;
import
org.springframework.web.bind.annotation.*
;
import
java.util.List
;
/**
* @author Jakub Balga
*/
@RestController
@RequestMapping
(
"/rest/grape"
)
public
class
GrapeRestController
{
private
final
GrapeService
grapeService
;
public
GrapeRestController
(
GrapeService
grapeService
)
{
this
.
grapeService
=
grapeService
;
}
@RequestMapping
(
method
=
RequestMethod
.
GET
,
produces
=
MediaType
.
APPLICATION_JSON_VALUE
)
public
List
<
GrapeDto
>
index
()
{
return
grapeService
.
getAll
();
}
@RequestMapping
(
value
=
"/{id}"
,
method
=
RequestMethod
.
GET
,
produces
=
MediaType
.
APPLICATION_JSON_VALUE
)
public
final
GrapeDto
getGrape
(
@PathVariable
(
"id"
)
long
id
)
{
GrapeDto
grape
=
grapeService
.
get
(
id
);
if
(
grape
==
null
)
{
throw
new
ResourceNotFoundException
();
}
return
grape
;
}
@RequestMapping
(
value
=
"/create"
,
method
=
RequestMethod
.
POST
,
consumes
=
MediaType
.
APPLICATION_JSON_VALUE
)
public
final
void
createGrape
(
@RequestBody
GrapeDto
grape
)
{
if
(
grape
==
null
)
{
throw
new
NullPointerException
(
"Grape DTO is null"
);
}
try
{
grapeService
.
create
(
grape
);
}
catch
(
Exception
ex
)
{
throw
new
IllegalArgumentException
(
"Cannot create entity, already exists"
);
}
}
@RequestMapping
(
value
=
"/edit"
,
method
=
RequestMethod
.
POST
,
consumes
=
MediaType
.
APPLICATION_JSON_VALUE
)
public
final
void
editGrape
(
@RequestBody
GrapeDto
grape
)
{
if
(
grape
==
null
)
{
throw
new
NullPointerException
(
"Grape DTO is null"
);
}
try
{
grapeService
.
update
(
grape
);
}
catch
(
Exception
ex
)
{
throw
new
IllegalArgumentException
(
"Entity with this ID does not exist, cannot update"
);
}
}
@RequestMapping
(
value
=
"/delete"
,
method
=
RequestMethod
.
DELETE
)
public
final
void
deleteGrape
(
@RequestBody
GrapeDto
grape
)
{
try
{
grapeService
.
delete
(
grape
);
}
catch
(
Exception
ex
)
{
throw
new
IllegalArgumentException
(
"Entity with this ID does not exist, cannot delete"
);
}
}
}
winery/webapp/src/main/java/cz/muni/fi/pa165/winery/webapp/rest/controllers/ResourceNotFoundException.java
0 → 100644
View file @
cb57e13d
package
cz.muni.fi.pa165.winery.webapp.rest.controllers
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.web.bind.annotation.ResponseStatus
;
/**
* @author Jakub Balga
*/
@ResponseStatus
(
value
=
HttpStatus
.
NOT_FOUND
,
reason
=
"The requested resource was not found"
)
public
class
ResourceNotFoundException
extends
RuntimeException
{
}
winery/webapp/src/main/java/cz/muni/fi/pa165/winery/webapp/security/WebSecurityConfiguration.java
View file @
cb57e13d
...
...
@@ -38,7 +38,7 @@ public class WebSecurityConfiguration extends WebSecurityConfigurerAdapter {
@Override
protected
void
configure
(
HttpSecurity
http
)
throws
Exception
{
http
.
authorizeRequests
()
.
antMatchers
(
"/assets/**"
,
"/css/**"
,
"/js/**"
,
"/error"
,
"/login"
).
permitAll
()
.
antMatchers
(
"/assets/**"
,
"/css/**"
,
"/js/**"
,
"/error"
,
"/login"
,
"/rest/**"
).
permitAll
()
.
anyRequest
().
authenticated
()
.
and
()
.
csrf
()
...
...
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