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

Feature/weos 1378 #150

Merged
merged 43 commits into from
Mar 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
98f105b
doc: WEOS-1378 Started work on file upload spec
akeemphilbert Feb 26, 2022
e9abed6
feature: WEOS-1378 Added more scenarios to File Upload
akeemphilbert Mar 4, 2022
fe75905
Merge branch 'dev' into feature/WEOS-1378
RandyDeo Mar 9, 2022
0ec5733
test: Integration test for Update
RandyDeo Mar 9, 2022
79e4267
test: Integration test for Update
RandyDeo Mar 9, 2022
1203144
feature: WEOS-1378
RandyDeo Mar 15, 2022
cf58d30
Merge branch 'dev' into feature/WEOS-1378
RandyDeo Mar 15, 2022
9140b03
Merge branch 'feature/WEOS-1378' into WEOS-1394
RandyDeo Mar 15, 2022
3e786a0
feature: WEOS-1342
RandyDeo Mar 15, 2022
26f7cd0
feature: WEOS-1378
RandyDeo Mar 16, 2022
20d2da0
feature: WEOS-1378
RandyDeo Mar 16, 2022
1065b84
feature: WEOS-1378
RandyDeo Mar 16, 2022
070bc4e
Merge branch 'dev' into feature/WEOS-1378
RandyDeo Mar 16, 2022
dcd7509
Merge branch 'feature/WEOS-1378' into WEOS-1394
RandyDeo Mar 16, 2022
6c52976
feature: WEOS-1378
RandyDeo Mar 16, 2022
00cef2a
feature: WEOS-1378 As a developer I should be able to set a middlewar…
shaniah868 Mar 16, 2022
af216f8
feature: WEOS-1378
RandyDeo Mar 17, 2022
1680e05
feature: WEOS-1378
RandyDeo Mar 18, 2022
96b7769
feature: WEOS-1378
RandyDeo Mar 21, 2022
11a7ea2
feature: WEOS-1378
RandyDeo Mar 21, 2022
87ba1c9
Merge branch 'dev' into feature/WEOS-1378
RandyDeo Mar 21, 2022
b36f3a7
Merge branch 'dev' into WEOS-1394
RandyDeo Mar 21, 2022
f62313a
feature: WEOS-1378
RandyDeo Mar 21, 2022
f2afb20
feature: WEOS-1378
RandyDeo Mar 21, 2022
6cfac1c
Merge branch 'feature/WEOS-1378' into WEOS-1394
RandyDeo Mar 21, 2022
6b54de1
Merge pull request #146 from wepala/WEOS-1394
shaniah868 Mar 21, 2022
b84ef01
Merge branch 'dev' into feature/WEOS-1378
RandyDeo Mar 22, 2022
7eeb762
feature: WEOS-1378
RandyDeo Mar 22, 2022
7d7ef1a
feature: WEOS-1378
RandyDeo Mar 22, 2022
82bb428
feature: WEOS-1378
RandyDeo Mar 22, 2022
4359b79
feature: WEOS-1378 As a developer I should be able to set a middlewar…
shaniah868 Mar 22, 2022
3bad2bc
feature: WEOS-1378 As a developer I should be able to set a middlewar…
shaniah868 Mar 22, 2022
d5cab32
feature: WEOS-1378
RandyDeo Mar 22, 2022
9b3978f
feature:WEOS-1378
RandyDeo Mar 25, 2022
7dd2292
feature:WEOS-1378
RandyDeo Mar 25, 2022
f4960d9
feature:WEOS-1378
RandyDeo Mar 25, 2022
ed86494
Merge branch 'dev' into feature/WEOS-1378
RandyDeo Mar 25, 2022
7905068
Merge branch 'dev' into feature/WEOS-1378
RandyDeo Mar 28, 2022
1c4f99e
feature:WEOS-1378
RandyDeo Mar 28, 2022
57a86ab
feature:WEOS-1378
RandyDeo Mar 28, 2022
a99c928
feature:WEOS-1378
RandyDeo Mar 28, 2022
3006112
feature:WEOS-1378
RandyDeo Mar 28, 2022
d46eeba
feature:WEOS-1378
RandyDeo Mar 29, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ components:
type: string
description:
type: string
x-upload:
folder: ./files
limit: 10000
active:
type: boolean
status:
Expand Down Expand Up @@ -759,3 +762,25 @@ paths:
responses:
200:
description: Delete author

