You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

47 lines
1.5 KiB

  1. package Api
  2. import (
  3. "log"
  4. "git.tovijaeschke.xyz/tovi/SuddenImpactRecords/Api/Auth"
  5. "github.com/gorilla/mux"
  6. )
  7. func InitApiEndpoints() *mux.Router {
  8. var (
  9. router *mux.Router
  10. )
  11. log.Println("Initializing API routes...")
  12. router = mux.NewRouter()
  13. // Define routes for posts api
  14. router.HandleFunc("/post", getPosts).Methods("GET")
  15. router.HandleFunc("/post", createPost).Methods("POST")
  16. router.HandleFunc("/post/{postID}", getPost).Methods("GET")
  17. router.HandleFunc("/post/{postID}", updatePost).Methods("PUT")
  18. router.HandleFunc("/post/{postID}", deletePost).Methods("DELETE")
  19. router.HandleFunc("/frontPagePosts", getFrontPagePosts).Methods("GET")
  20. router.HandleFunc("/post/{postID}/image", createPostImage).Methods("POST")
  21. router.HandleFunc("/post/{postID}/image/{imageID}", deletePostImage).Methods("DELETE")
  22. // Define routes for users api
  23. router.HandleFunc("/admin/user", getUsers).Methods("GET")
  24. router.HandleFunc("/admin/user", createUser).Methods("POST")
  25. router.HandleFunc("/admin/user/{userID}", getUser).Methods("GET")
  26. router.HandleFunc("/admin/user/{userID}", updatePost).Methods("PUT")
  27. router.HandleFunc("/admin/user/{userID}", deletePost).Methods("DELETE")
  28. router.HandleFunc("/admin/user/{userID}/update-password", Auth.UpdatePassword).Methods("PUT")
  29. // Define routes for authentication
  30. router.HandleFunc("/admin/login", Auth.Login).Methods("POST")
  31. router.HandleFunc("/admin/logout", Auth.Logout).Methods("GET")
  32. //router.PathPrefix("/").Handler(http.StripPrefix("/images/", http.FileServer(http.Dir("./uploads"))))
  33. return router
  34. }