adjustment detail installation
This commit is contained in:
@@ -6,13 +6,15 @@ import (
|
||||
eu "simrs-vx/internal/domain/main-entities/user"
|
||||
|
||||
erc "simrs-vx/internal/domain/references/common"
|
||||
erg "simrs-vx/internal/domain/references/organization"
|
||||
)
|
||||
|
||||
type CreateDto struct {
|
||||
User_Id *uint `json:"user_id"`
|
||||
Person_Id *uint `json:"person_id"`
|
||||
Number *string `json:"number" validate:"maxLength=20"`
|
||||
Status_Code erc.ActiveStatusCode `json:"status_code" validate:"maxLength=10"`
|
||||
User_Id *uint `json:"user_id"`
|
||||
Person_Id *uint `json:"person_id"`
|
||||
Number *string `json:"number" validate:"maxLength=20"`
|
||||
Status_Code erc.ActiveStatusCode `json:"status_code" validate:"maxLength=10"`
|
||||
Position_Code *erg.EmployeePositionCode `json:"position_code"`
|
||||
}
|
||||
|
||||
type ReadListDto struct {
|
||||
|
||||
@@ -2,6 +2,7 @@ package installation
|
||||
|
||||
import (
|
||||
ecore "simrs-vx/internal/domain/base-entities/core"
|
||||
eipb "simrs-vx/internal/domain/main-entities/installation-position/base"
|
||||
|
||||
ere "simrs-vx/internal/domain/references/encounter"
|
||||
)
|
||||
@@ -49,16 +50,18 @@ type MetaDto struct {
|
||||
|
||||
type ResponseDto struct {
|
||||
ecore.SmallMain
|
||||
Code string `json:"code"`
|
||||
Name string `json:"name"`
|
||||
EncounterClass_Code ere.EncounterClassCode `json:"encounterClass_code"`
|
||||
Code string `json:"code"`
|
||||
Name string `json:"name"`
|
||||
EncounterClass_Code ere.EncounterClassCode `json:"encounterClass_code"`
|
||||
InstallationPositions []eipb.Basic `json:"installationPositions,omitempty"`
|
||||
}
|
||||
|
||||
func (d Installation) ToResponse() ResponseDto {
|
||||
resp := ResponseDto{
|
||||
Code: d.Code,
|
||||
Name: d.Name,
|
||||
EncounterClass_Code: d.EncounterClass_Code,
|
||||
Code: d.Code,
|
||||
Name: d.Name,
|
||||
EncounterClass_Code: d.EncounterClass_Code,
|
||||
InstallationPositions: d.InstallationPositions,
|
||||
}
|
||||
resp.SmallMain = d.SmallMain
|
||||
return resp
|
||||
|
||||
@@ -3,6 +3,7 @@ package unit
|
||||
import (
|
||||
ecore "simrs-vx/internal/domain/base-entities/core"
|
||||
ei "simrs-vx/internal/domain/main-entities/installation"
|
||||
eipb "simrs-vx/internal/domain/main-entities/unit-position/base"
|
||||
)
|
||||
|
||||
type CreateDto struct {
|
||||
@@ -51,8 +52,9 @@ type ResponseDto struct {
|
||||
ecore.SmallMain
|
||||
Installation_Id *uint16 `json:"installation_id"`
|
||||
Installation *ei.Installation
|
||||
Code string `json:"code"`
|
||||
Name string `json:"name"`
|
||||
Code string `json:"code"`
|
||||
Name string `json:"name"`
|
||||
UnitPositions []eipb.Basic `json:"unitPositions,omitempty"`
|
||||
}
|
||||
|
||||
func (d Unit) ToResponse() ResponseDto {
|
||||
@@ -60,6 +62,7 @@ func (d Unit) ToResponse() ResponseDto {
|
||||
Installation_Id: d.Installation_Id,
|
||||
Code: d.Code,
|
||||
Name: d.Name,
|
||||
UnitPositions: d.UnitPositions,
|
||||
}
|
||||
resp.SmallMain = d.SmallMain
|
||||
if d.Installation != nil {
|
||||
|
||||
@@ -38,6 +38,8 @@ func (obj myBase) GetDetail(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
dto := e.ReadDetailDto{}
|
||||
|
||||
sf.UrlQueryParam(&dto, *r.URL)
|
||||
dto.Id = uint16(id)
|
||||
res, err := u.ReadDetail(dto)
|
||||
rw.DataResponse(w, res, err)
|
||||
|
||||
@@ -38,6 +38,8 @@ func (obj myBase) GetDetail(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
dto := e.ReadDetailDto{}
|
||||
|
||||
sf.UrlQueryParam(&dto, *r.URL)
|
||||
dto.Id = uint16(id)
|
||||
res, err := u.ReadDetail(dto)
|
||||
rw.DataResponse(w, res, err)
|
||||
|
||||
@@ -120,10 +120,10 @@ func GenToken(input eu.LoginDto) (*d.Data, error) {
|
||||
outputData["employee_id"] = employee.Id
|
||||
role = append(role, "emp-"+string(*employee.Position_Code))
|
||||
|
||||
if employee.Division_Code != nil {
|
||||
atClaims["employee_division_code"] = employee.Division_Code
|
||||
outputData["employee_division_code"] = employee.Division_Code
|
||||
}
|
||||
//if employee.Division_Code != nil {
|
||||
// atClaims["employee_division_code"] = employee.Division_Code
|
||||
// outputData["employee_division_code"] = employee.Division_Code
|
||||
//}
|
||||
|
||||
// employee position
|
||||
if employee.Id > 0 && employee.Position_Code != nil {
|
||||
@@ -159,7 +159,7 @@ func GenToken(input eu.LoginDto) (*d.Data, error) {
|
||||
errorGetPosition := d.FieldErrors{"authentication": d.FieldError{Code: "auth-getData-failed", Message: el.GenMessage("auth-getData-failed")}}
|
||||
|
||||
// division position
|
||||
divsionPositions, err := getDivisionPosition(employee.Id)
|
||||
divisionPositions, err := getDivisionPosition(employee.Id)
|
||||
if err != nil {
|
||||
return nil, errorGetPosition
|
||||
}
|
||||
@@ -188,7 +188,7 @@ func GenToken(input eu.LoginDto) (*d.Data, error) {
|
||||
return nil, errorGetPosition
|
||||
}
|
||||
|
||||
role = append(role, divsionPositions...)
|
||||
role = append(role, divisionPositions...)
|
||||
role = append(role, installationPositions...)
|
||||
role = append(role, unitPositions...)
|
||||
role = append(role, specialistPositions...)
|
||||
|
||||
@@ -2,11 +2,8 @@ package division
|
||||
|
||||
import (
|
||||
e "simrs-vx/internal/domain/main-entities/division"
|
||||
edp "simrs-vx/internal/domain/main-entities/division-position"
|
||||
"strconv"
|
||||
|
||||
udp "simrs-vx/internal/use-case/main-use-case/division-position"
|
||||
|
||||
dg "github.com/karincake/apem/db-gorm-pg"
|
||||
d "github.com/karincake/dodol"
|
||||
|
||||
@@ -64,7 +61,7 @@ func Create(input e.CreateDto) (*d.Data, error) {
|
||||
"structure": "single-data",
|
||||
"status": "created",
|
||||
},
|
||||
Data: data.ToResponse(nil),
|
||||
Data: data.ToResponse(),
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -145,40 +142,6 @@ func ReadDetail(input e.ReadDetailDto) (*d.Data, error) {
|
||||
return err
|
||||
}
|
||||
|
||||
// get data divisionPositions
|
||||
dataDivisionPosition, err := udp.ReadList(edp.ReadListDto{
|
||||
FilterDto: edp.FilterDto{
|
||||
Division_Id: &input.Id,
|
||||
},
|
||||
Includes: "employee,employee.User",
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
list, _ := dataDivisionPosition.Data.([]edp.ResponseDto)
|
||||
if len(list) > 0 {
|
||||
for _, dp := range list {
|
||||
dataDP = append(dataDP, e.ResponseDivisionPosition{
|
||||
SmallMain: dp.SmallMain,
|
||||
Division_Id: &dp.Id,
|
||||
Code: dp.Code,
|
||||
Name: dp.Name,
|
||||
HeadStatus: dp.HeadStatus,
|
||||
Employee_Id: dp.Employee_Id,
|
||||
Employee: e.ResponseDivisionEmployee{
|
||||
Main: dp.Employee.Main,
|
||||
User_Id: dp.Employee.User_Id,
|
||||
User: dp.Employee.User,
|
||||
Person_Id: dp.Employee.Person_Id,
|
||||
Person: dp.Employee.Person,
|
||||
Number: dp.Employee.Number,
|
||||
Status_Code: dp.Employee.Status_Code,
|
||||
},
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
mwRunner.setMwType(pu.MWTPost)
|
||||
// Run post-middleware
|
||||
if err := mwRunner.RunReadDetailMiddleware(readDetailPostMw, &input, data); err != nil {
|
||||
@@ -198,7 +161,7 @@ func ReadDetail(input e.ReadDetailDto) (*d.Data, error) {
|
||||
"structure": "single-data",
|
||||
"status": "fetched",
|
||||
},
|
||||
Data: data.ToResponse(dataDP),
|
||||
Data: data.ToResponse(),
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -253,7 +216,7 @@ func Update(input e.UpdateDto) (*d.Data, error) {
|
||||
"structure": "single-data",
|
||||
"status": "updated",
|
||||
},
|
||||
Data: data.ToResponse(nil),
|
||||
Data: data.ToResponse(),
|
||||
}, nil
|
||||
|
||||
}
|
||||
@@ -307,7 +270,7 @@ func Delete(input e.DeleteDto) (*d.Data, error) {
|
||||
"structure": "single-data",
|
||||
"status": "deleted",
|
||||
},
|
||||
Data: data.ToResponse(nil),
|
||||
Data: data.ToResponse(),
|
||||
}, nil
|
||||
|
||||
}
|
||||
|
||||
@@ -19,7 +19,6 @@ func setData[T *e.CreateDto | *e.UpdateDto](input T, data *e.Employee) {
|
||||
|
||||
data.User_Id = inputSrc.User_Id
|
||||
data.Person_Id = inputSrc.Person_Id
|
||||
data.Division_Code = inputSrc.Division_Code
|
||||
data.Number = inputSrc.Number
|
||||
data.Status_Code = inputSrc.Status_Code
|
||||
data.Position_Code = inputSrc.Position_Code
|
||||
|
||||
@@ -81,7 +81,9 @@ func ReadDetailData(input e.ReadDetailDto, event *pl.Event, dbx ...*gorm.DB) (*e
|
||||
tx = dg.I
|
||||
}
|
||||
|
||||
if err := tx.First(&data, input.Id).Error; err != nil {
|
||||
if err := tx.
|
||||
Scopes(gh.Preload(input.Includes)).
|
||||
First(&data, input.Id).Error; err != nil {
|
||||
if processedErr := pu.HandleReadError(err, event, source, input.Id, data); processedErr != nil {
|
||||
return nil, processedErr
|
||||
}
|
||||
|
||||
@@ -81,7 +81,9 @@ func ReadDetailData(input e.ReadDetailDto, event *pl.Event, dbx ...*gorm.DB) (*e
|
||||
tx = dg.I
|
||||
}
|
||||
|
||||
if err := tx.First(&data, input.Id).Error; err != nil {
|
||||
if err := tx.
|
||||
Scopes(gh.Preload(input.Includes)).
|
||||
First(&data, input.Id).Error; err != nil {
|
||||
if processedErr := pu.HandleReadError(err, event, source, input.Id, data); processedErr != nil {
|
||||
return nil, processedErr
|
||||
}
|
||||
|
||||
@@ -46,7 +46,6 @@ func setDataEmployeeUpdate(src e.EmployeUpdateDto) ee.UpdateDto {
|
||||
CreateDto: ee.CreateDto{
|
||||
User_Id: src.User_Id,
|
||||
Person_Id: src.Person_Id,
|
||||
Division_Code: src.Division_Code,
|
||||
Number: src.Number,
|
||||
Status_Code: src.Status_Code,
|
||||
Position_Code: &src.Position_Code,
|
||||
|
||||
Reference in New Issue
Block a user