Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
A
assignment1
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Mathilde Hertaas
assignment1
Commits
1f179a4e
Commit
1f179a4e
authored
3 months ago
by
Mathilde Hertaas
Browse files
Options
Downloads
Patches
Plain Diff
updatet user feedback in population
parent
d875847c
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
handelers/constants.go
+4
-1
4 additions, 1 deletion
handelers/constants.go
handelers/populasjonhandler.go
+11
-15
11 additions, 15 deletions
handelers/populasjonhandler.go
with
15 additions
and
16 deletions
handelers/constants.go
+
4
−
1
View file @
1f179a4e
...
...
@@ -54,4 +54,7 @@ const DATA = "data"
//extern API
const
COUNTRIESNOW_API
=
"http://129.241.150.113:3500/api/v0.1/countries"
const
RESTCOUNTRIES_API
=
"http://129.241.150.113:8080/v3.1/all"
\ No newline at end of file
const
RESTCOUNTRIES_API
=
"http://129.241.150.113:8080/v3.1/all"
//population
const
YEAR_LIMIT_REMINDER
=
"You can also specify how many years to display with {?<startYear-endYear>}.
\n
"
\ No newline at end of file
This diff is collapsed.
Click to expand it.
handelers/populasjonhandler.go
+
11
−
15
View file @
1f179a4e
...
...
@@ -47,7 +47,13 @@ func getPopulationForCountry(alpha2Code string, startYear, endYear int) (*Popula
// Konverter ISO 3166-1 alpha-2 til alpha-3
alpha3Code
,
exists
:=
isoAlpha2ToAlpha3
[
strings
.
ToUpper
(
alpha2Code
)]
if
!
exists
{
return
nil
,
fmt
.
Errorf
(
"invalid country code: %s"
,
alpha2Code
)
return
nil
,
fmt
.
Errorf
(
ERROR_RETRIEVING_COUNTRY_DATA
+
COUNTRY_CODE_REMINDER
+
YEAR_LIMIT_REMINDER
+
EXAMPLE_URL
+
ASSISTANCE_REMINDER
,
alpha2Code
,
POPULATION_URL_EXAMPLE
,
HOMEPAGE_DEFAULT
)
}
// Finn landet basert på ISO 3166-1 alpha-3 kode
...
...
@@ -59,19 +65,11 @@ func getPopulationForCountry(alpha2Code string, startYear, endYear int) (*Popula
}
}
if
countryData
==
nil
{
return
nil
,
fmt
.
Errorf
(
"country not found"
)
}
// Filtrer basert på år
// en tom liste fyllt med PopulationCount, altså fylles med spesifikke år og antall
var
filteredValues
[]
PopulationYears
var
total
int
count
:=
0
// itererer over alle verdiene som følger med et land sin populasjonsdata
// over alle årstall-verdi strukturene
for
_
,
stk
:=
range
countryData
.
PopulationCounts
{
if
(
startYear
==
0
||
stk
.
Year
>=
startYear
)
&&
(
endYear
==
0
||
stk
.
Year
<=
endYear
)
{
filteredValues
=
append
(
filteredValues
,
stk
)
...
...
@@ -80,7 +78,6 @@ func getPopulationForCountry(alpha2Code string, startYear, endYear int) (*Popula
}
}
// Beregn gjennomsnitt
mean
:=
0
if
count
>
0
{
mean
=
int
(
math
.
Round
(
float64
(
total
)
/
float64
(
count
)))
...
...
@@ -94,9 +91,8 @@ func getPopulationForCountry(alpha2Code string, startYear, endYear int) (*Popula
}
func
PopulationHandler
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
path
:=
strings
.
TrimPrefix
(
r
.
URL
.
Path
,
"/countryinfo/v1/population/"
)
// NO
countryCode
:=
strings
.
ToUpper
(
path
)
// ISO 3166-2-kode
path
:=
strings
.
TrimPrefix
(
r
.
URL
.
Path
,
POPULATION_DEFAULT
)
countryCode
:=
strings
.
ToUpper
(
path
)
// ISO 3166-2
query
:=
r
.
URL
.
RawQuery
limit
:=
strings
.
Replace
(
query
,
"limit="
,
""
,
1
)
...
...
@@ -119,6 +115,6 @@ func PopulationHandler(w http.ResponseWriter, r *http.Request) {
return
}
w
.
Header
()
.
Set
(
"Content-Type"
,
"application/json"
)
w
.
Header
()
.
Set
(
HEADER_CONTENT_TYPE
,
FORMAT_JSON
)
json
.
NewEncoder
(
w
)
.
Encode
(
result
)
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment