smm_core/internal/app/mappers.go

53 lines
1.4 KiB
Go
Raw Normal View History

2024-11-24 15:24:44 +00:00
package app
import (
"git.3crabs.ru/save_my_money/smm_core/internal/services/budget"
2024-11-25 06:36:14 +00:00
"git.3crabs.ru/save_my_money/smm_core/internal/services/category"
2024-11-24 15:24:44 +00:00
"git.3crabs.ru/save_my_money/smm_core/internal/services/user"
2024-11-25 09:38:03 +00:00
"git.3crabs.ru/save_my_money/smm_core/internal/services/waste"
2024-11-24 15:24:44 +00:00
proto "git.3crabs.ru/save_my_money/smm_core/proto"
)
func mapUser(user *user.UserEntity) *proto.User {
return &proto.User{
Id: int32(user.Id),
Username: user.Username,
}
}
func mapBudget(budget *budget.BudgetEntity) *proto.Budget {
return &proto.Budget{
Id: int32(budget.Id),
Name: budget.Name,
StartDay: int32(budget.StartDay),
MonthlyLimit: int32(budget.MonthlyLimit),
2024-11-25 06:36:14 +00:00
Categories: mapCategories(budget.Categories),
2024-11-24 15:24:44 +00:00
}
}
2024-11-25 06:36:14 +00:00
func mapCategory(category *category.CategoryEntity) *proto.Category {
return &proto.Category{
Id: int32(category.Id),
Name: category.Name,
Favorite: category.Favorite,
MonthlyLimit: int32(category.MonthlyLimit),
}
}
func mapCategories(categories []*category.CategoryEntity) []*proto.Category {
res := make([]*proto.Category, 0, len(categories))
for _, item := range categories {
res = append(res, mapCategory(item))
}
return res
}
2024-11-25 09:38:03 +00:00
func mapWaste(waste *waste.WasteEntity) *proto.Waste {
return &proto.Waste{
Id: int32(waste.Id),
Name: waste.Name,
Price: int32(waste.Price),
Amount: waste.Amount,
}
}