parse time to formated date
This commit is contained in:
@@ -6,6 +6,8 @@ import (
|
||||
"antrian-operasi/internal/shared"
|
||||
baseResponse "antrian-operasi/internal/shared"
|
||||
|
||||
"time"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
@@ -179,7 +181,7 @@ func (h DashboardHandler) GetAntrianPerHari(c *gin.Context) {
|
||||
}
|
||||
|
||||
response := baseResponse.ToBaseResponse(
|
||||
data,
|
||||
ListAntrianPerHari(data).ParseToResponse(req.Year, time.Month(req.Month)),
|
||||
true,
|
||||
200,
|
||||
"success get antrean per hari")
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
package dashboard
|
||||
|
||||
import "time"
|
||||
|
||||
type ListPerbandinganStatusAntrean []PerbandinganStatusAntreanQueryResult
|
||||
type ListAntrianPerHari []AntrianPerHari
|
||||
|
||||
func (list ListPerbandinganStatusAntrean) findJumlahById(id int) int {
|
||||
for _, item := range list {
|
||||
@@ -20,3 +23,47 @@ func (list ListPerbandinganStatusAntrean) MapToResponse() []PerbandinganStatusAn
|
||||
{IdStatus: 4, Status: "Batal", Jumlah: list.findJumlahById(4)},
|
||||
}
|
||||
}
|
||||
|
||||
func getMonthRange(year int, month time.Month) (time.Time, time.Time) {
|
||||
start := time.Date(year, month, 1, 0, 0, 0, 0, time.Local)
|
||||
end := start.AddDate(0, 1, 0)
|
||||
|
||||
return start, end
|
||||
}
|
||||
|
||||
func (list ListAntrianPerHari) ParseToResponse(year int, month time.Month) []AntrianPerHariResponse {
|
||||
dataMap := make(map[string]AntrianPerHari)
|
||||
|
||||
for _, item := range list {
|
||||
key := item.TanggalDaftar.Format("2006-01-02")
|
||||
dataMap[key] = item
|
||||
}
|
||||
|
||||
start, end := getMonthRange(year, month)
|
||||
|
||||
var result []AntrianPerHariResponse
|
||||
|
||||
for d := start; d.Before(end); d = d.AddDate(0, 0, 1) {
|
||||
key := d.Format("2006-01-02")
|
||||
|
||||
if val, ok := dataMap[key]; ok {
|
||||
result = append(result, AntrianPerHariResponse{
|
||||
TanggalDaftar: d.Format("2006-01-02"),
|
||||
Belum: val.Belum,
|
||||
Selesai: val.Selesai,
|
||||
Tunda: val.Tunda,
|
||||
Batal: val.Batal,
|
||||
})
|
||||
} else {
|
||||
result = append(result, AntrianPerHariResponse{
|
||||
TanggalDaftar: d.Format("2006-01-02"),
|
||||
Belum: 0,
|
||||
Selesai: 0,
|
||||
Tunda: 0,
|
||||
Batal: 0,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
@@ -54,6 +54,14 @@ type AntrianPerHari struct {
|
||||
Batal int `db:"batal"`
|
||||
}
|
||||
|
||||
type AntrianPerHariResponse struct {
|
||||
TanggalDaftar string
|
||||
Belum int
|
||||
Selesai int
|
||||
Tunda int
|
||||
Batal int
|
||||
}
|
||||
|
||||
type TableAntreanPerSpesialis struct {
|
||||
Spesialis string `db:"spesialis"`
|
||||
Total int `db:"total"`
|
||||
|
||||
Reference in New Issue
Block a user