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.6 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(router *mux.Router) {
  8. var (
  9. api *mux.Router
  10. )
  11. log.Println("Initializing API routes...")
  12. api = router.PathPrefix("/api/v1/").Subrouter()
  13. // Define routes for posts api
  14. api.HandleFunc("/post", getPosts).Methods("GET")
  15. api.HandleFunc("/post", createPost).Methods("POST")
  16. api.HandleFunc("/post/{postID}", getPost).Methods("GET")
  17. api.HandleFunc("/post/{postID}", updatePost).Methods("PUT")
  18. api.HandleFunc("/post/{postID}", deletePost).Methods("DELETE")
  19. api.HandleFunc("/frontPagePosts", getFrontPagePosts).Methods("GET")
  20. api.HandleFunc("/post/{postID}/image", createPostImage).Methods("POST")
  21. api.HandleFunc("/post/{postID}/image/{imageID}", deletePostImage).Methods("DELETE")
  22. // Define routes for users api
  23. api.HandleFunc("/admin/user", getUsers).Methods("GET")
  24. api.HandleFunc("/admin/user", createUser).Methods("POST")
  25. api.HandleFunc("/admin/user/{userID}", getUser).Methods("GET")
  26. api.HandleFunc("/admin/user/{userID}", updateUser).Methods("PUT")
  27. api.HandleFunc("/admin/user/{userID}", deletePost).Methods("DELETE")
  28. api.HandleFunc("/admin/user/{userID}/update-password", Auth.UpdatePassword).Methods("PUT")
  29. // Define routes for authentication
  30. api.HandleFunc("/admin/login", Auth.Login).Methods("POST")
  31. api.HandleFunc("/admin/logout", Auth.Logout).Methods("GET")
  32. api.HandleFunc("/admin/me", Auth.Me).Methods("GET")
  33. //router.PathPrefix("/").Handler(http.StripPrefix("/images/", http.FileServer(http.Dir("./uploads"))))
  34. }