Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions catfeeder-machine/rest-api.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,15 @@ func CreateNewFeedTime(w http.ResponseWriter, r *http.Request) {
PrintFeedingTimes(ft)
}

/***
* @brief: Handle to feed the cat.
***/
func CreateFeedNow(w http.ResponseWriter, r *http.Request) {
fmt.Println("Place holder to feed cat now, will update once TID003 is complete")
}

/**
* @brief: Handle for recieving a specific feeding time.
* @brief: Handle for returning a specific feeding time.
**/
func ReturnSingleFeedingTime(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
Expand All @@ -57,7 +64,7 @@ func ReturnSingleFeedingTime(w http.ResponseWriter, r *http.Request) {
}

/**
* @brief: Handle for recieving all the feeding times.
* @brief: Handle for returning all the feeding times.
**/
func ReturnAllFeedingTimes(w http.ResponseWriter, r *http.Request) {
mut.Lock()
Expand All @@ -68,12 +75,13 @@ func ReturnAllFeedingTimes(w http.ResponseWriter, r *http.Request) {
}

/**
* @brief: Handle to recieving info on REST API.
* @brief: Handle to returning info on REST API.
**/
func HomePage(w http.ResponseWriter, r *http.Request) {
fmt.Fprintln(w, "Cat Feeding times")
fmt.Fprintln(w, "-----------------------")
fmt.Fprintln(w, "Create new feeding times with '/feedingTime'")
fmt.Fprintln(w, "Create request to feed cat now with '/feedNow'")
fmt.Fprintln(w, "Return all feeding time with '/feedingTimes'")
fmt.Fprintln(w, "Return single feeding time with '/feedingTime/<ID>'")
}
Expand All @@ -85,6 +93,7 @@ func HandleRequests() {
myRouter := mux.NewRouter().StrictSlash(true)
myRouter.HandleFunc("/", HomePage)
myRouter.HandleFunc("/feedingTime", CreateNewFeedTime).Methods("POST")
myRouter.HandleFunc("/feedNow", CreateFeedNow).Methods("POST")
myRouter.HandleFunc("/feedingTimes", ReturnAllFeedingTimes).Methods("GET")
myRouter.HandleFunc("/feedingTime/{id}", ReturnSingleFeedingTime).Methods("GET")
log.Fatal(http.ListenAndServe(":6969", myRouter))
Expand Down