2024-08-11 03:51:22 +02:00
|
|
|
package user_handler
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"github.com/go-logr/logr"
|
|
|
|
|
"github.com/gofiber/fiber/v2"
|
|
|
|
|
"github.com/lysand-org/versia-go/internal/service"
|
|
|
|
|
"github.com/lysand-org/versia-go/internal/validators"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type Handler struct {
|
|
|
|
|
federationService service.FederationService
|
2024-08-20 22:43:26 +02:00
|
|
|
requestSigner service.RequestSigner
|
|
|
|
|
|
|
|
|
|
userService service.UserService
|
|
|
|
|
inboxService service.InboxService
|
2024-08-11 03:51:22 +02:00
|
|
|
|
|
|
|
|
bodyValidator validators.BodyValidator
|
|
|
|
|
requestValidator validators.RequestValidator
|
|
|
|
|
|
|
|
|
|
log logr.Logger
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-20 22:43:26 +02:00
|
|
|
func New(federationService service.FederationService, requestSigner service.RequestSigner, userService service.UserService, inboxService service.InboxService, bodyValidator validators.BodyValidator, requestValidator validators.RequestValidator, log logr.Logger) *Handler {
|
2024-08-11 03:51:22 +02:00
|
|
|
return &Handler{
|
|
|
|
|
federationService: federationService,
|
2024-08-20 22:43:26 +02:00
|
|
|
requestSigner: requestSigner,
|
|
|
|
|
|
|
|
|
|
userService: userService,
|
|
|
|
|
inboxService: inboxService,
|
2024-08-11 03:51:22 +02:00
|
|
|
|
|
|
|
|
bodyValidator: bodyValidator,
|
|
|
|
|
requestValidator: requestValidator,
|
|
|
|
|
|
|
|
|
|
log: log,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (i *Handler) Register(r fiber.Router) {
|
|
|
|
|
// TODO: Handle this differently
|
|
|
|
|
// There might be other routes that might want to also add their stuff to the robots.txt
|
|
|
|
|
r.Get("/robots.txt", i.RobotsTXT)
|
|
|
|
|
|
|
|
|
|
r.Get("/.well-known/webfinger", i.Webfinger)
|
|
|
|
|
|
2024-08-27 00:41:10 +02:00
|
|
|
r.Get("/api/app/users/search", i.SearchUser)
|
2024-08-11 03:51:22 +02:00
|
|
|
r.Get("/api/app/users/:id", i.GetUser)
|
|
|
|
|
r.Post("/api/app/users/", i.CreateUser)
|
|
|
|
|
|
|
|
|
|
r.Get("/api/users/:id", i.GetLysandUser)
|
|
|
|
|
r.Post("/api/users/:id/inbox", i.LysandInbox)
|
|
|
|
|
}
|