Skip to content
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

Phillip/test fileupload #55

Open
wants to merge 21 commits into
base: master
Choose a base branch
from
Open

Phillip/test fileupload #55

wants to merge 21 commits into from

Conversation

phiphi282
Copy link
Contributor

@phiphi282 phiphi282 commented Jun 28, 2018

added file upload

it works

I would prefer to not make tests for upload.go for now

@phiphi282 phiphi282 requested a review from ldb June 28, 2018 23:07
@codecov
Copy link

codecov bot commented Jun 28, 2018

Codecov Report

Merging #55 into master will increase coverage by 0.29%.
The diff coverage is 91.66%.

Impacted Files Coverage Δ
http/server.go 0% <0%> (ø) ⬆️
service/courseEntryService/courseEntryService.go 75% <100%> (+7.25%) ⬆️
http/courseEntryHandler.go 67.5% <100%> (+2.63%) ⬆️
config/config.go 100% <100%> (ø) ⬆️

Copy link
Contributor

@ldb ldb left a 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.

README.md Outdated
@@ -33,13 +33,180 @@ You can start it over the command line (your container name might be different f

### Registration
- `/api/register` Register a new user.

```json
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indentation.

@@ -35,6 +37,20 @@ func TestAppServer_PostCourseEntryHandler(t *testing.T) {
}
return nil, entry
}

service.StoreCourseEntryFilesFn = func(files [][]byte, id string, date time.Time) (error, []string) {
if len(files) == 0 {
Copy link
Contributor

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?

@@ -26,11 +28,13 @@ func (a *AppServer) initialize() {
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)
Copy link
Contributor

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.

Copy link
Contributor Author

@phiphi282 phiphi282 Jun 29, 2018

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

}
}

type Uploader interface {
UploadFile(file []byte, course string, filename string) (error, string)
Copy link
Contributor

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 {
Copy link
Contributor

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?

Copy link
Contributor Author

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

@@ -39,6 +48,18 @@ func (cES CourseEntryService) StoreCourseEntry(entry *eduboard.CourseEntry, cfu
return nil, entry
}

func (cES CourseEntryService) StoreCourseEntryFiles(files [][]byte, id string, date time.Time) (error, []string) {
Copy link
Contributor

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Leftover?

@@ -43,9 +43,17 @@ func (a *AppServer) PostCourseEntryHandler() httprouter.Handle {
return
}

pURLs, err := url.URLifyStrings(request.Pictures)
err, paths := a.CourseEntryService.StoreCourseEntryFiles(request.Pictures, id, request.Date)
Copy link
Contributor

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.

Copy link
Contributor Author

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
@@ -46,6 +46,7 @@ type CourseEntryDeleter interface {

type CourseEntryService interface {
StoreCourseEntry(entry *CourseEntry, cfu CourseFindUpdater) (err error, courseEntry *CourseEntry)
StoreCourseEntryFiles(files [][]byte, id string, date time.Time) (err error, paths []string)
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants