Compare commits
No commits in common. "3df4c2dfaaa2855f6c51fe03f2302e4b1700cd78" and "2172b8232efa1e0fd1eef0f56d5dbe7722bde114" have entirely different histories.
3df4c2dfaa
...
2172b8232e
55
main.go
55
main.go
|
@ -59,57 +59,6 @@ func main() {
|
|||
|
||||
r.Get("/api/v1/holidays", getHolidays(holidayService))
|
||||
|
||||
templates, err := template.New("").ParseFiles("templates/index.gohtml", "templates/search.gohtml", "templates/search_date.gohtml", "templates/docs.gohtml")
|
||||
if err != nil {
|
||||
log.Fatalf("couldn't load templates: %v", err)
|
||||
}
|
||||
|
||||
r.Get("/docs", func(w http.ResponseWriter, r *http.Request) {
|
||||
templates, err := template.New("").ParseFiles("templates/docs.gohtml")
|
||||
if err != nil {
|
||||
log.Fatalf("couldn't load templates: %v", err)
|
||||
}
|
||||
renderTemplate(w, r, 200, templates, "docs.gohtml", 0)
|
||||
})
|
||||
|
||||
r.Get("/", func(w http.ResponseWriter, r *http.Request) {
|
||||
renderTemplate(w, r, 200, templates, "index.gohtml", 0)
|
||||
})
|
||||
|
||||
r.Get("/search", func(w http.ResponseWriter, r *http.Request) {
|
||||
r.ParseForm()
|
||||
country := r.FormValue("country")
|
||||
year := time.Now().Year()
|
||||
if y := r.FormValue("year"); y != "" {
|
||||
if yr, err := strconv.ParseInt(y, 10, 64); err == nil {
|
||||
year = int(yr)
|
||||
}
|
||||
}
|
||||
|
||||
search := holiday.Search{Year: &year, Country: country}
|
||||
|
||||
holidays, _ := holidayService.Find(search, holiday.Paging{PageSize: 100})
|
||||
holidayResponse := mapHolidays(holidays)
|
||||
|
||||
renderTemplate(w, r, 200, templates, "search.gohtml", holidayResponse)
|
||||
})
|
||||
|
||||
r.Get("/search/date", func(w http.ResponseWriter, r *http.Request) {
|
||||
r.ParseForm()
|
||||
country := r.FormValue("country")
|
||||
date := time.Now()
|
||||
if y := r.FormValue("date"); y != "" {
|
||||
date = parseDate(y)
|
||||
}
|
||||
|
||||
search := holiday.Search{Date: &date, Country: country}
|
||||
|
||||
holidays, _ := holidayService.Find(search, holiday.Paging{PageSize: 100})
|
||||
holidayResponse := mapHolidays(holidays)
|
||||
|
||||
renderTemplate(w, r, 200, templates, "search_date.gohtml", holidayResponse)
|
||||
})
|
||||
|
||||
r.Mount("/admin", adminDashboard(holidayService))
|
||||
|
||||
log.Fatal(http.ListenAndServe(":5281", r))
|
||||
|
@ -128,7 +77,7 @@ func adminDashboard(service holiday.Service) http.Handler {
|
|||
}
|
||||
},
|
||||
"deferint": func(value *int) int { return *value },
|
||||
}).ParseFiles("templates/admin_dashboard.gohtml", "templates/holiday.gohtml", "templates/error.gohtml")
|
||||
}).ParseFiles("templates/index.gohtml", "templates/holiday.gohtml", "templates/error.gohtml")
|
||||
if err != nil {
|
||||
log.Fatalf("couldn't load templates: %v", err)
|
||||
}
|
||||
|
@ -262,7 +211,7 @@ func adminDashboard(service holiday.Service) http.Handler {
|
|||
response["holidays"] = holidayResponse
|
||||
response["search"] = search
|
||||
|
||||
renderTemplate(w, r, 200, templates, "admin_dashboard.gohtml", response)
|
||||
renderTemplate(w, r, 200, templates, "index.gohtml", response)
|
||||
})
|
||||
|
||||
return r
|
||||
|
|
|
@ -1,102 +0,0 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Holiday-api</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1><a href="/admin">Holiday-api</a></h1>
|
||||
<p>Welcome to admin interface for holiday api</p>
|
||||
|
||||
<div>
|
||||
<a href="/admin/holiday">Add a holiday</a>
|
||||
</div>
|
||||
<div>
|
||||
<form id="filter-holidays" action="/admin" method="get">
|
||||
<label for="country">Country</label>
|
||||
<select id="country" name="country">
|
||||
<option value="HR" {{if eq .search.Country "HR"}}selected{{end}}>Croatia</option>
|
||||
<option value="GB" {{if eq .search.Country "GB"}}selected{{end}}>Great Britain</option>
|
||||
<option value="US" {{if eq .search.Country "US"}}selected{{end}}>USA</option>
|
||||
<option value="FR" {{if eq .search.Country "FR"}}selected{{end}}>France</option>
|
||||
</select>
|
||||
|
||||
|
||||
<label for="year">Year</label>
|
||||
<select id="year" name="year">
|
||||
<option value="2020" {{if eq (deferint .search.Year) 2020}}selected{{end}}>2020</option>
|
||||
<option value="2021" {{if eq (deferint .search.Year) 2021}}selected{{end}}>2021</option>
|
||||
<option value="2022" {{if eq (deferint .search.Year) 2022}}selected{{end}}>2022</option>
|
||||
<option value="2023" {{if eq (deferint .search.Year) 2023}}selected{{end}}>2023</option>
|
||||
<option value="2024" {{if eq (deferint .search.Year) 2024}}selected{{end}}>2024</option>
|
||||
<option value="2025" {{if eq (deferint .search.Year) 2025}}selected{{end}}>2025</option>
|
||||
<option value="2026" {{if eq (deferint .search.Year) 2026}}selected{{end}}>2026</option>
|
||||
<option value="2027" {{if eq (deferint .search.Year) 2027}}selected{{end}}>2027</option>
|
||||
</select>
|
||||
|
||||
<div>
|
||||
<label>State holiday</label>
|
||||
|
||||
<label for="state-holiday-true">True</label>
|
||||
<input type="radio" value="true" {{if boolcmp .search.StateHoliday "true"}}checked{{end}} id="state-holiday-true" name="stateHoliday">
|
||||
|
||||
<label for="state-holiday-false">False</label>
|
||||
<input type="radio" value="false" {{if boolcmp .search.StateHoliday "false"}}checked{{end}} id="state-holiday-false" name="stateHoliday">
|
||||
|
||||
<label for="state-holiday-any">Any</label>
|
||||
<input type="radio" value="" {{if boolcmp .search.StateHoliday "nil"}}checked{{end}} id="state-holiday-any" name="stateHoliday">
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label>Religious holiday</label>
|
||||
|
||||
<label for="religious-holiday-true">True</label>
|
||||
<input type="radio" value="true" {{if boolcmp .search.ReligiousHoliday "true"}}checked{{end}} id="religious-holiday-true" name="religiousHoliday">
|
||||
|
||||
<label for="religious-holiday-false">False</label>
|
||||
<input type="radio" value="false" {{if boolcmp .search.ReligiousHoliday "false"}}checked{{end}} id="religious-holiday-false" name="religiousHoliday">
|
||||
|
||||
<label for="religious-holiday-any">Any</label>
|
||||
<input type="radio" value="" {{if boolcmp .search.ReligiousHoliday "nil"}}checked{{end}} id="religious-holiday-any" name="religiousHoliday">
|
||||
|
||||
</div>
|
||||
|
||||
<button type="submit">Search</button>
|
||||
</form>
|
||||
</div>
|
||||
<div>
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Name</th>
|
||||
<th>Description</th>
|
||||
<th>Date</th>
|
||||
<th>State holiday</th>
|
||||
<th>Religious holiday</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{{range $entry := .holidays.Holidays}}
|
||||
<tr>
|
||||
<td>{{$entry.Name}}</td>
|
||||
<td>{{$entry.Description}}</td>
|
||||
<td>{{$entry.Date.Format "2006-01-02"}}</td>
|
||||
<td>{{$entry.IsStateHoliday}}</td>
|
||||
<td>{{$entry.IsReligiousHoliday}}</td>
|
||||
<td>
|
||||
<a href="/admin/holiday?id={{$entry.Id}}">Edit</a>
|
||||
<form action="/admin/holiday/delete" method="post">
|
||||
<input id="id" type="hidden" name="id" value="{{$entry.Id}}">
|
||||
<button type="submit">Delete</button>
|
||||
</form>
|
||||
</td>
|
||||
</tr>
|
||||
{{end}}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
|
@ -1,104 +0,0 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Holiday-api</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1><a href="/">Holiday-api</a></h1>
|
||||
<p>Create query</p>
|
||||
|
||||
<form>
|
||||
<label for="country">Country</label>
|
||||
<select id="country" name="country">
|
||||
<option value="HR">Croatia</option>
|
||||
<option value="GB">Great Britain</option>
|
||||
<option value="US">USA</option>
|
||||
<option value="FR">France</option>
|
||||
</select>
|
||||
|
||||
<div>
|
||||
<label>Date selector</label>
|
||||
<br>
|
||||
|
||||
<div style="border: 1px solid black">
|
||||
<label for="date-year">Select year</label>
|
||||
<input type="radio" id="date-year" name="date-selector" value="year">
|
||||
|
||||
<label for="date-year-year">Year</label>
|
||||
<select id="date-year-year" name="year">
|
||||
<option value="2020">2020</option>
|
||||
<option value="2021">2021</option>
|
||||
<option value="2022">2022</option>
|
||||
<option value="2023">2023</option>
|
||||
<option value="2024">2024</option>
|
||||
<option value="2025">2025</option>
|
||||
<option value="2026">2026</option>
|
||||
<option value="2027">2027</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div style="border: 1px solid black">
|
||||
<label for="date-date">Select date</label>
|
||||
<input type="radio" id="date-date" name="date-selector" value="date">
|
||||
|
||||
<label for="date-date-date">Date</label>
|
||||
<input type="date" id="date-date-date" name="date-date-date">
|
||||
</div>
|
||||
|
||||
<div style="border: 1px solid black">
|
||||
<label for="date-date-range">Select date range</label>
|
||||
<input type="radio" id="date-date-range" name="date-selector" value="date-range">
|
||||
|
||||
<label for="date-date-start-range">Start range</label>
|
||||
<input type="date" id="date-date-start-range" name="date-date-start-range">
|
||||
|
||||
<label for="date-date-start-range-required">Required</label>
|
||||
<input type="checkbox" id="date-date-start-range-required" name="date-date-start-range-required">
|
||||
|
||||
<label for="date-date-end-range">End range</label>
|
||||
<input type="date" id="date-date-end-range" name="date-date-end-range">
|
||||
|
||||
<label for="date-date-end-range-required">Required</label>
|
||||
<input type="checkbox" id="date-date-end-range-required" name="date-date-end-range-required">
|
||||
|
||||
</div>
|
||||
|
||||
<div style="border: 1px solid black">
|
||||
<label for="date-all">All</label>
|
||||
<input type="radio" id="date-all" name="date-selector" value="all">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label>State holiday</label>
|
||||
<br>
|
||||
|
||||
<label for="state-holiday-true">True</label>
|
||||
<input type="radio" value="true" id="state-holiday-true" name="stateHoliday">
|
||||
|
||||
<label for="state-holiday-false">False</label>
|
||||
<input type="radio" value="false" id="state-holiday-false" name="stateHoliday">
|
||||
|
||||
<label for="state-holiday-any">Any</label>
|
||||
<input type="radio" value="" id="state-holiday-any" name="stateHoliday">
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label>Religious holiday</label>
|
||||
<br>
|
||||
|
||||
<label for="religious-holiday-true">True</label>
|
||||
<input type="radio" value="true" id="religious-holiday-true" name="religiousHoliday">
|
||||
|
||||
<label for="religious-holiday-false">False</label>
|
||||
<input type="radio" value="false" id="religious-holiday-false" name="religiousHoliday">
|
||||
|
||||
<label for="religious-holiday-any">Any</label>
|
||||
<input type="radio" value="" id="religious-holiday-any" name="religiousHoliday">
|
||||
</div>
|
||||
</form>
|
||||
</body>
|
||||
</html>
|
|
@ -7,55 +7,96 @@
|
|||
<title>Holiday-api</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1><a href="/">Holiday-api</a></h1>
|
||||
<p>Welcome to holiday api - simple page for tracking holidays</p>
|
||||
<h1>Holiday-api</h1>
|
||||
<p>Welcome to admin interface for holiday api</p>
|
||||
|
||||
<div>
|
||||
<h2>Is a holiday?</h2>
|
||||
<form method="get" action="/search/date">
|
||||
<label for="country">Country</label>
|
||||
<select id="country" name="country">
|
||||
<option value="HR">Croatia</option>
|
||||
<option value="GB">Great Britain</option>
|
||||
<option value="US">USA</option>
|
||||
<option value="FR">France</option>
|
||||
</select>
|
||||
|
||||
<label for="date">Date</label>
|
||||
<input id="date" name="date" type="date">
|
||||
|
||||
<button type="submit">Check is a holiday</button>
|
||||
</form>
|
||||
<a href="/admin/holiday">Add a holiday</a>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<h2>Find holidays for</h2>
|
||||
<form method="get" action="/search">
|
||||
<form id="filter-holidays" action="/admin" method="get">
|
||||
<label for="country">Country</label>
|
||||
<select id="country" name="country">
|
||||
<option value="HR">Croatia</option>
|
||||
<option value="GB">Great Britain</option>
|
||||
<option value="US">USA</option>
|
||||
<option value="FR">France</option>
|
||||
<option value="HR" {{if eq .search.Country "HR"}}selected{{end}}>Croatia</option>
|
||||
<option value="GB" {{if eq .search.Country "GB"}}selected{{end}}>Great Britain</option>
|
||||
<option value="US" {{if eq .search.Country "US"}}selected{{end}}>USA</option>
|
||||
<option value="FR" {{if eq .search.Country "FR"}}selected{{end}}>France</option>
|
||||
</select>
|
||||
|
||||
|
||||
<label for="year">Year</label>
|
||||
<select id="year" name="year">
|
||||
<option value="2020">2020</option>
|
||||
<option value="2021">2021</option>
|
||||
<option value="2022">2022</option>
|
||||
<option value="2023">2023</option>
|
||||
<option value="2024">2024</option>
|
||||
<option value="2025">2025</option>
|
||||
<option value="2026">2026</option>
|
||||
<option value="2027">2027</option>
|
||||
<option value="2020" {{if eq (deferint .search.Year) 2020}}selected{{end}}>2020</option>
|
||||
<option value="2021" {{if eq (deferint .search.Year) 2021}}selected{{end}}>2021</option>
|
||||
<option value="2022" {{if eq (deferint .search.Year) 2022}}selected{{end}}>2022</option>
|
||||
<option value="2023" {{if eq (deferint .search.Year) 2023}}selected{{end}}>2023</option>
|
||||
<option value="2024" {{if eq (deferint .search.Year) 2024}}selected{{end}}>2024</option>
|
||||
<option value="2025" {{if eq (deferint .search.Year) 2025}}selected{{end}}>2025</option>
|
||||
<option value="2026" {{if eq (deferint .search.Year) 2026}}selected{{end}}>2026</option>
|
||||
<option value="2027" {{if eq (deferint .search.Year) 2027}}selected{{end}}>2027</option>
|
||||
</select>
|
||||
<button type="submit">Find holidays</button>
|
||||
|
||||
<div>
|
||||
<label>State holiday</label>
|
||||
|
||||
<label for="state-holiday-true">True</label>
|
||||
<input type="radio" value="true" {{if boolcmp .search.StateHoliday "true"}}checked{{end}} id="state-holiday-true" name="stateHoliday">
|
||||
|
||||
<label for="state-holiday-false">False</label>
|
||||
<input type="radio" value="false" {{if boolcmp .search.StateHoliday "false"}}checked{{end}} id="state-holiday-false" name="stateHoliday">
|
||||
|
||||
<label for="state-holiday-any">Any</label>
|
||||
<input type="radio" value="" {{if boolcmp .search.StateHoliday "nil"}}checked{{end}} id="state-holiday-any" name="stateHoliday">
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label>Religious holiday</label>
|
||||
|
||||
<label for="religious-holiday-true">True</label>
|
||||
<input type="radio" value="true" {{if boolcmp .search.ReligiousHoliday "true"}}checked{{end}} id="religious-holiday-true" name="religiousHoliday">
|
||||
|
||||
<label for="religious-holiday-false">False</label>
|
||||
<input type="radio" value="false" {{if boolcmp .search.ReligiousHoliday "false"}}checked{{end}} id="religious-holiday-false" name="religiousHoliday">
|
||||
|
||||
<label for="religious-holiday-any">Any</label>
|
||||
<input type="radio" value="" {{if boolcmp .search.ReligiousHoliday "nil"}}checked{{end}} id="religious-holiday-any" name="religiousHoliday">
|
||||
|
||||
</div>
|
||||
|
||||
<button type="submit">Search</button>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<h2>Create api query</h2>
|
||||
<a href="/docs">Goto query editor</a>
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Name</th>
|
||||
<th>Description</th>
|
||||
<th>Date</th>
|
||||
<th>State holiday</th>
|
||||
<th>Religious holiday</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{{range $entry := .holidays.Holidays}}
|
||||
<tr>
|
||||
<td>{{$entry.Name}}</td>
|
||||
<td>{{$entry.Description}}</td>
|
||||
<td>{{$entry.Date.Format "2006-01-02"}}</td>
|
||||
<td>{{$entry.IsStateHoliday}}</td>
|
||||
<td>{{$entry.IsReligiousHoliday}}</td>
|
||||
<td>
|
||||
<a href="/admin/holiday?id={{$entry.Id}}">Edit</a>
|
||||
<form action="/admin/holiday/delete" method="post">
|
||||
<input id="id" type="hidden" name="id" value="{{$entry.Id}}">
|
||||
<button type="submit">Delete</button>
|
||||
</form>
|
||||
</td>
|
||||
</tr>
|
||||
{{end}}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
|
@ -1,38 +0,0 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Holiday-api</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1><a href="/">Holiday-api</a></h1>
|
||||
<p>Search results</p>
|
||||
|
||||
<div>
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Name</th>
|
||||
<th>Description</th>
|
||||
<th>Date</th>
|
||||
<th>State holiday</th>
|
||||
<th>Religious holiday</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{{range $entry := .Holidays}}
|
||||
<tr>
|
||||
<td>{{$entry.Name}}</td>
|
||||
<td>{{$entry.Description}}</td>
|
||||
<td>{{$entry.Date.Format "2006-01-02"}}</td>
|
||||
<td>{{$entry.IsStateHoliday}}</td>
|
||||
<td>{{$entry.IsReligiousHoliday}}</td>
|
||||
</tr>
|
||||
{{end}}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
|
@ -1,43 +0,0 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Holiday-api</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1><a href="/">Holiday-api</a></h1>
|
||||
|
||||
<p>{{if .Holidays}}Yes it is a holday{{else}}No it isn't a holiday{{end}}</p>
|
||||
|
||||
<p>Search results</p>
|
||||
|
||||
<div>
|
||||
{{if .Holidays}}
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Name</th>
|
||||
<th>Description</th>
|
||||
<th>Date</th>
|
||||
<th>State holiday</th>
|
||||
<th>Religious holiday</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{{range $entry := .Holidays}}
|
||||
<tr>
|
||||
<td>{{$entry.Name}}</td>
|
||||
<td>{{$entry.Description}}</td>
|
||||
<td>{{$entry.Date.Format "2006-01-02"}}</td>
|
||||
<td>{{$entry.IsStateHoliday}}</td>
|
||||
<td>{{$entry.IsReligiousHoliday}}</td>
|
||||
</tr>
|
||||
{{end}}
|
||||
</tbody>
|
||||
</table>
|
||||
{{end}}
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in New Issue