diff --git a/go-sso.exe~ b/go-sso.exe~ index e708634..34d5167 100644 Binary files a/go-sso.exe~ and b/go-sso.exe~ differ diff --git a/internal/http/dto/organization_location_dto.go b/internal/http/dto/organization_location_dto.go new file mode 100644 index 0000000..ffe7eb8 --- /dev/null +++ b/internal/http/dto/organization_location_dto.go @@ -0,0 +1,30 @@ +package dto + +import ( + "app/go-sso/internal/entity" + "app/go-sso/internal/http/response" +) + +func ConvertToOrganizationLocationResponse(orgLocations *[]entity.OrganizationLocation) *[]response.OrganizationLocationResponse { + var responseLocations []response.OrganizationLocationResponse + for _, orgLocation := range *orgLocations { + responseLocations = append(responseLocations, response.OrganizationLocationResponse{ + ID: orgLocation.ID, + OrganizationID: orgLocation.OrganizationID, + Name: orgLocation.Name, + CreatedAt: orgLocation.CreatedAt, + UpdatedAt: orgLocation.UpdatedAt, + }) + } + return &responseLocations +} + +func ConvertToSingleOrganizationLocationResponse(orgLocation *entity.OrganizationLocation) *response.OrganizationLocationResponse { + return &response.OrganizationLocationResponse{ + ID: orgLocation.ID, + OrganizationID: orgLocation.OrganizationID, + Name: orgLocation.Name, + CreatedAt: orgLocation.CreatedAt, + UpdatedAt: orgLocation.UpdatedAt, + } +} diff --git a/internal/http/response/job_level_response.go b/internal/http/response/job_level_response.go new file mode 100644 index 0000000..ff50d6d --- /dev/null +++ b/internal/http/response/job_level_response.go @@ -0,0 +1,9 @@ +package response + +import "github.com/google/uuid" + +type JobLevelResponse struct { + ID uuid.UUID `json:"id"` + Name string `json:"name"` + Level string `json:"level"` +} diff --git a/internal/http/response/ogranization_structure_response.go b/internal/http/response/ogranization_structure_response.go new file mode 100644 index 0000000..5a233dc --- /dev/null +++ b/internal/http/response/ogranization_structure_response.go @@ -0,0 +1,17 @@ +package response + +import "github.com/google/uuid" + +type OrganizationStructureResponse struct { + ID uuid.UUID `json:"id"` + OrganizationID uuid.UUID `json:"organization_id"` + Name string `json:"name"` + JobLevelID uuid.UUID `json:"job_level_id"` + ParentID *uuid.UUID `json:"parent_id,omitempty"` + Level int `json:"level"` + Path string `json:"path"` + Organization OrganizationResponse `json:"organization"` + JobLevel JobLevelResponse `json:"job_level"` + Parent *OrganizationStructureResponse `json:"parent,omitempty"` + Children []OrganizationStructureResponse `json:"children,omitempty"` +} diff --git a/internal/http/response/organization_location.go b/internal/http/response/organization_location.go new file mode 100644 index 0000000..9a92cd6 --- /dev/null +++ b/internal/http/response/organization_location.go @@ -0,0 +1,15 @@ +package response + +import ( + "time" + + "github.com/google/uuid" +) + +type OrganizationLocationResponse struct { + ID uuid.UUID `json:"id"` + OrganizationID uuid.UUID `json:"organization_id"` + Name string `json:"name"` + CreatedAt time.Time `json:"created_at"` + UpdatedAt time.Time `json:"updated_at"` +} diff --git a/internal/http/response/organization_response.go b/internal/http/response/organization_response.go index 7e863d9..faf5986 100644 --- a/internal/http/response/organization_response.go +++ b/internal/http/response/organization_response.go @@ -7,29 +7,4 @@ type OrganizationResponse struct { OrganizationTypeID uuid.UUID `json:"organization_type_id"` Name string `json:"name"` OrganizationType OrganizationTypeResponse -} - -type OrganizationTypeResponse struct { - ID uuid.UUID `json:"id"` - Name string `json:"name"` -} - -type JobLevelResponse struct { - ID uuid.UUID `json:"id"` - Name string `json:"name"` - Level string `json:"level"` -} - -type OrganizationStructureResponse struct { - ID uuid.UUID `json:"id"` - OrganizationID uuid.UUID `json:"organization_id"` - Name string `json:"name"` - JobLevelID uuid.UUID `json:"job_level_id"` - ParentID *uuid.UUID `json:"parent_id,omitempty"` - Level int `json:"level"` - Path string `json:"path"` - Organization OrganizationResponse `json:"organization"` - JobLevel JobLevelResponse `json:"job_level"` - Parent *OrganizationStructureResponse `json:"parent,omitempty"` - Children []OrganizationStructureResponse `json:"children,omitempty"` -} +} \ No newline at end of file diff --git a/internal/http/response/organization_type_response.go b/internal/http/response/organization_type_response.go new file mode 100644 index 0000000..71b944b --- /dev/null +++ b/internal/http/response/organization_type_response.go @@ -0,0 +1,8 @@ +package response + +import "github.com/google/uuid" + +type OrganizationTypeResponse struct { + ID uuid.UUID `json:"id"` + Name string `json:"name"` +} diff --git a/internal/repository/organization_location_repository.go b/internal/repository/organization_location_repository.go index 1b1a8a6..9c1afbf 100644 --- a/internal/repository/organization_location_repository.go +++ b/internal/repository/organization_location_repository.go @@ -12,6 +12,7 @@ import ( type IOrganizationLocationRepository interface { FindAllPaginated(page int, pageSize int, search string) (*[]entity.OrganizationLocation, int64, error) FindById(id uuid.UUID) (*entity.OrganizationLocation, error) + FindByOrganizationID(organizationID uuid.UUID) (*[]entity.OrganizationLocation, error) } type OrganizationLocationRepository struct { @@ -56,6 +57,15 @@ func (r *OrganizationLocationRepository) FindById(id uuid.UUID) (*entity.Organiz return &organizationLocation, nil } +func (r *OrganizationLocationRepository) FindByOrganizationID(organizationID uuid.UUID) (*[]entity.OrganizationLocation, error) { + var organizationLocations []entity.OrganizationLocation + err := r.DB.Where("organization_id = ?", organizationID).Find(&organizationLocations).Error + if err != nil { + return nil, err + } + return &organizationLocations, nil +} + func OrganizationLocationRepositoryFactory(log *logrus.Logger) IOrganizationLocationRepository { db := config.NewDatabase() return NewOrganizationLocationRepository(log, db) diff --git a/internal/usecase/organization_location/find_all_paginated_usecase.go b/internal/usecase/organization_location/find_all_paginated_usecase.go index b86da02..b302d0b 100644 --- a/internal/usecase/organization_location/find_all_paginated_usecase.go +++ b/internal/usecase/organization_location/find_all_paginated_usecase.go @@ -1,7 +1,8 @@ package usecase import ( - "app/go-sso/internal/entity" + "app/go-sso/internal/http/dto" + "app/go-sso/internal/http/response" "app/go-sso/internal/repository" "github.com/sirupsen/logrus" @@ -14,8 +15,8 @@ type IFindAllPaginatedUseCaseRequest struct { } type IFindAllPaginatedUseCaseResponse struct { - OrganizationLocations *[]entity.OrganizationLocation `json:"organization_locations"` - Total int64 `json:"total"` + OrganizationLocations *[]response.OrganizationLocationResponse `json:"organization_locations"` + Total int64 `json:"total"` } type IFindAllPaginatedUseCase interface { @@ -44,7 +45,7 @@ func (uc *FindAllPaginatedUseCase) Execute(req *IFindAllPaginatedUseCaseRequest) } return &IFindAllPaginatedUseCaseResponse{ - OrganizationLocations: organizationLocations, + OrganizationLocations: dto.ConvertToOrganizationLocationResponse(organizationLocations), Total: total, }, nil }