Skip to content

Commit 9d81933

Browse files
committed
refactor jpa mappers
1 parent ec5c5c8 commit 9d81933

2 files changed

Lines changed: 22 additions & 17 deletions

File tree

src/main/java/com/mastercloudapps/twitterscheduler/infrastructure/jpa/pending/PendingTweetJpaMapper.java

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,14 @@ public PendingTweet mapEntity(final PendingTweetJpaEntity pendingTweetEntity) {
1616
throw new RepositoryException("Empty entity");
1717
}
1818

19-
return PendingTweet
19+
final var builder = PendingTweet
2020
.builder()
2121
.id(pendingTweetEntity.getId())
2222
.message(pendingTweetEntity.getMessage())
2323
.publicationDate(pendingTweetEntity.getPublicationDate())
24-
.createdAt(pendingTweetEntity.getCreatedAt())
25-
.build();
24+
.createdAt(pendingTweetEntity.getCreatedAt());
25+
26+
return builder.build();
2627
}
2728

2829
public PendingTweetJpaEntity mapCreatePendingTweet(final PendingTweet pendingTweet) {
@@ -31,12 +32,13 @@ public PendingTweetJpaEntity mapCreatePendingTweet(final PendingTweet pendingTwe
3132
throw new RepositoryException("Empty domain object");
3233
}
3334

34-
return PendingTweetJpaEntity
35+
final var builder = PendingTweetJpaEntity
3536
.builder()
3637
.message(pendingTweet.message().message())
3738
.publicationDate(pendingTweet.publicationDate().instant())
38-
.createdAt(pendingTweet.createdAt().instant())
39-
.build();
39+
.createdAt(pendingTweet.createdAt().instant());
40+
41+
return builder.build();
4042
}
4143

4244
public PendingTweetJpaEntity mapDomainObject(final PendingTweet pendingTweet) {
@@ -45,13 +47,14 @@ public PendingTweetJpaEntity mapDomainObject(final PendingTweet pendingTweet) {
4547
throw new RepositoryException("Empty domain object");
4648
}
4749

48-
return PendingTweetJpaEntity
50+
final var builder = PendingTweetJpaEntity
4951
.builder()
5052
.id(pendingTweet.id().id())
5153
.message(pendingTweet.message().message())
5254
.publicationDate(pendingTweet.publicationDate().instant())
53-
.createdAt(pendingTweet.createdAt().instant())
54-
.build();
55+
.createdAt(pendingTweet.createdAt().instant());
56+
57+
return builder.build();
5558
}
5659

57-
}
60+
}

src/main/java/com/mastercloudapps/twitterscheduler/infrastructure/jpa/tweet/TweetJpaMapper.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,17 @@ public Tweet mapEntity(final TweetJpaEntity tweetEntity) {
1616
throw new RepositoryException("Empty entity");
1717
}
1818

19-
return Tweet
19+
final var builder = Tweet
2020
.builder()
2121
.id(tweetEntity.getId())
2222
.message(tweetEntity.getMessage())
2323
.url(tweetEntity.getUrl())
2424
.requestedPublicationDate(tweetEntity.getRequestedPublicationDate())
2525
.publishedAt(tweetEntity.getPublishedAt())
2626
.createdAt(tweetEntity.getCreatedAt())
27-
.publicationType(tweetEntity.getPublicationType())
28-
.build();
27+
.publicationType(tweetEntity.getPublicationType());
28+
29+
return builder.build();
2930
}
3031

3132
public TweetJpaEntity mapDomainObject(final Tweet tweet) {
@@ -34,16 +35,17 @@ public TweetJpaEntity mapDomainObject(final Tweet tweet) {
3435
throw new RepositoryException("Empty domain object");
3536
}
3637

37-
return TweetJpaEntity
38+
final var builder = TweetJpaEntity
3839
.builder()
3940
.id(tweet.id().id())
4041
.message(tweet.message().message())
4142
.url(tweet.url().url())
4243
.requestedPublicationDate(tweet.requestedPublicationDate().instant())
4344
.publishedAt(tweet.publishedAt().instant())
4445
.createdAt(tweet.createdAt().instant())
45-
.publicationType(tweet.publicationType())
46-
.build();
46+
.publicationType(tweet.publicationType());
47+
48+
return builder.build();
4749
}
4850

49-
}
51+
}

0 commit comments

Comments
 (0)