-
Notifications
You must be signed in to change notification settings - Fork 1
Phillip/test fileupload #55
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
Codecov Report
|
ldb
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it possible that this PR contains changes from previous branches that were since merged with master? If yes, can you please rebase to remove that excess code? Will continue the review then.
| ### Registration | ||
| - `/api/register` Register a new user. | ||
|
|
||
| ```json |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indentation.
http/courseEntryHandler_test.go
Outdated
| } | ||
|
|
||
| service.StoreCourseEntryFilesFn = func(files [][]byte, id string, date time.Time) (error, []string) { | ||
| if len(files) == 0 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe use a switch construct here?
| privateChain := Chain(protected, Logger(a.Logger), CORS, NewAuthMiddleware(a.UserService)) | ||
| publicChain := Chain(public, Logger(a.Logger), CORS) | ||
| staticChain := Chain(http.FileServer(http.Dir(a.Static)), Logger(a.Logger), CORS) | ||
| filesChain := Chain(http.StripPrefix("/files", http.FileServer(http.Dir(a.Files))), Logger(a.Logger), CORS) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't it be Chain(http.FileServer(http.Dir(a.Files))), http.StripPrefix("/files")...? The first argument of Chain is the final handler.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
http.StripPrefix takes in a string that will be removed from the beginning from the handlers path
So it needs to take in both arguments
4e85910 to
a407051
Compare
| } | ||
|
|
||
| type Uploader interface { | ||
| UploadFile(file []byte, course string, filename string) (error, string) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
error should be the last value returned.
| } | ||
| } | ||
|
|
||
| type Uploader interface { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is this Interface used for? Wasn't the file uploaded to this server?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The interface is used for mocking the upload function in our tests
| return nil, entry | ||
| } | ||
|
|
||
| func (cES CourseEntryService) StoreCourseEntryFiles(files [][]byte, id string, date time.Time) (error, []string) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again, error last.
upload/upload.go
Outdated
| type Uploader struct{} | ||
|
|
||
| func (u *Uploader) UploadFile(file []byte, course string, filename string) (error, string) { | ||
| // check content type |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Leftover?
http/courseEntryHandler.go
Outdated
| } | ||
|
|
||
| pURLs, err := url.URLifyStrings(request.Pictures) | ||
| err, paths := a.CourseEntryService.StoreCourseEntryFiles(request.Pictures, id, request.Date) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems unusual to me. Aren't files usually uploaded using multipart/form-data? Also, what kind of data is the file content here? Is is Base64 encoded? I did not see any decoding in this PR. As a last thought, there is no limit on file size.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the json decoder decodes the base64 encoded bytes-file automagically.
The filesize is not limited yet.
courseEntry.go
Outdated
|
|
||
| type CourseEntryService interface { | ||
| StoreCourseEntry(entry *CourseEntry, cfu CourseFindUpdater) (err error, courseEntry *CourseEntry) | ||
| StoreCourseEntryFiles(files [][]byte, id string, date time.Time) (err error, paths []string) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you think about passing a []io.Reader here instead of [][]byte? That would make any storing / uploading etc way more flexible.
added file upload
it works
I would prefer to not make tests for upload.go for now