Skip to content

Commit

Permalink
Add FindOrganizationStructureByID message handling and implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
IlhamSetiaji committed Dec 10, 2024
1 parent 30ffa90 commit 15a8fe5
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 0 deletions.
Binary file added go-sso.exe~
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package messaging

import (
"app/go-sso/internal/repository"

"github.com/google/uuid"
"github.com/sirupsen/logrus"
)

type IFindOrganizationStructureByIDMessageRequest struct {
OrganizationStructureID uuid.UUID `json:"organization_structure_id"`
}

type IFindOrganizationStructureByIDMessageResponse struct {
OrganizationStructureID string `json:"organization_structure_id"`
Name string `json:"name"`
}

type IFindOrganizationStructureByIDMessage interface {
Execute(request IFindOrganizationStructureByIDMessageRequest) (*IFindOrganizationStructureByIDMessageResponse, error)
}

type FindOrganizationStructureByIDMessage struct {
Log *logrus.Logger
Repository repository.IOrganizationStructureRepository
}

func NewFindOrganizationStructureByIDMessage(log *logrus.Logger, repository repository.IOrganizationStructureRepository) IFindOrganizationStructureByIDMessage {
return &FindOrganizationStructureByIDMessage{
Log: log,
Repository: repository,
}
}

func (m *FindOrganizationStructureByIDMessage) Execute(request IFindOrganizationStructureByIDMessageRequest) (*IFindOrganizationStructureByIDMessageResponse, error) {
organizationStructure, err := m.Repository.FindById(request.OrganizationStructureID)
if err != nil {
return nil, err
}

return &IFindOrganizationStructureByIDMessageResponse{
OrganizationStructureID: organizationStructure.ID.String(),
Name: organizationStructure.Name,
}, nil
}

func FindOrganizationStructureByIDMessageFactory(log *logrus.Logger) IFindOrganizationStructureByIDMessage {
repository := repository.OrganizationStructureRepositoryFactory(log)
return NewFindOrganizationStructureByIDMessage(log, repository)
}
27 changes: 27 additions & 0 deletions internal/rabbitmq/consumer.go
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,33 @@ func handleMsg(docMsg *request.RabbitMQRequest, log *logrus.Logger) {
"job_level_id": jobLevelID,
"exists": message.Exists,
}
case "find_organization_structure_by_id":
organizationStructureID, ok := docMsg.MessageData["organization_structure_id"].(string)
if !ok {
log.Printf("Invalid request format: missing 'organization_structure_id'")
msgData = map[string]interface{}{
"error": errors.New("missing 'organization_structure_id'").Error(),
}
break
}

messageFactory := orgMessaging.FindOrganizationStructureByIDMessageFactory(log)
message, err := messageFactory.Execute(orgMessaging.IFindOrganizationStructureByIDMessageRequest{
OrganizationStructureID: uuid.MustParse(organizationStructureID),
})

if err != nil {
log.Printf("Failed to execute message: %v", err)
msgData = map[string]interface{}{
"error": err.Error(),
}
break
}

msgData = map[string]interface{}{
"organization_structure_id": organizationStructureID,
"name": message.Name,
}
default:
log.Printf("Unknown message type: %s", docMsg.MessageType)

Expand Down

0 comments on commit 15a8fe5

Please sign in to comment.