package platform import ( "errors" "github.com/gin-gonic/gin" "github.com/google/uuid" "base/internal/application/auth" "base/internal/dto" "base/internal/server/middleware" ) // SetupProfile godoc // @Summary setup profile after registration // @Description complete profile with handle, role, level, and short bio. Requires authentication. // @Tags Platform // @Accept json // @Produce json // @Security Bearer // @Param request body dto.SetupProfileRequest true "setup profile request" // @Success 200 {object} dto.SuccessResponse "success response" // @Failure 400 {object} dto.ErrorResponse "invalid request" // @Failure 401 {object} dto.ErrorResponse "unauthorized" // @Failure 404 {object} dto.ErrorResponse "user not found" // @Failure 409 {object} dto.ErrorResponse "profile already exists or handle already taken" // @Failure 500 {object} dto.ErrorResponse "internal server error" // @Router /api/v1/user/platform/setup-profile [post] func (ctl *Controller) SetupProfile(c *gin.Context) { lg := ctl.logger.With(). Str("module", "platform"). Str("router", "auth"). Str("handler", "SetupProfile"). Logger() userIDVal, exists := c.Get(middleware.UserIDKey) if !exists { r := dto.Unauthorized() c.JSON(r.Status, r) return } userIDStr, ok := userIDVal.(string) if !ok { r := dto.Unauthorized() c.JSON(r.Status, r) return } userID, err := uuid.Parse(userIDStr) if err != nil { r := dto.BadRequest().WithMessage("invalid user ID") c.JSON(r.Status, r) return } var req dto.SetupProfileRequest if !ctl.validateRequest(c, &req) { return } err = ctl.authService.SetupProfile(c.Request.Context(), userID, req) if err != nil { lg.Error().Err(err).Msg("failed to setup profile") switch { case errors.Is(err, auth.ErrProfileAlreadyExists): r := dto.Conflict().WithMessage("profile already exists") c.JSON(r.Status, r) case errors.Is(err, auth.ErrHandleAlreadyTaken): r := dto.Conflict().WithMessage("handle already taken") c.JSON(r.Status, r) case errors.Is(err, auth.ErrUserNotFound): r := dto.NotFound().WithMessage("user not found") c.JSON(r.Status, r) default: r := dto.InternalServerError() c.JSON(r.Status, r) } return } r := dto.OK().WithMessage("profile created successfully") c.JSON(r.Status, r) } // GetUserInfo godoc // @Summary get account info // @Description returns user and profile_id for the authenticated user // @Tags Platform // @Produce json // @Security Bearer // @Success 200 {object} dto.UserInfoResponse "account info" // @Failure 401 {object} dto.ErrorResponse "unauthorized" // @Failure 404 {object} dto.ErrorResponse "user not found" // @Failure 500 {object} dto.ErrorResponse "internal server error" // @Router /api/v1/platform/user/info [get] func (ctl *Controller) GetUserInfo(c *gin.Context) { lg := ctl.logger.With(). Str("module", "platform"). Str("router", "account"). Str("handler", "GetUserInfo"). Logger() userIDVal, exists := c.Get(middleware.UserIDKey) if !exists { r := dto.Unauthorized() c.JSON(r.Status, r) return } userIDStr, ok := userIDVal.(string) if !ok { r := dto.Unauthorized() c.JSON(r.Status, r) return } userID, err := uuid.Parse(userIDStr) if err != nil { r := dto.BadRequest().WithMessage("invalid user ID") c.JSON(r.Status, r) return } info, err := ctl.authService.GetUserInfo(c.Request.Context(), userID) if err != nil { lg.Error().Err(err).Msg("failed to get account info") switch { case errors.Is(err, auth.ErrUserNotFound): r := dto.NotFound().WithMessage("user not found") c.JSON(r.Status, r) default: r := dto.InternalServerError() c.JSON(r.Status, r) } return } r := dto.OK().WithData(info) c.JSON(r.Status, r) }