storagenode/heldamount GetPayment added, console/server updated
Change-Id: I51ebe69f9dc7920e59e91d7ba26617ee61889f78
This commit is contained in:
parent
7b0371e9e2
commit
988bb52855
@ -71,6 +71,29 @@ func (heldamount *HeldAmount) GetMonthlyHeldAmount(w http.ResponseWriter, r *htt
|
||||
heldamount.writeData(w, paystubData)
|
||||
}
|
||||
|
||||
// GetMonthlyPayment returns payment data from satellite for specific month.
|
||||
func (heldamount *HeldAmount) GetMonthlyPayment(w http.ResponseWriter, r *http.Request) {
|
||||
ctx := r.Context()
|
||||
defer mon.Task()(&ctx)(nil)
|
||||
|
||||
period := r.URL.Query().Get("period")
|
||||
id := r.URL.Query().Get("satelliteID")
|
||||
|
||||
satelliteID, err := storj.NodeIDFromString(id)
|
||||
if err != nil {
|
||||
heldamount.writeError(w, http.StatusBadRequest, Error.Wrap(err))
|
||||
return
|
||||
}
|
||||
|
||||
paymentData, err := heldamount.service.GetPayment(ctx, satelliteID, period)
|
||||
if err != nil {
|
||||
heldamount.writeError(w, http.StatusInternalServerError, Error.Wrap(err))
|
||||
return
|
||||
}
|
||||
|
||||
heldamount.writeData(w, paymentData)
|
||||
}
|
||||
|
||||
// writeData is helper method to write JSON to http.ResponseWriter and log encoding error.
|
||||
func (heldamount *HeldAmount) writeData(w http.ResponseWriter, data interface{}) {
|
||||
w.Header().Set(contentType, applicationJSON)
|
||||
|
@ -90,7 +90,8 @@ func NewServer(logger *zap.Logger, assets http.FileSystem, notifications *notifi
|
||||
notificationRouter.Handle("/list", http.HandlerFunc(notificationController.ListNotifications)).Methods(http.MethodGet)
|
||||
notificationRouter.Handle("/{id}/read", http.HandlerFunc(notificationController.ReadNotification)).Methods(http.MethodPost)
|
||||
notificationRouter.Handle("/readall", http.HandlerFunc(notificationController.ReadAllNotifications)).Methods(http.MethodPost)
|
||||
heldamountRouter.Handle("/{period}", http.HandlerFunc(heldamountController.GetMonthlyHeldAmount)).Methods(http.MethodGet)
|
||||
heldamountRouter.Handle("/paystub/{period}/{satelliteID}", http.HandlerFunc(heldamountController.GetMonthlyHeldAmount)).Methods(http.MethodGet)
|
||||
heldamountRouter.Handle("/payment/{period}/{satelliteID}", http.HandlerFunc(heldamountController.GetMonthlyPayment)).Methods(http.MethodGet)
|
||||
|
||||
server.server = http.Server{
|
||||
Handler: router,
|
||||
|
@ -101,6 +101,37 @@ func (service *Service) GetPaystubStats(ctx context.Context, satelliteID storj.N
|
||||
}, nil
|
||||
}
|
||||
|
||||
// GetPayment retrieves payment data from particular satellite
|
||||
func (service *Service) GetPayment(ctx context.Context, satelliteID storj.NodeID, period string) (_ *Payment, err error) {
|
||||
defer mon.Task()(&ctx)(&err)
|
||||
|
||||
client, err := service.dial(ctx, satelliteID)
|
||||
if err != nil {
|
||||
return nil, HeldAmountServiceErr.Wrap(err)
|
||||
}
|
||||
defer func() { err = errs.Combine(err, client.Close()) }()
|
||||
|
||||
requestedPeriod, err := stringToTime(period)
|
||||
if err != nil {
|
||||
return nil, HeldAmountServiceErr.Wrap(err)
|
||||
}
|
||||
|
||||
resp, err := client.GetPayment(ctx, &pb.GetPaymentRequest{Period: requestedPeriod})
|
||||
if err != nil {
|
||||
return nil, HeldAmountServiceErr.Wrap(err)
|
||||
}
|
||||
|
||||
return &Payment{
|
||||
ID: resp.Id,
|
||||
Created: resp.CreatedAt,
|
||||
SatelliteID: satelliteID,
|
||||
Period: period,
|
||||
Amount: resp.Amount,
|
||||
Receipt: resp.Receipt,
|
||||
Notes: resp.Notes,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// dial dials the HeldAmount client for the satellite by id
|
||||
func (service *Service) dial(ctx context.Context, satelliteID storj.NodeID) (_ *Client, err error) {
|
||||
defer mon.Task()(&ctx)(&err)
|
||||
|
Loading…
Reference in New Issue
Block a user