add Upload and Download files

This commit is contained in:
2026-07-12 18:05:52 +07:00
parent 2ecc6ecd6a
commit 487b1aa436
13 changed files with 854 additions and 63 deletions
+35
View File
@@ -2,12 +2,15 @@ package app
import (
"context"
"evening_detective_server/internal/modules/file_storage"
"evening_detective_server/internal/modules/processor_jwt"
"evening_detective_server/internal/modules/roles"
"evening_detective_server/internal/services/file_service"
"evening_detective_server/internal/services/ui_service"
"evening_detective_server/internal/services/users_service"
proto "evening_detective_server/proto"
"google.golang.org/genproto/googleapis/api/httpbody"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)
@@ -17,15 +20,18 @@ type server struct {
usersService *users_service.UsersService
uiService *ui_service.UiService
fileService *file_service.FileService
}
func NewServer(
usersService *users_service.UsersService,
uiService *ui_service.UiService,
fileService *file_service.FileService,
) proto.EveningDetectiveServerServer {
return &server{
usersService: usersService,
uiService: uiService,
fileService: fileService,
}
}
@@ -167,3 +173,32 @@ func (s *server) GetPermissions(
Permissions: permissions,
}, nil
}
func (s *server) UploadFile(ctx context.Context, req *proto.UploadFileReq) (*proto.UploadFileRsp, error) {
filename, err := s.fileService.UploadFile(
ctx,
&file_storage.File{
Name: req.Filename,
Data: req.Data,
},
)
if err != nil {
return &proto.UploadFileRsp{
Error: err.Error(),
}, nil
}
return &proto.UploadFileRsp{
Filename: filename,
}, nil
}
func (s *server) DownloadFile(ctx context.Context, req *proto.DownloadFileReq) (*httpbody.HttpBody, error) {
file, err := s.fileService.DownloadFile(ctx, req.Filename)
if err != nil {
return &httpbody.HttpBody{}, nil
}
return &httpbody.HttpBody{
Data: file.Data,
ContentType: file.Mime,
}, nil
}