Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: New RPCs #87

Merged
merged 1 commit into from
Jan 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,7 @@ linters:
- interfacer
- maligned
- nosnakecase
- prealloc
- scopelint
- structcheck
- testpackage
Expand Down
51 changes: 51 additions & 0 deletions cmd/svc/license/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import (
"github.com/bufbuild/protovalidate-go"
"github.com/sirupsen/logrus"
"github.com/volatiletech/sqlboiler/v4/boil"
"github.com/volatiletech/sqlboiler/v4/queries/qm"
"google.golang.org/protobuf/types/known/timestamppb"

"github.com/kevinmichaelchen/temporal-saga-grpc/cmd/svc/license/models"
)
Expand Down Expand Up @@ -74,3 +76,52 @@ func (s *Service) CreateLicense(

return out, nil
}

// GetLicense - Gets a License.
func (s *Service) GetLicense(
ctx context.Context,
req *connect.Request[licensev1beta1.GetLicenseRequest],
) (*connect.Response[licensev1beta1.GetLicenseResponse], error) {
record, err := models.FindLicense(ctx, s.db, req.Msg.GetId())
if err != nil {
return nil, fmt.Errorf("unable to retrieve item: %w", err)
}

return connect.NewResponse(&licensev1beta1.GetLicenseResponse{
License: &licensev1beta1.License{
Id: record.ID,
Start: timestamppb.New(record.StartTime),
End: timestamppb.New(record.EndTime),
UserId: record.UserID,
},
}), nil
}

// ListLicenses - Lists licenses.
func (s *Service) ListLicenses(
ctx context.Context,
req *connect.Request[licensev1beta1.ListLicensesRequest],
) (*connect.Response[licensev1beta1.ListLicensesResponse], error) {
var mods []qm.QueryMod
// TODO account for parent and page_token fields
mods = append(mods, qm.Limit(max(1, int(req.Msg.GetPageSize()))))

items, err := models.Licenses(mods...).All(ctx, s.db)
if err != nil {
return nil, fmt.Errorf("unable to retrieve items: %w", err)
}

var licenses []*licensev1beta1.License
for _, item := range items {
licenses = append(licenses, &licensev1beta1.License{
Id: item.ID,
Start: timestamppb.New(item.StartTime),
End: timestamppb.New(item.EndTime),
UserId: item.UserID,
})
}

return connect.NewResponse(&licensev1beta1.ListLicensesResponse{
Licenses: licenses,
}), nil
}
45 changes: 45 additions & 0 deletions cmd/svc/org/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/sirupsen/logrus"
"github.com/volatiletech/null/v8"
"github.com/volatiletech/sqlboiler/v4/boil"
"github.com/volatiletech/sqlboiler/v4/queries/qm"

"github.com/kevinmichaelchen/temporal-saga-grpc/cmd/svc/org/models"
)
Expand Down Expand Up @@ -57,3 +58,47 @@ func (s *Service) CreateOrg(

return out, nil
}

// GetOrg - Gets an org.
func (s *Service) GetOrg(
ctx context.Context,
req *connect.Request[orgPB.GetOrgRequest],
) (*connect.Response[orgPB.GetOrgResponse], error) {
record, err := models.FindOrg(ctx, s.db, req.Msg.GetId())
if err != nil {
return nil, fmt.Errorf("unable to retrieve item: %w", err)
}

return connect.NewResponse(&orgPB.GetOrgResponse{
Org: &orgPB.Org{
Id: record.ID,
Name: record.Name.String,
},
}), nil
}

