Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: user current status mismatch #35

Merged
merged 1 commit into from
Jun 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ COPY --from=builder /usr/src/app/bin/vitty ./bin/vitty

COPY --from=builder /usr/src/app/credentials ./credentials


RUN apk --no-cache add tzdata
RUN chmod +x ./bin/vitty

CMD ["./bin/vitty", "run"]
7 changes: 5 additions & 2 deletions vitty-backend-api/api/initialize.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package api

import (
"time"

v1 "github.com/GDGVIT/vitty-backend/vitty-backend-api/api/v1"
v2 "github.com/GDGVIT/vitty-backend/vitty-backend-api/api/v2"
"github.com/gofiber/fiber/v2"
Expand All @@ -11,8 +13,6 @@ import (
func NewWebApi() *fiber.App {
// New fiber app
fiberApp := fiber.New()

fiberApp = fiber.New()
fiberApp.Use(logger.New())
fiberApp.Use(cors.New(
cors.Config{
Expand All @@ -36,6 +36,9 @@ func NewWebApi() *fiber.App {
})
})

local, _ := time.LoadLocation("Asia/Kolkata")
time.Local = local

api := fiberApp.Group("/api")
v1.V1Handler(api)
v2.V2Handler(api)
Expand Down
46 changes: 23 additions & 23 deletions vitty-backend-api/internal/models/slots.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,30 +37,30 @@ type Timings struct {
}

var TheoryTimings = []Timings{
{StartTime: "08:00", EndTime: "08:50"},
{StartTime: "09:00", EndTime: "09:50"},
{StartTime: "10:00", EndTime: "10:50"},
{StartTime: "11:00", EndTime: "11:50"},
{StartTime: "12:00", EndTime: "12:50"},
{StartTime: "14:00", EndTime: "14:50"},
{StartTime: "15:00", EndTime: "15:50"},
{StartTime: "16:00", EndTime: "16:50"},
{StartTime: "17:00", EndTime: "17:50"},
{StartTime: "18:00", EndTime: "18:50"},
{StartTime: "19:00", EndTime: "19:50"},
{StartTime: "0000-01-01T09:00", EndTime: "0000-01-01T09:50"},
{StartTime: "0000-01-01T10:00", EndTime: "0000-01-01T10:50"},
{StartTime: "0000-01-01T11:00", EndTime: "0000-01-01T11:50"},
{StartTime: "0000-01-01T12:00", EndTime: "0000-01-01T12:50"},
{StartTime: "0000-01-01T08:00", EndTime: "0000-01-01T08:50"},
{StartTime: "0000-01-01T14:00", EndTime: "0000-01-01T14:50"},
{StartTime: "0000-01-01T15:00", EndTime: "0000-01-01T15:50"},
{StartTime: "0000-01-01T16:00", EndTime: "0000-01-01T16:50"},
{StartTime: "0000-01-01T17:00", EndTime: "0000-01-01T17:50"},
{StartTime: "0000-01-01T18:00", EndTime: "0000-01-01T18:50"},
{StartTime: "0000-01-01T19:00", EndTime: "0000-01-01T19:50"},
}

var LabTimings = []Timings{
{StartTime: "08:00", EndTime: "08:50"},
{StartTime: "08:51", EndTime: "09:40"},
{StartTime: "09:51", EndTime: "10:40"},
{StartTime: "10:41", EndTime: "11:30"},
{StartTime: "11:40", EndTime: "12:30"},
{StartTime: "12:31", EndTime: "13:20"},
{StartTime: "14:00", EndTime: "14:50"},
{StartTime: "14:51", EndTime: "15:40"},
{StartTime: "15:51", EndTime: "16:40"},
{StartTime: "16:41", EndTime: "17:30"},
{StartTime: "17:40", EndTime: "18:30"},
{StartTime: "18:31", EndTime: "19:20"},
{StartTime: "0000-01-01T08:00", EndTime: "0000-01-01T08:50"},
{StartTime: "0000-01-01T08:51", EndTime: "0000-01-01T09:40"},
{StartTime: "0000-01-01T09:51", EndTime: "0000-01-01T10:40"},
{StartTime: "0000-01-01T10:41", EndTime: "0000-01-01T11:30"},
{StartTime: "0000-01-01T11:40", EndTime: "0000-01-01T12:30"},
{StartTime: "0000-01-01T12:31", EndTime: "0000-01-01T13:20"},
{StartTime: "0000-01-01T14:00", EndTime: "0000-01-01T14:50"},
{StartTime: "0000-01-01T14:51", EndTime: "0000-01-01T15:40"},
{StartTime: "0000-01-01T15:51", EndTime: "0000-01-01T16:40"},
{StartTime: "0000-01-01T16:41", EndTime: "0000-01-01T17:30"},
{StartTime: "0000-01-01T17:40", EndTime: "0000-01-01T18:30"},
{StartTime: "0000-01-01T18:31", EndTime: "0000-01-01T19:20"},
}
50 changes: 42 additions & 8 deletions vitty-backend-api/internal/models/timetable.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (
"golang.org/x/exp/slices"
)

const STD_REF_TIME = "2006-01-02T15:04"

type Slot struct {
Name string `json:"name"`
Code string `json:"code"`
Expand All @@ -28,11 +30,39 @@ func (t Timetable) GetDaySlots(day time.Weekday) map[string][]Slot {
var data []Slot
daySlots := DailySlots[day.String()]

var err error
// Theory slots
for _, slot := range t.Slots {
if slot.Type == "Theory" && slices.Contains(daySlots["Theory"], slot.Slot) {
index := slices.Index(daySlots["Theory"], slot.Slot)
slot.StartTime, err = time.ParseInLocation(STD_REF_TIME, TheoryTimings[index].StartTime, time.Local)
if err != nil {
log.Println("Error parsing time: ", err)
return nil
}

slot.EndTime, err = time.ParseInLocation(STD_REF_TIME, TheoryTimings[index].EndTime, time.Local)

if err != nil {
log.Println("Error parsing time: ", err)
return nil
}

data = append(data, slot)
} else if slot.Type == "Lab" && slices.Contains(daySlots["Lab"], slot.Slot) {
index := slices.Index(daySlots["Lab"], slot.Slot)
slot.StartTime, err = time.ParseInLocation(STD_REF_TIME, LabTimings[index].StartTime, time.Local)
if err != nil {
log.Println("Error parsing time: ", err)
return nil
}

slot.EndTime, err = time.ParseInLocation(STD_REF_TIME, LabTimings[index].EndTime, time.Local)

if err != nil {
log.Println("Error parsing time: ", err)
return nil
}
data = append(data, slot)
}
}
Expand All @@ -48,25 +78,29 @@ func (t Timetable) GetDaywiseTimetable() map[string][]Slot {
if slices.Contains(value["Theory"], slot.Slot) {
index := slices.Index(value["Theory"], slot.Slot)
var err error
slot.StartTime, err = time.Parse("15:04", TheoryTimings[index].StartTime)
slot.StartTime, err = time.ParseInLocation(STD_REF_TIME, TheoryTimings[index].StartTime, time.Local)
if err != nil {
log.Println("Error parsing time: ", err)
return nil
}
slot.EndTime, err = time.Parse("15:04", TheoryTimings[index].EndTime)
slot.EndTime, err = time.ParseInLocation(STD_REF_TIME, TheoryTimings[index].EndTime, time.Local)
if err != nil {
log.Println("Error parsing time: ", err)
return nil
}
resp[day] = append(resp[day], slot)
} else if slices.Contains(value["Lab"], slot.Slot) {
index := slices.Index(value["Lab"], slot.Slot)
var err error
slot.StartTime, err = time.Parse("15:04", LabTimings[index].StartTime)
slot.StartTime, err = time.ParseInLocation(STD_REF_TIME, LabTimings[index].StartTime, time.Local)
if err != nil {
log.Println("Error parsing time: ", err)
return nil
}
slot.EndTime, err = time.Parse("15:04", LabTimings[index].EndTime)
slot.EndTime, err = time.ParseInLocation(STD_REF_TIME, LabTimings[index].EndTime, time.Local)
if err != nil {
log.Println("Error parsing time: ", err)
return nil
}
resp[day] = append(resp[day], slot)
}
Expand All @@ -80,22 +114,22 @@ func (s *Slot) AddSlotTime() error {
if slices.Contains(value["Theory"], s.Slot) {
index := slices.Index(value["Theory"], s.Slot)
var err error
s.StartTime, err = time.Parse("15:04", TheoryTimings[index].StartTime)
s.StartTime, err = time.ParseInLocation(STD_REF_TIME, TheoryTimings[index].StartTime, time.Local)
if err != nil {
return err
}
s.EndTime, err = time.Parse("15:04", TheoryTimings[index].EndTime)
s.EndTime, err = time.ParseInLocation(STD_REF_TIME, TheoryTimings[index].EndTime, time.Local)
if err != nil {
return err
}
} else if slices.Contains(value["Lab"], s.Slot) {
index := slices.Index(value["Lab"], s.Slot)
var err error
s.StartTime, err = time.Parse("15:04", LabTimings[index].StartTime)
s.StartTime, err = time.ParseInLocation(STD_REF_TIME, LabTimings[index].StartTime, time.Local)
if err != nil {
return err
}
s.EndTime, err = time.Parse("15:04", LabTimings[index].EndTime)
s.EndTime, err = time.ParseInLocation(STD_REF_TIME, LabTimings[index].EndTime, time.Local)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion vitty-backend-api/internal/models/users.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func (u *User) GetCurrentStatus() map[string]interface{} {
// If no, status = free
// Get current time(indian timezone) without `date` part
now := time.Now()
currTime := time.Date(0, 1, 1, now.Hour(), now.Minute(), now.Second(), 0, time.UTC).Add(5*time.Hour + 30*time.Minute)
currTime := time.Date(0, 1, 1, now.Hour(), now.Minute(), now.Second(), 0, time.Local)
// Remove date part
fmt.Println("Current time: ", currTime)
daySlots := u.GetTimeTable().GetDaySlots(time.Now().Weekday())
Expand Down
Loading