forked from ebhomengo/niki
55 lines
1.5 KiB
Go
55 lines
1.5 KiB
Go
package adminbenefactoraggregatorservice
|
|
|
|
import (
|
|
"context"
|
|
|
|
param "git.gocasts.ir/ebhomengo/niki/param/admin/benefactor"
|
|
response "git.gocasts.ir/ebhomengo/niki/pkg/response_builder"
|
|
richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error"
|
|
)
|
|
|
|
func (s Service) GetByIDs(ctx context.Context, ids []any) (map[uint]param.Data, error) {
|
|
const op = "adminbenefactoraggregatorservice.GetByIDs"
|
|
data := make(map[uint]param.Data)
|
|
|
|
benefactors, err := s.repo.GetByIDs(ctx, ids)
|
|
if err != nil {
|
|
return nil, richerror.New(op).WithErr(err)
|
|
}
|
|
for _, benefactor := range benefactors {
|
|
data[benefactor.ID] = param.Data{
|
|
ID: benefactor.ID,
|
|
FirstName: benefactor.FirstName,
|
|
LastName: benefactor.LastName,
|
|
PhoneNumber: benefactor.PhoneNumber,
|
|
Description: benefactor.Description,
|
|
Email: benefactor.Email,
|
|
Gender: benefactor.Gender,
|
|
BirthDate: response.GetNullDate(benefactor.BirthDate),
|
|
Status: benefactor.Status,
|
|
}
|
|
}
|
|
return data, nil
|
|
}
|
|
|
|
func (s Service) GetByID(ctx context.Context, id uint) (param.Data, error) {
|
|
const op = "adminbenefactoraggregatorservice.GetByID"
|
|
|
|
bnf, gErr := s.repo.GetByID(ctx, id)
|
|
if gErr != nil {
|
|
return param.Data{}, richerror.New(op).WithErr(gErr)
|
|
}
|
|
|
|
return param.Data{
|
|
ID: bnf.ID,
|
|
FirstName: bnf.FirstName,
|
|
LastName: bnf.LastName,
|
|
PhoneNumber: bnf.PhoneNumber,
|
|
Description: bnf.Description,
|
|
Email: bnf.Email,
|
|
Gender: bnf.Gender,
|
|
BirthDate: response.GetNullDate(bnf.BirthDate),
|
|
Status: bnf.Status,
|
|
}, nil
|
|
}
|