// ListOrgs - Lists orgs.
func (s *Service) ListOrgs(
ctx context.Context,
req *connect.Request[orgPB.ListOrgsRequest],
) (*connect.Response[orgPB.ListOrgsResponse], error) {
var mods []qm.QueryMod
mods = append(mods, qm.Limit(max(1, int(req.Msg.GetPageSize()))))

items, err := models.Orgs(mods...).All(ctx, s.db)
if err != nil {
return nil, fmt.Errorf("unable to retrieve items: %w", err)
}

var orgs []*orgPB.Org
for _, item := range items {
orgs = append(orgs, &orgPB.Org{
Id: item.ID,
Name: item.Name.String,
})
}

return connect.NewResponse(&orgPB.ListOrgsResponse{
Orgs: orgs,
}), nil
}
48 changes: 48 additions & 0 deletions cmd/svc/profile/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/sirupsen/logrus"
"github.com/volatiletech/null/v8"
"github.com/volatiletech/sqlboiler/v4/boil"
"github.com/volatiletech/sqlboiler/v4/queries/qm"

"github.com/kevinmichaelchen/temporal-saga-grpc/cmd/svc/profile/models"
)
Expand Down Expand Up @@ -60,3 +61,50 @@ func (s *Service) CreateProfile(

return out, nil
}

// GetProfile - Gets a profile.
func (s *Service) GetProfile(
ctx context.Context,
req *connect.Request[profilePB.GetProfileRequest],
) (*connect.Response[profilePB.GetProfileResponse], error) {
record, err := models.FindProfile(ctx, s.db, req.Msg.GetId())
if err != nil {
return nil, fmt.Errorf("unable to retrieve item: %w", err)
}

return connect.NewResponse(&profilePB.GetProfileResponse{
Profile: &profilePB.Profile{
Id: record.ID,
FullName: record.FullName.String,
OrgId: record.OrgID,
},
}), nil
}

// ListProfiles - Lists profiles.
func (s *Service) ListProfiles(
ctx context.Context,
req *connect.Request[profilePB.ListProfilesRequest],
) (*connect.Response[profilePB.ListProfilesResponse], error) {
var mods []qm.QueryMod
// TODO account for parent and page_token fields
mods = append(mods, qm.Limit(max(1, int(req.Msg.GetPageSize()))))

items, err := models.Profiles(mods...).All(ctx, s.db)
if err != nil {
return nil, fmt.Errorf("unable to retrieve items: %w", err)
}

var profiles []*profilePB.Profile
for _, item := range items {
profiles = append(profiles, &profilePB.Profile{
Id: item.ID,
FullName: item.FullName.String,
OrgId: item.OrgID,
})
}

return connect.NewResponse(&profilePB.ListProfilesResponse{
Profiles: profiles,
}), nil
}
12 changes: 6 additions & 6 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ module github.com/kevinmichaelchen/temporal-saga-grpc
go 1.21.5

