Skip to content

Commit

Permalink
refactor: remove domains prefix from invitee endpoints
Browse files Browse the repository at this point in the history
Signed-off-by: Felix Gateru <[email protected]>
  • Loading branch information
felixgateru committed Feb 7, 2025
1 parent e693882 commit 77fc6b3
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 32 deletions.
6 changes: 3 additions & 3 deletions apidocs/openapi/domains.yml
Original file line number Diff line number Diff line change
Expand Up @@ -812,7 +812,7 @@ paths:
"500":
$ref: "#/components/responses/ServiceError"

/domains/invitations:
/invitations:
get:
operationId: listUserInvitations
tags:
Expand Down Expand Up @@ -850,7 +850,7 @@ paths:
"500":
$ref: "#/components/responses/ServiceError"

/domains/invitations/accept:
/invitations/accept:
post:
operationId: acceptInvitation
summary: Accept invitation
Expand All @@ -874,7 +874,7 @@ paths:
"500":
$ref: "#/components/responses/ServiceError"

/domains/invitations/reject:
/invitations/reject:
post:
operationId: rejectInvitation
summary: Reject invitation
Expand Down
6 changes: 3 additions & 3 deletions domains/api/http/endpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1303,7 +1303,7 @@ func TestListInvitation(t *testing.T) {
req := testRequest{
client: is.Client(),
method: http.MethodGet,
url: is.URL + "/domains" + "/invitations?" + tc.query,
url: is.URL + "/invitations?" + tc.query,
token: tc.token,
contentType: tc.contentType,
}
Expand Down Expand Up @@ -1560,7 +1560,7 @@ func TestAcceptInvitation(t *testing.T) {
req := testRequest{
client: is.Client(),
method: http.MethodPost,
url: is.URL + "/domains/invitations/accept",
url: is.URL + "/invitations/accept",
token: tc.token,
contentType: tc.contentType,
body: strings.NewReader(tc.data),
Expand Down Expand Up @@ -1640,7 +1640,7 @@ func TestRejectInvitation(t *testing.T) {
req := testRequest{
client: is.Client(),
method: http.MethodPost,
url: is.URL + "/domains/invitations/reject",
url: is.URL + "/invitations/reject",
token: tc.token,
contentType: tc.contentType,
body: strings.NewReader(tc.data),
Expand Down
44 changes: 22 additions & 22 deletions domains/api/http/transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func MakeHandler(svc domains.Service, authn authn.Authentication, mux *chi.Mux,
decodeListInvitationsReq,
api.EncodeResponse,
opts...,
), "list_invitations").ServeHTTP)
), "list_domain_invitations").ServeHTTP)
r.Route("/{userID}", func(r chi.Router) {
r.Get("/", otelhttp.NewHandler(kithttp.NewServer(
viewInvitationEndpoint(svc),
Expand All @@ -114,28 +114,28 @@ func MakeHandler(svc domains.Service, authn authn.Authentication, mux *chi.Mux,
), "delete_invitation").ServeHTTP)
})
})
})

r.Route("/invitations", func(r chi.Router) {
r.Use(api.AuthenticateMiddleware(authn, false))
r.Get("/", otelhttp.NewHandler(kithttp.NewServer(
listUserInvitationsEndpoint(svc),
decodeListInvitationsReq,
api.EncodeResponse,
opts...,
), "list_invitations").ServeHTTP)
r.Post("/accept", otelhttp.NewHandler(kithttp.NewServer(
acceptInvitationEndpoint(svc),
decodeAcceptInvitationReq,
api.EncodeResponse,
opts...,
), "accept_invitation").ServeHTTP)
r.Post("/reject", otelhttp.NewHandler(kithttp.NewServer(
rejectInvitationEndpoint(svc),
decodeAcceptInvitationReq,
api.EncodeResponse,
opts...,
), "reject_invitation").ServeHTTP)
})
mux.Route("/invitations", func(r chi.Router) {
r.Use(api.AuthenticateMiddleware(authn, false))
r.Get("/", otelhttp.NewHandler(kithttp.NewServer(
listUserInvitationsEndpoint(svc),
decodeListInvitationsReq,
api.EncodeResponse,
opts...,
), "list_user_invitations").ServeHTTP)
r.Post("/accept", otelhttp.NewHandler(kithttp.NewServer(
acceptInvitationEndpoint(svc),
decodeAcceptInvitationReq,
api.EncodeResponse,
opts...,
), "accept_invitation").ServeHTTP)
r.Post("/reject", otelhttp.NewHandler(kithttp.NewServer(
rejectInvitationEndpoint(svc),
decodeAcceptInvitationReq,
api.EncodeResponse,
opts...,
), "reject_invitation").ServeHTTP)
})

mux.Get("/health", supermq.Health("domains", instanceID))
Expand Down
7 changes: 3 additions & 4 deletions pkg/sdk/invitations.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,7 @@ func (sdk mgSDK) Invitation(userID, domainID, token string) (invitation Invitati
}

func (sdk mgSDK) Invitations(pm PageMetadata, token string) (invitations InvitationPage, err error) {
path := sdk.domainsURL + "/" + domainsEndpoint
url, err := sdk.withQueryParams(path, invitationsEndpoint, pm)
url, err := sdk.withQueryParams(sdk.domainsURL, invitationsEndpoint, pm)
if err != nil {
return InvitationPage{}, errors.NewSDKError(err)
}
Expand Down Expand Up @@ -96,7 +95,7 @@ func (sdk mgSDK) AcceptInvitation(domainID, token string) (err error) {
return errors.NewSDKError(err)
}

url := sdk.domainsURL + "/" + domainsEndpoint + "/" + invitationsEndpoint + "/" + acceptEndpoint
url := sdk.domainsURL + "/" + invitationsEndpoint + "/" + acceptEndpoint

_, _, sdkerr := sdk.processRequest(http.MethodPost, url, token, data, nil, http.StatusNoContent)

Expand All @@ -114,7 +113,7 @@ func (sdk mgSDK) RejectInvitation(domainID, token string) (err error) {
return errors.NewSDKError(err)
}

url := sdk.domainsURL + "/" + domainsEndpoint + "/" + invitationsEndpoint + "/" + rejectEndpoint
url := sdk.domainsURL + "/" + invitationsEndpoint + "/" + rejectEndpoint

_, _, sdkerr := sdk.processRequest(http.MethodPost, url, token, data, nil, http.StatusNoContent)

Expand Down

0 comments on commit 77fc6b3

Please sign in to comment.