Skip to content

Commit

Permalink
Merge pull request #245 from NIAEFEUP/refactor/dynamic-school-year
Browse files Browse the repository at this point in the history
Course api year is now dynamic
  • Loading branch information
tomaspalma authored Aug 14, 2024
2 parents 1d7b230 + 511fb19 commit cc15919
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
7 changes: 5 additions & 2 deletions src/api/backend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ const BE_CONFIG = Number(prod_val) ? config : dev_config
const BACKEND_URL = import.meta.env.VITE_APP_BACKEND_URL || `${BE_CONFIG.api.protocol}://${BE_CONFIG.api.host}:${BE_CONFIG.api.port}${BE_CONFIG.api.pathPrefix}`
const SEMESTER = import.meta.env.VITE_APP_SEMESTER || getSemester()

// If we are in september 2024 we use 2024, if we are january 2025 we use 2024 because the first year of the academic year (2024/2025)
const CURRENT_YEAR = ((new Date()).getMonth() + 1) < 8 ? (new Date()).getFullYear() - 1 : (new Date()).getFullYear()

/**
* Make a request to the backend server.
* @param route route to be appended to backend url
Expand All @@ -27,7 +30,7 @@ const apiRequest = async (route: string) => {
* @returns all majors from the backend
*/
const getMajors = async () => {
return await apiRequest(`/course/${config.api.year}`)
return await apiRequest(`/course/${CURRENT_YEAR}`)
}

/**
Expand All @@ -41,7 +44,7 @@ const getCourses = async (major: Major) => {
}

const getCoursesByMajorId = async (id: number) => {
return await apiRequest(`/course_units/${id}/${config.api.year}/${SEMESTER}/`)
return await apiRequest(`/course_units/${id}/${CURRENT_YEAR}/${SEMESTER}/`)
}

/**
Expand Down
3 changes: 1 addition & 2 deletions src/config/local.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
"port": 8100,
"protocol" : "http",
"pathPrefix": "",
"host": "localhost",
"year": 2023
"host": "localhost"
}
}
3 changes: 1 addition & 2 deletions src/config/prod.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
"port": 443,
"protocol" : "https",
"host": "ni.fe.up.pt",
"pathPrefix" : "/tts/api",
"year": 2023
"pathPrefix" : "/tts/api"
}
}

0 comments on commit cc15919

Please sign in to comment.