lot of new functionalities
This commit is contained in:
26
servers/web/api/protected/handler.go
Normal file
26
servers/web/api/protected/handler.go
Normal file
@@ -0,0 +1,26 @@
|
||||
package protected
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"git.coopgo.io/coopgo-apps/parcoursmob/core/application"
|
||||
"github.com/spf13/viper"
|
||||
)
|
||||
|
||||
type Handler struct {
|
||||
apiKey string
|
||||
config *viper.Viper
|
||||
applicationHandler *application.ApplicationHandler
|
||||
}
|
||||
|
||||
func NewHandler(cfg *viper.Viper, appHandler *application.ApplicationHandler) *Handler {
|
||||
return &Handler{
|
||||
apiKey: cfg.GetString("services.api.api_key"),
|
||||
config: cfg,
|
||||
applicationHandler: appHandler,
|
||||
}
|
||||
}
|
||||
|
||||
func (h *Handler) NotFound(w http.ResponseWriter, r *http.Request) {
|
||||
w.WriteHeader(http.StatusNotFound)
|
||||
}
|
||||
29
servers/web/api/protected/users.go
Normal file
29
servers/web/api/protected/users.go
Normal file
@@ -0,0 +1,29 @@
|
||||
package protected
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"git.coopgo.io/coopgo-platform/mobility-accounts/storage"
|
||||
"github.com/rs/zerolog/log"
|
||||
)
|
||||
|
||||
func (h *Handler) RegisterUserHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
var user storage.Account
|
||||
if err := json.NewDecoder(r.Body).Decode(&user); err != nil {
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
result, err := h.applicationHandler.RegisterUser(context.Background(), user)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("Failed to register user")
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
w.WriteHeader(http.StatusOK)
|
||||
json.NewEncoder(w).Encode(result)
|
||||
}
|
||||
Reference in New Issue
Block a user