|
| 1 | +/* |
| 2 | +Copyright 2024 The KodeRover Authors. |
| 3 | +
|
| 4 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +you may not use this file except in compliance with the License. |
| 6 | +You may obtain a copy of the License at |
| 7 | +
|
| 8 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +
|
| 10 | +Unless required by applicable law or agreed to in writing, software |
| 11 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +See the License for the specific language governing permissions and |
| 14 | +limitations under the License. |
| 15 | +*/ |
| 16 | + |
| 17 | +package handler |
| 18 | + |
| 19 | +import ( |
| 20 | + "github.com/gin-gonic/gin" |
| 21 | + e "github.com/koderover/zadig/v2/pkg/tool/errors" |
| 22 | + |
| 23 | + "github.com/koderover/zadig/v2/pkg/microservice/aslan/core/stat/service" |
| 24 | + internalhandler "github.com/koderover/zadig/v2/pkg/shared/handler" |
| 25 | +) |
| 26 | + |
| 27 | +// func CreateWeeklyDeployStat(c *gin.Context) { |
| 28 | +// ctx := internalhandler.NewContext(c) |
| 29 | +// defer func() { internalhandler.JSONResponse(c, ctx) }() |
| 30 | + |
| 31 | +// ctx.RespErr = service.CreateWeeklyDeployStat(ctx.Logger) |
| 32 | +// } |
| 33 | + |
| 34 | +// func CreateMonthlyDeployStat(c *gin.Context) { |
| 35 | +// ctx := internalhandler.NewContext(c) |
| 36 | +// defer func() { internalhandler.JSONResponse(c, ctx) }() |
| 37 | + |
| 38 | +// ctx.RespErr = service.CreateMonthlyDeployStat(ctx.Logger) |
| 39 | +// } |
| 40 | + |
| 41 | +// @Summary 获取回滚统计总数 |
| 42 | +// @Description |
| 43 | +// @Tags stat |
| 44 | +// @Accept json |
| 45 | +// @Produce json |
| 46 | +// @Param startDate query int true "开始时间,格式为时间戳" |
| 47 | +// @Param endDate query int true "结束时间,格式为时间戳" |
| 48 | +// @Param projects query []string true "项目列表" |
| 49 | +// @Success 200 {object} service.RollbackTotalStat |
| 50 | +// @Router /api/aslan/stat/v2/quality/rollback/total [get] |
| 51 | +func GetRollbackTotalStat(c *gin.Context) { |
| 52 | + ctx := internalhandler.NewContext(c) |
| 53 | + defer func() { internalhandler.JSONResponse(c, ctx) }() |
| 54 | + |
| 55 | + args := new(getStatGeneralReq) |
| 56 | + if err := c.ShouldBindQuery(args); err != nil { |
| 57 | + ctx.RespErr = e.ErrInvalidParam.AddErr(err) |
| 58 | + return |
| 59 | + } |
| 60 | + |
| 61 | + ctx.Resp, ctx.RespErr = service.GetRollbackTotalStat(args.StartTime, args.EndTime, args.Projects, ctx.Logger) |
| 62 | +} |
| 63 | + |
| 64 | +// @Summary 获取回滚次数TopN的服务 |
| 65 | +// @Description |
| 66 | +// @Tags stat |
| 67 | +// @Accept json |
| 68 | +// @Produce json |
| 69 | +// @Param startDate query int true "开始时间,格式为时间戳" |
| 70 | +// @Param endDate query int true "结束时间,格式为时间戳" |
| 71 | +// @Param top query int true "TopN" |
| 72 | +// @Param production query string true "环境类型,可选值为 production、testing、both" |
| 73 | +// @Success 200 {array} mongodb.RollbackServiceCount |
| 74 | +// @Router /api/aslan/stat/v2/quality/rollback/service/top [get] |
| 75 | +func GetTopRollbackedService(c *gin.Context) { |
| 76 | + ctx := internalhandler.NewContext(c) |
| 77 | + defer func() { internalhandler.JSONResponse(c, ctx) }() |
| 78 | + |
| 79 | + args := new(getStateReqWithTop) |
| 80 | + if err := c.ShouldBindQuery(args); err != nil { |
| 81 | + ctx.RespErr = e.ErrInvalidParam.AddErr(err) |
| 82 | + return |
| 83 | + } |
| 84 | + |
| 85 | + ctx.Resp, ctx.RespErr = service.GetTopRollbackedProject(args.StartTime, args.EndTime, args.Top, args.ProductionType, args.Projects, ctx.Logger) |
| 86 | +} |
| 87 | + |
| 88 | +func GetRollbackWeeklyTrend(c *gin.Context) { |
| 89 | + ctx := internalhandler.NewContext(c) |
| 90 | + defer func() { internalhandler.JSONResponse(c, ctx) }() |
| 91 | + |
| 92 | + args := new(getStatGeneralReq) |
| 93 | + if err := c.ShouldBindQuery(args); err != nil { |
| 94 | + ctx.RespErr = e.ErrInvalidParam.AddErr(err) |
| 95 | + return |
| 96 | + } |
| 97 | + |
| 98 | + ctx.Resp, ctx.RespErr = service.GetDeployWeeklyTrend(args.StartTime, args.EndTime, args.Projects, args.ProductionType, ctx.Logger) |
| 99 | +} |
| 100 | + |
| 101 | +func GetRollbackMonthlyTrend(c *gin.Context) { |
| 102 | + ctx := internalhandler.NewContext(c) |
| 103 | + defer func() { internalhandler.JSONResponse(c, ctx) }() |
| 104 | + |
| 105 | + args := new(getStatGeneralReq) |
| 106 | + if err := c.ShouldBindQuery(args); err != nil { |
| 107 | + ctx.RespErr = e.ErrInvalidParam.AddErr(err) |
| 108 | + return |
| 109 | + } |
| 110 | + |
| 111 | + // ctx.Resp, ctx.RespErr = service.GetRollbackMonthlyTrend(args.StartTime, args.EndTime, args.Projects, args.ProductionType, ctx.Logger) |
| 112 | +} |
| 113 | + |
| 114 | +// @Summary 获取回滚数据详情 |
| 115 | +// @Description |
| 116 | +// @Tags stat |
| 117 | +// @Accept json |
| 118 | +// @Produce json |
| 119 | +// @Param startDate query int true "开始时间,格式为时间戳" |
| 120 | +// @Param endDate query int true "结束时间,格式为时间戳" |
| 121 | +// @Param projects query []string true "项目列表" |
| 122 | +// @Param production query string true "环境类型,可选值为 production、testing、both" |
| 123 | +// @Success 200 {object} service.GetRollbackStatResponse |
| 124 | +// @Router /api/aslan/stat/v2/quality/rollback/stat [get] |
| 125 | +func GetRollbackStat(c *gin.Context) { |
| 126 | + ctx := internalhandler.NewContext(c) |
| 127 | + defer func() { internalhandler.JSONResponse(c, ctx) }() |
| 128 | + |
| 129 | + args := new(getStatGeneralReq) |
| 130 | + if err := c.ShouldBindQuery(args); err != nil { |
| 131 | + ctx.RespErr = e.ErrInvalidParam.AddErr(err) |
| 132 | + return |
| 133 | + } |
| 134 | + |
| 135 | + ctx.Resp, ctx.RespErr = service.GetRollbackStat(args.StartTime, args.EndTime, args.ProductionType, args.Projects, ctx.Logger) |
| 136 | +} |
0 commit comments