Skip to content

Commit fa1fa5f

Browse files
committed
finalized light mode, added break/lesson indicators, changed weather widget layout
1 parent 2e43854 commit fa1fa5f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+1194
-1583
lines changed

Diff for: .gitignore

-1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,5 @@ go.work.sum
2626
.VSCodeCounter
2727
.vscode
2828
app/db
29-
web/optivum-better-schedule-frontend/src/components/_.vue
3029
app/dist
3130
build

Diff for: api/v1/handlers/atmosphere.go

+47-21
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ package handlers
44
import (
55
"encoding/json"
66
"fmt"
7-
"math"
87
"net/http"
98
"os"
109
"sort"
@@ -53,7 +52,15 @@ func WeatherForecastHandler(c *gin.Context) {
5352
return
5453
}
5554

56-
forecastList := openWeatherData["list"].([]interface{})
55+
forecastList, ok := openWeatherData["list"].([]interface{})
56+
if !ok {
57+
Respond(c, http.StatusInternalServerError, models.APIResponse{
58+
Message: "invalid forecast data format",
59+
Success: false,
60+
})
61+
return
62+
}
63+
5764
forecastResponse := &models.ForecastResponse{
5865
Name: openWeatherData["city"].(map[string]interface{})["name"].(string),
5966
}
@@ -76,7 +83,6 @@ func WeatherForecastHandler(c *gin.Context) {
7683
sort.Strings(dates)
7784

7885
now := time.Now().UTC()
79-
currentTimeOfDaySeconds := now.Hour()*3600 + now.Minute()*60 + now.Second()
8086

8187
datesProcessed := 0
8288
for _, dateStr := range dates {
@@ -89,21 +95,20 @@ func WeatherForecastHandler(c *gin.Context) {
8995
continue
9096
}
9197

92-
if datesProcessed >= 3 {
93-
break
94-
}
95-
9698
forecasts := forecastsByDate[dateStr]
9799

98-
minTimeDiff := int64(1<<63 - 1)
99100
var closestForecast map[string]interface{}
101+
minTimeDiff := int64(1<<63 - 1)
100102

101103
for _, fMap := range forecasts {
102104
fDt := int64(fMap["dt"].(float64))
103105
fTime := time.Unix(fDt, 0).UTC()
104106

105-
fTimeOfDaySeconds := fTime.Hour() * 3600 + fTime.Minute() * 60 + fTime.Second()
106-
timeDiff := int64(math.Abs(float64(fTimeOfDaySeconds - currentTimeOfDaySeconds)))
107+
if fTime.Before(now) {
108+
continue
109+
}
110+
111+
timeDiff := fDt - now.Unix()
107112

108113
if timeDiff < minTimeDiff {
109114
minTimeDiff = timeDiff
@@ -112,32 +117,53 @@ func WeatherForecastHandler(c *gin.Context) {
112117
}
113118

114119
if closestForecast != nil {
115-
condition := closestForecast["weather"].([]interface{})[0].(map[string]interface{})
116-
temperature := closestForecast["main"].(map[string]interface{})
117-
sunrise := int64(openWeatherData["city"].(map[string]interface{})["sunrise"].(float64))
118-
sunset := int64(openWeatherData["city"].(map[string]interface{})["sunset"].(float64))
120+
conditionList, ok := closestForecast["weather"].([]interface{})
121+
if !ok || len(conditionList) == 0 {
122+
continue
123+
}
124+
conditionMap, ok := conditionList[0].(map[string]interface{})
125+
if !ok {
126+
continue
127+
}
128+
129+
temperatureMap, ok := closestForecast["main"].(map[string]interface{})
130+
if !ok {
131+
continue
132+
}
133+
134+
cityMap, ok := openWeatherData["city"].(map[string]interface{})
135+
if !ok {
136+
continue
137+
}
138+
139+
sunrise := int64(cityMap["sunrise"].(float64))
140+
sunset := int64(cityMap["sunset"].(float64))
119141

120142
dt := int64(closestForecast["dt"].(float64))
121143
t := time.Unix(dt, 0).UTC()
122144
dayOfWeek := int64(t.Weekday())
123145

124146
forecastResponse.Forecast = append(forecastResponse.Forecast, &models.Forecast{
125147
Condition: &models.Condition{
126-
Name: condition["main"].(string),
127-
Description: condition["description"].(string),
148+
Name: conditionMap["main"].(string),
149+
Description: conditionMap["description"].(string),
128150
},
129151
Temperature: &models.Temperature{
130-
Current: temperature["temp"].(float64),
131-
Min: temperature["temp_min"].(float64),
132-
Max: temperature["temp_max"].(float64),
152+
Current: temperatureMap["temp"].(float64),
153+
Min: temperatureMap["temp_min"].(float64),
154+
Max: temperatureMap["temp_max"].(float64),
133155
},
134156
Sunrise: sunrise,
135157
Sunset: sunset,
136158
DayOfWeek: dayOfWeek,
137159
})
138-
}
139160

140-
datesProcessed++
161+
datesProcessed++
162+
163+
if datesProcessed >= 3 {
164+
break
165+
}
166+
}
141167
}
142168

143169
Respond(c, http.StatusOK, forecastResponse)

Diff for: common/utils/utils.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,9 @@ func OpenDoc(baseUrl, endpoint string) (*goquery.Document, error) {
5656
break
5757
}
5858
if res != nil {
59-
res.Body.Close()
59+
if err := res.Body.Close(); err != nil {
60+
return nil, fmt.Errorf("error closing response body: %w", err)
61+
}
6062
}
6163
time.Sleep(1 * time.Second)
6264
}

Diff for: makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ BINARY_NAME := $(PROJECT_NAME)
33

44
PROJECT_ROOT := $(CURDIR)
55
BACKEND_SOURCE_DIR := $(PROJECT_ROOT)/app
6-
FRONTEND_SOURCE_DIR := $(PROJECT_ROOT)/web/optivum-better-schedule-frontend
6+
FRONTEND_SOURCE_DIR := $(PROJECT_ROOT)/web/prod
77

88
BUILD_DIR := $(PROJECT_ROOT)/build
99
CURRENT_BUILD_DIR := $(BUILD_DIR)/$(BINARY_NAME)

Diff for: web/optivum-better-schedule-frontend/src/App.vue

-38
This file was deleted.

Diff for: web/optivum-better-schedule-frontend/src/components/RoomButton.vue

-145
This file was deleted.

0 commit comments

Comments
 (0)