Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 0 additions & 26 deletions internal/service/committee_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,6 @@ func (rc *committeeReaderOrchestrator) GetBase(ctx context.Context, uid string)
// Get committee base from storage
committeeBase, revision, err := rc.committeeReader.GetBase(ctx, uid)
if err != nil {
slog.ErrorContext(ctx, "failed to get committee base",
"error", err,
"committee_uid", uid,
)
return nil, 0, err
}
Comment thread
andrest50 marked this conversation as resolved.

Expand All @@ -90,10 +86,6 @@ func (rc *committeeReaderOrchestrator) GetSettings(ctx context.Context, uid stri
// Get committee settings from storage
committeeSettings, revision, err := rc.committeeReader.GetSettings(ctx, uid)
if err != nil {
slog.ErrorContext(ctx, "failed to get committee settings",
"error", err,
"committee_uid", uid,
)
return nil, 0, err
}

Expand Down Expand Up @@ -137,31 +129,17 @@ func (rc *committeeReaderOrchestrator) GetMember(ctx context.Context, committeeU
// First, verify that the committee exists
_, _, err := rc.committeeReader.GetBase(ctx, committeeUID)
if err != nil {
slog.ErrorContext(ctx, "failed to get committee base - committee does not exist",
"error", err,
"committee_uid", committeeUID,
)
return nil, 0, err
}

// Get committee member from storage
committeeMember, revision, err := rc.committeeReader.GetMember(ctx, memberUID)
if err != nil {
slog.ErrorContext(ctx, "failed to get committee member",
"error", err,
"committee_uid", committeeUID,
"member_uid", memberUID,
)
return nil, 0, err
}
Comment thread
andrest50 marked this conversation as resolved.

// Verify that the member belongs to the requested committee
if committeeMember.CommitteeUID != committeeUID {
slog.ErrorContext(ctx, "committee member does not belong to the requested committee",
"committee_uid", committeeUID,
"member_uid", memberUID,
"member_committee_uid", committeeMember.CommitteeUID,
)
return nil, 0, errs.NewValidation("committee member does not belong to the requested committee")
}

Expand All @@ -184,10 +162,6 @@ func (rc *committeeReaderOrchestrator) ListMembers(ctx context.Context, committe
// Get all committee members from storage
members, err := rc.committeeReader.ListMembers(ctx, committeeUID)
if err != nil {
slog.ErrorContext(ctx, "failed to list committee members",
"error", err,
"committee_uid", committeeUID,
)
return nil, err
}
Comment thread
andrest50 marked this conversation as resolved.

Expand Down
44 changes: 0 additions & 44 deletions internal/service/message_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,36 +71,22 @@ func (m *messageHandlerOrchestrator) HandleCommitteeGetAttribute(ctx context.Con
// Validate that the committee ID is a valid UUID.
_, err := uuid.Parse(uid)
if err != nil {
slog.ErrorContext(ctx, "error parsing committee ID", "error", err)
return nil, err
}
Comment thread
andrest50 marked this conversation as resolved.

// Use the committee reader to get the committee base information
committee, _, err := m.committeeReader.GetBase(ctx, uid)
if err != nil {
slog.ErrorContext(ctx, "failed to get committee base",
"error", err,
"committee_uid", uid,
)
return nil, err
}

value, ok := fields.LookupByTag(committee, "json", attribute)
if !ok {
slog.ErrorContext(ctx, "attribute not found in committee",
"attribute", attribute,
"committee_uid", uid,
)
return nil, errors.NewNotFound(fmt.Sprintf("attribute %s not found in committee %s", attribute, uid))
}

strValue, ok := value.(string)
if !ok {
slog.ErrorContext(ctx, "attribute value is not a string",
"attribute", attribute,
"committee_uid", uid,
"value_type", fmt.Sprintf("%T", value),
)
return nil, errors.NewValidation(fmt.Sprintf("attribute %s value is not a string", attribute))
}

Expand All @@ -120,37 +106,24 @@ func (m *messageHandlerOrchestrator) HandleCommitteeListMembers(ctx context.Cont
// Validate that the committee ID is a valid UUID.
_, err := uuid.Parse(uid)
if err != nil {
slog.ErrorContext(ctx, "error parsing committee ID", "error", err)
return nil, err
}

// Check if the committee exists first
_, _, err = m.committeeReader.GetBase(ctx, uid)
if err != nil {
slog.ErrorContext(ctx, "failed to get committee base",
"error", err,
"committee_uid", uid,
)
return nil, err
}
Comment thread
andrest50 marked this conversation as resolved.

// Get all members for the committee
members, err := m.committeeReader.ListMembers(ctx, uid)
if err != nil {
slog.ErrorContext(ctx, "failed to list committee members",
"error", err,
"committee_uid", uid,
)
return nil, err
}

// Marshal the members to JSON
membersJSON, err := json.Marshal(members)
if err != nil {
slog.ErrorContext(ctx, "failed to marshal committee members",
"error", err,
"committee_uid", uid,
)
return nil, errors.NewUnexpected("failed to marshal committee members", err)
}

Expand All @@ -167,7 +140,6 @@ func (m *messageHandlerOrchestrator) HandleCommitteeListMembers(ctx context.Cont
func (m *messageHandlerOrchestrator) HandleCommitteeMailingListChanged(ctx context.Context, msg port.TransportMessenger) ([]byte, error) {
var event model.CommitteeMailingListChangedEvent
if err := json.Unmarshal(msg.Data(), &event); err != nil {
slog.ErrorContext(ctx, "failed to unmarshal CommitteeMailingListChangedEvent", "error", err)
return nil, err
}

Expand All @@ -183,8 +155,6 @@ func (m *messageHandlerOrchestrator) HandleCommitteeMailingListChanged(ctx conte

committee, changed, err := m.committeeWriter.UpdateHasMailingList(ctx, event.CommitteeUID, event.HasMailingList)
if err != nil {
slog.ErrorContext(ctx, "failed to update has_mailing_list",
"committee_uid", event.CommitteeUID, "error", err)
return nil, err
}
if !changed {
Expand All @@ -202,15 +172,11 @@ func (m *messageHandlerOrchestrator) HandleCommitteeMailingListChanged(ctx conte

indexerMsg, err := buildIndexerMessage(ctx, model.ActionUpdated, committee, fullCommittee.Tags())
if err != nil {
slog.ErrorContext(ctx, "failed to build indexer message",
"committee_uid", event.CommitteeUID, "error", err)
return nil, err
}
indexerMsg.IndexingConfig = buildCommitteeIndexingConfig(fullCommittee)

if err := m.committeePublisher.Indexer(ctx, constants.IndexCommitteeSubject, indexerMsg, false); err != nil {
slog.ErrorContext(ctx, "failed to publish committee indexer update",
"committee_uid", event.CommitteeUID, "error", err)
return nil, err
}

Expand All @@ -229,7 +195,6 @@ func (m *messageHandlerOrchestrator) HandleCommitteeUpdated(ctx context.Context,

var event model.CommitteeEvent
if err := json.Unmarshal(msg.Data(), &event); err != nil {
slog.ErrorContext(ctx, "failed to unmarshal CommitteeEvent", "error", err)
return nil, err
}

Expand Down Expand Up @@ -267,8 +232,6 @@ func (m *messageHandlerOrchestrator) HandleCommitteeUpdated(ctx context.Context,

members, err := m.committeeReader.ListMembers(ctx, data.CommitteeUID)
if err != nil {
slog.ErrorContext(ctx, "failed to list members for sync",
"committee_uid", data.CommitteeUID, "error", err)
return nil, err
}

Expand Down Expand Up @@ -333,7 +296,6 @@ func (m *messageHandlerOrchestrator) HandleCommitteeTotalMembersSync(ctx context

var event model.CommitteeEvent
if err := json.Unmarshal(msg.Data(), &event); err != nil {
slog.ErrorContext(ctx, "failed to unmarshal CommitteeEvent for total_members sync", "error", err)
return err
}

Expand Down Expand Up @@ -365,16 +327,12 @@ func (m *messageHandlerOrchestrator) HandleCommitteeTotalMembersSync(ctx context

Comment on lines 317 to 321
members, err := m.committeeReader.ListMembers(ctx, committeeUID)
if err != nil {
slog.ErrorContext(ctx, "failed to list members for total_members sync",
"committee_uid", committeeUID, "error", err)
return err
}
actualCount := len(members)

committee, revision, err := m.committeeReader.GetBase(ctx, committeeUID)
if err != nil {
slog.ErrorContext(ctx, "failed to get committee base for total_members sync",
"committee_uid", committeeUID, "error", err)
return err
}
Comment thread
andrest50 marked this conversation as resolved.

Expand All @@ -395,8 +353,6 @@ func (m *messageHandlerOrchestrator) HandleCommitteeTotalMembersSync(ctx context
committee.TotalMembers = actualCount

if _, err := m.committeeWriterOrchestrator.Update(ctx, &model.Committee{CommitteeBase: *committee}, revision, false); err != nil {
slog.ErrorContext(ctx, "failed to update committee total_members",
"committee_uid", committeeUID, "error", err)
return err
}

Expand Down
Loading