fix(backend): 入库/出库列表 status 支持多状态 IN 查询 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
@@ -40,7 +41,7 @@ func (h *StockInHandler) List(c *gin.Context) {
|
||||
Where("shop_id = ? AND deleted_at IS NULL", shopID)
|
||||
|
||||
if status := c.Query("status"); status != "" {
|
||||
query = query.Where("status = ?", status)
|
||||
query = query.Where("status IN ?", strings.Split(status, ","))
|
||||
}
|
||||
if startDate := c.Query("start_date"); startDate != "" {
|
||||
query = query.Where("order_date >= ?", startDate)
|
||||
|
||||
@@ -343,4 +343,9 @@ func TestStockInHandler_List_FilterByStatus(t *testing.T) {
|
||||
w = makeRequest(r, "GET", "/api/v1/stock-in/orders?status=draft", token, nil)
|
||||
resp = parseResponse(w)
|
||||
assert.Equal(t, float64(1), resp["total"].(float64))
|
||||
|
||||
// 逗号分隔的多状态:pending + draft 应返回两条(审核标签页用法)
|
||||
w = makeRequest(r, "GET", "/api/v1/stock-in/orders?status=pending,draft", token, nil)
|
||||
resp = parseResponse(w)
|
||||
assert.Equal(t, float64(2), resp["total"].(float64))
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package handler
|
||||
import (
|
||||
"net/http"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"gorm.io/gorm"
|
||||
@@ -33,7 +34,7 @@ func (h *StockOutHandler) List(c *gin.Context) {
|
||||
Where("shop_id = ? AND deleted_at IS NULL", shopID)
|
||||
|
||||
if status := c.Query("status"); status != "" {
|
||||
query = query.Where("status = ?", status)
|
||||
query = query.Where("status IN ?", strings.Split(status, ","))
|
||||
}
|
||||
if startDate := c.Query("start_date"); startDate != "" {
|
||||
query = query.Where("order_date >= ?", startDate)
|
||||
|
||||
Reference in New Issue
Block a user