98 lines
2.2 KiB
Go
98 lines
2.2 KiB
Go
package reporter
|
|
|
|
import (
|
|
"fmt"
|
|
"net/http"
|
|
"strconv"
|
|
"time"
|
|
|
|
"code.gitea.io/gitea/models"
|
|
"code.gitea.io/gitea/modules/context"
|
|
)
|
|
|
|
func GetActivity(ctx *context.APIContext) {
|
|
// swagger:operation GET /activity activity activity
|
|
// ---
|
|
// summary: Statistics of commit and pull request data,Platform required data **
|
|
// produces:
|
|
// - application/json
|
|
// parameters:
|
|
// - name: from
|
|
// in: query
|
|
// description: Query begin timestamp
|
|
// type: string
|
|
// required: false
|
|
// - name: to
|
|
// in: query
|
|
// description: Query end timestamp
|
|
// type: string
|
|
// required: false
|
|
// responses:
|
|
// "200":
|
|
// "$ref": "#/responses/PlatformDTO"
|
|
// "404":
|
|
// "$ref": "#/responses/notFound"
|
|
|
|
opt := GetParamOption(ctx)
|
|
|
|
if opt == nil {
|
|
return
|
|
}
|
|
list, err := models.GetActivity(opt)
|
|
fmt.Println("-==========list====\n", list)
|
|
if err != nil {
|
|
ctx.ServerError("GetActivity", err)
|
|
return
|
|
}
|
|
ctx.JSON(http.StatusOK, list)
|
|
}
|
|
|
|
func GetParamOption(ctx *context.APIContext) (opt *models.GetGetActivityOptions) {
|
|
Layout := "2006-01-02 15:04:05"
|
|
//##top
|
|
top := ctx.QueryInt64("top")
|
|
if top <= 0 {
|
|
top = 5
|
|
} else if top >= 20 {
|
|
top = 20
|
|
}
|
|
|
|
//##from
|
|
FromDate, err := strconv.ParseInt(ctx.QueryTrim("from"), 10, 64)
|
|
if err != nil {
|
|
ctx.Error(http.StatusBadRequest, "param.from", err)
|
|
return
|
|
}
|
|
if FromDate <= 0 {
|
|
ctx.Error(http.StatusBadRequest, "param.from", fmt.Errorf("请指定from参数"))
|
|
return
|
|
//from=time.Now().Format("2006-01-02")
|
|
}
|
|
|
|
from := time.Unix(FromDate, 0).Format(Layout)
|
|
//fmt.Println("********from:",from," ", FromDate," convert:",time.Unix( FromDate,0).Format("2006-01-02 15:04:05"))
|
|
|
|
//##to
|
|
ToDate, err := strconv.ParseInt(ctx.QueryTrim("to"), 10, 64)
|
|
if err != nil {
|
|
ctx.Error(http.StatusBadRequest, "param.to ", err)
|
|
return
|
|
}
|
|
if ToDate <= 0 {
|
|
ctx.Error(http.StatusBadRequest, "param.to", fmt.Errorf("请指定to参数"))
|
|
return
|
|
}
|
|
|
|
to := time.Unix(ToDate, 0).Format(Layout)
|
|
|
|
//fmt.Println("********to:",to ," ", ToDate," convert:",time.Unix( ToDate,0).Format(Layout))
|
|
opt = &models.GetGetActivityOptions{
|
|
FromDateUnix: FromDate,
|
|
ToDateUnix: ToDate,
|
|
FromDate: from,
|
|
ToDate: to,
|
|
Top: top,
|
|
}
|
|
return opt
|
|
}
|