Skip to content

Commit 11d7db4

Browse files
authored
modified uploads (#265)
1 parent 61bc60f commit 11d7db4

File tree

2 files changed

+21
-6
lines changed

2 files changed

+21
-6
lines changed

backend/endpoints/models/volume_models.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@ type (
1818

1919
// ValidImageUploadRequest is the request model for an handler that uploads an IMAGE to a docker volume
2020
ValidDocumentUploadRequest struct {
21-
DocumentID uuid.UUID `schema:"DocumentID,required"`
22-
Content string `schema:"Content,required"` // TODO: Add check that content is valid JSON
21+
Parent uuid.UUID `schema:"Parent,required"`
22+
DocumentName string `schema:"DocumentName,required"`
23+
Content string `schema:"Content,required"` // TODO: Add check that content is valid JSON
2324
}
2425

2526
// ValidPublishDocumentRequest is the request model for any handler that publishes a document

backend/endpoints/volume_endpoints.go

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,27 @@ func UploadImage(form ValidImageUploadRequest, df DependencyFactory) handlerResp
5757
// UploadImage takes an image from a request and uploads it to the published docker volume
5858
func UploadDocument(form ValidDocumentUploadRequest, df DependencyFactory) handlerResponse[NewEntityResponse] {
5959
unpublishedVol := df.GetUnpublishedVolumeRepo()
60+
fsRepo := df.GetFilesystemRepo()
6061
log := df.GetLogger()
6162

6263
// fetch the target file form the unpublished volume
63-
filename := form.DocumentID.String()
64-
file, err := unpublishedVol.GetFromVolume(filename)
64+
entityToCreate := repositories.FilesystemEntry{
65+
LogicalName: form.DocumentName, ParentFileID: form.Parent,
66+
IsDocument: true, OwnerUserId: 1,
67+
}
68+
69+
entity, err := fsRepo.CreateEntry(entityToCreate)
6570
if err != nil {
66-
log.Write(fmt.Sprintf("failed to get file: %s from volume", filename))
71+
log.Write("failed to create a repository entry")
72+
log.Write(err.Error())
73+
return handlerResponse[NewEntityResponse]{
74+
Status: http.StatusNotAcceptable,
75+
}
76+
}
77+
78+
file, err := unpublishedVol.GetFromVolume(entity.EntityID.String())
79+
if err != nil {
80+
log.Write(fmt.Sprintf("failed to get file: %s from volume", entity.EntityID.String()))
6781
log.Write(err.Error())
6882
return handlerResponse[NewEntityResponse]{
6983
Status: http.StatusNotFound,
@@ -80,7 +94,7 @@ func UploadDocument(form ValidDocumentUploadRequest, df DependencyFactory) handl
8094
}
8195

8296
return handlerResponse[NewEntityResponse]{
83-
Response: NewEntityResponse{NewID: form.DocumentID},
97+
Response: NewEntityResponse{NewID: entity.EntityID},
8498
Status: http.StatusOK,
8599
}
86100
}

0 commit comments

Comments
 (0)