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.

46 lines
1.4 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("/user", getUsers).Methods("GET")
  24. router.HandleFunc("/user", createUser).Methods("POST")
  25. router.HandleFunc("/user/{userID}", getUser).Methods("GET")
  26. router.HandleFunc("/user/{userID}", updatePost).Methods("PUT")
  27. router.HandleFunc("/user/{userID}", deletePost).Methods("DELETE")
  28. // Define routes for authentication
  29. router.HandleFunc("/admin/login", Auth.Login).Methods("POST")
  30. router.HandleFunc("/admin/logout", Auth.Logout).Methods("GET")
  31. //router.PathPrefix("/").Handler(http.StripPrefix("/images/", http.FileServer(http.Dir("./uploads"))))
  32. return router
  33. }