|
|
|
@@ -0,0 +1,98 @@ |
|
|
|
package repo |
|
|
|
|
|
|
|
import ( |
|
|
|
"net/http" |
|
|
|
"time" |
|
|
|
|
|
|
|
"code.gitea.io/gitea/models" |
|
|
|
"code.gitea.io/gitea/modules/context" |
|
|
|
"code.gitea.io/gitea/modules/setting" |
|
|
|
) |
|
|
|
|
|
|
|
func QueryInvitationCurrentMonth(ctx *context.Context) { |
|
|
|
|
|
|
|
currentTimeNow := time.Now() |
|
|
|
pageEndTime := time.Date(currentTimeNow.Year(), currentTimeNow.Month(), currentTimeNow.Day(), 0, 0, 0, 0, currentTimeNow.Location()) |
|
|
|
pageStartTime := time.Date(currentTimeNow.Year(), currentTimeNow.Month(), 1, 0, 0, 0, 0, currentTimeNow.Location()) |
|
|
|
|
|
|
|
queryData(ctx, pageStartTime.Unix(), pageEndTime.Unix()) |
|
|
|
} |
|
|
|
|
|
|
|
func QueryInvitationCurrentWeek(ctx *context.Context) { |
|
|
|
currentTimeNow := time.Now() |
|
|
|
offset := int(time.Monday - currentTimeNow.Weekday()) |
|
|
|
if offset > 0 { |
|
|
|
offset = -6 |
|
|
|
} |
|
|
|
pageStartTime := time.Date(currentTimeNow.Year(), currentTimeNow.Month(), currentTimeNow.Day(), 0, 0, 0, 0, time.Local).AddDate(0, 0, offset) |
|
|
|
pageEndTime := time.Date(currentTimeNow.Year(), currentTimeNow.Month(), currentTimeNow.Day(), 0, 0, 0, 0, currentTimeNow.Location()) |
|
|
|
queryData(ctx, pageStartTime.Unix(), pageEndTime.Unix()) |
|
|
|
} |
|
|
|
|
|
|
|
func QueryInvitationLastWeek(ctx *context.Context) { |
|
|
|
currentTimeNow := time.Now() |
|
|
|
offset := int(time.Monday - currentTimeNow.Weekday()) |
|
|
|
if offset > 0 { |
|
|
|
offset = -6 |
|
|
|
} |
|
|
|
pageEndTime := time.Date(currentTimeNow.Year(), currentTimeNow.Month(), currentTimeNow.Day(), 0, 0, 0, 0, time.Local).AddDate(0, 0, offset) |
|
|
|
pageStartTime := pageEndTime.AddDate(0, 0, -7) |
|
|
|
queryData(ctx, pageStartTime.Unix(), pageEndTime.Unix()) |
|
|
|
} |
|
|
|
|
|
|
|
func QueryInvitationCurrentYear(ctx *context.Context) { |
|
|
|
currentTimeNow := time.Now() |
|
|
|
pageStartTime := time.Date(currentTimeNow.Year(), 1, 1, 0, 0, 0, 0, currentTimeNow.Location()) |
|
|
|
pageEndTime := time.Date(currentTimeNow.Year(), currentTimeNow.Month(), currentTimeNow.Day(), 0, 0, 0, 0, currentTimeNow.Location()) |
|
|
|
queryData(ctx, pageStartTime.Unix(), pageEndTime.Unix()) |
|
|
|
} |
|
|
|
|
|
|
|
func QueryInvitationLast30Day(ctx *context.Context) { |
|
|
|
currentTimeNow := time.Now() |
|
|
|
pageStartTime := time.Date(currentTimeNow.Year(), currentTimeNow.Month(), currentTimeNow.Day(), 0, 0, 0, 0, time.Local).AddDate(0, 0, -30) |
|
|
|
pageEndTime := time.Date(currentTimeNow.Year(), currentTimeNow.Month(), currentTimeNow.Day(), 0, 0, 0, 0, currentTimeNow.Location()) |
|
|
|
queryData(ctx, pageStartTime.Unix(), pageEndTime.Unix()) |
|
|
|
} |
|
|
|
|
|
|
|
func QueryInvitationLastMonth(ctx *context.Context) { |
|
|
|
currentTimeNow := time.Now() |
|
|
|
thisMonth := time.Date(currentTimeNow.Year(), currentTimeNow.Month(), 1, 0, 0, 0, 0, currentTimeNow.Location()) |
|
|
|
pageStartTime := thisMonth.AddDate(0, -1, 0) |
|
|
|
pageEndTime := time.Date(currentTimeNow.Year(), currentTimeNow.Month(), 1, 23, 59, 59, 0, currentTimeNow.Location()).AddDate(0, 0, -1) |
|
|
|
queryData(ctx, pageStartTime.Unix(), pageEndTime.Unix()) |
|
|
|
} |
|
|
|
|
|
|
|
func QueryInvitationYesterday(ctx *context.Context) { |
|
|
|
currentTimeNow := time.Now().AddDate(0, 0, -1) |
|
|
|
pageStartTime := time.Date(currentTimeNow.Year(), currentTimeNow.Month(), currentTimeNow.Day(), 0, 0, 0, 0, time.Local) |
|
|
|
pageEndTime := time.Date(currentTimeNow.Year(), currentTimeNow.Month(), currentTimeNow.Day(), 23, 59, 59, 0, currentTimeNow.Location()) |
|
|
|
queryData(ctx, pageStartTime.Unix(), pageEndTime.Unix()) |
|
|
|
} |
|
|
|
|
|
|
|
func QueryInvitationAll(ctx *context.Context) { |
|
|
|
currentTimeNow := time.Now() |
|
|
|
pageStartTime := time.Date(2022, 8, 5, 0, 0, 0, 0, currentTimeNow.Location()) |
|
|
|
pageEndTime := time.Date(currentTimeNow.Year(), currentTimeNow.Month(), currentTimeNow.Day(), 0, 0, 0, 0, currentTimeNow.Location()) |
|
|
|
queryData(ctx, pageStartTime.Unix(), pageEndTime.Unix()) |
|
|
|
} |
|
|
|
|
|
|
|
func queryData(ctx *context.Context, startTime int64, endTime int64) { |
|
|
|
page, pageSize := getPageInfo(ctx) |
|
|
|
result, count := models.QueryInvitaionPage(startTime, endTime, (page-1)*pageSize, pageSize) |
|
|
|
mapInterface := make(map[string]interface{}) |
|
|
|
mapInterface["data"] = result |
|
|
|
mapInterface["count"] = count |
|
|
|
ctx.JSON(http.StatusOK, mapInterface) |
|
|
|
} |
|
|
|
|
|
|
|
func getPageInfo(ctx *context.Context) (int, int) { |
|
|
|
page := ctx.QueryInt("page") |
|
|
|
if page <= 0 { |
|
|
|
page = 1 |
|
|
|
} |
|
|
|
pageSize := ctx.QueryInt("pageSize") |
|
|
|
if pageSize <= 0 { |
|
|
|
pageSize = setting.UI.IssuePagingNum |
|
|
|
} |
|
|
|
return page, pageSize |
|
|
|
} |