ess-etl-go/internal/services/employee_wi.go

51 lines
1.3 KiB
Go
Raw Normal View History

package services
import (
"context"
"fmt"
"gitea.urkob.com/urko/ess-etl-go/pkg/adapter/repository/mongodb"
"gitea.urkob.com/urko/ess-etl-go/pkg/adapter/repository/mongodb/employee_wi"
"gitea.urkob.com/urko/ess-etl-go/pkg/domain"
"go.mongodb.org/mongo-driver/bson"
)
type EmployeeWIService struct {
ctx context.Context
repo *employee_wi.Repo
}
func NewEmployeeWIService(ctx context.Context, repo *employee_wi.Repo) EmployeeWIService {
return EmployeeWIService{
ctx: ctx,
repo: repo,
}
}
func (p *EmployeeWIService) GetByEmployeeNumber(ctx context.Context, employeeNumber int) ([]domain.EmployeeWorkInformation, error) {
model, err := p.repo.Find(ctx, bson.M{
"employee_number": employeeNumber,
})
if err != nil {
return nil, fmt.Errorf("repo.FindById: %s", err)
}
return model, nil
}
func (p *EmployeeWIService) GetByAll(ctx context.Context, id string) (*domain.EmployeeWorkInformation, error) {
model, err := p.repo.FindById(ctx, mongodb.MustObjectID(id))
if err != nil {
return nil, fmt.Errorf("repo.FindById: %s", err)
}
return model, nil
}
func (p *EmployeeWIService) InsertMany(ctx context.Context, ei []domain.EmployeeWorkInformation) error {
err := p.repo.InsertMany(ctx, ei)
if err != nil {
return fmt.Errorf("repo.AddAppointmentTo: %s", err)
}
return nil
}