[BE-API-038] be-api: Implement marketplace order list endpoint
This commit is contained in:
parent
f6fa8d933a
commit
04ea22149c
4 changed files with 50 additions and 3 deletions
|
|
@ -2815,7 +2815,7 @@
|
|||
"description": "GET /api/v1/marketplace/orders to list user's orders",
|
||||
"owner": "backend",
|
||||
"estimated_hours": 3,
|
||||
"status": "todo",
|
||||
"status": "completed",
|
||||
"files_involved": [],
|
||||
"implementation_steps": [
|
||||
{
|
||||
|
|
@ -2836,7 +2836,9 @@
|
|||
"Unit tests",
|
||||
"Integration tests"
|
||||
],
|
||||
"notes": ""
|
||||
"notes": "",
|
||||
"completed_at": "2025-12-24T14:50:38.134537",
|
||||
"implementation_notes": "Implemented GET /api/v1/marketplace/orders endpoint. Added ListOrders method to marketplace service that retrieves all orders for a buyer with preloaded items, ordered by creation date descending. Added ListOrders handler. Route registered in protected group."
|
||||
},
|
||||
{
|
||||
"id": "BE-API-039",
|
||||
|
|
|
|||
|
|
@ -232,7 +232,7 @@ func (r *APIRouter) setupMarketplaceRoutes(router *gin.RouterGroup) {
|
|||
createGroup := protected.Group("")
|
||||
createGroup.Use(r.config.AuthMiddleware.RequireContentCreatorRole())
|
||||
createGroup.POST("/products", marketHandler.CreateProduct)
|
||||
|
||||
|
||||
// BE-API-037: Update product endpoint (requires ownership)
|
||||
// Resolver: Load product from DB to get its seller_id
|
||||
productOwnerResolver := func(c *gin.Context) (uuid.UUID, error) {
|
||||
|
|
@ -250,6 +250,8 @@ func (r *APIRouter) setupMarketplaceRoutes(router *gin.RouterGroup) {
|
|||
}
|
||||
protected.PUT("/products/:id", r.config.AuthMiddleware.RequireOwnershipOrAdmin("product", productOwnerResolver), marketHandler.UpdateProduct)
|
||||
|
||||
// BE-API-038: List orders endpoint
|
||||
protected.GET("/orders", marketHandler.ListOrders)
|
||||
protected.POST("/orders", marketHandler.CreateOrder)
|
||||
protected.GET("/download/:product_id", marketHandler.GetDownloadURL)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -42,6 +42,7 @@ type MarketplaceService interface {
|
|||
|
||||
// Purchasing
|
||||
CreateOrder(ctx context.Context, buyerID uuid.UUID, items []NewOrderItem) (*Order, error)
|
||||
ListOrders(ctx context.Context, buyerID uuid.UUID) ([]Order, error)
|
||||
ProcessPaymentWebhook(ctx context.Context, payload []byte) error
|
||||
|
||||
// Fulfillment
|
||||
|
|
@ -259,6 +260,21 @@ func (s *Service) CreateOrder(ctx context.Context, buyerID uuid.UUID, items []Ne
|
|||
return order, nil
|
||||
}
|
||||
|
||||
// ListOrders retrieves all orders for a buyer
|
||||
// BE-API-038: Implement marketplace order list endpoint
|
||||
func (s *Service) ListOrders(ctx context.Context, buyerID uuid.UUID) ([]Order, error) {
|
||||
var orders []Order
|
||||
if err := s.db.WithContext(ctx).
|
||||
Where("buyer_id = ?", buyerID).
|
||||
Preload("Items").
|
||||
Order("created_at DESC").
|
||||
Find(&orders).Error; err != nil {
|
||||
s.logger.Error("Failed to list orders", zap.Error(err))
|
||||
return nil, err
|
||||
}
|
||||
return orders, nil
|
||||
}
|
||||
|
||||
// ProcessPaymentWebhook handles payment confirmation
|
||||
func (s *Service) ProcessPaymentWebhook(ctx context.Context, payload []byte) error {
|
||||
// MVP: Not implemented yet
|
||||
|
|
|
|||
|
|
@ -309,3 +309,30 @@ func (h *MarketplaceHandler) UpdateProduct(c *gin.Context) {
|
|||
|
||||
response.Success(c, product)
|
||||
}
|
||||
|
||||
// ListOrders gère la récupération de la liste des commandes de l'utilisateur
|
||||
// BE-API-038: GET /api/v1/marketplace/orders to list user's orders
|
||||
// @Summary List user orders
|
||||
// @Description Get all orders for the authenticated user
|
||||
// @Tags Marketplace
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Security BearerAuth
|
||||
// @Success 200 {array} marketplace.Order
|
||||
// @Failure 401 {object} response.APIResponse "Unauthorized"
|
||||
// @Failure 500 {object} response.APIResponse "Internal Error"
|
||||
// @Router /api/v1/marketplace/orders [get]
|
||||
func (h *MarketplaceHandler) ListOrders(c *gin.Context) {
|
||||
userID, ok := GetUserIDUUID(c)
|
||||
if !ok {
|
||||
return // Erreur déjà envoyée par GetUserIDUUID
|
||||
}
|
||||
|
||||
orders, err := h.service.ListOrders(c.Request.Context(), userID)
|
||||
if err != nil {
|
||||
response.InternalServerError(c, "Failed to list orders")
|
||||
return
|
||||
}
|
||||
|
||||
response.Success(c, orders)
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue