Skip to content

Commit ec1b11b

Browse files
author
Guilherme Biff Zarelli
committed
test: structure
1 parent c7947e7 commit ec1b11b

File tree

17 files changed

+103
-617
lines changed

17 files changed

+103
-617
lines changed

adapter/input/jaxrs-controller-v1/src/main/java/br/com/helpdev/controller/MessageController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public class MessageController {
5353
@POST
5454
@Consumes(MediaType.APPLICATION_JSON)
5555
public Response create(final MessageCreateDto messageDto) throws NotificationException {
56-
var entity = mapper.toEntity(messageDto);
56+
var entity = mapper.toDomain(messageDto);
5757
var message = pushRequestNotification.push(entity);
5858
return Response.status(Response.Status.CREATED)
5959
.entity(mapper.toDto(message))

adapter/input/jaxrs-controller-v1/src/main/java/br/com/helpdev/controller/mapper/ControllerMessageMapper.java

Lines changed: 12 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import br.com.helpdev.domain.Message;
1212
import br.com.helpdev.domain.Recipient;
1313
import br.com.helpdev.domain.vo.MessageBody;
14+
import br.com.helpdev.domain.vo.MessageId;
1415
import br.com.helpdev.domain.vo.Phone;
1516
import java.util.Collection;
1617
import java.util.Collections;
@@ -24,7 +25,7 @@ public class ControllerMessageMapper {
2425

2526
public MessageResponseDto toDto(final Message message) {
2627
return MessageResponseDto.builder()
27-
.id(message.getId().value())
28+
.id(message.getId().map(MessageId::value).orElse(null))
2829
.scheduleDate(message.getScheduleDate())
2930
.body(message.getBody().value())
3031
.channel(parse(message.getChannel()))
@@ -33,7 +34,7 @@ public MessageResponseDto toDto(final Message message) {
3334
.build();
3435
}
3536

36-
public Message toEntity(final MessageCreateDto message) {
37+
public Message toDomain(final MessageCreateDto message) {
3738
return Message.builder()
3839
.body(MessageBody.from(message.getBody()))
3940
.scheduleDate(message.getScheduleDate())
@@ -43,47 +44,32 @@ public Message toEntity(final MessageCreateDto message) {
4344
}
4445

4546
public Collection<ChatResponseDto> parse(final Collection<Chat> chats) {
46-
if (chats == null) {
47-
return Collections.emptyList();
48-
}
49-
return chats.stream()
47+
return chats == null ? Collections.emptyList() : chats.stream()
5048
.map(c -> ChatResponseDto.builder()
5149
.date(c.getDate())
5250
.status(StatusResponseDto.findByStatus(c.getStatus()))
5351
.build())
5452
.collect(Collectors.toList());
5553
}
5654

57-
public CommunicationChannel parse(final CommunicationChannelDto dto) {
58-
if (dto == null) {
59-
return null;
60-
}
61-
return CommunicationChannel.valueOf(dto.name());
55+
private CommunicationChannel parse(final CommunicationChannelDto dto) {
56+
return dto == null ? null : CommunicationChannel.valueOf(dto.name());
6257
}
6358

64-
public CommunicationChannelDto parse(final CommunicationChannel value) {
65-
if (value == null) {
66-
return null;
67-
}
68-
return CommunicationChannelDto.valueOf(value.name());
59+
private CommunicationChannelDto parse(final CommunicationChannel value) {
60+
return value == null ? null : CommunicationChannelDto.valueOf(value.name());
6961
}
7062

71-
public Recipient parse(final RecipientDto recipient) {
72-
if (recipient == null) {
73-
return null;
74-
}
75-
return Recipient.builder()
63+
private Recipient parse(final RecipientDto recipient) {
64+
return recipient == null ? null : Recipient.builder()
7665
.email(recipient.getEmail())
7766
.name(recipient.getName())
7867
.phone(Phone.from(recipient.getPhoneId(), recipient.getPhoneNumber()))
7968
.build();
8069
}
8170

82-
public RecipientDto parse(final Recipient recipient) {
83-
if (recipient == null) {
84-
return null;
85-
}
86-
return RecipientDto.builder()
71+
private RecipientDto parse(final Recipient recipient) {
72+
return recipient == null ? null : RecipientDto.builder()
8773
.email(recipient.getEmail())
8874
.name(recipient.getName())
8975
.phoneId(recipient.getPhone().getPhoneId().orElse(null))

0 commit comments

Comments
 (0)