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.

50 lines
1.8 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. api.HandleFunc("/posts/front-page", getFrontPagePosts).Methods("GET")
  14. api.HandleFunc("/post", getPostsPublic).Methods("GET")
  15. api.HandleFunc("/post/{postID}", getPostPublic).Methods("GET")
  16. // Define routes for posts api
  17. api.HandleFunc("/admin/post", getPosts).Methods("GET")
  18. api.HandleFunc("/admin/post/{postID}", getPost).Methods("GET")
  19. api.HandleFunc("/admin/post", createPost).Methods("POST")
  20. api.HandleFunc("/admin/post/{postID}", updatePost).Methods("PUT")
  21. api.HandleFunc("/admin/post/{postID}", deletePost).Methods("DELETE")
  22. api.HandleFunc("/admin/post/{postID}/publish", publishPost).Methods("GET")
  23. api.HandleFunc("/admin/post/{postID}/image", createPostImage).Methods("POST")
  24. api.HandleFunc("/admin/post/{postID}/image/{imageID}", deletePostImage).Methods("DELETE")
  25. // Define routes for users api
  26. api.HandleFunc("/admin/user", getUsers).Methods("GET")
  27. api.HandleFunc("/admin/user", createUser).Methods("POST")
  28. api.HandleFunc("/admin/user/{userID}", getUser).Methods("GET")
  29. api.HandleFunc("/admin/user/{userID}", updateUser).Methods("PUT")
  30. api.HandleFunc("/admin/user/{userID}", deletePost).Methods("DELETE")
  31. api.HandleFunc("/admin/user/{userID}/update-password", Auth.UpdatePassword).Methods("PUT")
  32. // Define routes for authentication
  33. api.HandleFunc("/admin/login", Auth.Login).Methods("POST")
  34. api.HandleFunc("/admin/logout", Auth.Logout).Methods("GET")
  35. api.HandleFunc("/admin/me", Auth.Me).Methods("GET")
  36. //router.PathPrefix("/").Handler(http.StripPrefix("/images/", http.FileServer(http.Dir("./uploads"))))
  37. }