Commit 18967e90 authored by Khalid Ali's avatar Khalid Ali
Browse files

DTO to Entity fixed

parent 9b0f5678
...@@ -7,14 +7,13 @@ import lombok.Setter; ...@@ -7,14 +7,13 @@ import lombok.Setter;
import java.text.ParseException; import java.text.ParseException;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.Date; import java.util.Date;
import java.util.TimeZone;
@Data @Data
@Getter @Getter
@Setter @Setter
public class ListingDto { public class ListingDto {
private final SimpleDateFormat dateFormat private static final SimpleDateFormat dateFormat
= new SimpleDateFormat("yyyy-MM-dd HH:mm"); = new SimpleDateFormat("yyyy-MM-dd HH:mm");
private Long id; private Long id;
...@@ -37,8 +36,7 @@ public class ListingDto { ...@@ -37,8 +36,7 @@ public class ListingDto {
private String title; private String title;
public Date getCreateDateConverted(String timezone) throws ParseException { public Date getCreateDateConverted() throws ParseException {
dateFormat.setTimeZone(TimeZone.getTimeZone(timezone));
return dateFormat.parse(this.createDate); return dateFormat.parse(this.createDate);
} }
......
...@@ -11,6 +11,7 @@ import org.springframework.http.HttpStatus; ...@@ -11,6 +11,7 @@ import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType; import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import java.text.ParseException;
import java.util.List; import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;
...@@ -42,7 +43,7 @@ public class BookshareApiController { ...@@ -42,7 +43,7 @@ public class BookshareApiController {
@PostMapping(value = "/listing/", consumes = MediaType.APPLICATION_JSON_VALUE) @PostMapping(value = "/listing/", consumes = MediaType.APPLICATION_JSON_VALUE)
@ResponseStatus(HttpStatus.CREATED) @ResponseStatus(HttpStatus.CREATED)
public ListingDto newListing(@RequestBody ListingDto listingDto) { public ListingDto newListing(@RequestBody ListingDto listingDto) throws ParseException {
ListingEntity post = convertToEntity(listingDto); ListingEntity post = convertToEntity(listingDto);
ListingEntity postCreated = listingService.addListing(post); ListingEntity postCreated = listingService.addListing(post);
return convertToDto(postCreated); return convertToDto(postCreated);
...@@ -55,7 +56,7 @@ public class BookshareApiController { ...@@ -55,7 +56,7 @@ public class BookshareApiController {
@PutMapping(value = "/listing/{id}") @PutMapping(value = "/listing/{id}")
@ResponseStatus(HttpStatus.OK) @ResponseStatus(HttpStatus.OK)
void updateListing(@RequestBody ListingDto listingDto) { void updateListing(@RequestBody ListingDto listingDto) throws ParseException {
ListingEntity listingEntity = convertToEntity(listingDto); ListingEntity listingEntity = convertToEntity(listingDto);
listingService.updateListing(listingEntity); listingService.updateListing(listingEntity);
} }
...@@ -66,15 +67,9 @@ public class BookshareApiController { ...@@ -66,15 +67,9 @@ public class BookshareApiController {
return listingDto; return listingDto;
} }
private ListingEntity convertToEntity(ListingDto listingDto) { private ListingEntity convertToEntity(ListingDto listingDto) throws ParseException {
// post.setCreateDate(ListingDto.getCreateDateConverted( ListingEntity post = modelMapper.map(listingDto, ListingEntity.class);
// userService.getCurrentUser().getPreference().getTimezone())); post.setCreateDate(ListingDto.getCreateDateConverted());
// return post;
// if (ListingDto.getId() != null) {
// ListingEntity oldPost = listingService.getPostById(postDto.getId());
// post.setRedditID(oldPost.getRedditID());
// post.setSent(oldPost.isSent());
// }
return modelMapper.map(listingDto, ListingEntity.class);
} }
} }
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment