Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Khalid Ali
bookshare-backend
Commits
71694bce
Commit
71694bce
authored
Dec 17, 2018
by
Khalid Ali
Browse files
PUT request returns status OK or NOT_FOUND
parent
17cf929d
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/main/java/com/gmu/bookshare/service/ListingService.java
View file @
71694bce
...
...
@@ -36,8 +36,12 @@ public class ListingService {
return
listingRepository
.
findByIsbn
(
isbn
).
get
(
0
);
}
public
void
updateListing
(
ListingEntity
listingEntity
)
{
listingRepository
.
save
(
listingEntity
);
public
ListingEntity
updateListing
(
ListingEntity
listingEntity
)
{
if
(
listingRepository
.
findById
(
listingEntity
.
getId
()).
isPresent
())
listingRepository
.
save
(
listingEntity
);
else
return
null
;
return
listingEntity
;
}
public
void
deleteListing
(
Long
id
)
{
...
...
src/main/java/com/gmu/bookshare/web/BookshareApiController.java
View file @
71694bce
...
...
@@ -9,6 +9,7 @@ import org.modelmapper.ModelMapper;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.MediaType
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.web.bind.annotation.*
;
import
java.text.ParseException
;
...
...
@@ -54,11 +55,15 @@ public class BookshareApiController {
return
convertToDto
(
listingService
.
getById
(
id
));
}
@PutMapping
(
value
=
"/listing/{id}"
)
@ResponseStatus
(
HttpStatus
.
OK
)
void
updateListing
(
@RequestBody
ListingDto
listingDto
)
throws
ParseException
{
@PutMapping
(
value
=
"/listing/{id}"
,
produces
=
MediaType
.
APPLICATION_JSON_VALUE
)
ResponseEntity
<
ListingDto
>
updateListing
(
@RequestBody
ListingDto
listingDto
)
throws
ParseException
{
ListingEntity
listingEntity
=
convertToEntity
(
listingDto
);
listingService
.
updateListing
(
listingEntity
);
ListingEntity
ret
=
listingService
.
updateListing
(
listingEntity
);
if
(
ret
==
null
)
{
return
new
ResponseEntity
<>(
HttpStatus
.
NOT_FOUND
);
}
else
{
return
new
ResponseEntity
<>(
convertToDto
(
ret
),
HttpStatus
.
OK
);
}
}
@DeleteMapping
(
value
=
"/listing/{id}"
)
...
...
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