delete users
This commit is contained in:
		@ -779,3 +779,17 @@ func (app *application) EditUser(w http.ResponseWriter, r *http.Request) {
 | 
			
		||||
	resp.OK = true
 | 
			
		||||
	app.writeJSON(w, http.StatusOK, resp)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (app *application) DeleteUser(w http.ResponseWriter, r *http.Request) {
 | 
			
		||||
	id := chi.URLParam(r, "id")
 | 
			
		||||
	userID, _ := strconv.Atoi(id)
 | 
			
		||||
	err := app.DB.DeleteUser(userID)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		app.errorLog.Println(err)
 | 
			
		||||
		app.badRequest(w, r, err)
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
	var resp jsonResponse
 | 
			
		||||
	resp.OK = true
 | 
			
		||||
	app.writeJSON(w, http.StatusOK, resp)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -40,6 +40,7 @@ func (app *application) routes() http.Handler {
 | 
			
		||||
		mux.Post("/all-users", app.AllUsers)
 | 
			
		||||
		mux.Post("/all-users/{id}", app.OneUser)
 | 
			
		||||
		mux.Post("/all-users/edit/{id}", app.EditUser)
 | 
			
		||||
		mux.Post("/all-users/delete/{id}", app.DeleteUser)
 | 
			
		||||
	})
 | 
			
		||||
	mux.Post("/api/forgot-password", app.SendPasswordResetEmail)
 | 
			
		||||
	mux.Post("/api/reset-password", app.ResetPassword)
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user