mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-05-20 13:31:56 +00:00
adjust employee
This commit is contained in:
@@ -4,7 +4,7 @@ import (
|
||||
"time"
|
||||
|
||||
entity "gitlab.com/mbugroup/lti-api.git/internal/entities"
|
||||
kandangDTO "gitlab.com/mbugroup/lti-api.git/internal/modules/master/kandangs/dto"
|
||||
kandangGroupDTO "gitlab.com/mbugroup/lti-api.git/internal/modules/master/kandang-groups/dto"
|
||||
)
|
||||
|
||||
// === DTO Structs ===
|
||||
@@ -15,12 +15,12 @@ type EmployeesRelationDTO struct {
|
||||
}
|
||||
|
||||
type EmployeesListDTO struct {
|
||||
Id uint `json:"id"`
|
||||
Name string `json:"name"`
|
||||
IsActive bool `json:"is_active"`
|
||||
Kandangs []kandangDTO.KandangRelationDTO `json:"kandangs"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
Id uint `json:"id"`
|
||||
Name string `json:"name"`
|
||||
IsActive bool `json:"is_active"`
|
||||
Kandangs []kandangGroupDTO.KandangGroupRelationDTO `json:"kandangs"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
}
|
||||
|
||||
type EmployeesDetailDTO struct {
|
||||
@@ -37,12 +37,12 @@ func ToEmployeesRelationDTO(e entity.Employees) EmployeesRelationDTO {
|
||||
}
|
||||
|
||||
func ToEmployeesListDTO(e entity.Employees) EmployeesListDTO {
|
||||
kandangs := make([]kandangDTO.KandangRelationDTO, 0, len(e.EmployeeKandangs))
|
||||
kandangs := make([]kandangGroupDTO.KandangGroupRelationDTO, 0, len(e.EmployeeKandangs))
|
||||
for _, rel := range e.EmployeeKandangs {
|
||||
if rel.Kandang.Id == 0 {
|
||||
continue
|
||||
}
|
||||
kandangs = append(kandangs, kandangDTO.ToKandangRelationDTO(rel.Kandang))
|
||||
kandangs = append(kandangs, kandangGroupDTO.ToKandangGroupRelationDTO(rel.Kandang))
|
||||
}
|
||||
|
||||
return EmployeesListDTO{
|
||||
|
||||
@@ -52,7 +52,7 @@ func (s employeesService) ensureEmployeeAccess(c *fiber.Ctx, employeeID uint) er
|
||||
db := s.Repository.DB().WithContext(c.Context()).
|
||||
Table("employees e").
|
||||
Joins("JOIN employee_kandangs ek ON ek.employee_id = e.id").
|
||||
Joins("JOIN kandangs k ON k.id = ek.kandang_id").
|
||||
Joins("JOIN kandang_groups k ON k.id = ek.kandang_id").
|
||||
Joins("JOIN locations loc ON loc.id = k.location_id").
|
||||
Joins("JOIN areas a ON a.id = loc.area_id").
|
||||
Where("e.id = ?", employeeID).
|
||||
@@ -79,7 +79,7 @@ func (s employeesService) ensureKandangIDsAccess(c *fiber.Ctx, kandangIDs []uint
|
||||
}
|
||||
|
||||
db := s.Repository.DB().WithContext(c.Context()).
|
||||
Table("kandangs k").
|
||||
Table("kandang_groups k").
|
||||
Joins("JOIN locations loc ON loc.id = k.location_id").
|
||||
Joins("JOIN areas a ON a.id = loc.area_id").
|
||||
Where("k.id IN ?", kandangIDs)
|
||||
@@ -109,7 +109,7 @@ func (s employeesService) GetAll(c *fiber.Ctx, params *validation.Query) ([]enti
|
||||
employeess, total, err := s.Repository.GetAll(c.Context(), offset, params.Limit, func(db *gorm.DB) *gorm.DB {
|
||||
db = s.withRelations(db)
|
||||
db = db.Joins("JOIN employee_kandangs ek ON ek.employee_id = employees.id").
|
||||
Joins("JOIN kandangs k ON k.id = ek.kandang_id").
|
||||
Joins("JOIN kandang_groups k ON k.id = ek.kandang_id").
|
||||
Joins("JOIN locations loc ON loc.id = k.location_id").
|
||||
Joins("JOIN areas a ON a.id = loc.area_id")
|
||||
var scopeErr error
|
||||
|
||||
Reference in New Issue
Block a user