feat(attachments): add upload, metadata and content endpoints
This commit is contained in:
@@ -97,16 +97,19 @@ func Run() error {
|
||||
userService := service.NewUserService(queries)
|
||||
chatService := service.NewChatService(pool, queries)
|
||||
messageService := service.NewMessageService(pool, queries)
|
||||
attachmentService := service.NewAttachmentService(queries, s3Client, cfg.S3.MaxUploadBytes, cfg.S3.MaxImagePixels)
|
||||
|
||||
router := NewRouter(
|
||||
log,
|
||||
cfg.Server.InstanceID,
|
||||
cfg.Server.MaxInflightRequests,
|
||||
cfg.S3.MaxUploadBytes,
|
||||
pool,
|
||||
authService,
|
||||
userService,
|
||||
chatService,
|
||||
messageService,
|
||||
attachmentService,
|
||||
)
|
||||
|
||||
server := &http.Server{
|
||||
|
||||
@@ -16,11 +16,13 @@ func NewRouter(
|
||||
log *slog.Logger,
|
||||
instanceID string,
|
||||
maxInflightRequests int,
|
||||
maxUploadBytes int,
|
||||
db handler.Pinger,
|
||||
authService *service.AuthService,
|
||||
userService *service.UserService,
|
||||
chatService *service.ChatService,
|
||||
messageService *service.MessageService,
|
||||
attachmentService *service.AttachmentService,
|
||||
) http.Handler {
|
||||
router := chi.NewRouter()
|
||||
|
||||
@@ -29,6 +31,7 @@ func NewRouter(
|
||||
userHandler := handler.NewUserHandler(userService)
|
||||
chatHandler := handler.NewChatHandler(chatService)
|
||||
messageHandler := handler.NewMessageHandler(messageService)
|
||||
attachmentHandler := handler.NewAttachmentHandler(attachmentService, maxUploadBytes)
|
||||
|
||||
router.Use(middleware.InstanceID(instanceID))
|
||||
router.Use(middleware.RequestTimeout(5 * time.Second))
|
||||
@@ -55,6 +58,10 @@ func NewRouter(
|
||||
|
||||
r.Post("/api/v1/chats/{chat_id}/messages", messageHandler.Create)
|
||||
r.Get("/api/v1/chats/{chat_id}/messages", messageHandler.List)
|
||||
|
||||
r.Post("/api/v1/chats/{chat_id}/attachments", attachmentHandler.Upload)
|
||||
r.Get("/api/v1/attachments/{attachment_id}", attachmentHandler.Get)
|
||||
r.Get("/api/v1/attachments/{attachment_id}/content", attachmentHandler.GetContent)
|
||||
})
|
||||
|
||||
router.Handle("/swagger/*", http.StripPrefix("/swagger/", http.FileServer(http.Dir("web/swagger"))))
|
||||
|
||||
Reference in New Issue
Block a user