From 7df4a6b10696120452cf3afa6d4c81da6ef01814 Mon Sep 17 00:00:00 2001 From: Mathilde Hertaas <maimh@stud.ntnu.no> Date: Thu, 6 Mar 2025 12:49:06 +0100 Subject: [PATCH] separated populasion class and added constant class --- handelers/konstanter.go | 6 ++++++ handelers/populasjonhandler.go | 39 ---------------------------------- handelers/strukter.go | 28 ++++++++++++++++++++++++ 3 files changed, 34 insertions(+), 39 deletions(-) create mode 100644 handelers/konstanter.go diff --git a/handelers/konstanter.go b/handelers/konstanter.go new file mode 100644 index 0000000..9f88f55 --- /dev/null +++ b/handelers/konstanter.go @@ -0,0 +1,6 @@ +package handelers + +const HOMEPAGE_DEFAULT = "http://localhost:8080/" //url til hjemmeside +const INFO_DEFAULT = "http://localhost:8080/countryinfo/vi/info/" // url info for brukerspesifikasjon +const POPULATION_DEFAULT = "" +const STATUS_DEFAULT = "" \ No newline at end of file diff --git a/handelers/populasjonhandler.go b/handelers/populasjonhandler.go index b81780c..afc7abd 100644 --- a/handelers/populasjonhandler.go +++ b/handelers/populasjonhandler.go @@ -9,42 +9,6 @@ import ( "strings" ) -// responsstruktur for befolkningsdata -type PopulationResponse struct { - Error bool `json:"error"` - Msg string `json:"msg"` - Data []Country `json:"data"` -} - -// land og dens befolkningsdata -type Country struct { - Name string `json:"country"` - Code string `json:"iso3"` // Trebokstavskode (ISO 3166-1 alpha-3) - PopulationCounts []PopulationCount `json:"populationCounts"` -} - - - - -// befolkningsdate for et bestemt år (brukes i den endelige repsonsen under values) -type PopulationCount struct { - Year int `json:"year"` - Value int `json:"value"` -} - -// Responsstruktur for vårt API(det som vises på skjerm) -type PopulationAPIResponse struct { - Name string `json:"land"` - Gjennomsnitt int `json:"gjennomsnittlig populasjon"` - Values []PopulationCount `json:"årlige populasjoner"` -} - - - - - - - // ISO 3166-1 alpha-2 til alpha-3 landkoder var isoAlpha2ToAlpha3 = make(map[string]string) @@ -129,9 +93,6 @@ func getPopulationForCountry(alpha2Code string, startYear, endYear int) (*Popula }, nil } - - - func PopulationHandler(w http.ResponseWriter, r *http.Request) { // r.URL.Path er den fulle URL som ble sendt til serveren altså /population/NO // deretter fjerner den /population/ så vi sitter igjen med NO diff --git a/handelers/strukter.go b/handelers/strukter.go index 69a56af..4a97f3b 100644 --- a/handelers/strukter.go +++ b/handelers/strukter.go @@ -34,4 +34,32 @@ type CombinedInfo struct { Flags string `json:"flags"` Capital string `json:"capital"` Cities string `json:"cities"` +} + +// responsstruktur for befolkningsdata +type PopulationResponse struct { + Error bool `json:"error"` + Msg string `json:"msg"` + Data []Country `json:"data"` +} + +// land og dens befolkningsdata +type Country struct { + Name string `json:"country"` + Code string `json:"iso3"` // Trebokstavskode (ISO 3166-1 alpha-3) + PopulationCounts []PopulationCount `json:"populationCounts"` +} + + +// befolkningsdate for et bestemt år (brukes i den endelige repsonsen under values) +type PopulationCount struct { + Year int `json:"year"` + Value int `json:"value"` +} + +// Responsstruktur for vårt API(det som vises på skjerm) +type PopulationAPIResponse struct { + Name string `json:"land"` + Gjennomsnitt int `json:"gjennomsnittlig populasjon"` + Values []PopulationCount `json:"årlige populasjoner"` } \ No newline at end of file -- GitLab