/files:
get:
operationId: getFiles
responses:
200:
description: Files
x-folder: "./files"
post:
operationId: uploadFile
requestBody:
content:
multipart/form-data:
schema:
type: string
format: binary
x-upload:
folder: "./files"
limit: 1000
responses:
201:
description: File successfully uploaded
1 change: 1 addition & 0 deletions context/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ const AUTHORIZATION string = "Authorization"
const ACCEPT string = "Accept"
const CONTENT_TYPE_RESPONSE string = "_content_type_response"
const BASIC_RESPONSE string = "_basic_response"
const UPLOAD_RESPONSE string = "_upload_response"

//Path initializers are run per path and can be used to configure routes that are not defined in the open api spec
const METHODS_FOUND ContextKey = "_methods_found"
Expand Down
37 changes: 33 additions & 4 deletions controllers/rest/controller_standard.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,17 @@ func CreateMiddleware(api *RESTAPI, projection projections.Projection, commandDi
return func(ctxt echo.Context) error {
//look up the schema for the content type so that we could identify the rules
newContext := ctxt.Request().Context()

uploadResponse := newContext.Value(weoscontext.UPLOAD_RESPONSE)
if uploadResponse != nil {
if uploadErr, ok := uploadResponse.(*echo.HTTPError); ok {
if uploadErr.Error() != "" {
ctxt.Logger().Error(uploadErr)
return uploadErr
}
}
}

if entityFactory != nil {
newContext = context.WithValue(newContext, weoscontext.ENTITY_FACTORY, entityFactory)
} else {
Expand Down Expand Up @@ -689,6 +700,8 @@ func DefaultResponseMiddleware(api *RESTAPI, projection projections.Projection,
}

fileName := ""
folderFound := true
folderErr := ""
var templates []string

if api.Swagger != nil {
Expand All @@ -703,7 +716,9 @@ func DefaultResponseMiddleware(api *RESTAPI, projection projections.Projection,
} else {
_, err = os.Stat(folderPath)
if os.IsNotExist(err) {
api.e.Logger.Warnf("error finding folder: '%s' specified on path: '%s'", folderPath, pathName)
folderFound = false
folderErr = "error finding folder: " + folderPath + " specified on path: " + pathName
api.e.Logger.Errorf(folderErr)
} else if err != nil {
api.e.Logger.Error(err)
} else {
Expand Down Expand Up @@ -743,6 +758,10 @@ func DefaultResponseMiddleware(api *RESTAPI, projection projections.Projection,

return func(next echo.HandlerFunc) echo.HandlerFunc {
return func(ctxt echo.Context) error {
if !folderFound {
api.e.Logger.Errorf(folderErr)
return NewControllerError(folderErr, nil, http.StatusNotFound)
}
ctx := ctxt.Request().Context()
if activatedResponse {
var responseType *CResponseType
Expand Down Expand Up @@ -886,10 +905,20 @@ func DefaultResponseController(api *RESTAPI, projection projections.Projection,
return func(context echo.Context) error {
newContext := context.Request().Context()
value := newContext.Value(weoscontext.BASIC_RESPONSE)
if value == nil {
return nil
uploadResponse := newContext.Value(weoscontext.UPLOAD_RESPONSE)

if uploadResponse == nil {
if value == nil {
return nil
}
return NewControllerError(value.(error).Error(), value.(error), http.StatusBadRequest)
} else {
if err, ok := uploadResponse.(*echo.HTTPError); ok {
return err
}
return context.JSON(http.StatusCreated, "File successfully Uploaded")
}
return value.(error)

}
}

Expand Down
2 changes: 0 additions & 2 deletions controllers/rest/fixtures/blog-integration.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,6 @@ components:
type: string
description:
type: string
author:
$ref: "#/components/schemas/Author"
created:
type: string
format: date-time
Expand Down
Loading