Skip to content

Commit

Permalink
fix: rename relation methods to match generated proto implementation (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
akoserwal authored Jun 5, 2024
1 parent 6ec3e68 commit 887b966
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 20 deletions.
6 changes: 3 additions & 3 deletions internal/biz/relationships.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func NewCreateRelationshipsUsecase(repo ZanzibarRepository, logger log.Logger) *
}

func (rc *CreateRelationshipsUsecase) CreateRelationships(ctx context.Context, r []*v0.Relationship, touch bool) error {
rc.log.WithContext(ctx).Infof("CreateRelationships: %v %s", r, touch)
rc.log.WithContext(ctx).Infof("CreateTuples: %v %s", r, touch)
return rc.repo.CreateRelationships(ctx, r, TouchSemantics(touch))
}

Expand All @@ -66,7 +66,7 @@ func NewReadRelationshipsUsecase(repo ZanzibarRepository, logger log.Logger) *Re
}

func (rc *ReadRelationshipsUsecase) ReadRelationships(ctx context.Context, req *v0.ReadTuplesRequest) (chan *RelationshipResult, chan error, error) {
rc.log.WithContext(ctx).Infof("ReadRelationships: %v", req)
rc.log.WithContext(ctx).Infof("ReadTuples: %v", req)

limit := uint32(MaxStreamingCount)
continuation := ContinuationToken("")
Expand Down Expand Up @@ -100,6 +100,6 @@ func NewDeleteRelationshipsUsecase(repo ZanzibarRepository, logger log.Logger) *
}

func (rc *DeleteRelationshipsUsecase) DeleteRelationships(ctx context.Context, r *v0.RelationTupleFilter) error {
rc.log.WithContext(ctx).Infof("DeleteRelationships: %v", r)
rc.log.WithContext(ctx).Infof("DeleteTuples: %v", r)
return rc.repo.DeleteRelationships(ctx, r)
}
2 changes: 1 addition & 1 deletion internal/server/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func NewHTTPServer(c *conf.Server, relationships *service.RelationshipsService,
}

srv := http.NewServer(opts...)

v0.RegisterKesselTupleServiceHTTPServer(srv, relationships)
v0.RegisterKesselCheckServiceHTTPServer(srv, check)
h.RegisterKesselHealthHTTPServer(srv, health)
return srv
Expand Down
6 changes: 3 additions & 3 deletions internal/service/relationships.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func NewRelationshipsService(logger log.Logger, createUseCase *biz.CreateRelatio
}
}

