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

Implement Tenant History Command #470

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
32 changes: 32 additions & 0 deletions cmd/metal-api/internal/service/tenant-service.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
v1 "github.com/metal-stack/masterdata-api/api/rest/v1"
mdmv1 "github.com/metal-stack/masterdata-api/api/v1"
mdm "github.com/metal-stack/masterdata-api/pkg/client"
internalV1 "github.com/metal-stack/metal-api/cmd/metal-api/internal/service/v1"
Pilzington marked this conversation as resolved.
Show resolved Hide resolved
"go.uber.org/zap"
"google.golang.org/protobuf/types/known/wrapperspb"

Expand Down Expand Up @@ -72,6 +73,17 @@ func (r *tenantResource) webService() *restful.WebService {
Returns(http.StatusOK, "OK", []v1.TenantResponse{}).
DefaultReturns("Error", httperrors.HTTPErrorResponse{}))

ws.Route(ws.POST("/{id}/history").
To(viewer(r.getTenantHistory)).
Operation("getTenantHistory").
Doc("get tenant with this id at the given timestamp").
Param(ws.PathParameter("id", "identifier of the tenant").DataType("string")).
Metadata(restfulspec.KeyOpenAPITags, tags).
Pilzington marked this conversation as resolved.
Show resolved Hide resolved
Reads(internalV1.TenantGetHistoryRequest{}).
Pilzington marked this conversation as resolved.
Show resolved Hide resolved
Writes(v1.TenantResponse{}).
Returns(http.StatusOK, "OK", v1.TenantResponse{}).
DefaultReturns("Error", httperrors.HTTPErrorResponse{}))

ws.Route(ws.DELETE("/{id}").
To(admin(r.deleteTenant)).
Operation("deleteTenant").
Expand Down Expand Up @@ -186,6 +198,26 @@ func (r *tenantResource) createTenant(request *restful.Request, response *restfu
r.send(request, response, http.StatusCreated, pcres)
}

func (r *tenantResource) getTenantHistory(request *restful.Request, response *restful.Response) {
id := request.PathParameter("id")

var tghr internalV1.TenantGetHistoryRequest
err := request.ReadEntity(&tghr)
if err != nil {
r.sendError(request, response, httperrors.BadRequest(err))
return
}

thres, err := r.mdc.Tenant().GetHistory(request.Request.Context(), &mdmv1.TenantGetHistoryRequest{Id: id, At: tghr.At})
if err != nil {
r.sendError(request, response, defaultError(err))
return
}
v1t := mapper.ToV1Tenant(thres.Tenant)

r.send(request, response, http.StatusOK, &v1t)
}

func (r *tenantResource) deleteTenant(request *restful.Request, response *restful.Response) {
id := request.PathParameter("id")

Expand Down
9 changes: 9 additions & 0 deletions cmd/metal-api/internal/service/v1/tenant.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package v1

import "google.golang.org/protobuf/types/known/timestamppb"

type (
TenantGetHistoryRequest struct {
At *timestamppb.Timestamp
Pilzington marked this conversation as resolved.
Show resolved Hide resolved
}
)