moviedb/backend/delViews.go

61 lines
1.3 KiB
Go

package main
import (
"fmt"
"net/http"
"strconv"
"github.com/gorilla/mux"
)
func delOneMovie(w http.ResponseWriter, r *http.Request) {
movieIDstr := mux.Vars(r)["id"]
movieID, err := strconv.Atoi(movieIDstr)
if err != nil {
fmt.Fprintf(w, "Error: invalid movie ID passed")
return
}
err = db.DeleteMovie(movieID)
if err != nil {
fmt.Fprintf(w, "Error deleting movie")
return
}
fmt.Fprintf(w, "Movie deleted succesfully")
}
func delOneTag(w http.ResponseWriter, r *http.Request) {
tagIDstr := mux.Vars(r)["id"]
tagID, err := strconv.Atoi(tagIDstr)
if err != nil {
fmt.Fprintf(w, "Error: invalid tag ID passed")
return
}
err = db.DeleteTag(tagID)
if err != nil {
fmt.Fprintf(w, "Error deleting tag")
return
}
fmt.Fprintf(w, "Tag deleted succesfully")
}
func delTaggedMovie(w http.ResponseWriter, r *http.Request) {
movieIDstr := mux.Vars(r)["mid"]
tagIDstr := mux.Vars(r)["tid"]
movieID, err := strconv.Atoi(movieIDstr)
if err != nil {
fmt.Fprintf(w, "Error: invalid movie ID passed")
return
}
tagID, err := strconv.Atoi(tagIDstr)
if err != nil {
fmt.Fprintf(w, "Error: invalid tag ID passed")
return
}
err = db.UnTagMovie(tagID, movieID)
if err != nil {
fmt.Fprintf(w, "Error untagging movie")
return
}
fmt.Fprintf(w, "Untagged movie")
}