-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
327551e
commit d73700e
Showing
5 changed files
with
51 additions
and
17 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
48 changes: 33 additions & 15 deletions
48
src/main/java/com/friends/easybud/category/converter/CategoryConverter.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 |
---|---|---|
@@ -1,33 +1,51 @@ | ||
package com.friends.easybud.category.converter; | ||
|
||
import com.friends.easybud.category.domain.SecondaryCategory; | ||
import com.friends.easybud.category.domain.TertiaryCategory; | ||
import com.friends.easybud.category.dto.CategoryResponse.AccountCategoryDto; | ||
import com.friends.easybud.category.dto.CategoryResponse.AccountCategoryListDto; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
public class CategoryConverter { | ||
|
||
public static AccountCategoryDto toAccountCategoryDto(TertiaryCategory tertiaryCategory) { | ||
return AccountCategoryDto.builder() | ||
.primaryCategoryId(tertiaryCategory.getSecondaryCategory().getPrimaryCategory().getId()) | ||
.primaryCategoryContent(tertiaryCategory.getSecondaryCategory().getPrimaryCategory().getContent()) | ||
.secondaryCategoryId(tertiaryCategory.getSecondaryCategory().getId()) | ||
.secondaryCategoryContent(tertiaryCategory.getSecondaryCategory().getContent()) | ||
.tertiaryCategoryId(tertiaryCategory.getId()) | ||
.tertiaryCategoryContent(tertiaryCategory.getContent()) | ||
.isDefault(tertiaryCategory.getIsDefault()) | ||
.build(); | ||
public static AccountCategoryDto toAccountCategoryDto(SecondaryCategory secondaryCategory, | ||
TertiaryCategory tertiaryCategory) { | ||
AccountCategoryDto.AccountCategoryDtoBuilder builder = AccountCategoryDto.builder() | ||
.primaryCategoryId(secondaryCategory.getPrimaryCategory().getId()) | ||
.primaryCategoryContent(secondaryCategory.getPrimaryCategory().getContent()) | ||
.secondaryCategoryId(secondaryCategory.getId()) | ||
.secondaryCategoryContent(secondaryCategory.getContent()); | ||
|
||
if (tertiaryCategory != null) { | ||
builder.tertiaryCategoryId(tertiaryCategory.getId()) | ||
.tertiaryCategoryContent(tertiaryCategory.getContent()) | ||
.isDefault(tertiaryCategory.getIsDefault()); | ||
} | ||
|
||
return builder.build(); | ||
} | ||
|
||
public static AccountCategoryListDto toAccountCategoryListDto(List<TertiaryCategory> tertiaryCategories) { | ||
List<AccountCategoryDto> accountCategoryDtos = tertiaryCategories.stream() | ||
.map(CategoryConverter::toAccountCategoryDto) | ||
.collect(Collectors.toList()); | ||
public static AccountCategoryListDto toAccountCategoryListDto(List<SecondaryCategory> secondaryCategories, | ||
List<TertiaryCategory> tertiaryCategories) { | ||
List<AccountCategoryDto> accountCategoryDtos = new ArrayList<>(); | ||
|
||
for (SecondaryCategory secondaryCategory : secondaryCategories) { | ||
List<TertiaryCategory> relatedTertiaryCategories = tertiaryCategories.stream() | ||
.filter(tc -> tc.getSecondaryCategory().equals(secondaryCategory)) | ||
.collect(Collectors.toList()); | ||
|
||
if (relatedTertiaryCategories.isEmpty()) { | ||
accountCategoryDtos.add(toAccountCategoryDto(secondaryCategory, null)); | ||
} else { | ||
relatedTertiaryCategories.forEach(tertiaryCategory -> | ||
accountCategoryDtos.add(toAccountCategoryDto(secondaryCategory, tertiaryCategory))); | ||
} | ||
} | ||
|
||
return AccountCategoryListDto.builder() | ||
.accountCategories(accountCategoryDtos) | ||
.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
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