fix/status-review-sync-20260409 #1

Merged
long merged 65 commits from fix/status-review-sync-20260409 into main 2026-04-18 15:05:51 +00:00
4 changed files with 66 additions and 48 deletions
Showing only changes of commit e00af0bce4 - Show all commits

View File

@@ -27,7 +27,7 @@ func NewLogHandler(loginLogService *service.LoginLogService, operationLogService
func (h *LogHandler) GetMyLoginLogs(c *gin.Context) {
userID, ok := getUserIDFromContext(c)
if !ok {
c.JSON(http.StatusUnauthorized, gin.H{"error": "unauthorized"})
c.JSON(http.StatusUnauthorized, gin.H{"code": 401, "message": "unauthorized"})
return
}
@@ -41,17 +41,21 @@ func (h *LogHandler) GetMyLoginLogs(c *gin.Context) {
}
c.JSON(http.StatusOK, gin.H{
"list": logs,
"total": total,
"page": page,
"page_size": pageSize,
"code": 0,
"message": "success",
"data": gin.H{
"list": logs,
"total": total,
"page": page,
"page_size": pageSize,
},
})
}
func (h *LogHandler) GetMyOperationLogs(c *gin.Context) {
userID, ok := getUserIDFromContext(c)
if !ok {
c.JSON(http.StatusUnauthorized, gin.H{"error": "unauthorized"})
c.JSON(http.StatusUnauthorized, gin.H{"code": 401, "message": "unauthorized"})
return
}
@@ -65,17 +69,21 @@ func (h *LogHandler) GetMyOperationLogs(c *gin.Context) {
}
c.JSON(http.StatusOK, gin.H{
"list": logs,
"total": total,
"page": page,
"page_size": pageSize,
"code": 0,
"message": "success",
"data": gin.H{
"list": logs,
"total": total,
"page": page,
"page_size": pageSize,
},
})
}
func (h *LogHandler) GetLoginLogs(c *gin.Context) {
var req service.ListLoginLogRequest
if err := c.ShouldBindQuery(&req); err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
c.JSON(http.StatusBadRequest, gin.H{"code": 400, "message": err.Error()})
return
}
@@ -102,17 +110,21 @@ func (h *LogHandler) GetLoginLogs(c *gin.Context) {
}
c.JSON(http.StatusOK, gin.H{
"list": logs,
"total": total,
"page": req.Page,
"page_size": req.PageSize,
"code": 0,
"message": "success",
"data": gin.H{
"list": logs,
"total": total,
"page": req.Page,
"page_size": req.PageSize,
},
})
}
func (h *LogHandler) GetOperationLogs(c *gin.Context) {
var req service.ListOperationLogRequest
if err := c.ShouldBindQuery(&req); err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
c.JSON(http.StatusBadRequest, gin.H{"code": 400, "message": err.Error()})
return
}
@@ -139,17 +151,21 @@ func (h *LogHandler) GetOperationLogs(c *gin.Context) {
}
c.JSON(http.StatusOK, gin.H{
"list": logs,
"total": total,
"page": req.Page,
"page_size": req.PageSize,
"code": 0,
"message": "success",
"data": gin.H{
"list": logs,
"total": total,
"page": req.Page,
"page_size": req.PageSize,
},
})
}
func (h *LogHandler) ExportLoginLogs(c *gin.Context) {
var req service.ExportLoginLogRequest
if err := c.ShouldBindQuery(&req); err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
c.JSON(http.StatusBadRequest, gin.H{"code": 400, "message": err.Error()})
return
}

View File

