-
Notifications
You must be signed in to change notification settings - Fork 794
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
096dd29
commit 9f8cce7
Showing
3 changed files
with
78 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
src/main/java/guru/springframework/msscbeerservice/web/mappers/BeerMapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package guru.springframework.msscbeerservice.web.mappers; | ||
|
||
import guru.springframework.msscbeerservice.domain.Beer; | ||
import guru.springframework.msscbeerservice.web.model.BeerDto; | ||
import org.mapstruct.Mapper; | ||
|
||
/** | ||
* Created by jt on 2019-05-25. | ||
*/ | ||
@Mapper(uses = {DateMapper.class}) | ||
public interface BeerMapper { | ||
|
||
BeerDto BeerToBeerDto(Beer beer); | ||
|
||
Beer BeerDtoToBeer(BeerDto dto); | ||
} |
31 changes: 31 additions & 0 deletions
31
src/main/java/guru/springframework/msscbeerservice/web/mappers/DateMapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package guru.springframework.msscbeerservice.web.mappers; | ||
|
||
import org.springframework.stereotype.Component; | ||
|
||
import java.sql.Timestamp; | ||
import java.time.OffsetDateTime; | ||
import java.time.ZoneOffset; | ||
|
||
/** | ||
* Created by jt on 2019-05-25. | ||
*/ | ||
@Component | ||
public class DateMapper { | ||
public OffsetDateTime asOffsetDateTime(Timestamp ts){ | ||
if (ts != null){ | ||
return OffsetDateTime.of(ts.toLocalDateTime().getYear(), ts.toLocalDateTime().getMonthValue(), | ||
ts.toLocalDateTime().getDayOfMonth(), ts.toLocalDateTime().getHour(), ts.toLocalDateTime().getMinute(), | ||
ts.toLocalDateTime().getSecond(), ts.toLocalDateTime().getNano(), ZoneOffset.UTC); | ||
} else { | ||
return null; | ||
} | ||
} | ||
|
||
public Timestamp asTimestamp(OffsetDateTime offsetDateTime){ | ||
if(offsetDateTime != null) { | ||
return Timestamp.valueOf(offsetDateTime.atZoneSameInstant(ZoneOffset.UTC).toLocalDateTime()); | ||
} else { | ||
return null; | ||
} | ||
} | ||
} |