chore: init

This commit is contained in:
DevMiner 2024-08-11 03:51:22 +02:00
commit 320715f3e7
174 changed files with 42083 additions and 0 deletions

View file

@ -0,0 +1,33 @@
package follow_handler
import (
"github.com/go-logr/logr"
"github.com/gofiber/fiber/v2"
"github.com/lysand-org/versia-go/config"
"github.com/lysand-org/versia-go/internal/service"
"github.com/lysand-org/versia-go/pkg/webfinger"
)
type Handler struct {
followService service.FollowService
federationService service.FederationService
hostMeta webfinger.HostMeta
log logr.Logger
}
func New(followService service.FollowService, federationService service.FederationService, log logr.Logger) *Handler {
return &Handler{
followService: followService,
federationService: federationService,
hostMeta: webfinger.NewHostMeta(config.C.PublicAddress),
log: log.WithName("users"),
}
}
func (i *Handler) Register(r fiber.Router) {
r.Get("/api/follows/:id", i.GetLysandFollow)
}

View file

@ -0,0 +1,28 @@
package follow_handler
import (
"github.com/gofiber/fiber/v2"
"github.com/google/uuid"
"github.com/lysand-org/versia-go/internal/api_schema"
)
func (i *Handler) GetLysandFollow(c *fiber.Ctx) error {
parsedRequestedFollowID, err := uuid.Parse(c.Params("id"))
if err != nil {
return api_schema.ErrBadRequest(map[string]any{"reason": "Invalid follow ID"})
}
f, err := i.followService.GetFollow(c.UserContext(), parsedRequestedFollowID)
if err != nil {
i.log.Error(err, "Failed to query follow", "id", parsedRequestedFollowID)
return api_schema.ErrInternalServerError(map[string]any{"reason": "Failed to query follow"})
}
if f == nil {
return c.Status(fiber.StatusNotFound).JSON(fiber.Map{
"error": "Follow not found",
})
}
return c.JSON(f.ToLysand())
}