From 6b5b6403828004a7250a44690ac1ab5627f78928 Mon Sep 17 00:00:00 2001 From: Jonathan Marcantonio Date: Mon, 17 Jun 2024 14:10:33 -0400 Subject: [PATCH] Add validation code for Read & Delete tuples Signed-off-by: Jonathan Marcantonio --- internal/service/lookup.go | 4 ++-- internal/service/relationships.go | 10 ++++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/internal/service/lookup.go b/internal/service/lookup.go index 176ad69..dba3fdd 100644 --- a/internal/service/lookup.go +++ b/internal/service/lookup.go @@ -20,8 +20,6 @@ func NewLookupService(subjectsUseCase *biz.GetSubjectsUsecase) *LookupService { } func (s *LookupService) LookupSubjects(req *pb.LookupSubjectsRequest, conn pb.KesselLookupService_LookupSubjectsServer) error { - ctx := conn.Context() - if err := req.ValidateAll(); err != nil { return errors.BadRequest("Invalid request", err.Error()) } @@ -30,6 +28,8 @@ func (s *LookupService) LookupSubjects(req *pb.LookupSubjectsRequest, conn pb.Ke return errors.BadRequest("Invalid request", err.Error()) } + ctx := conn.Context() + subs, errs, err := s.subjectsUsecase.Get(ctx, req) if err != nil { diff --git a/internal/service/relationships.go b/internal/service/relationships.go index 49d7963..6bec9b7 100644 --- a/internal/service/relationships.go +++ b/internal/service/relationships.go @@ -46,6 +46,11 @@ func (s *RelationshipsService) CreateTuples(ctx context.Context, req *pb.CreateT } func (s *RelationshipsService) ReadTuples(req *pb.ReadTuplesRequest, conn pb.KesselTupleService_ReadTuplesServer) error { + if err := req.ValidateAll(); err != nil { + s.log.Infof("Request failed to pass validation: %v", req) + return errors.BadRequest("Invalid request", err.Error()) + } + ctx := conn.Context() relationships, errs, err := s.readUsecase.ReadRelationships(ctx, req) @@ -75,6 +80,11 @@ func (s *RelationshipsService) ReadTuples(req *pb.ReadTuplesRequest, conn pb.Kes func (s *RelationshipsService) DeleteTuples(ctx context.Context, req *pb.DeleteTuplesRequest) (*pb.DeleteTuplesResponse, error) { s.log.Infof("Delete relationships request: %v", req) + if err := req.ValidateAll(); err != nil { + s.log.Infof("Request failed to pass validation: %v", req) + return nil, errors.BadRequest("Invalid request", err.Error()) + } + err := s.deleteUsecase.DeleteRelationships(ctx, req.Filter) if err != nil { return nil, err