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 1505 #173

Merged
merged 56 commits into from
Jun 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
97a5702
feature: WEOS-1505 reduce reliance on dynamic struct library
akeemphilbert May 2, 2022
a1e6e77
feature: WEOS-1507
akeemphilbert May 8, 2022
54ce1d9
feature: WEOS-1508 Fix broken tests
akeemphilbert May 10, 2022
c3dcf9c
feature: WEOS-1508 Fix broken tests
akeemphilbert May 11, 2022
7799128
feature: WEOS-1508 Fix broken tests
akeemphilbert May 11, 2022
f3dc744
bug: Fix issue where couldn't create item because a property was an o…
akeemphilbert May 16, 2022
09eb98a
bug: Fix issue getting entity by key and weos id
akeemphilbert May 16, 2022
0f7be37
bug: Fix issue where the entity was not correctly pulled from the con…
akeemphilbert May 16, 2022
2866659
bug: Return map instead of the entity on the view
akeemphilbert May 16, 2022
0daf398
bug: Fixed domain service tests
akeemphilbert May 17, 2022
eb34a3b
bug: Added test to show that adding event handlers to default event s…
akeemphilbert May 17, 2022
7fb1cdc
bug: Fixed 1 test
akeemphilbert May 17, 2022
89f0b21
bug: Fix issue where the content entity returns it's own id
akeemphilbert May 17, 2022
599416f
bug: Fix issue where entity was not being updated
akeemphilbert May 17, 2022
788e43f
bug: Add debug statement to update handler
akeemphilbert May 18, 2022
0e3302f
bug: Fix for update using the wrong entity id
akeemphilbert May 18, 2022
15f3188
bug: Fix for serving files when api is deployed on a sub path
akeemphilbert May 18, 2022
77ced9e
bug: Fixed issue where get by methods were returning an entity when t…
akeemphilbert May 18, 2022
a79b7cd
bug: Fixed for date parsing
akeemphilbert May 26, 2022
49ae6b1
WEOS-1505
akeemphilbert May 28, 2022
a835c38
WEOS-1505 Fixed issue with replacing associations
akeemphilbert May 28, 2022
817fd72
WEOS-1505 Fixed issues with sequence no not being returned
akeemphilbert May 29, 2022
2252ca7
WEOS-1505 Fixed issues with view content
akeemphilbert May 29, 2022
fc8ff40
WEOS-1505 Fixed issues with delete
akeemphilbert May 29, 2022
9e7c935
WEOS-1505 Fixed edit content issues
akeemphilbert May 29, 2022
34fc436
WEOS-1505 Fixed test fixtures
akeemphilbert May 29, 2022
8dd4c3f
WEOS-1505 Fixed remaining security tests
akeemphilbert May 29, 2022
1cb0b6e
WEOS-1505 Made setting up payload recursive
akeemphilbert May 29, 2022
49c5005
WEOS-1505 Fixed test that checks that collection is saved correctly
akeemphilbert May 29, 2022
3e989eb
WEOS-1505 Fixed integration test for postgres
akeemphilbert May 30, 2022
6fac409
WEOS-1505 Fixed integration test for postgres
akeemphilbert May 30, 2022
bb6c349
WEOS-1505 Fixed for gorm projection test for postgres
akeemphilbert May 30, 2022
8145fc7
WEOS-1505 Preload associations when an entity returned
akeemphilbert May 30, 2022
1663c43
feature: Make it so that list could be filtered by related property p…
akeemphilbert May 30, 2022
43e4e28
feature: Fixed route log output from showing up multiple times
akeemphilbert May 30, 2022
081557e
fix: Fix base path so it can be used on a sub path
akeemphilbert May 30, 2022
cefa67d
fix: Fix base path so it can be used on a sub path
akeemphilbert May 30, 2022
c2061de
fix: Fix base path so it can be used on a sub path
akeemphilbert May 30, 2022
f71b322
feature: WEOS-1509
akeemphilbert Jun 3, 2022
bc4ca3a
feature: WEOS-1509 Debugging issue saving associations
akeemphilbert Jun 4, 2022
d9530a0
feature: WEOS-1509 Deprecate initializing builders in initializers
akeemphilbert Jun 4, 2022
ed4e6d3
feature: WEOS-1509 Fixing issues after updating to new GORM model gen…
akeemphilbert Jun 5, 2022
24644d9
feature: WEOS-1509 Fixing issues after updating to new GORM model gen…
akeemphilbert Jun 5, 2022
568e798
feature: WEOS-1509 Limit the depth that is rendered
akeemphilbert Jun 6, 2022
881efbe
feature: WEOS-1509 Limit the depth that is rendered
akeemphilbert Jun 6, 2022
475d6ba
feature: WEOS-1509 Limit the depth that is rendered
akeemphilbert Jun 6, 2022
88315df
feature: WEOS-1509 Limit the depth that is rendered
akeemphilbert Jun 8, 2022
b6fdb56
feature: WEOS-1509 Fix property (and table row) casing issue
akeemphilbert Jun 8, 2022
40bc93d
feature: WEOS-1509 Skip test that is only failing in the pipeline
akeemphilbert Jun 8, 2022
e652ce6
feature: WEOS-1509 Skip test because contenttypeby entity id is depre…
akeemphilbert Jun 8, 2022
530acab
feature: WEOS-1505 fix issues in mysql
akeemphilbert Jun 9, 2022
a403b4a
feature: WEOS-1505 fix issues in mysql
akeemphilbert Jun 9, 2022
6a8716d
feature: WEOS-1505 fix issues in mysql
akeemphilbert Jun 9, 2022
22af306
feature: WEOS-1505 turned off tests for mysql since the issues seems …
akeemphilbert Jun 9, 2022
f295585
feature: WEOS-1505
akeemphilbert Jun 9, 2022
0f2960f
feature: WEOS-1505
akeemphilbert Jun 9, 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
8 changes: 4 additions & 4 deletions .github/workflows/dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ jobs:
run: go test -v ./...
- name: Run Postgres end to end tests
run: go test -v -driver=postgres
- name: Run MySQL end to end tests
run: go test -v -driver=mysql
# - name: Run MySQL end to end tests
# run: go test -v -driver=mysql
- name: Run Postgres projections tests
run: go test -v ./projections -driver=postgres
- name: Run Mysql projections tests
run: go test -v ./projections -driver=mysql
# - name: Run Mysql projections tests
# run: go test -v ./projections -driver=mysql
- uses: crazy-max/ghaction-xgo@v1
name: build linux and mac
with:
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ jobs:
run: go test -v ./...
- name: Run Postgres end to end tests
run: go test -v -driver=postgres
- name: Run MySQL end to end tests
run: go test -v -driver=mysql
# - name: Run MySQL end to end tests
# run: go test -v -driver=mysql
- name: Run Postgres projections tests
run: go test -v ./projections -driver=postgres
- name: Run Mysql projections tests
run: go test -v ./projections -driver=mysql
# - name: Run Mysql projections tests
# run: go test -v ./projections -driver=mysql
- uses: crazy-max/ghaction-xgo@v1
name: build linux and mac
with:
Expand Down
16 changes: 8 additions & 8 deletions controllers/rest/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -336,16 +336,16 @@ func (p *RESTAPI) RegisterDefaultSwaggerAPI(pathMiddleware []echo.MiddlewareFunc
return NewControllerError("Got an error formatting response", err, http.StatusInternalServerError)
}
static := http.FileServer(statikFS)
sh := http.StripPrefix(SWAGGERUIENDPOINT, static)
sh := http.StripPrefix(p.Config.BasePath+SWAGGERUIENDPOINT, static)
handler := echo.WrapHandler(sh)
p.e.GET(SWAGGERUIENDPOINT+"*", handler, pathMiddleware...)
p.e.GET(p.Config.BasePath+SWAGGERUIENDPOINT+"*", handler, pathMiddleware...)

