2024-08-11 03:51:22 +02:00
|
|
|
package user_handler
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"github.com/gofiber/fiber/v2"
|
|
|
|
|
"github.com/google/uuid"
|
|
|
|
|
"github.com/lysand-org/versia-go/internal/api_schema"
|
|
|
|
|
)
|
|
|
|
|
|
2024-08-27 19:59:12 +02:00
|
|
|
func (i *Handler) GetVersiaUser(c *fiber.Ctx) error {
|
2024-08-11 03:51:22 +02:00
|
|
|
parsedRequestedUserID, err := uuid.Parse(c.Params("id"))
|
|
|
|
|
if err != nil {
|
|
|
|
|
return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{
|
|
|
|
|
"error": "Invalid user ID",
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-27 02:11:26 +02:00
|
|
|
u, err := i.userService.GetLocalUserByID(c.UserContext(), parsedRequestedUserID)
|
2024-08-11 03:51:22 +02:00
|
|
|
if err != nil {
|
|
|
|
|
i.log.Error(err, "Failed to query user", "id", parsedRequestedUserID)
|
|
|
|
|
|
|
|
|
|
return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{
|
|
|
|
|
"error": "Failed to query user",
|
|
|
|
|
"id": parsedRequestedUserID,
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
if u == nil {
|
|
|
|
|
return api_schema.ErrNotFound(map[string]any{"id": parsedRequestedUserID})
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-27 19:59:12 +02:00
|
|
|
if err := i.requestSigner.SignAndSend(c, u.Signer, u.ToVersia()); err != nil {
|
|
|
|
|
i.log.Error(err, "Failed to sign response body", "id", parsedRequestedUserID)
|
|
|
|
|
|
|
|
|
|
return api_schema.ErrInternalServerError(map[string]any{
|
|
|
|
|
"reason": "failed to sign response body",
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return nil
|
2024-08-11 03:51:22 +02:00
|
|
|
}
|