Skip to content

Commit

Permalink
first draft to to get tenant history
Browse files Browse the repository at this point in the history
  • Loading branch information
Pilzington committed Sep 28, 2023
1 parent 6f952f6 commit ff89e16
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
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"
"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).
Reads(internalV1.TenantGetHistoryRequest{}).
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
}
)

0 comments on commit ff89e16

Please sign in to comment.