update report function
This commit is contained in:
@@ -3,6 +3,7 @@ package api
|
||||
import (
|
||||
"net/http"
|
||||
"slices"
|
||||
"strings"
|
||||
|
||||
"gitea.tecamino.com/paadi/memberDB/models"
|
||||
"github.com/gin-gonic/gin"
|
||||
@@ -31,6 +32,13 @@ func (a *APIHandler) GetReport(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
if len(request.Date) == 0 {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"data": report,
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
var events []models.Event
|
||||
|
||||
if len(request.Name) > 0 {
|
||||
@@ -38,6 +46,7 @@ func (a *APIHandler) GetReport(c *gin.Context) {
|
||||
} else {
|
||||
events, err = a.DbHandler.GetEvent(0)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
a.logger.Error("GetReport", err)
|
||||
c.JSON(http.StatusBadRequest, gin.H{
|
||||
@@ -53,40 +62,15 @@ func (a *APIHandler) GetReport(c *gin.Context) {
|
||||
|
||||
addedMember := make(map[uint]bool)
|
||||
|
||||
for _, e := range events {
|
||||
// skip if date lower or not equal from date as well as greater than to date
|
||||
if (e.Date < request.Date.From || e.Date > request.Date.From) && e.Date != request.Date.From {
|
||||
continue
|
||||
}
|
||||
if len(events) == 0 {
|
||||
c.JSON(http.StatusOK, gin.H{})
|
||||
return
|
||||
}
|
||||
|
||||
// skip if day not selected
|
||||
switch e.Day {
|
||||
case "Monday":
|
||||
if !request.Weekdays.Monday {
|
||||
continue
|
||||
}
|
||||
case "Tuesday":
|
||||
if !request.Weekdays.Tuesday {
|
||||
continue
|
||||
}
|
||||
case "Wednesday":
|
||||
if !request.Weekdays.Wednesday {
|
||||
continue
|
||||
}
|
||||
case "Thursday":
|
||||
if !request.Weekdays.Thursday {
|
||||
continue
|
||||
}
|
||||
case "Friday":
|
||||
if !request.Weekdays.Friday {
|
||||
continue
|
||||
}
|
||||
case "Saturday":
|
||||
if !request.Weekdays.Saturday {
|
||||
continue
|
||||
}
|
||||
case "Sunday":
|
||||
if !request.Weekdays.Sunday {
|
||||
for _, e := range events {
|
||||
|
||||
for _, d := range request.Date {
|
||||
if !strings.Contains(e.Date, d) {
|
||||
continue
|
||||
}
|
||||
}
|
||||
@@ -136,8 +120,13 @@ func (a *APIHandler) GetReport(c *gin.Context) {
|
||||
for _, m := range members {
|
||||
if _, ok := addedMember[m.Id]; ok {
|
||||
continue
|
||||
} else if !slices.Contains(request.Groups, m.Group.Id) {
|
||||
continue
|
||||
} else if len(request.Groups) > 0 {
|
||||
if m.Group == nil {
|
||||
continue
|
||||
} else if !slices.Contains(request.Groups, m.Group.Id) {
|
||||
continue
|
||||
}
|
||||
|
||||
}
|
||||
report.NonAttendees = append(report.NonAttendees, &m)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user