@@ -23,7 +23,7 @@ func NewPermissionHandler(permissionService *service.PermissionService) *Permiss
func (h *PermissionHandler) CreatePermission(c *gin.Context) {
var req service.CreatePermissionRequest
if err := c.ShouldBindJSON(&req); err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
c.JSON(http.StatusBadRequest, gin.H{"code": 400, "message": err.Error()})
return
}
@@ -43,7 +43,7 @@ func (h *PermissionHandler) CreatePermission(c *gin.Context) {
func (h *PermissionHandler) ListPermissions(c *gin.Context) {
var req service.ListPermissionRequest
if err := c.ShouldBindQuery(&req); err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
c.JSON(http.StatusBadRequest, gin.H{"code": 400, "message": err.Error()})
return
}
@@ -63,7 +63,7 @@ func (h *PermissionHandler) ListPermissions(c *gin.Context) {
func (h *PermissionHandler) GetPermission(c *gin.Context) {
id, err := strconv.ParseInt(c.Param("id"), 10, 64)
if err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": "invalid permission id"})
c.JSON(http.StatusBadRequest, gin.H{"code": 400, "message": "invalid permission id"})
return
}
@@ -83,13 +83,13 @@ func (h *PermissionHandler) GetPermission(c *gin.Context) {
func (h *PermissionHandler) UpdatePermission(c *gin.Context) {
id, err := strconv.ParseInt(c.Param("id"), 10, 64)
if err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": "invalid permission id"})
c.JSON(http.StatusBadRequest, gin.H{"code": 400, "message": "invalid permission id"})
return
}
var req service.UpdatePermissionRequest
if err := c.ShouldBindJSON(&req); err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
c.JSON(http.StatusBadRequest, gin.H{"code": 400, "message": err.Error()})
return
}
@@ -109,7 +109,7 @@ func (h *PermissionHandler) UpdatePermission(c *gin.Context) {
func (h *PermissionHandler) DeletePermission(c *gin.Context) {
id, err := strconv.ParseInt(c.Param("id"), 10, 64)
if err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": "invalid permission id"})
c.JSON(http.StatusBadRequest, gin.H{"code": 400, "message": "invalid permission id"})
return
}
@@ -127,7 +127,7 @@ func (h *PermissionHandler) DeletePermission(c *gin.Context) {
func (h *PermissionHandler) UpdatePermissionStatus(c *gin.Context) {
id, err := strconv.ParseInt(c.Param("id"), 10, 64)
if err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": "invalid permission id"})
c.JSON(http.StatusBadRequest, gin.H{"code": 400, "message": "invalid permission id"})
return
}
@@ -136,7 +136,7 @@ func (h *PermissionHandler) UpdatePermissionStatus(c *gin.Context) {
}
if err := c.ShouldBindJSON(&req); err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
c.JSON(http.StatusBadRequest, gin.H{"code": 400, "message": err.Error()})
return
}
@@ -147,7 +147,7 @@ func (h *PermissionHandler) UpdatePermissionStatus(c *gin.Context) {
case "disabled", "0":
status = domain.PermissionStatusDisabled
default:
c.JSON(http.StatusBadRequest, gin.H{"error": "invalid status"})
c.JSON(http.StatusBadRequest, gin.H{"code": 400, "message": "invalid status"})
return
}

View File

@@ -35,7 +35,7 @@ func (h *WebhookHandler) CreateWebhook(c *gin.Context) {
return
}
c.JSON(http.StatusCreated, gin.H{"code": 0, "data": webhook})
c.JSON(http.StatusCreated, gin.H{"code": 0, "message": "success", "data": webhook})
}
func (h *WebhookHandler) ListWebhooks(c *gin.Context) {
@@ -59,11 +59,14 @@ func (h *WebhookHandler) ListWebhooks(c *gin.Context) {
}
c.JSON(http.StatusOK, gin.H{
"code": 0,
"data": webhooks,
"total": total,
"page": page,
"page_size": pageSize,
"code": 0,
"message": "success",
"data": gin.H{
"list": webhooks,
"total": total,
"page": page,
"page_size": pageSize,
},
})
}
@@ -121,5 +124,5 @@ func (h *WebhookHandler) GetWebhookDeliveries(c *gin.Context) {
return
}
c.JSON(http.StatusOK, gin.H{"code": 0, "data": deliveries})
c.JSON(http.StatusOK, gin.H{"code": 0, "message": "success", "data": gin.H{"deliveries": deliveries}})
}

View File

@@ -255,10 +255,8 @@ func TestWebhookHandler_ListWebhooks_Success(t *testing.T) {
if result["code"].(float64) != 0 {
t.Fatalf("expected code 0, got %v", result["code"])
}
if result["data"] == nil {
t.Fatal("expected data in response")
}
if result["total"] == nil {
data := result["data"].(map[string]interface{})
if data["total"] == nil {
t.Fatal("expected total in response")
}
}
@@ -436,15 +434,16 @@ func TestWebhookHandler_ListWebhooks_Pagination(t *testing.T) {
var result map[string]interface{}
json.NewDecoder(resp.Body).Decode(&result)
data := result["data"].([]interface{})
if len(data) != 2 {
t.Fatalf("expected 2 webhooks per page, got %d", len(data))
data := result["data"].(map[string]interface{})
list := data["list"].([]interface{})
if len(list) != 2 {
t.Fatalf("expected 2 webhooks per page, got %d", len(list))
}
if result["page"].(float64) != 1 {
t.Fatalf("expected page 1, got %v", result["page"])
if data["page"].(float64) != 1 {
t.Fatalf("expected page 1, got %v", data["page"])
}
if result["page_size"].(float64) != 2 {
t.Fatalf("expected page_size 2, got %v", result["page_size"])
if data["page_size"].(float64) != 2 {
t.Fatalf("expected page_size 2, got %v", data["page_size"])
}
}