-func StatusHandler(w http.ResponseWriter, r *http.Request) {
- if r.URL.Path != "/" {
- http.Error(w, "404 not found.", http.StatusNotFound)
+const StatusPath = "/status"
+const AddJobPath = "/jobs"
+const jobIdToken = "infoJobId"
+const deleteJobPath = AddJobPath + "/{" + jobIdToken + "}"
+
+func NewRouter() *mux.Router {
+ r := mux.NewRouter()
+ r.HandleFunc(StatusPath, statusHandler).Methods(http.MethodGet).Name("status")
+ r.HandleFunc(AddJobPath, addInfoJobHandler).Methods(http.MethodPost).Name("add")
+ r.HandleFunc(deleteJobPath, deleteInfoJobHandler).Methods(http.MethodDelete).Name("delete")
+ r.NotFoundHandler = ¬FoundHandler{}
+ r.MethodNotAllowedHandler = &methodNotAllowedHandler{}
+ return r
+}
+
+func statusHandler(w http.ResponseWriter, r *http.Request) {}
+
+func addInfoJobHandler(w http.ResponseWriter, r *http.Request) {
+ b, readErr := ioutil.ReadAll(r.Body)
+ if readErr != nil {
+ http.Error(w, fmt.Sprintf("Unable to read body due to: %v", readErr), http.StatusBadRequest)
+ return
+ }
+ jobInfo := jobs.JobInfo{}
+ if unmarshalErr := json.Unmarshal(b, &jobInfo); unmarshalErr != nil {
+ http.Error(w, fmt.Sprintf("Invalid json body. Cause: %v", unmarshalErr), http.StatusBadRequest)