require (
buf.build/gen/go/kevinmichaelchen/licenseapis/connectrpc/go v1.14.0-20240105230935-96a83ee74301.1
buf.build/gen/go/kevinmichaelchen/licenseapis/protocolbuffers/go v1.32.0-20240105230935-96a83ee74301.1
buf.build/gen/go/kevinmichaelchen/orgapis/connectrpc/go v1.14.0-20240105230936-cc69561a5883.1
buf.build/gen/go/kevinmichaelchen/orgapis/protocolbuffers/go v1.32.0-20240105230936-cc69561a5883.1
buf.build/gen/go/kevinmichaelchen/profileapis/connectrpc/go v1.14.0-20240105230937-9f5a2b967cc7.1
buf.build/gen/go/kevinmichaelchen/profileapis/protocolbuffers/go v1.32.0-20240105230937-9f5a2b967cc7.1
buf.build/gen/go/kevinmichaelchen/licenseapis/connectrpc/go v1.14.0-20240106023353-b0ccffe2bf81.1
buf.build/gen/go/kevinmichaelchen/licenseapis/protocolbuffers/go v1.32.0-20240106023353-b0ccffe2bf81.1
buf.build/gen/go/kevinmichaelchen/orgapis/connectrpc/go v1.14.0-20240106023354-7971463d1bab.1
buf.build/gen/go/kevinmichaelchen/orgapis/protocolbuffers/go v1.32.0-20240106023354-7971463d1bab.1
buf.build/gen/go/kevinmichaelchen/profileapis/connectrpc/go v1.14.0-20240106023355-4074133bf516.1
buf.build/gen/go/kevinmichaelchen/profileapis/protocolbuffers/go v1.32.0-20240106023355-4074133bf516.1
buf.build/gen/go/kevinmichaelchen/temporalapis/connectrpc/go v1.14.0-20240105233422-8054bf72d102.1
buf.build/gen/go/kevinmichaelchen/temporalapis/protocolbuffers/go v1.32.0-20240105233422-8054bf72d102.1
connectrpc.com/connect v1.14.0
Expand Down
24 changes: 12 additions & 12 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go v1.32.0-20231115204500-e097f827e652.1 h1:u0olL4yf2p7Tl5jfsAK5keaFi+JFJuv1CDHrbiXkxkk=
buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go v1.32.0-20231115204500-e097f827e652.1/go.mod h1:tiTMKD8j6Pd/D2WzREoweufjzaJKHZg35f/VGcZ2v3I=
buf.build/gen/go/kevinmichaelchen/licenseapis/connectrpc/go v1.14.0-20240105230935-96a83ee74301.1 h1:iz8B4/o/Tu9kCU1O61ce9LoMO4cruyKOxZg+Xn3jkIk=
buf.build/gen/go/kevinmichaelchen/licenseapis/connectrpc/go v1.14.0-20240105230935-96a83ee74301.1/go.mod h1:TWnyka2/a0+psN92AVScMT7Sq3mKdjCAWLjcfLQDMgk=
buf.build/gen/go/kevinmichaelchen/licenseapis/protocolbuffers/go v1.32.0-20240105230935-96a83ee74301.1 h1:uxRlX4/HFwA//ZcSZdryz5Nk9hzsLWRUMnmJjwQGA7s=
buf.build/gen/go/kevinmichaelchen/licenseapis/protocolbuffers/go v1.32.0-20240105230935-96a83ee74301.1/go.mod h1:f0zTv4+cZ3+O0fQx7E6JKpPLhQuUJMkl+M7Ott4b4wo=
buf.build/gen/go/kevinmichaelchen/orgapis/connectrpc/go v1.14.0-20240105230936-cc69561a5883.1 h1:w6j+cfXANJ3mFei+DLs8afQp305z35sSXJdrVTP+Kig=
buf.build/gen/go/kevinmichaelchen/orgapis/connectrpc/go v1.14.0-20240105230936-cc69561a5883.1/go.mod h1:2c3rsXGY3Zpto2kEM0hr3bTrvRqcUQzlPF5Glj/Xjno=
buf.build/gen/go/kevinmichaelchen/orgapis/protocolbuffers/go v1.32.0-20240105230936-cc69561a5883.1 h1:pHMAxU1GI79GvmdTi2mfOKDRaPWqZ7UqMSoyxBVLp9U=
buf.build/gen/go/kevinmichaelchen/orgapis/protocolbuffers/go v1.32.0-20240105230936-cc69561a5883.1/go.mod h1:VX7SaxTl48U3BUn1ZWGPaw3Z3trZei6Lijff1hWDCmM=
buf.build/gen/go/kevinmichaelchen/profileapis/connectrpc/go v1.14.0-20240105230937-9f5a2b967cc7.1 h1:+pGDboLYUQSzr+YieYCoY1AP9RtL69rLKhBx5tNzwT4=
buf.build/gen/go/kevinmichaelchen/profileapis/connectrpc/go v1.14.0-20240105230937-9f5a2b967cc7.1/go.mod h1:yZWWCij9/6ffN2PJwEYWgs7DjkWa5cXl2AR8Xvnc+Ng=
buf.build/gen/go/kevinmichaelchen/profileapis/protocolbuffers/go v1.32.0-20240105230937-9f5a2b967cc7.1 h1:YaUHKKR7AZRrnCiZ+QOQuw2wQB0DlOe8KBdN7bDymhs=
buf.build/gen/go/kevinmichaelchen/profileapis/protocolbuffers/go v1.32.0-20240105230937-9f5a2b967cc7.1/go.mod h1:mdFxPRDe6P7qFVw9urFLZ3SkG+ZdPW5q5QXFGjGr8DE=
buf.build/gen/go/kevinmichaelchen/licenseapis/connectrpc/go v1.14.0-20240106023353-b0ccffe2bf81.1 h1:HXlREx5iasiZ7RLIcM+Sa9KXLfznGMzfRUvtFJPa3pA=
buf.build/gen/go/kevinmichaelchen/licenseapis/connectrpc/go v1.14.0-20240106023353-b0ccffe2bf81.1/go.mod h1:bH7/XrbxIE+ZFdY12NEIikndXo36yoc7AV6sJDLR/M0=
buf.build/gen/go/kevinmichaelchen/licenseapis/protocolbuffers/go v1.32.0-20240106023353-b0ccffe2bf81.1 h1:Bhg6zySqAAGMy8+lw+EhV1iIU/vDoUekSnFKlvFWX3s=
buf.build/gen/go/kevinmichaelchen/licenseapis/protocolbuffers/go v1.32.0-20240106023353-b0ccffe2bf81.1/go.mod h1:f0zTv4+cZ3+O0fQx7E6JKpPLhQuUJMkl+M7Ott4b4wo=
buf.build/gen/go/kevinmichaelchen/orgapis/connectrpc/go v1.14.0-20240106023354-7971463d1bab.1 h1:AcL7ufchnekd8PUAipa2TUv93Xo07XOExmoL8Ae5J+4=
buf.build/gen/go/kevinmichaelchen/orgapis/connectrpc/go v1.14.0-20240106023354-7971463d1bab.1/go.mod h1:tq6x6ypkRXOLfa/pojKOaoAtdiwaNhK520RwZdnYRMU=
buf.build/gen/go/kevinmichaelchen/orgapis/protocolbuffers/go v1.32.0-20240106023354-7971463d1bab.1 h1:XGdlUgsatFaPXeMj+KSSIBxC+esBQMK6vLvaSV71iYA=
buf.build/gen/go/kevinmichaelchen/orgapis/protocolbuffers/go v1.32.0-20240106023354-7971463d1bab.1/go.mod h1:VX7SaxTl48U3BUn1ZWGPaw3Z3trZei6Lijff1hWDCmM=
buf.build/gen/go/kevinmichaelchen/profileapis/connectrpc/go v1.14.0-20240106023355-4074133bf516.1 h1:oVo3ozoMXc1uqT9cQIs4duxnJ4XEAvMLu20aP98ahGQ=
buf.build/gen/go/kevinmichaelchen/profileapis/connectrpc/go v1.14.0-20240106023355-4074133bf516.1/go.mod h1:ErjiGiWNjH317M2DV6eeGDYZgvgLmwX7kzFBqHEYo6Q=
buf.build/gen/go/kevinmichaelchen/profileapis/protocolbuffers/go v1.32.0-20240106023355-4074133bf516.1 h1:g4MnvhuIRX2BQ4BTkSwwkzv6GDJ/jlZNcB4gycwm1ko=
buf.build/gen/go/kevinmichaelchen/profileapis/protocolbuffers/go v1.32.0-20240106023355-4074133bf516.1/go.mod h1:mdFxPRDe6P7qFVw9urFLZ3SkG+ZdPW5q5QXFGjGr8DE=
buf.build/gen/go/kevinmichaelchen/temporalapis/connectrpc/go v1.14.0-20240105233422-8054bf72d102.1 h1:DjZa2Ji1Rje54fcm1SU2EfRRyEwfHNrt1SIz2JxaFMA=
buf.build/gen/go/kevinmichaelchen/temporalapis/connectrpc/go v1.14.0-20240105233422-8054bf72d102.1/go.mod h1:lAv2Uero9GS0WGHvco9tw82GY5J/U0uuBdccsHV4Acc=
buf.build/gen/go/kevinmichaelchen/temporalapis/protocolbuffers/go v1.32.0-20240105233422-8054bf72d102.1 h1:TOugHIye1MzyV7Vjzff13UZWidUVPp0xwmejtOBEXew=
Expand Down
34 changes: 34 additions & 0 deletions idl/licenseapis/license/v1beta1/api.proto
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@ service LicenseService {
rpc CreateLicense(CreateLicenseRequest) returns (CreateLicenseResponse) {
option idempotency_level = IDEMPOTENT;
}
// Get a License.
rpc GetLicense(GetLicenseRequest) returns (GetLicenseResponse) {
option idempotency_level = IDEMPOTENT;
}
// ListLicenses - Lists Licenses.
rpc ListLicenses(ListLicensesRequest) returns (ListLicensesResponse) {
option idempotency_level = IDEMPOTENT;
}
}

message CreateLicenseRequest {
Expand All @@ -28,3 +36,29 @@ message CreateLicenseRequest {
}

message CreateLicenseResponse {}

message License {
string id = 1;
google.protobuf.Timestamp start = 2;
google.protobuf.Timestamp end = 3;
string user_id = 4;
}

message GetLicenseRequest {
string id = 1;
}

message GetLicenseResponse {
License license = 1;
}

message ListLicensesRequest {
string parent = 1;
int32 page_size = 2;
string page_token = 3;
}

message ListLicensesResponse {
repeated License licenses = 1;
string next_page_token = 2;
}
32 changes: 32 additions & 0 deletions idl/orgapis/org/v1beta1/api.proto
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@ service OrgService {
rpc CreateOrg(CreateOrgRequest) returns (CreateOrgResponse) {
option idempotency_level = IDEMPOTENT;
}
// GetOrg - Gets an Organization.
rpc GetOrg(GetOrgRequest) returns (GetOrgResponse) {
option idempotency_level = IDEMPOTENT;
}
// ListOrgs - Lists Organizations.
rpc ListOrgs(ListOrgsRequest) returns (ListOrgsResponse) {
option idempotency_level = IDEMPOTENT;
}
}

message CreateOrgRequest {
Expand All @@ -18,3 +26,27 @@ message CreateOrgRequest {
}

message CreateOrgResponse {}

message Org {
string id = 1;
string name = 2;
}

message GetOrgRequest {
string id = 1;
}

message GetOrgResponse {
Org org = 1;
}

message ListOrgsRequest {
string parent = 1;
int32 page_size = 2;
string page_token = 3;
}

message ListOrgsResponse {
repeated Org orgs = 1;
string next_page_token = 2;
}
33 changes: 33 additions & 0 deletions idl/profileapis/profile/v1beta1/api.proto
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@ service ProfileService {
rpc CreateProfile(CreateProfileRequest) returns (CreateProfileResponse) {
option idempotency_level = IDEMPOTENT;
}
// GetProfile - Gets a Profile.
rpc GetProfile(GetProfileRequest) returns (GetProfileResponse) {
option idempotency_level = IDEMPOTENT;
}
// ListProfiles - Lists Profiles.
rpc ListProfiles(ListProfilesRequest) returns (ListProfilesResponse) {
option idempotency_level = IDEMPOTENT;
}
}

message CreateProfileRequest {
Expand All @@ -19,3 +27,28 @@ message CreateProfileRequest {
}

message CreateProfileResponse {}

message Profile {
string id = 1;
string full_name = 2;
string org_id = 3;
}

message GetProfileRequest {
string id = 1;
}

message GetProfileResponse {
Profile profile = 1;
}

message ListProfilesRequest {
string parent = 1;
int32 page_size = 2;
string page_token = 3;
}

message ListProfilesResponse {
repeated Profile profiles = 1;
string next_page_token = 2;
}
Loading