-
Notifications
You must be signed in to change notification settings - Fork 1
/
handlers.go
45 lines (39 loc) · 929 Bytes
/
handlers.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package main
import (
"log"
"net/http"
"strconv"
"github.com/go-chi/chi"
)
// handleSearch is responsible for sending search results
func (s *Server) handleSearch(w http.ResponseWriter, r *http.Request) {
title := r.URL.Query().Get("title")
year := r.URL.Query().Get("year")
offsetStr := r.URL.Query().Get("offset")
var offset int
var err error
if offsetStr != "" {
offset, err = strconv.Atoi(offsetStr)
if err != nil {
log.Println(err)
return
}
}
switch {
case title != "" && year != "":
s.SearchTitleYear(w, r, title, year, offset)
case title != "":
s.SearchTitle(w, r, title, offset)
case year != "":
// s.SearchYear(w, r, year)
// Don't allow year only searches.
fallthrough
default:
http.Error(w, "You must enter a query.", 404)
return
}
}
func (s *Server) handleID(w http.ResponseWriter, r *http.Request) {
movieID := chi.URLParam(r, "movieID")
s.GetByID(w, r, movieID)
}