Feat(ktm-booking): Initial commit
Some checks failed
ktm-booking-bot/ktm-booking-bot/pipeline/head Something is wrong with the build of this commit

This commit is contained in:
2022-09-27 02:50:07 +08:00
commit 7cf10b07d4
44 changed files with 4569 additions and 0 deletions

View File

@@ -0,0 +1,45 @@
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))
}