return nil
}

//RegisterDefaultSwaggerJson registers a default swagger json response
func (p *RESTAPI) RegisterDefaultSwaggerJSON(pathMiddleware []echo.MiddlewareFunc) error {
p.e.GET(SWAGGERJSONENDPOINT, func(c echo.Context) error {
p.e.GET(p.Config.BasePath+SWAGGERJSONENDPOINT, func(c echo.Context) error {
return c.JSON(http.StatusOK, p.Swagger)
}, pathMiddleware...)
return nil
Expand Down Expand Up @@ -484,10 +484,10 @@ func (p *RESTAPI) Initialize(ctxt context.Context) error {
for _, initializer := range p.GetPostPathInitializers() {
globalContext, err = initializer(globalContext, p, path, p.Swagger, pathData)
}
//output registered endpoints for debugging purposes
for _, route := range p.EchoInstance().Routes() {
p.EchoInstance().Logger.Debugf("Registered routes '%s' '%s'", route.Method, route.Path)
}
}
//output registered endpoints for debugging purposes
for _, route := range p.EchoInstance().Routes() {
p.EchoInstance().Logger.Debugf("Registered routes '%s' '%s'", route.Method, route.Path)
}
return err
}
Expand Down Expand Up @@ -570,7 +570,7 @@ func (p *RESTAPI) SQLConnectionFromConfig(config *model.DBConfig) (*sql.DB, *gor
case "mysql":
gormDB, err = gorm.Open(dialects.NewMySQL(mysql.Config{
Conn: db,
}), nil)
}), &gorm.Config{DisableForeignKeyConstraintWhenMigrating: true})
if err != nil {
return nil, nil, err
}
Expand Down
5 changes: 3 additions & 2 deletions controllers/rest/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,11 @@ func TestRESTAPI_Initialize_CreateAddedToPost(t *testing.T) {
body := bytes.NewReader(reqBytes)
resp := httptest.NewRecorder()
req := httptest.NewRequest(http.MethodPost, "/blogs", body)
req.Header.Set("Content-Type", "application/json")
e.ServeHTTP(resp, req)
//confirm that the response is not 404
if resp.Result().StatusCode == http.StatusNotFound {
t.Errorf("expected the response code to not be %d, got %d", http.StatusNotFound, resp.Result().StatusCode)
if resp.Result().StatusCode != http.StatusCreated {
t.Errorf("expected the response code to be %d, got %d", http.StatusCreated, resp.Result().StatusCode)
}
os.Remove("test.db")
time.Sleep(1 * time.Second)
Expand Down
78 changes: 29 additions & 49 deletions controllers/rest/controller_standard.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ func CreateMiddleware(api *RESTAPI, projection projections.Projection, commandDi
}
return NewControllerError(errr.Error(), err, http.StatusBadRequest)
} else {
ctxt.Logger().Debugf("error creating content type '%s'", err)
return NewControllerError("unexpected error creating content type", err, http.StatusBadRequest)
}
}
Expand All @@ -97,7 +98,9 @@ func CreateController(api *RESTAPI, projection projections.Projection, commandDi
if err != nil {
return err
}
Etag = NewEtag(result)
if result != nil {
Etag = NewEtag(result)
}
}
if result == nil {
return NewControllerError("No entity found", err, http.StatusNotFound)
Expand Down Expand Up @@ -126,6 +129,7 @@ func CreateBatchMiddleware(api *RESTAPI, projection projections.Projection, comm

err := commandDispatcher.Dispatch(newContext, model.CreateBatch(newContext, payload, entityFactory.Name()), eventSource, projection, ctxt.Logger())
if err != nil {
ctxt.Logger().Debugf("error creating batch '%s", err)
if errr, ok := err.(*model.DomainError); ok {
return NewControllerError(errr.Error(), err, http.StatusBadRequest)
} else {
Expand Down Expand Up @@ -210,7 +214,6 @@ func UpdateController(api *RESTAPI, projection projections.Projection, commandDi
var Etag string
var identifiers []string
var result *model.ContentEntity
var result1 map[string]interface{}
newContext := ctxt.Request().Context()
weosID := newContext.Value(weoscontext.ENTITY_ID)
if weosID == nil || weosID == "" {
Expand All @@ -231,31 +234,28 @@ func UpdateController(api *RESTAPI, projection projections.Projection, commandDi

}

result1, err = projection.GetByKey(newContext, entityFactory, primaryKeys)
result, err = projection.GetByKey(newContext, entityFactory, primaryKeys)
if err != nil {
return err
}
weos_id, ok := result1["weos_id"].(string)
sequenceString := fmt.Sprint(result1["sequence_no"])
weos_id := result.ID
sequenceString := fmt.Sprint(result.SequenceNo)
sequenceNo, _ := strconv.Atoi(sequenceString)
Etag = NewEtag(&model.ContentEntity{
AggregateRoot: model.AggregateRoot{
SequenceNo: int64(sequenceNo),
BasicEntity: model.BasicEntity{ID: weos_id},
},
})
if (len(result1) == 0) || !ok || weos_id == "" {
if result == nil {
return NewControllerError("No entity found", err, http.StatusNotFound)
} else if err != nil {
return NewControllerError(err.Error(), err, http.StatusBadRequest)
}
delete(result1, "sequence_no")
delete(result1, "weos_id")
delete(result1, "table_alias")

ctxt.Response().Header().Set("Etag", Etag)

return ctxt.JSON(http.StatusOK, result1)
return ctxt.JSON(http.StatusOK, result)
} else {
if projection != nil {

Expand All @@ -274,7 +274,7 @@ func UpdateController(api *RESTAPI, projection projections.Projection, commandDi
entity := map[string]interface{}{}
result.ID = ""
result.SequenceNo = 0
bytes, err := json.Marshal(result.Property)
bytes, err := json.Marshal(result)
if err != nil {
return err
}
Expand Down Expand Up @@ -340,7 +340,7 @@ func ViewMiddleware(api *RESTAPI, projection projections.Projection, commandDisp
identifiers[p] = newContext.Value(p)
}

var result map[string]interface{}
var result *model.ContentEntity
var err error
var entityID string
var seq string
Expand Down Expand Up @@ -378,9 +378,9 @@ func ViewMiddleware(api *RESTAPI, projection projections.Projection, commandDisp
return NewControllerError("Invalid sequence number", err, http.StatusBadRequest)
}
//if sequence no. was sent in the request but we don't have the entity let's get it from projection
if entityID == "" && seqInt != 0 {
entityID, ok = result["weos_id"].(string)
if !ok {
if entityID == "" && seqInt != 0 && result != nil {
entityID = result.ID
if entityID == "" {
ctxt.Logger().Debugf("the item '%v' does not have an entity id stored", identifiers)
}
}
Expand Down Expand Up @@ -413,26 +413,24 @@ func ViewMiddleware(api *RESTAPI, projection projections.Projection, commandDisp
return NewControllerError("No entity found", err, http.StatusNotFound)
}
if r != nil && r.ID != "" { //get the map from the entity
result = r.ToMap()
result = r
}
result["weos_id"] = r.ID
result["sequence_no"] = r.SequenceNo
err = er
if err == nil && r.SequenceNo < int64(seqInt) && etag != "" { //if the etag is set then let's return the header
return ctxt.JSON(http.StatusNotModified, r.Property)
return ctxt.JSON(http.StatusNotModified, r.ToMap())
}
} else {
//get entity by entity_id

if projection != nil {
result, err = projection.GetByEntityID(ctxt.Request().Context(), entityFactory, entityID)
result, err = projection.GetContentEntity(ctxt.Request().Context(), entityFactory, entityID)
}

}
}

//add result to context
newContext = context.WithValue(newContext, weoscontext.ENTITY, result) //TODO store the entity instead (this requires the different projection calls to return entities)
newContext = context.WithValue(newContext, weoscontext.ENTITY, result)
request := ctxt.Request().WithContext(newContext)
ctxt.SetRequest(request)
return next(ctxt)
Expand All @@ -446,8 +444,6 @@ func ViewController(api *RESTAPI, projection projections.Projection, commandDisp
newContext := ctxt.Request().Context()

var err error
var weosID string
var ok bool

if err = weoscontext.GetError(newContext); err != nil {
return NewControllerError("Error occurred", err, http.StatusBadRequest)
Expand All @@ -462,27 +458,11 @@ func ViewController(api *RESTAPI, projection projections.Projection, commandDisp
if entity == nil {
return NewControllerError("No entity found", err, http.StatusNotFound)
}
if weosID, ok = entity["weos_id"].(string); !ok {
return NewControllerError("No entity found", err, http.StatusNotFound)
}
sequenceString := fmt.Sprint(entity["sequence_no"])
sequenceNo, _ := strconv.Atoi(sequenceString)

etag := NewEtag(&model.ContentEntity{
AggregateRoot: model.AggregateRoot{
SequenceNo: int64(sequenceNo),
BasicEntity: model.BasicEntity{ID: weosID},
},
})

//remove sequence number and weos_id from response
delete(entity, "weos_id")
delete(entity, "sequence_no")
delete(entity, "table_alias")
etag := NewEtag(entity)

//set etag
ctxt.Response().Header().Set("Etag", etag)
return ctxt.JSON(http.StatusOK, entity)
return ctxt.JSON(http.StatusOK, entity.ToMap())
}
}

Expand All @@ -509,8 +489,9 @@ func ListMiddleware(api *RESTAPI, projection projections.Projection, commandDisp
msg := "this operator " + values.(*FilterProperties).Operator + " does not support multiple values "
return NewControllerError(msg, nil, http.StatusBadRequest)
}
// checking if the field is valid based on schema provided
if schema.Properties[key] == nil {
// checking if the field is valid based on schema provided, split on "."
parts := strings.Split(key, ".")
if schema.Properties[parts[0]] == nil {
if key == "id" && schema.ExtensionProps.Extensions[IdentifierExtension] == nil {
continue
}
Expand Down Expand Up @@ -596,8 +577,7 @@ func DeleteMiddleware(api *RESTAPI, projection projections.Projection, commandDi

var err error
var identifiers []string
var result1 map[string]interface{}
var ok bool
var result1 *model.ContentEntity

//Uses the identifiers to pull the weosID, to be later used to get Seq NO
if etagInterface == nil {
Expand Down Expand Up @@ -625,16 +605,16 @@ func DeleteMiddleware(api *RESTAPI, projection projections.Projection, commandDi
}

}
weosID, ok = result1["weos_id"].(string)
weosID = result1.ID

if (len(result1) == 0) || !ok || weosID == "" {
if result1 == nil || weosID == "" {
return NewControllerError("No entity found", err, http.StatusNotFound)
} else if err != nil {
return NewControllerError(err.Error(), err, http.StatusBadRequest)
}
}

//Dispatch the actual delete to projecitons
//Dispatch the actual delete to projections
err = commandDispatcher.Dispatch(newContext, model.Delete(newContext, entityFactory.Name(), weosID), eventSource, projection, ctxt.Logger())
if err != nil {
if errr, ok := err.(*model.DomainError); ok {
Expand Down Expand Up @@ -722,7 +702,7 @@ func DefaultResponseMiddleware(api *RESTAPI, projection projections.Projection,
} else if err != nil {
api.e.Logger.Error(err)
} else {
api.e.Static(pathName, folderPath)
api.e.Static(api.Config.BasePath+pathName, folderPath)
}
}
}
Expand Down
Loading