Base générale d'UI
This commit is contained in:
46
internal/route/board.go
Normal file
46
internal/route/board.go
Normal file
@ -0,0 +1,46 @@
|
||||
package route
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"forge.cadoles.com/wpetit/gitea-kan/internal/repository"
|
||||
"github.com/pkg/errors"
|
||||
"gitlab.com/wpetit/goweb/middleware/container"
|
||||
)
|
||||
|
||||
func serveBoards(w http.ResponseWriter, r *http.Request) {
|
||||
ctn := container.Must(r.Context())
|
||||
repo := repository.Must(ctn)
|
||||
|
||||
boards, err := repo.Boards().List()
|
||||
if err != nil {
|
||||
panic(errors.Wrap(err, "could not retrieve boards list"))
|
||||
}
|
||||
|
||||
encoder := json.NewEncoder(w)
|
||||
if err := encoder.Encode(boards); err != nil {
|
||||
panic(errors.Wrap(err, "could not encode boards list"))
|
||||
}
|
||||
}
|
||||
|
||||
func saveBoard(w http.ResponseWriter, r *http.Request) {
|
||||
ctn := container.Must(r.Context())
|
||||
repo := repository.Must(ctn)
|
||||
|
||||
decoder := json.NewDecoder(r.Body)
|
||||
board := &repository.Board{}
|
||||
|
||||
if err := decoder.Decode(board); err != nil {
|
||||
panic(errors.Wrap(err, "could not decode board"))
|
||||
}
|
||||
|
||||
if err := repo.Boards().Save(board); err != nil {
|
||||
panic(errors.Wrap(err, "could not save board"))
|
||||
}
|
||||
|
||||
encoder := json.NewEncoder(w)
|
||||
if err := encoder.Encode(board); err != nil {
|
||||
panic(errors.Wrap(err, "could not encode board"))
|
||||
}
|
||||
}
|
@ -6,8 +6,6 @@ import (
|
||||
"net/http/httputil"
|
||||
"net/url"
|
||||
|
||||
"github.com/davecgh/go-spew/spew"
|
||||
|
||||
"forge.cadoles.com/wpetit/gitea-kan/internal/config"
|
||||
"forge.cadoles.com/wpetit/gitea-kan/internal/middleware"
|
||||
"github.com/pkg/errors"
|
||||
@ -32,12 +30,13 @@ func proxyAPIRequest(w http.ResponseWriter, r *http.Request) {
|
||||
accessToken := sess.Get(middleware.SessionOAuth2AccessToken)
|
||||
|
||||
proxy := httputil.NewSingleHostReverseProxy(apiBaseURL)
|
||||
proxy.Director = func(r *http.Request) {
|
||||
r.Host = apiBaseURL.Host
|
||||
r.URL.Scheme = apiBaseURL.Scheme
|
||||
r.URL.Host = apiBaseURL.Host
|
||||
r.Header.Add("Authorization", fmt.Sprintf("token %s", accessToken))
|
||||
spew.Dump(r)
|
||||
proxy.Director = func(rr *http.Request) {
|
||||
rr.Host = apiBaseURL.Host
|
||||
rr.URL.Scheme = apiBaseURL.Scheme
|
||||
rr.URL.Host = apiBaseURL.Host
|
||||
rr.Method = r.Method
|
||||
rr.Header.Add("Accept", "application/json")
|
||||
rr.Header.Add("Authorization", fmt.Sprintf("token %s", accessToken))
|
||||
}
|
||||
|
||||
proxy.ServeHTTP(w, r)
|
||||
|
@ -19,7 +19,9 @@ func Mount(r *chi.Mux, config *config.Config) {
|
||||
r.Group(func(r chi.Router) {
|
||||
r.Use(middleware.Authenticate)
|
||||
r.Get("/logout", handleLogout)
|
||||
r.Get("/gitea/api/*", http.StripPrefix("/gitea", http.HandlerFunc(proxyAPIRequest)).ServeHTTP)
|
||||
r.Get("/api/boards", serveBoards)
|
||||
r.Post("/api/boards", saveBoard)
|
||||
r.Handle("/gitea/api/*", http.StripPrefix("/gitea", http.HandlerFunc(proxyAPIRequest)))
|
||||
r.Get("/*", static.Dir(config.HTTP.PublicDir, "", html5PushStateHandler))
|
||||
})
|
||||
})
|
||||
|
Reference in New Issue
Block a user