adjustment detail division
This commit is contained in:
@@ -2,6 +2,10 @@ package division
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
ecore "simrs-vx/internal/domain/base-entities/core"
|
ecore "simrs-vx/internal/domain/base-entities/core"
|
||||||
|
ep "simrs-vx/internal/domain/main-entities/person"
|
||||||
|
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 {
|
type CreateDto struct {
|
||||||
@@ -26,8 +30,9 @@ type FilterDto struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type ReadDetailDto struct {
|
type ReadDetailDto struct {
|
||||||
Id uint16 `json:"id"`
|
Id uint16 `json:"id"`
|
||||||
Code *string `json:"code"`
|
Code *string `json:"code"`
|
||||||
|
Includes string `json:"includes"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type UpdateDto struct {
|
type UpdateDto struct {
|
||||||
@@ -47,14 +52,36 @@ type MetaDto struct {
|
|||||||
|
|
||||||
type ResponseDto struct {
|
type ResponseDto struct {
|
||||||
ecore.SmallMain
|
ecore.SmallMain
|
||||||
Code string `json:"code"`
|
Code string `json:"code"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
Parent_Id *uint16 `json:"parent_id"`
|
Parent_Id *uint16 `json:"parent_id"`
|
||||||
Parent *Division `json:"parent,omitempty"`
|
Parent *Division `json:"parent,omitempty"`
|
||||||
Childrens []Division `json:"childrens,omitempty"`
|
Childrens []Division `json:"childrens,omitempty"`
|
||||||
|
DivisionPosition []ResponseDivisionPosition `json:"divisionPositions,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d Division) ToResponse() ResponseDto {
|
type ResponseDivisionPosition struct {
|
||||||
|
ecore.SmallMain // adjust this according to the needs
|
||||||
|
Division_Id *uint16 `json:"division_id"`
|
||||||
|
Code string `json:"code"`
|
||||||
|
Name string `json:"name"`
|
||||||
|
HeadStatus bool `json:"headStatus"`
|
||||||
|
Employee_Id *uint `json:"employee_id"`
|
||||||
|
Employee ResponseDivisionEmployee `json:"employee"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type ResponseDivisionEmployee struct {
|
||||||
|
ecore.Main // adjust this according to the needs
|
||||||
|
User_Id *uint `json:"user_id"`
|
||||||
|
User *eu.User `json:"user,omitempty"`
|
||||||
|
Person_Id *uint `json:"person_id"`
|
||||||
|
Person *ep.Person `json:"person,omitempty"`
|
||||||
|
Position_Code *erg.EmployeePositionCode `json:"position_code"`
|
||||||
|
Number *string `json:"number"`
|
||||||
|
Status_Code erc.ActiveStatusCode `json:"status_code"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d Division) ToResponse(divPos []ResponseDivisionPosition) ResponseDto {
|
||||||
resp := ResponseDto{
|
resp := ResponseDto{
|
||||||
Code: d.Code,
|
Code: d.Code,
|
||||||
Name: d.Name,
|
Name: d.Name,
|
||||||
@@ -63,13 +90,17 @@ func (d Division) ToResponse() ResponseDto {
|
|||||||
Childrens: d.Childrens,
|
Childrens: d.Childrens,
|
||||||
}
|
}
|
||||||
resp.SmallMain = d.SmallMain
|
resp.SmallMain = d.SmallMain
|
||||||
|
|
||||||
|
if divPos != nil {
|
||||||
|
resp.DivisionPosition = divPos
|
||||||
|
}
|
||||||
return resp
|
return resp
|
||||||
}
|
}
|
||||||
|
|
||||||
func ToResponseList(data []Division) []ResponseDto {
|
func ToResponseList(data []Division) []ResponseDto {
|
||||||
resp := make([]ResponseDto, len(data))
|
resp := make([]ResponseDto, len(data))
|
||||||
for i, u := range data {
|
for i, u := range data {
|
||||||
resp[i] = u.ToResponse()
|
resp[i] = u.ToResponse(nil)
|
||||||
}
|
}
|
||||||
return resp
|
return resp
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,8 +27,9 @@ type FilterDto struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type ReadDetailDto struct {
|
type ReadDetailDto struct {
|
||||||
Id uint16 `json:"id"`
|
Id uint16 `json:"id"`
|
||||||
Code *string `json:"code"`
|
Code *string `json:"code"`
|
||||||
|
Includes string `json:"includes"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type UpdateDto struct {
|
type UpdateDto struct {
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ type ReadDetailDto struct {
|
|||||||
Id uint16 `json:"id"`
|
Id uint16 `json:"id"`
|
||||||
Installation_Id *uint16 `json:"installation_id"`
|
Installation_Id *uint16 `json:"installation_id"`
|
||||||
Code *string `json:"code"`
|
Code *string `json:"code"`
|
||||||
|
Includes string `json:"includes"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type UpdateDto struct {
|
type UpdateDto struct {
|
||||||
|
|||||||
@@ -37,7 +37,9 @@ func (obj myBase) GetDetail(w http.ResponseWriter, r *http.Request) {
|
|||||||
if id <= 0 {
|
if id <= 0 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
dto := e.ReadDetailDto{}
|
dto := e.ReadDetailDto{}
|
||||||
|
sf.UrlQueryParam(&dto, *r.URL)
|
||||||
dto.Id = uint16(id)
|
dto.Id = uint16(id)
|
||||||
res, err := u.ReadDetail(dto)
|
res, err := u.ReadDetail(dto)
|
||||||
rw.DataResponse(w, res, err)
|
rw.DataResponse(w, res, err)
|
||||||
|
|||||||
@@ -2,8 +2,11 @@ package division
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
e "simrs-vx/internal/domain/main-entities/division"
|
e "simrs-vx/internal/domain/main-entities/division"
|
||||||
|
edp "simrs-vx/internal/domain/main-entities/division-position"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
|
udp "simrs-vx/internal/use-case/main-use-case/division-position"
|
||||||
|
|
||||||
dg "github.com/karincake/apem/db-gorm-pg"
|
dg "github.com/karincake/apem/db-gorm-pg"
|
||||||
d "github.com/karincake/dodol"
|
d "github.com/karincake/dodol"
|
||||||
|
|
||||||
@@ -61,7 +64,7 @@ func Create(input e.CreateDto) (*d.Data, error) {
|
|||||||
"structure": "single-data",
|
"structure": "single-data",
|
||||||
"status": "created",
|
"status": "created",
|
||||||
},
|
},
|
||||||
Data: data.ToResponse(),
|
Data: data.ToResponse(nil),
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -121,6 +124,7 @@ func ReadList(input e.ReadListDto) (*d.Data, error) {
|
|||||||
func ReadDetail(input e.ReadDetailDto) (*d.Data, error) {
|
func ReadDetail(input e.ReadDetailDto) (*d.Data, error) {
|
||||||
var data *e.Division
|
var data *e.Division
|
||||||
var err error
|
var err error
|
||||||
|
var dataDP []e.ResponseDivisionPosition
|
||||||
|
|
||||||
event := pl.Event{
|
event := pl.Event{
|
||||||
Feature: "ReadDetail",
|
Feature: "ReadDetail",
|
||||||
@@ -142,6 +146,40 @@ func ReadDetail(input e.ReadDetailDto) (*d.Data, error) {
|
|||||||
return err
|
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)
|
mwRunner.setMwType(pu.MWTPost)
|
||||||
// Run post-middleware
|
// Run post-middleware
|
||||||
if err := mwRunner.RunReadDetailMiddleware(readDetailPostMw, &input, data); err != nil {
|
if err := mwRunner.RunReadDetailMiddleware(readDetailPostMw, &input, data); err != nil {
|
||||||
@@ -161,7 +199,7 @@ func ReadDetail(input e.ReadDetailDto) (*d.Data, error) {
|
|||||||
"structure": "single-data",
|
"structure": "single-data",
|
||||||
"status": "fetched",
|
"status": "fetched",
|
||||||
},
|
},
|
||||||
Data: data.ToResponse(),
|
Data: data.ToResponse(dataDP),
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -216,7 +254,7 @@ func Update(input e.UpdateDto) (*d.Data, error) {
|
|||||||
"structure": "single-data",
|
"structure": "single-data",
|
||||||
"status": "updated",
|
"status": "updated",
|
||||||
},
|
},
|
||||||
Data: data.ToResponse(),
|
Data: data.ToResponse(nil),
|
||||||
}, nil
|
}, nil
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -270,7 +308,7 @@ func Delete(input e.DeleteDto) (*d.Data, error) {
|
|||||||
"structure": "single-data",
|
"structure": "single-data",
|
||||||
"status": "deleted",
|
"status": "deleted",
|
||||||
},
|
},
|
||||||
Data: data.ToResponse(),
|
Data: data.ToResponse(nil),
|
||||||
}, nil
|
}, nil
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -91,7 +91,9 @@ func ReadDetailData(input e.ReadDetailDto, event *pl.Event, dbx ...*gorm.DB) (*e
|
|||||||
tx = dg.I
|
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 {
|
if processedErr := pu.HandleReadError(err, event, source, input.Id, data); processedErr != nil {
|
||||||
return nil, processedErr
|
return nil, processedErr
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user