@@ -57,13 +57,27 @@ func UploadImage(form ValidImageUploadRequest, df DependencyFactory) handlerResp
57
57
// UploadImage takes an image from a request and uploads it to the published docker volume
58
58
func UploadDocument (form ValidDocumentUploadRequest , df DependencyFactory ) handlerResponse [NewEntityResponse ] {
59
59
unpublishedVol := df .GetUnpublishedVolumeRepo ()
60
+ fsRepo := df .GetFilesystemRepo ()
60
61
log := df .GetLogger ()
61
62
62
63
// 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 )
65
70
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 ()))
67
81
log .Write (err .Error ())
68
82
return handlerResponse [NewEntityResponse ]{
69
83
Status : http .StatusNotFound ,
@@ -80,7 +94,7 @@ func UploadDocument(form ValidDocumentUploadRequest, df DependencyFactory) handl
80
94
}
81
95
82
96
return handlerResponse [NewEntityResponse ]{
83
- Response : NewEntityResponse {NewID : form . DocumentID },
97
+ Response : NewEntityResponse {NewID : entity . EntityID },
84
98
Status : http .StatusOK ,
85
99
}
86
100
}
0 commit comments