Delete rooms done
This commit is contained in:
@@ -92,3 +92,28 @@ func handlePartialVoteArea(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
renderTemplate(w, "vote-area", data)
|
||||
}
|
||||
|
||||
func handleDeleteRoom(w http.ResponseWriter, r *http.Request) {
|
||||
roomID := getRoomID(r)
|
||||
user := r.Context().Value(userKey).(*lib.User)
|
||||
|
||||
room, err := lib.GetRoomByID(roomID)
|
||||
if err != nil {
|
||||
http.Error(w, "room not found", http.StatusNotFound)
|
||||
return
|
||||
}
|
||||
|
||||
if room.OwnerID != user.ID {
|
||||
http.Error(w, "unauthorized", http.StatusUnauthorized)
|
||||
return
|
||||
}
|
||||
|
||||
err = lib.DeleteRoom(roomID)
|
||||
if err != nil {
|
||||
log.Printf("delete room error: %v", err)
|
||||
http.Error(w, "failed to delete room", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
w.WriteHeader(http.StatusOK)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user