add save batch endpoint to file service

This commit is contained in:
Asim Aslam
2021-05-23 18:10:00 +01:00
parent 025a0036a8
commit 2bcbf256fe
4 changed files with 269 additions and 94 deletions

View File

@@ -75,6 +75,27 @@ func (e *File) Save(ctx context.Context, req *file.SaveRequest, rsp *file.SaveRe
log.Info("Received File.Save request")
// prefix the tenant
req.File.Id = tenantId + "/" + req.File.Id
req.File.Project = tenantId + "/" + req.File.Project
// create the file
err := e.db.Create(req.File)
if err != nil {
return err
}
return nil
}
func (e *File) BatchSave(ctx context.Context, req *file.BatchSaveRequest, rsp *file.BatchSaveResponse) error {
tenantId, ok := tenant.FromContext(ctx)
if !ok {
tenantId = "micro"
}
log.Info("Received File.BatchSave request")
for _, reqFile := range req.Files {
// prefix the tenant
reqFile.Id = tenantId + "/" + reqFile.Id
@@ -90,6 +111,7 @@ func (e *File) Save(ctx context.Context, req *file.SaveRequest, rsp *file.SaveRe
return nil
}
func (e *File) List(ctx context.Context, req *file.ListRequest, rsp *file.ListResponse) error {
log.Info("Received File.List request")
@@ -116,6 +138,10 @@ func (e *File) List(ctx context.Context, req *file.ListRequest, rsp *file.ListRe
file.Id = strings.TrimPrefix(file.Id, tenantId+"/")
file.Project = strings.TrimPrefix(file.Project, tenantId+"/")
// strip the file contents
// no file listing ever contains it
file.Data = ""
// if requesting all files or path matches
if req.Path == "" || strings.HasPrefix(file.Path, req.Path) {
rsp.Files = append(rsp.Files, file)