func (s *RelationshipsService) CreateRelationships(ctx context.Context, req *pb.CreateTuplesRequest) (*pb.CreateTuplesResponse, error) {
func (s *RelationshipsService) CreateTuples(ctx context.Context, req *pb.CreateTuplesRequest) (*pb.CreateTuplesResponse, error) {
s.log.Infof("Create relationships request: %v", req)

err := s.createUsecase.CreateRelationships(ctx, req.Tuples, req.GetUpsert()) //The generated .GetUpsert() defaults to false
Expand All @@ -37,7 +37,7 @@ func (s *RelationshipsService) CreateRelationships(ctx context.Context, req *pb.
return &pb.CreateTuplesResponse{}, nil
}

func (s *RelationshipsService) ReadRelationships(req *pb.ReadTuplesRequest, conn pb.KesselTupleService_ReadTuplesServer) error {
func (s *RelationshipsService) ReadTuples(req *pb.ReadTuplesRequest, conn pb.KesselTupleService_ReadTuplesServer) error {
ctx := conn.Context()

relationships, errs, err := s.readUsecase.ReadRelationships(ctx, req)
Expand All @@ -64,7 +64,7 @@ func (s *RelationshipsService) ReadRelationships(req *pb.ReadTuplesRequest, conn
return nil
}

func (s *RelationshipsService) DeleteRelationships(ctx context.Context, req *pb.DeleteTuplesRequest) (*pb.DeleteTuplesResponse, error) {
func (s *RelationshipsService) DeleteTuples(ctx context.Context, req *pb.DeleteTuplesRequest) (*pb.DeleteTuplesResponse, error) {
s.log.Infof("Delete relationships request: %v", req)

err := s.deleteUsecase.DeleteRelationships(ctx, req.Filter)
Expand Down
26 changes: 13 additions & 13 deletions internal/service/relationships_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func TestRelationshipsService_CreateRelationships(t *testing.T) {
expected,
},
}
_, err = relationshipsService.CreateRelationships(ctx, req)
_, err = relationshipsService.CreateTuples(ctx, req)
assert.NoError(t, err)

readReq := &v0.ReadTuplesRequest{Filter: &v0.RelationTupleFilter{
Expand All @@ -67,7 +67,7 @@ func TestRelationshipsService_CreateRelationships(t *testing.T) {
},
}
collectingServer := NewRelationships_ReadRelationshipsServerStub(ctx)
err = relationshipsService.ReadRelationships(readReq, collectingServer)
err = relationshipsService.ReadTuples(readReq, collectingServer)
if err != nil {
t.FailNow()
}
Expand Down Expand Up @@ -97,7 +97,7 @@ func TestRelationshipsService_CreateRelationshipsWithTouchFalse(t *testing.T) {
expected,
},
}
_, err = relationshipsService.CreateRelationships(ctx, req)
_, err = relationshipsService.CreateTuples(ctx, req)
assert.NoError(t, err)

readReq := &v0.ReadTuplesRequest{Filter: &v0.RelationTupleFilter{
Expand All @@ -111,7 +111,7 @@ func TestRelationshipsService_CreateRelationshipsWithTouchFalse(t *testing.T) {
},
}
collectingServer := NewRelationships_ReadRelationshipsServerStub(ctx)
err = relationshipsService.ReadRelationships(readReq, collectingServer)
err = relationshipsService.ReadTuples(readReq, collectingServer)
if err != nil {
t.FailNow()
}
Expand All @@ -127,7 +127,7 @@ func TestRelationshipsService_CreateRelationshipsWithTouchFalse(t *testing.T) {
assert.Equal(t, expected.Relation, resp.Tuple.Relation)
}

_, err = relationshipsService.CreateRelationships(ctx, req)
_, err = relationshipsService.CreateTuples(ctx, req)
assert.Equal(t, status.Convert(err).Code(), codes.AlreadyExists)

}
Expand All @@ -144,7 +144,7 @@ func TestRelationshipsService_CreateRelationshipsWithBadSubjectType(t *testing.T
expected,
},
}
_, err = relationshipsService.CreateRelationships(ctx, req)
_, err = relationshipsService.CreateTuples(ctx, req)
assert.Error(t, err)
assert.Equal(t, status.Convert(err).Code(), codes.FailedPrecondition)
assert.Contains(t, err.Error(), "object definition `"+badSubjectType+"` not found")
Expand All @@ -162,7 +162,7 @@ func TestRelationshipsService_CreateRelationshipsWithBadObjectType(t *testing.T)
expected,
},
}
_, err = relationshipsService.CreateRelationships(ctx, req)
_, err = relationshipsService.CreateTuples(ctx, req)
assert.Error(t, err)
assert.Equal(t, status.Convert(err).Code(), codes.FailedPrecondition)
assert.Contains(t, err.Error(), "object definition `"+badObjectType+"` not found")
Expand All @@ -181,7 +181,7 @@ func TestRelationshipsService_DeleteRelationships(t *testing.T) {
expected,
},
}
_, err = relationshipsService.CreateRelationships(ctx, req)
_, err = relationshipsService.CreateTuples(ctx, req)
assert.NoError(t, err)

delreq := &v0.DeleteTuplesRequest{Filter: &v0.RelationTupleFilter{
Expand All @@ -193,7 +193,7 @@ func TestRelationshipsService_DeleteRelationships(t *testing.T) {
SubjectType: pointerize("user"),
},
}}
_, err = relationshipsService.DeleteRelationships(ctx, delreq)
_, err = relationshipsService.DeleteTuples(ctx, delreq)
assert.NoError(t, err)

readReq := &v0.ReadTuplesRequest{Filter: &v0.RelationTupleFilter{
Expand All @@ -208,7 +208,7 @@ func TestRelationshipsService_DeleteRelationships(t *testing.T) {
}

collectingServer := NewRelationships_ReadRelationshipsServerStub(ctx)
err = relationshipsService.ReadRelationships(readReq, collectingServer)
err = relationshipsService.ReadTuples(readReq, collectingServer)
if err != nil {
t.FailNow()
}
Expand Down Expand Up @@ -260,7 +260,7 @@ func TestRelationshipsService_ReadRelationships(t *testing.T) {
expected,
},
}
_, err = relationshipsService.CreateRelationships(ctx, reqCr)
_, err = relationshipsService.CreateTuples(ctx, reqCr)
assert.NoError(t, err)

req := &v0.ReadTuplesRequest{Filter: &v0.RelationTupleFilter{
Expand All @@ -275,7 +275,7 @@ func TestRelationshipsService_ReadRelationships(t *testing.T) {
}

collectingServer := NewRelationships_ReadRelationshipsServerStub(ctx)
err = relationshipsService.ReadRelationships(req, collectingServer)
err = relationshipsService.ReadTuples(req, collectingServer)
if err != nil {
t.FailNow()
}
Expand Down Expand Up @@ -317,7 +317,7 @@ func createRelationship(subjectId string, subjectType *v0.ObjectType, subjectRel
}
}

// Below is the boilerplate for creating test servers for streaming ReadRelationships rpc
// Below is the boilerplate for creating test servers for streaming ReadTuples rpc

func NewRelationships_ReadRelationshipsServerStub(ctx context.Context) *Relationships_ReadRelationshipsServerStub {
return &Relationships_ReadRelationshipsServerStub{
Expand Down

0 comments on commit 887b966

Please sign in to comment.