Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/activities' into v0.10.1-alpha.5
Browse files Browse the repository at this point in the history
  • Loading branch information
rahmatrhd committed May 22, 2024
2 parents e4a8c29 + 4437425 commit 6964cdc
Show file tree
Hide file tree
Showing 22 changed files with 2,524 additions and 1,584 deletions.
22 changes: 22 additions & 0 deletions api/handler/v1beta1/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -973,6 +973,28 @@ func (a *adapter) fromConditionProto(c *guardianv1beta1.Condition) *domain.Condi
}
}

func (a *adapter) ToAppealActivityProto(e *domain.Event) (*guardianv1beta1.AppealActivity, error) {
if e == nil {
return nil, nil
}

activityProto := &guardianv1beta1.AppealActivity{
AppealId: e.ParentID,
Timestamp: timestamppb.New(e.Timestamp),
Type: e.Type,
Actor: e.Actor,
}

if e.Data != nil {
data, err := structpb.NewStruct(e.Data)
if err != nil {
return nil, err
}
activityProto.Data = data
}
return activityProto, nil
}

func (a *adapter) toConditionProto(c *domain.Condition) (*guardianv1beta1.Condition, error) {
if c == nil {
return nil, nil
Expand Down
20 changes: 20 additions & 0 deletions api/handler/v1beta1/appeal.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,26 @@ func (s *GRPCServer) CancelAppeal(ctx context.Context, req *guardianv1beta1.Canc
}, nil
}

func (s *GRPCServer) ListAppealActivities(ctx context.Context, req *guardianv1beta1.ListAppealActivitiesRequest) (*guardianv1beta1.ListAppealActivitiesResponse, error) {
activities, err := s.appealService.ListActivities(ctx, req.GetAppealId())
if err != nil {
return nil, s.internalError(ctx, "failed to get appeal activities: %v", err)
}

activityProtos := make([]*guardianv1beta1.AppealActivity, 0, len(activities))
for _, a := range activities {
activityProto, err := s.adapter.ToAppealActivityProto(a)
if err != nil {
return nil, s.internalError(ctx, "failed to parse appeal activity: %v", err)
}
activityProtos = append(activityProtos, activityProto)
}

return &guardianv1beta1.ListAppealActivitiesResponse{
Activities: activityProtos,
}, nil
}

func (s *GRPCServer) listAppeals(ctx context.Context, filters *domain.ListAppealsFilter) ([]*guardianv1beta1.Appeal, int64, error) {
eg, ctx := errgroup.WithContext(ctx)
var appeals []*domain.Appeal
Expand Down
2 changes: 2 additions & 0 deletions api/handler/v1beta1/grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ type ProtoAdapter interface {
ToActivityProto(*domain.Activity) (*guardianv1beta1.ProviderActivity, error)

ToCommentProto(*domain.Comment) *guardianv1beta1.AppealComment
ToAppealActivityProto(e *domain.Event) (*guardianv1beta1.AppealActivity, error)
}

//go:generate mockery --name=resourceService --exported --with-expecter
Expand Down Expand Up @@ -101,6 +102,7 @@ type appealService interface {
UpdateApproval(ctx context.Context, approvalAction domain.ApprovalAction) (*domain.Appeal, error)
ListComments(context.Context, domain.ListCommentsFilter) ([]*domain.Comment, error)
CreateComment(context.Context, *domain.Comment) error
ListActivities(context.Context, string) ([]*domain.Event, error)
}

//go:generate mockery --name=approvalService --exported --with-expecter
Expand Down
55 changes: 55 additions & 0 deletions api/handler/v1beta1/mocks/appealService.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 6964cdc

Please sign in to comment.