mirror of
https://github.com/versia-pub/versia-go.git
synced 2026-03-14 04:59:16 +01:00
chore: init
This commit is contained in:
commit
320715f3e7
174 changed files with 42083 additions and 0 deletions
33
internal/handlers/follow_handler/handler.go
Normal file
33
internal/handlers/follow_handler/handler.go
Normal 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)
|
||||
}
|
||||
28
internal/handlers/follow_handler/lysand_follow_get.go
Normal file
28
internal/handlers/follow_handler/lysand_follow_get.go
Normal 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())
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue