Skip to content

Commit

Permalink
Add validation code for Read & Delete tuples
Browse files Browse the repository at this point in the history
Signed-off-by: Jonathan Marcantonio <[email protected]>
  • Loading branch information
lennysgarage committed Jun 17, 2024
1 parent 9de8edb commit 6b5b640
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
4 changes: 2 additions & 2 deletions internal/service/lookup.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
Expand All @@ -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 {
Expand Down
10 changes: 10 additions & 0 deletions internal/service/relationships.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 6b5b640

Please sign in to comment.