2023-03-31 11:49:03 +02:00
|
|
|
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 {
|
2023-04-24 12:03:15 +02:00
|
|
|
return fmt.Errorf("repo.InsertMany: %s", err)
|
2023-03-31 11:49:03 +02:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|