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
18967e90
Commit
18967e90
authored
Dec 17, 2018
by
Khalid Ali
Browse files
DTO to Entity fixed
parent
9b0f5678
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/main/java/com/gmu/bookshare/model/ListingDto.java
View file @
18967e90
...
...
@@ -7,14 +7,13 @@ import lombok.Setter;
import
java.text.ParseException
;
import
java.text.SimpleDateFormat
;
import
java.util.Date
;
import
java.util.TimeZone
;
@Data
@Getter
@Setter
public
class
ListingDto
{
private
final
SimpleDateFormat
dateFormat
private
static
final
SimpleDateFormat
dateFormat
=
new
SimpleDateFormat
(
"yyyy-MM-dd HH:mm"
);
private
Long
id
;
...
...
@@ -37,8 +36,7 @@ public class ListingDto {
private
String
title
;
public
Date
getCreateDateConverted
(
String
timezone
)
throws
ParseException
{
dateFormat
.
setTimeZone
(
TimeZone
.
getTimeZone
(
timezone
));
public
Date
getCreateDateConverted
()
throws
ParseException
{
return
dateFormat
.
parse
(
this
.
createDate
);
}
...
...
src/main/java/com/gmu/bookshare/web/BookshareApiController.java
View file @
18967e90
...
...
@@ -11,6 +11,7 @@ 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
;
...
...
@@ -42,7 +43,7 @@ public class BookshareApiController {
@PostMapping
(
value
=
"/listing/"
,
consumes
=
MediaType
.
APPLICATION_JSON_VALUE
)
@ResponseStatus
(
HttpStatus
.
CREATED
)
public
ListingDto
newListing
(
@RequestBody
ListingDto
listingDto
)
{
public
ListingDto
newListing
(
@RequestBody
ListingDto
listingDto
)
throws
ParseException
{
ListingEntity
post
=
convertToEntity
(
listingDto
);
ListingEntity
postCreated
=
listingService
.
addListing
(
post
);
return
convertToDto
(
postCreated
);
...
...
@@ -55,7 +56,7 @@ public class BookshareApiController {
@PutMapping
(
value
=
"/listing/{id}"
)
@ResponseStatus
(
HttpStatus
.
OK
)
void
updateListing
(
@RequestBody
ListingDto
listingDto
)
{
void
updateListing
(
@RequestBody
ListingDto
listingDto
)
throws
ParseException
{
ListingEntity
listingEntity
=
convertToEntity
(
listingDto
);
listingService
.
updateListing
(
listingEntity
);
}
...
...
@@ -66,15 +67,9 @@ public class BookshareApiController {
return
listingDto
;
}
private
ListingEntity
convertToEntity
(
ListingDto
listingDto
)
{
// post.setCreateDate(ListingDto.getCreateDateConverted(
// userService.getCurrentUser().getPreference().getTimezone()));
//
// if (ListingDto.getId() != null) {
// ListingEntity oldPost = listingService.getPostById(postDto.getId());
// post.setRedditID(oldPost.getRedditID());
// post.setSent(oldPost.isSent());
// }
return
modelMapper
.
map
(
listingDto
,
ListingEntity
.
class
);
private
ListingEntity
convertToEntity
(
ListingDto
listingDto
)
throws
ParseException
{
ListingEntity
post
=
modelMapper
.
map
(
listingDto
,
ListingEntity
.
class
);
post
.
setCreateDate
(
ListingDto
.
getCreateDateConverted
());
return
post
;
}
}
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