2018-12-16 16:27:33 +01:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"ExpiryDatesManager/server/model"
|
2018-12-20 20:50:01 +01:00
|
|
|
"ExpiryDatesManager/server/controllers"
|
2019-01-05 16:19:24 +01:00
|
|
|
"ExpiryDatesManager/server/middleware"
|
2018-12-16 16:27:33 +01:00
|
|
|
"fmt"
|
2018-12-20 20:50:01 +01:00
|
|
|
"net/http"
|
|
|
|
"github.com/gorilla/mux"
|
2018-12-16 16:27:33 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
fmt.Printf("hello, world\n")
|
2018-12-20 20:50:01 +01:00
|
|
|
router := mux.NewRouter()
|
2019-01-13 21:09:49 +01:00
|
|
|
|
2019-01-05 16:19:24 +01:00
|
|
|
router.Use(middleware.JwtAuthentication)
|
2018-12-20 20:50:01 +01:00
|
|
|
|
2019-01-13 21:09:49 +01:00
|
|
|
router.Methods("OPTIONS").HandlerFunc(
|
|
|
|
func(w http.ResponseWriter, r *http.Request){
|
|
|
|
})
|
|
|
|
|
2019-01-05 16:19:24 +01:00
|
|
|
router.HandleFunc("/api/login", controllers.Authenticate).Methods("POST")
|
|
|
|
router.HandleFunc("/api/register", controllers.CreateAccount).Methods("POST")
|
|
|
|
router.HandleFunc("/api/products/{code}", controllers.GetProduct).Methods("GET")
|
|
|
|
router.HandleFunc("/api/products", controllers.CreateOrUpdateProduct).Methods("POST")
|
2018-12-20 20:50:01 +01:00
|
|
|
router.HandleFunc("/api/products", controllers.GetProducts).Methods("GET")
|
2019-01-13 21:09:49 +01:00
|
|
|
router.HandleFunc("/api/products/{id}", controllers.DeleteProduct).Methods("DELETE")
|
2018-12-20 20:50:01 +01:00
|
|
|
router.HandleFunc("/api/companies", controllers.GetCompanies).Methods("GET")
|
2019-01-05 16:19:24 +01:00
|
|
|
router.HandleFunc("/api/companies", controllers.CreateOrUpdateCompany).Methods("POST")
|
2019-01-13 21:09:49 +01:00
|
|
|
router.HandleFunc("/api/companies/{id}", controllers.DeleteCompany).Methods("DELETE")
|
2019-01-05 16:19:24 +01:00
|
|
|
router.HandleFunc("/api/reports", controllers.CreateOrUpdateReport).Methods("POST")
|
|
|
|
router.HandleFunc("/api/reports/{companyId}", controllers.GetReportsForCompany).Methods("GET")
|
2019-01-13 21:09:49 +01:00
|
|
|
router.HandleFunc("/api/reportPositions/{reportId}", controllers.GetReportWithPositions).Methods("GET")
|
2019-01-05 16:19:24 +01:00
|
|
|
router.HandleFunc("/api/expiryPositions", controllers.GetPositions).Methods("GET")
|
|
|
|
router.HandleFunc("/api/expiryPositions", controllers.CreateOrUpdatePosition).Methods("POST")
|
2019-01-13 21:09:49 +01:00
|
|
|
router.HandleFunc("/api/expiryPositions/{id}", controllers.DeletePosition).Methods("DELETE")
|
|
|
|
router.HandleFunc("/api/expiryPositions/{companyId}", controllers.GetPositionsForCompany).Methods("GET")
|
2019-01-05 16:19:24 +01:00
|
|
|
router.Handle("/", http.FileServer(http.Dir("../client/build")))
|
|
|
|
router.PathPrefix("/static/").Handler(http.StripPrefix("/static/", http.FileServer(http.Dir("../client/build/static"))))
|
|
|
|
router.PathPrefix("/").Handler(http.StripPrefix("/", http.FileServer(http.Dir("../client/build"))))
|
2018-12-16 16:27:33 +01:00
|
|
|
|
|
|
|
defer model.GetDB().Close()
|
|
|
|
|
2018-12-20 20:50:01 +01:00
|
|
|
err := http.ListenAndServe(":"+"8000", router)
|
|
|
|
if err != nil {
|
|
|
|
fmt.Print(err)
|
|
|
|
}
|
2018-12-16 16:27:33 +01:00
|
|
|
|
2018-12-20 20:50:01 +01:00
|
|
|
fmt.Println("udalo sie")
|
2018-12-16 16:27:33 +01:00
|
|
|
}
|