-
Notifications
You must be signed in to change notification settings - Fork 80
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
4df7833
commit 3b0afdd
Showing
9 changed files
with
169 additions
and
12 deletions.
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
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
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
13 changes: 13 additions & 0 deletions
13
service-api/src/main/java/greencity/dto/habit/ShortHabitDto.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,13 @@ | ||
package greencity.dto.habit; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Data; | ||
|
||
@Data | ||
@Builder | ||
@AllArgsConstructor | ||
public class ShortHabitDto { | ||
Long id; | ||
String description; | ||
} |
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
17 changes: 17 additions & 0 deletions
17
service/src/main/java/greencity/mapping/ShortHabitDtoMapper.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,17 @@ | ||
package greencity.mapping; | ||
|
||
import greencity.dto.habit.ShortHabitDto; | ||
import greencity.entity.Habit; | ||
import org.modelmapper.AbstractConverter; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
public class ShortHabitDtoMapper extends AbstractConverter<Habit, ShortHabitDto> { | ||
@Override | ||
protected ShortHabitDto convert(Habit habit) { | ||
return ShortHabitDto.builder() | ||
.id(habit.getId()) | ||
.description(habit.getHabitTranslations().getFirst().getName()) | ||
.build(); | ||
} | ||
} |
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
35 changes: 35 additions & 0 deletions
35
service/src/test/java/greencity/mapping/ShortHabitDtoMapperTest.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,35 @@ | ||
package greencity.mapping; | ||
|
||
import greencity.dto.habit.ShortHabitDto; | ||
import greencity.entity.Habit; | ||
import greencity.entity.HabitTranslation; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import java.util.Collections; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
class ShortHabitDtoMapperTest { | ||
|
||
private ShortHabitDtoMapper mapper; | ||
private final Long id = 1L; | ||
private final String habitTranslationName = "Test Habit"; | ||
private final HabitTranslation habitTranslation = HabitTranslation.builder().name(habitTranslationName).build(); | ||
|
||
private final Habit habit = Habit.builder() | ||
.id(id) | ||
.habitTranslations(Collections.singletonList(habitTranslation)) | ||
.build(); | ||
|
||
@BeforeEach | ||
void setUp() { | ||
mapper = new ShortHabitDtoMapper(); | ||
} | ||
|
||
@Test | ||
void convert_ShouldMapHabitToShortHabitDto() { | ||
ShortHabitDto result = mapper.convert(habit); | ||
|
||
assertEquals(id, result.getId()); | ||
assertEquals(habitTranslationName, result.getDescription()); | ||
} | ||
} |
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