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
9b0f5678
Commit
9b0f5678
authored
Dec 17, 2018
by
Khalid Ali
Browse files
Add getById and PUT request to controller
parent
6b2f7397
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/main/java/com/gmu/bookshare/service/ListingService.java
View file @
9b0f5678
...
...
@@ -14,7 +14,7 @@ public class ListingService {
private
final
ListingRepository
listingRepository
;
@Autowired
public
ListingService
(
ListingRepository
listingRepository
)
{
ListingService
(
ListingRepository
listingRepository
)
{
this
.
listingRepository
=
listingRepository
;
}
...
...
@@ -32,7 +32,11 @@ public class ListingService {
.
orElseThrow
(()
->
new
ListingNotFoundException
(
id
));
}
public
ListingEntity
getIsbn
(
int
isbn
)
{
ListingEntity
getIsbn
(
int
isbn
)
{
return
listingRepository
.
findByIsbn
(
isbn
).
get
(
0
);
}
public
void
updateListing
(
ListingEntity
listingEntity
)
{
listingRepository
.
save
(
listingEntity
);
}
}
src/main/java/com/gmu/bookshare/web/BookshareApiController.java
View file @
9b0f5678
...
...
@@ -11,7 +11,6 @@ import org.springframework.http.HttpStatus;
import
org.springframework.http.MediaType
;
import
org.springframework.web.bind.annotation.*
;
import
java.text.ParseException
;
import
java.util.List
;
import
java.util.stream.Collectors
;
...
...
@@ -43,7 +42,7 @@ public class BookshareApiController {
@PostMapping
(
value
=
"/listing/"
,
consumes
=
MediaType
.
APPLICATION_JSON_VALUE
)
@ResponseStatus
(
HttpStatus
.
CREATED
)
public
ListingDto
newListing
(
@RequestBody
ListingDto
listingDto
)
throws
ParseException
{
public
ListingDto
newListing
(
@RequestBody
ListingDto
listingDto
)
{
ListingEntity
post
=
convertToEntity
(
listingDto
);
ListingEntity
postCreated
=
listingService
.
addListing
(
post
);
return
convertToDto
(
postCreated
);
...
...
@@ -54,15 +53,21 @@ public class BookshareApiController {
return
convertToDto
(
listingService
.
getById
(
id
));
}
@PutMapping
(
value
=
"/listing/{id}"
)
@ResponseStatus
(
HttpStatus
.
OK
)
void
updateListing
(
@RequestBody
ListingDto
listingDto
)
{
ListingEntity
listingEntity
=
convertToEntity
(
listingDto
);
listingService
.
updateListing
(
listingEntity
);
}
private
ListingDto
convertToDto
(
ListingEntity
listingEntity
)
{
ListingDto
listingDto
=
modelMapper
.
map
(
listingEntity
,
ListingDto
.
class
);
listingDto
.
setCreateDate
(
listingEntity
.
getCreateDate
());
return
listingDto
;
}
private
ListingEntity
convertToEntity
(
ListingDto
listingDto
)
throws
ParseException
{
ListingEntity
post
=
modelMapper
.
map
(
listingDto
,
ListingEntity
.
class
);
// post.setCreateDate(ListingDto.getCreateDateConverted(
private
ListingEntity
convertToEntity
(
ListingDto
listingDto
)
{
// post.setCreateDate(ListingDto.getCreateDateConverted(
// userService.getCurrentUser().getPreference().getTimezone()));
//
// if (ListingDto.getId() != null) {
...
...
@@ -70,6 +75,6 @@ public class BookshareApiController {
// post.setRedditID(oldPost.getRedditID());
// post.setSent(oldPost.isSent());
// }
return
post
;
return
modelMapper
.
map
(
listingDto
,
ListingEntity
.
class
)
;
}
}
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