From e0ea03f6cff6c1b7a41b29df61295b19de2b95f6 Mon Sep 17 00:00:00 2001 From: matst80 Date: Tue, 14 Oct 2025 22:18:49 +0200 Subject: [PATCH] remove voucher --- cmd/cart/pool-server.go | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/cmd/cart/pool-server.go b/cmd/cart/pool-server.go index db00529..f4f4e69 100644 --- a/cmd/cart/pool-server.go +++ b/cmd/cart/pool-server.go @@ -469,6 +469,25 @@ func (s *PoolServer) AddVoucherHandler(w http.ResponseWriter, r *http.Request, c return nil } +func (s *PoolServer) RemoveVoucherHandler(w http.ResponseWriter, r *http.Request, cartId CartId) error { + + idStr := r.PathValue("voucherId") + id, err := strconv.ParseInt(idStr, 10, 64) + if err != nil { + w.WriteHeader(http.StatusInternalServerError) + w.Write([]byte(err.Error())) + return err + } + reply, err := s.ApplyLocal(cartId, &messages.RemoveVoucher{Id: uint32(id)}) + if err != nil { + w.WriteHeader(http.StatusInternalServerError) + w.Write([]byte(err.Error())) + return err + } + s.WriteResult(w, reply) + return nil +} + func (s *PoolServer) Serve() *http.ServeMux { mux := http.NewServeMux() @@ -491,6 +510,7 @@ func (s *PoolServer) Serve() *http.ServeMux { mux.HandleFunc("DELETE /delivery/{deliveryId}", CookieCartIdHandler(s.ProxyHandler(s.RemoveDeliveryHandler))) mux.HandleFunc("PUT /delivery/{deliveryId}/pickupPoint", CookieCartIdHandler(s.ProxyHandler(s.SetPickupPointHandler))) mux.HandleFunc("PUT /voucher", CookieCartIdHandler(s.ProxyHandler(s.AddVoucherHandler))) + mux.HandleFunc("DELETE /voucher/{voucherId}", CookieCartIdHandler(s.ProxyHandler(s.RemoveVoucherHandler))) //mux.HandleFunc("GET /checkout", CookieCartIdHandler(s.ProxyHandler(s.HandleCheckout))) //mux.HandleFunc("GET /confirmation/{orderId}", CookieCartIdHandler(s.ProxyHandler(s.HandleConfirmation))) @@ -503,6 +523,8 @@ func (s *PoolServer) Serve() *http.ServeMux { mux.HandleFunc("POST /byid/{id}/delivery", CartIdHandler(s.ProxyHandler(s.SetDeliveryHandler))) mux.HandleFunc("DELETE /byid/{id}/delivery/{deliveryId}", CartIdHandler(s.ProxyHandler(s.RemoveDeliveryHandler))) mux.HandleFunc("PUT /byid/{id}/delivery/{deliveryId}/pickupPoint", CartIdHandler(s.ProxyHandler(s.SetPickupPointHandler))) + mux.HandleFunc("PUT /byid/{id}/voucher", CookieCartIdHandler(s.ProxyHandler(s.AddVoucherHandler))) + mux.HandleFunc("DELETE /byid/{id}/voucher/{voucherId}", CookieCartIdHandler(s.ProxyHandler(s.RemoveVoucherHandler))) //mux.HandleFunc("GET /byid/{id}/checkout", CartIdHandler(s.ProxyHandler(s.HandleCheckout))) //mux.HandleFunc("GET /byid/{id}/confirmation", CartIdHandler(s.ProxyHandler(s.HandleConfirmation)))