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.
45 lines
1.2 KiB
45 lines
1.2 KiB
package user
|
|
|
|
import (
|
|
"errors"
|
|
"net/http"
|
|
|
|
"git.samuelpua.com/telboon/ktm-train-bot/backend/internal/common"
|
|
"github.com/go-chi/render"
|
|
)
|
|
|
|
// Set current user profile
|
|
// @Summary For setting current user profile
|
|
// @Description Description
|
|
// @Tags User
|
|
// @Accept json
|
|
// @Produce json
|
|
// @Param user body ProfileRequest true "User registration info"
|
|
// @Success 200 {object} UserResponse
|
|
// @Failure 400 {object} common.ErrResponse
|
|
// @Router /api/v1/user/profile [put]
|
|
func (env *Env) setProfileRouteHandler(w http.ResponseWriter, r *http.Request) {
|
|
ctx := r.Context()
|
|
|
|
data := &ProfileRequest{}
|
|
err := render.DecodeJSON(r.Body, data)
|
|
if err != nil {
|
|
render.Render(w, r, common.ErrInvalidRequest(err))
|
|
return
|
|
}
|
|
|
|
currUser, ok := ctx.Value(UserContextKey).(*User)
|
|
if !ok {
|
|
err := errors.New("user not logged in")
|
|
render.Render(w, r, common.ErrInternalError(err))
|
|
return
|
|
}
|
|
|
|
currUser, err = env.setProfile(currUser, data.KtmTrainUsername, data.KtmTrainPassword, data.KtmTrainCreditCardType, data.KtmTrainCreditCard, data.KtmTrainCreditCardExpiry, data.KtmTrainCreditCardCVV)
|
|
if err != nil {
|
|
render.Render(w, r, common.ErrInternalError(err))
|
|
return
|
|
}
|
|
|
|
render.Render(w, r, env.NewUserResponse(currUser))
|
|
}
|