From 086dec8cc3a95ac5a47f5c41d2393298f7b0dfed Mon Sep 17 00:00:00 2001 From: MacRae Linton <55759+macrael@users.noreply.github.com> Date: Thu, 21 Mar 2019 18:06:24 -0700 Subject: [PATCH 01/14] Get testing setup right for all the clear yes nos. tests don't pass in this commit, but the framework is there --- api/account.go | 22 +- api/admin/reject.go | 34 + api/collection.go | 23 +- api/database.go | 20 + api/history.go | 29 +- api/identification.go | 54 +- api/integration/clear_yes_no_test.go | 230 ++++++ .../form_version_test.go | 92 +-- .../mux_test.go | 2 +- api/integration/sections/history.go | 729 ++++++++++++++++++ api/integration/sections/identification.go | 293 +++++++ api/integration/setup.go | 146 ++++ api/postgresql/db.go | 10 +- docker-compose.yml | 4 +- 14 files changed, 1587 insertions(+), 101 deletions(-) create mode 100644 api/admin/reject.go create mode 100644 api/integration/clear_yes_no_test.go rename api/{integration_test => integration}/form_version_test.go (56%) rename api/{integration_test => integration}/mux_test.go (98%) create mode 100644 api/integration/sections/history.go create mode 100644 api/integration/sections/identification.go create mode 100644 api/integration/setup.go diff --git a/api/account.go b/api/account.go index d064fcbd2..09ba14173 100644 --- a/api/account.go +++ b/api/account.go @@ -1,8 +1,9 @@ package api import ( - "errors" "fmt" + + "github.com/pkg/errors" ) var ( @@ -187,3 +188,22 @@ func (entity *Account) BasicAuthentication(context DatabaseService, password str } return nil } + +// ClearNoBranches clears all the branches answered "No" that must be +// re answered after rejection +func (entity *Account) ClearNoBranches(context DatabaseService) error { + + // Identification.OtherNames + err := ClearIdentificationOtherNamesNos(context, entity.ID) + if err != nil { + return err + } + + // Your History + err = ClearHistoryResidenceNos(context, entity.ID) + if err != nil { + return err + } + + return nil +} diff --git a/api/admin/reject.go b/api/admin/reject.go new file mode 100644 index 000000000..94ab31b17 --- /dev/null +++ b/api/admin/reject.go @@ -0,0 +1,34 @@ +package admin + +import ( + "fmt" + + "github.com/pkg/errors" + + "github.com/18F/e-QIP-prototype/api" +) + +type Rejector struct { + DB api.DatabaseService + PDF api.PdfService +} + +func (r Rejector) Reject(account api.Account) error { + err := account.Unlock(r.DB) + if err != nil { + return errors.Wrap(err, "Reject failed to unlock account") + } + + // TODO: port over PDF.RemovePdfs. + // err = r.PDF.RemovePdfs(account) + // if err != nil { + // return errors.Wrap(err, "Reject failed to remove PDFs") + // } + + err = account.ClearNoBranches(r.DB) + if err != nil { + return errors.Wrap(err, "Reject failed to clear the no branches") + } + + return nil +} diff --git a/api/collection.go b/api/collection.go index ac5ba40ae..68e68e2a4 100644 --- a/api/collection.go +++ b/api/collection.go @@ -2,6 +2,9 @@ package api import ( "encoding/json" + "fmt" + + "github.com/pkg/errors" ) // Collection represents a structure composed of zero or more items. @@ -91,8 +94,8 @@ func (entity *Collection) Save(context DatabaseService, account int) (int, error return entity.ID, err } - // Custom errors - if entity.PayloadBranch.Type != "" { + // Only save the branch if it exists. + if entity.PayloadBranch.Type != "" || entity.Branch != nil { branchID, err := entity.Branch.Save(context, account) if err != nil { return 0, err @@ -388,6 +391,22 @@ func (ci CollectionItem) Each(action func(string, string, Entity, error) error) return err } +func (ci CollectionItem) GetItem(key string) (Entity, error) { + + item, ok := ci.Item[key] + if !ok { + return nil, errors.New(fmt.Sprintf("Key %s does not exist in collection item %s", key, ci.Name)) + } + + _, entity, err := getItemEntity(item) + if err != nil { + return nil, err + } + + return entity, nil + +} + // getItemEntity marshals a raw JSON format to a entity func getItemEntity(raw json.RawMessage) (string, Entity, error) { // Decode JSON to a payload diff --git a/api/database.go b/api/database.go index 67efc9b53..f6ffc3162 100644 --- a/api/database.go +++ b/api/database.go @@ -1,5 +1,25 @@ package api +import ( + "github.com/pkg/errors" +) + +type DatabaseErrorNotFound string + +func (d DatabaseErrorNotFound) Error() string { + return string(d) +} + +func IsDatabaseErrorNotFound(err error) bool { + _, valueOk := errors.Cause(err).(DatabaseErrorNotFound) + _, pointerOk := errors.Cause(err).(*DatabaseErrorNotFound) + + if valueOk || pointerOk { + return true + } + return false +} + // DatabaseService represents a persisted data storage. type DatabaseService interface { Configure() diff --git a/api/history.go b/api/history.go index abc9bc3e5..297575ef0 100644 --- a/api/history.go +++ b/api/history.go @@ -1,6 +1,10 @@ package api -import "encoding/json" +import ( + "encoding/json" + + "github.com/pkg/errors" +) // HistoryResidence represents the payload for the history residence section. type HistoryResidence struct { @@ -140,6 +144,29 @@ func (entity *HistoryResidence) Find(context DatabaseService) error { return nil } +func ClearHistoryResidenceNos(context DatabaseService, accountID int) error { + residence := HistoryResidence{} + _, err := residence.Get(context, accountID) + if err != nil { + if IsDatabaseErrorNotFound(err) { + return nil + } + return errors.Wrap(err, "Failed to clear nos: unable to load residence") + } + + if residence.List != nil && residence.List.Branch != nil { + if residence.List.Branch.Value == "No" { + residence.List.Branch.Value = "" + _, err = residence.Save(context, accountID) + if err != nil { + return errors.Wrap(err, "Failed to clear nos: unable to save residence") + } + } + } + + return nil +} + // HistoryEmployment represents the payload for the history employment section. type HistoryEmployment struct { PayloadList Payload `json:"List" sql:"-"` diff --git a/api/identification.go b/api/identification.go index c8e5492db..5e4ab7144 100644 --- a/api/identification.go +++ b/api/identification.go @@ -2,6 +2,8 @@ package api import ( "encoding/json" + + "github.com/pkg/errors" ) // IdentificationName represents the payload for the identification name section. @@ -602,19 +604,19 @@ func (entity *IdentificationSSN) Find(context DatabaseService) error { // IdentificationContacts represents the payload for the identification contact information section. type IdentificationContacts struct { - PayloadHomeEmail Payload `json:"HomeEmail" sql:"-"` - PayloadWorkEmail Payload `json:"WorkEmail" sql:"-"` + PayloadHomeEmail Payload `json:"HomeEmail" sql:"-"` + PayloadWorkEmail Payload `json:"WorkEmail" sql:"-"` PayloadPhoneNumbers Payload `json:"PhoneNumbers" sql:"-"` // Validator specific fields - HomeEmail *Email `json:"-"` - WorkEmail *Email `json:"-"` + HomeEmail *Email `json:"-"` + WorkEmail *Email `json:"-"` PhoneNumbers *Collection `json:"-"` // Persister specific fields ID int `json:"-"` - HomeEmailID int `json:"-" pg:", fk:HomeEmail"` - WorkEmailID int `json:"-" pg:", fk:WorkEmail"` + HomeEmailID int `json:"-" pg:", fk:HomeEmail"` + WorkEmailID int `json:"-" pg:", fk:WorkEmail"` PhoneNumbersID int `json:"-" pg:", fk:PhoneNumbers"` } @@ -957,7 +959,7 @@ func (entity *IdentificationOtherNames) Get(context DatabaseService, account int return entity.ID, err } - if entity.ID != 0 { + if entity.ID != 0 { // DUMB, we just set it to account above, so unless you are calling this with a null account.......... if err := context.Select(entity); err != nil { return entity.ID, err } @@ -1008,6 +1010,44 @@ func (entity *IdentificationOtherNames) Find(context DatabaseService) error { return nil } +func ClearIdentificationOtherNamesNos(context DatabaseService, accountID int) error { + otherNames := IdentificationOtherNames{} + _, err := otherNames.Get(context, accountID) + if err != nil { + if IsDatabaseErrorNotFound(err) { + return nil + } + return errors.Wrap(err, "Unable to load Other Names") + } + + otherNamesModified := false + if otherNames.HasOtherNames != nil { + if otherNames.HasOtherNames.Value == "No" { + otherNames.HasOtherNames.Value = "" + otherNamesModified = true + } else { + // the last thing in the list will be another branch, which must also be cleared. + if otherNames.List != nil { + if otherNames.List.Branch != nil { + if otherNames.List.Branch.Value == "No" { + otherNames.List.Branch.Value = "" + otherNamesModified = true + } + } + } + } + } + + if otherNamesModified { + _, err = otherNames.Save(context, accountID) + if err != nil { + return errors.Wrap(err, "Unable to save Other Names") + } + } + + return nil +} + // IdentificationPhysical represents the payload for the identification physical traits section. type IdentificationPhysical struct { PayloadComments Payload `json:"Comments" sql:"-"` diff --git a/api/integration/clear_yes_no_test.go b/api/integration/clear_yes_no_test.go new file mode 100644 index 000000000..edece1c3d --- /dev/null +++ b/api/integration/clear_yes_no_test.go @@ -0,0 +1,230 @@ +package integration + +import ( + "testing" + + "github.com/18F/e-QIP-prototype/api" + "github.com/18F/e-QIP-prototype/api/admin" + "github.com/18F/e-QIP-prototype/api/integration/sections" +) + +func TestClearEmptyAccount(t *testing.T) { + // get a setup environment. + services := cleanTestServices() + + account, err := createTestAccount(services.db) + if err != nil { + t.Fatal("couldn't create account", err) + } + + rejector := admin.Rejector{ + DB: services.db, + } + + err = rejector.Reject(account) + if err != nil { + t.Fatal("Failed to reject account: ", err) + } + +} + +func TestClearInformation(t *testing.T) { + + // get a setup environment. + services := cleanTestServices() + + account, err := createTestAccount(services.db) + if err != nil { + t.Fatal("couldn't create account", err) + } + + // Test top level no + resp := saveJSON(services, sections.IDOtherNamesNo, account.ID) + if resp.StatusCode != 200 { + t.Fatal("Failed to save topLevelNoJSON", resp.StatusCode) + } + + rejector := admin.Rejector{ + DB: services.db, + } + err = rejector.Reject(account) + if err != nil { + t.Fatal("Failed to reject account: ", err) + } + + // check that the no is no longer set. + resetNames := api.IdentificationOtherNames{} + _, err = resetNames.Get(services.db, account.ID) + if err != nil { + t.Fatal("couldn't reload other names", err) + } + if resetNames.HasOtherNames.Value != "" { + t.Fatal("OtherNames was not reset") + } + + // Test list no + resp = saveJSON(services, sections.IDOtherNamesYes, account.ID) + if resp.StatusCode != 200 { + t.Fatal("Failed to save listNoJSON", resp.StatusCode) + } + + err = rejector.Reject(account) + if err != nil { + t.Fatal("Failed to reject account: ", err) + } + + // check that the no is no longer set. + resetNames = api.IdentificationOtherNames{} + _, err = resetNames.Get(services.db, account.ID) + if err != nil { + t.Fatal("couldn't reload other names", err) + } + if resetNames.HasOtherNames.Value != "Yes" { + t.Fatal("topLevel Yes was changed") + } + if resetNames.List.Branch.Value != "" { + t.Fatal("List branch was not cleared") + } + + // test list unset + + resp = saveJSON(services, sections.IDOtherNamesUnfinishedList, account.ID) + if resp.StatusCode != 200 { + t.Fatal("Failed to save unfinishedListJSON", resp.StatusCode) + } + + err = rejector.Reject(account) + if err != nil { + t.Fatal("Failed to reject account: ", err) + } + + // check that the no is no longer set. + resetNames = api.IdentificationOtherNames{} + _, err = resetNames.Get(services.db, account.ID) + if err != nil { + t.Fatal("couldn't reload other names", err) + } + if resetNames.HasOtherNames.Value != "Yes" { + t.Fatal("topLevel Yes was changed") + } + if resetNames.List.Branch.Value != "" { + t.Fatal("List branch did not remain unset") + } + +} + +func TestClearHistoryResidence(t *testing.T) { + services := cleanTestServices() + + account, err := createTestAccount(services.db) + if err != nil { + t.Fatal("couldn't create account", err) + } + + // TEST complete list + resp := saveJSON(services, sections.HistResidenceSingle, account.ID) + if resp.StatusCode != 200 { + t.Fatal("Failed to save HistResidenceSingle", resp.StatusCode) + } + + rejector := admin.Rejector{ + DB: services.db, + } + err = rejector.Reject(account) + if err != nil { + t.Fatal("Failed to reject account: ", err) + } + + // check that the no is no longer set. + residence := api.HistoryResidence{} + _, err = residence.Get(services.db, account.ID) + if err != nil { + t.Fatal("couldn't reload residences") + } + if residence.List.Branch.Value != "" { + t.Fatal("residences was not reset") + } + + // TEST incomplete list + resp = saveJSON(services, sections.HistResidenceUnfinishedList, account.ID) + if resp.StatusCode != 200 { + t.Fatal("Failed to save HistResidenceSingle", resp.StatusCode) + } + + err = rejector.Reject(account) + if err != nil { + t.Fatal("Failed to reject account: ", err) + } + + // check that the no is no longer set. + residence = api.HistoryResidence{} + _, err = residence.Get(services.db, account.ID) + if err != nil { + t.Fatal("couldn't reload residences") + } + if residence.List.Branch.Value != "" { + t.Fatal("residences was not reset") + } +} + +func TestClearHistoryEmployment(t *testing.T) { + services := cleanTestServices() + + account, err := createTestAccount(services.db) + if err != nil { + t.Fatal("couldn't create account", err) + } + + // TEST complete list + resp := saveJSON(services, sections.HistEmployment, account.ID) + if resp.StatusCode != 200 { + t.Fatal("Failed to save HistResidenceSingle", resp.StatusCode) + } + + rejector := admin.Rejector{ + DB: services.db, + } + err = rejector.Reject(account) + if err != nil { + t.Fatal("Failed to reject account: ", err) + } + + // check that the no is no longer set. + employment := api.HistoryEmployment{} + _, err = employment.Get(services.db, account.ID) + if err != nil { + t.Fatal("couldn't reload employment") + } + + if employment.List.Branch.Value != "" { + t.Log("employment list was not reset") + t.Fail() + } + + // check the record doublecheck is no longer set + + if employment.EmploymentRecord.Value != "" { + t.Log("employment record was not reset") + t.Fail() + } + + // check that the reprimand is not set in the one entry + safeway := employment.List.Items[0] + reprimandEnt, repErr := safeway.GetItem("Reprimand") + if repErr != nil { + t.Fatal("couldn't get the reprimand", repErr) + } + + reprimands := reprimandEnt.(*api.Collection) + hasReprimandEnt, hasRepErr := reprimands.Items[0].GetItem("Has") + if hasRepErr != nil { + t.Fatal("couldn't get has rep", hasRepErr) + } + + hasReprimand := hasReprimandEnt.(*api.Branch) + if hasReprimand.Value != "" { + t.Log("has reprimand has not been reset") + t.Fail() + } + +} diff --git a/api/integration_test/form_version_test.go b/api/integration/form_version_test.go similarity index 56% rename from api/integration_test/form_version_test.go rename to api/integration/form_version_test.go index 4b6162d99..ba5101649 100644 --- a/api/integration_test/form_version_test.go +++ b/api/integration/form_version_test.go @@ -1,71 +1,22 @@ -package integration_test +package integration import ( "encoding/json" "fmt" "io/ioutil" "net/http/httptest" - "os" - "strings" "testing" - "github.com/18F/e-QIP-prototype/api" "github.com/18F/e-QIP-prototype/api/http" - "github.com/18F/e-QIP-prototype/api/log" - "github.com/18F/e-QIP-prototype/api/mock" - "github.com/18F/e-QIP-prototype/api/postgresql" ) -type serviceSet struct { - env api.Settings - log api.LogService - // token api.TokenService - db api.DatabaseService -} - -func cleanTestServices() serviceSet { - env := &mock.Native{} - os.Setenv(api.LogLevel, "info") - env.Configure() - - log := &log.Service{Log: log.NewLogger()} - - db := &postgresql.Service{ - Log: log, - Env: env, - } - - db.Configure() - - return serviceSet{ - env, - log, - db, - } -} - func TestFormVersionReturned(t *testing.T) { services := cleanTestServices() - // create/find test account (wow this should be in its own db) - account := api.Account{ - Username: "buzz1@example.com", - Email: "buzz1@example.com", - SFType: "SF86", - SFVersion: "2016-11", - } - - _, err := account.Get(services.db, -1) + account, err := createTestAccount(services.db) if err != nil { - if err.Error() == "pg: no rows in result set" { - _, err := account.Save(services.db, -1) - if err != nil { - t.Fatal(err) - } - } else { - t.Fatal(err) - } + t.Fatal("bad account", err) } // create request/response @@ -124,24 +75,9 @@ func TestFormVersionSave(t *testing.T) { services := cleanTestServices() - // create/find test account (wow this should be in its own db) - account := api.Account{ - Username: "buzz1@example.com", - Email: "buzz1@example.com", - SFType: "SF86", - SFVersion: "2016-11", - } - - _, err := account.Get(services.db, -1) + account, err := createTestAccount(services.db) if err != nil { - if err.Error() == "pg: no rows in result set" { - _, err := account.Save(services.db, -1) - if err != nil { - t.Fatal(err) - } - } else { - t.Fatal(err) - } + t.Fatal("bad account", err) } fmt.Println("Account ID", account.ID) @@ -153,23 +89,7 @@ func TestFormVersionSave(t *testing.T) { "form_version": "2016-11" }` - // create request/response - r := httptest.NewRequest("POST", "/me/save", strings.NewReader(metadataBody)) - // authenticate user. - authCtx := http.SetAccountIDInRequestContext(r, account.ID) - r = r.WithContext(authCtx) - - w := httptest.NewRecorder() - - saveHandler := http.SaveHandler{ - Env: services.env, - Log: services.log, - Database: services.db, - } - - saveHandler.ServeHTTP(w, r) - - resp := w.Result() + resp := saveJSON(services, metadataBody, account.ID) if resp.StatusCode != 400 { t.Log(fmt.Sprintf("Status should have been 400: %d", resp.StatusCode)) diff --git a/api/integration_test/mux_test.go b/api/integration/mux_test.go similarity index 98% rename from api/integration_test/mux_test.go rename to api/integration/mux_test.go index 08f2ce5e5..19ee1a1e8 100644 --- a/api/integration_test/mux_test.go +++ b/api/integration/mux_test.go @@ -1,4 +1,4 @@ -package integration_test +package integration import ( "context" diff --git a/api/integration/sections/history.go b/api/integration/sections/history.go new file mode 100644 index 000000000..616ffe8bc --- /dev/null +++ b/api/integration/sections/history.go @@ -0,0 +1,729 @@ +package sections + +const HistResidenceSingle = ` +{ + "type": "history.residence", + "props": { + "List": { + "type": "collection", + "props": { + "branch": { + "type": "branch", + "props": { + "value": "No" + } + }, + "items": [ + { + "Item": { + "Address": { + "type": "location", + "props": { + "layout": "Address", + "street": "316 Washington Ave", + "city": "Wheeling", + "state": "WV", + "zipcode": "26003", + "country": "United States", + "validated": true + } + }, + "Comments": { + "type": "textarea", + "props": { + "value": "" + } + }, + "Dates": { + "type": "daterange", + "props": { + "from": { + "type": "datecontrol", + "props": { + "month": "12", + "day": "13", + "year": "1990", + "estimated": false + } + }, + "to": { + "type": "datecontrol", + "props": { + "month": "8", + "day": "24", + "year": "2018", + "estimated": false + } + }, + "present": true + } + }, + "ReferenceAddress": { + "type": "location", + "props": { + "layout": "Address", + "street": "317 WASHINGTON AVE", + "city": "WHEELING", + "state": "WV", + "zipcode": "26003", + "country": "United States", + "validated": true + } + }, + "ReferenceEmail": { + "type": "email", + "props": { + "value": "ashley.Emily@testemail.com" + } + }, + "ReferenceEmailNotApplicable": { + "type": "notapplicable", + "props": { + "applicable": false + } + }, + "ReferenceLastContact": { + "type": "datecontrol", + "props": { + "month": "08", + "day": "01", + "year": "2018", + "estimated": false + } + }, + "ReferenceName": { + "type": "name", + "props": { + "first": "Ashley", + "firstInitialOnly": false, + "middle": "", + "middleInitialOnly": false, + "noMiddleName": true, + "last": "Emily", + "suffix": "", + "suffixOther": "" + } + }, + "ReferencePhoneDay": { + "type": "telephone", + "props": { + "timeOfDay": "Both", + "type": "Domestic", + "numberType": "", + "number": "7245555551", + "extension": "", + "noNumber": false + } + }, + "ReferencePhoneEvening": { + "type": "telephone", + "props": { + "timeOfDay": "Both", + "type": "Domestic", + "numberType": "", + "number": "7245555551", + "extension": "", + "noNumber": false + } + }, + "ReferencePhoneMobile": { + "type": "telephone", + "props": { + "timeOfDay": "Both", + "type": "Domestic", + "numberType": "", + "number": "7245555551", + "extension": "", + "noNumber": false + } + }, + "ReferenceRelationship": { + "type": "checkboxgroup", + "props": { + "values": [ + "Neighbor", + "Friend" + ] + } + }, + "ReferenceRelationshipComments": { + "type": "checkboxgroup", + "props": { + "values": null + } + }, + "ReferenceRelationshipOther": { + "type": "text", + "props": { + "value": "" + } + }, + "Role": { + "type": "radio", + "props": { + "value": "Own", + "checked": true + } + }, + "RoleOther": { + "type": "text", + "props": { + "value": "" + } + } + } + } + ] + } + } + } +} +` + +const HistResidenceUnfinishedList = ` +{ + "type": "history.residence", + "props": { + "List": { + "type": "collection", + "props": { + "branch": { + "type": "branch", + "props": { + "value": "" + } + }, + "items": [ + { + "Item": { + "Address": { + "type": "location", + "props": { + "layout": "Address", + "street": "316 Washington Ave", + "city": "Wheeling", + "state": "WV", + "zipcode": "26003", + "country": "United States", + "validated": true + } + }, + "Comments": { + "type": "textarea", + "props": { + "value": "" + } + }, + "Dates": { + "type": "daterange", + "props": { + "from": { + "type": "datecontrol", + "props": { + "month": "12", + "day": "13", + "year": "1990", + "estimated": false + } + }, + "to": { + "type": "datecontrol", + "props": { + "month": "8", + "day": "24", + "year": "2018", + "estimated": false + } + }, + "present": true + } + }, + "ReferenceAddress": { + "type": "location", + "props": { + "layout": "Address", + "street": "317 WASHINGTON AVE", + "city": "WHEELING", + "state": "WV", + "zipcode": "26003", + "country": "United States", + "validated": true + } + }, + "ReferenceEmail": { + "type": "email", + "props": { + "value": "ashley.Emily@testemail.com" + } + }, + "ReferenceEmailNotApplicable": { + "type": "notapplicable", + "props": { + "applicable": false + } + }, + "ReferenceLastContact": { + "type": "datecontrol", + "props": { + "month": "08", + "day": "01", + "year": "2018", + "estimated": false + } + }, + "ReferenceName": { + "type": "name", + "props": { + "first": "Ashley", + "firstInitialOnly": false, + "middle": "", + "middleInitialOnly": false, + "noMiddleName": true, + "last": "Emily", + "suffix": "", + "suffixOther": "" + } + }, + "ReferencePhoneDay": { + "type": "telephone", + "props": { + "timeOfDay": "Both", + "type": "Domestic", + "numberType": "", + "number": "7245555551", + "extension": "", + "noNumber": false + } + }, + "ReferencePhoneEvening": { + "type": "telephone", + "props": { + "timeOfDay": "Both", + "type": "Domestic", + "numberType": "", + "number": "7245555551", + "extension": "", + "noNumber": false + } + }, + "ReferencePhoneMobile": { + "type": "telephone", + "props": { + "timeOfDay": "Both", + "type": "Domestic", + "numberType": "", + "number": "7245555551", + "extension": "", + "noNumber": false + } + }, + "ReferenceRelationship": { + "type": "checkboxgroup", + "props": { + "values": [ + "Neighbor", + "Friend" + ] + } + }, + "ReferenceRelationshipComments": { + "type": "checkboxgroup", + "props": { + "values": null + } + }, + "ReferenceRelationshipOther": { + "type": "text", + "props": { + "value": "" + } + }, + "Role": { + "type": "radio", + "props": { + "value": "Own", + "checked": true + } + }, + "RoleOther": { + "type": "text", + "props": { + "value": "" + } + } + } + } + ] + } + } + } +} +` + +const HistEmployment = ` +{ + "type": "history.employment", + "props": { + "List": { + "type": "collection", + "props": { + "branch": { + "type": "branch", + "props": { + "value": "No" + } + }, + "items": [ + { + "Item": { + "Additional": { + "type": "collection", + "props": { + "branch": { + "type": "" + }, + "items": [ + { + "Item": { + "DatesEmployed": { + "type": "daterange", + "props": { + "from": { + "type": "datecontrol", + "props": { + "month": "", + "day": "", + "year": "", + "estimated": false + } + }, + "to": { + "type": "datecontrol", + "props": { + "month": "", + "day": "", + "year": "", + "estimated": false + } + }, + "present": false + } + }, + "Has": { + "type": "branch", + "props": { + "value": "No" + } + }, + "Position": { + "type": "text", + "props": { + "value": "" + } + }, + "Supervisor": { + "type": "text", + "props": { + "value": "" + } + } + } + } + ] + } + }, + "Address": { + "type": "location", + "props": { + "layout": "Address", + "street": "345 NATIONAL RD", + "city": "WHEELING", + "state": "WV", + "zipcode": "26003", + "country": "United States", + "validated": true + } + }, + "Dates": { + "type": "daterange", + "props": { + "from": { + "type": "datecontrol", + "props": { + "month": "06", + "day": "12", + "year": "2006", + "estimated": false + } + }, + "to": { + "type": "datecontrol", + "props": { + "month": "8", + "day": "24", + "year": "2018", + "estimated": false + } + }, + "present": true + } + }, + "DutyStation": { + "type": "text", + "props": { + "value": "" + } + }, + "Employment": { + "type": "text", + "props": { + "value": "FBI" + } + }, + "EmploymentActivity": { + "type": "employmentactivity", + "props": { + "value": "OtherFederal" + } + }, + "PhysicalAddress": { + "type": "physicaladdress", + "props": { + "HasDifferentAddress": { + "type": "branch", + "props": { + "value": "No" + } + }, + "Address": { + "type": "location", + "props": { + "layout": "", + "country": "" + } + }, + "Telephone": { + "type": "telephone", + "props": { + "timeOfDay": "", + "type": "", + "numberType": "", + "number": "", + "extension": "", + "noNumber": false + } + } + } + }, + "ReasonLeft": { + "type": "reasonleft", + "props": { + "Comments": { + "type": "textarea", + "props": { + "value": "" + } + }, + "Reasons": { + "type": "collection", + "props": { + "branch": { + "type": "" + }, + "items": [ + { + "Item": { + "Date": { + "type": "datecontrol", + "props": { + "month": "", + "day": "", + "year": "", + "estimated": false + } + }, + "Has": { + "type": "branch", + "props": { + "value": "No" + } + }, + "Reason": { + "type": "textarea", + "props": { + "value": "" + } + }, + "Text": { + "type": "textarea", + "props": { + "value": "" + } + } + } + } + ] + } + }, + "ReasonDescription": { + "type": "textarea", + "props": { + "value": "" + } + } + } + }, + "ReferenceAddress": { + "type": "location", + "props": { + "layout": "", + "country": "" + } + }, + "ReferenceName": { + "type": "name", + "props": { + "first": "", + "firstInitialOnly": false, + "middle": "", + "middleInitialOnly": false, + "noMiddleName": false, + "last": "", + "suffix": "", + "suffixOther": "" + } + }, + "ReferencePhone": { + "type": "telephone", + "props": { + "timeOfDay": "", + "type": "", + "numberType": "", + "number": "", + "extension": "", + "noNumber": false + } + }, + "Reprimand": { + "type": "collection", + "props": { + "branch": { + "type": "" + }, + "items": [ + { + "Item": { + "Date": { + "type": "datecontrol", + "props": { + "month": "", + "day": "", + "year": "", + "estimated": false + } + }, + "Has": { + "type": "branch", + "props": { + "value": "No" + } + }, + "Text": { + "type": "textarea", + "props": { + "value": "" + } + } + } + } + ] + } + }, + "Status": { + "type": "radio", + "props": { + "value": "FullTime" + } + }, + "Supervisor": { + "type": "supervisor", + "props": { + "SupervisorName": { + "type": "text", + "props": { + "value": "Gail Shannon" + } + }, + "Title": { + "type": "text", + "props": { + "value": "Lead Analyst" + } + }, + "Email": { + "type": "email", + "props": { + "value": "gail.shannon@testemail.gov" + } + }, + "EmailNotApplicable": { + "type": "notapplicable", + "props": { + "applicable": true + } + }, + "Address": { + "type": "location", + "props": { + "layout": "Address", + "street": "345 NATIONAL RD", + "city": "WHEELING", + "state": "WV", + "zipcode": "26003", + "country": "United States" + } + }, + "Telephone": { + "type": "telephone", + "props": { + "timeOfDay": "Both", + "type": "Domestic", + "numberType": "", + "number": "3163170345", + "extension": "067", + "noNumber": false + } + } + } + }, + "Telephone": { + "type": "telephone", + "props": { + "timeOfDay": "Both", + "type": "Domestic", + "numberType": "", + "number": "3163170345", + "extension": "", + "noNumber": false + } + }, + "Title": { + "type": "text", + "props": { + "value": "Analyst" + } + } + } + } + ] + } + }, + "EmploymentRecord": { + "type": "branch", + "props": { + "value": "No" + } + } + } +} + ` diff --git a/api/integration/sections/identification.go b/api/integration/sections/identification.go new file mode 100644 index 000000000..32f1dbe2d --- /dev/null +++ b/api/integration/sections/identification.go @@ -0,0 +1,293 @@ +package sections + +const IDOtherNamesNo = ` +{ + "type": "identification.othernames", + "props": { + "HasOtherNames": { + "type": "branch", + "props": { + "value": "No" + } + }, + "List": { + "type": "collection", + "props": { + "branch": { + "type": "branch", + "props": { + "value": "" + } + }, + "items": [] + } + } + } +} +` + +const IDOtherNamesYes = ` +{ + "type": "identification.othernames", + "props": { + "HasOtherNames": { + "type": "branch", + "props": { + "value": "Yes" + } + }, + "List": { + "type": "collection", + "props": { + "branch": { + "type": "branch", + "props": { + "value": "No" + } + }, + "items": [ + { + "Item": { + "DatesUsed": { + "type": "daterange", + "props": { + "from": { + "type": "datecontrol", + "props": { + "month": "01", + "day": "02", + "year": "1992", + "estimated": false + } + }, + "to": { + "type": "datecontrol", + "props": { + "month": "01", + "day": "01", + "year": "1993", + "estimated": false + } + }, + "present": false + } + }, + "MaidenName": { + "type": "radio", + "props": { + "value": "No" + } + }, + "Name": { + "type": "name", + "props": { + "first": "Kirk", + "firstInitialOnly": false, + "middle": "Enzo", + "middleInitialOnly": false, + "noMiddleName": false, + "last": "James", + "suffix": "", + "suffixOther": "" + } + }, + "Reason": { + "type": "textarea", + "props": { + "value": "For a good reason." + } + } + } + }, + { + "Item": { + "DatesUsed": { + "type": "daterange", + "props": { + "from": { + "type": "datecontrol", + "props": { + "month": "01", + "day": "01", + "year": "1996", + "estimated": false + } + }, + "to": { + "type": "datecontrol", + "props": { + "month": "01", + "day": "01", + "year": "1997", + "estimated": false + } + }, + "present": false + } + }, + "MaidenName": { + "type": "radio", + "props": { + "value": "No" + } + }, + "Name": { + "type": "name", + "props": { + "first": "Kirk", + "firstInitialOnly": false, + "middle": "Enzo", + "middleInitialOnly": false, + "noMiddleName": false, + "last": "Riker", + "suffix": "", + "suffixOther": "" + } + }, + "Reason": { + "type": "textarea", + "props": { + "value": "Another good reason." + } + } + } + } + ] + } + } + } +} + ` + +const IDOtherNamesUnfinishedList = ` +{ + "type": "identification.othernames", + "props": { + "HasOtherNames": { + "type": "branch", + "props": { + "value": "Yes" + } + }, + "List": { + "type": "collection", + "props": { + "branch": { + "type": "branch", + "props": { + "value": "No" + } + }, + "items": [ + { + "Item": { + "DatesUsed": { + "type": "daterange", + "props": { + "from": { + "type": "datecontrol", + "props": { + "month": "01", + "day": "02", + "year": "1992", + "estimated": false + } + }, + "to": { + "type": "datecontrol", + "props": { + "month": "01", + "day": "01", + "year": "1993", + "estimated": false + } + }, + "present": false + } + }, + "MaidenName": { + "type": "radio", + "props": { + "value": "No" + } + }, + "Name": { + "type": "name", + "props": { + "first": "Kirk", + "firstInitialOnly": false, + "middle": "Enzo", + "middleInitialOnly": false, + "noMiddleName": false, + "last": "James", + "suffix": "", + "suffixOther": "" + } + }, + "Reason": { + "type": "textarea", + "props": { + "value": "For a good reason." + } + } + } + }, + { + "Item": { + "DatesUsed": { + "type": "daterange", + "props": { + "from": { + "type": "datecontrol", + "props": { + "month": "01", + "day": "01", + "year": "1996", + "estimated": false + } + }, + "to": { + "type": "datecontrol", + "props": { + "month": "01", + "day": "01", + "year": "1997", + "estimated": false + } + }, + "present": false + } + }, + "MaidenName": { + "type": "radio", + "props": { + "value": "No" + } + }, + "Name": { + "type": "name", + "props": { + "first": "Kirk", + "firstInitialOnly": false, + "middle": "Enzo", + "middleInitialOnly": false, + "noMiddleName": false, + "last": "Riker", + "suffix": "", + "suffixOther": "" + } + }, + "Reason": { + "type": "textarea", + "props": { + "value": "Another good reason." + } + } + } + } + ] + } + } + } +} +` diff --git a/api/integration/setup.go b/api/integration/setup.go new file mode 100644 index 000000000..7e3b0be6c --- /dev/null +++ b/api/integration/setup.go @@ -0,0 +1,146 @@ +package integration + +import ( + "encoding/json" + "fmt" + "io/ioutil" + "math/rand" + gohttp "net/http" + "net/http/httptest" + "os" + "strings" + + "github.com/pkg/errors" + + "github.com/18F/e-QIP-prototype/api" + "github.com/18F/e-QIP-prototype/api/env" + "github.com/18F/e-QIP-prototype/api/http" + "github.com/18F/e-QIP-prototype/api/log" + "github.com/18F/e-QIP-prototype/api/postgresql" +) + +type serviceSet struct { + env api.Settings + log api.LogService + // token api.TokenService + db api.DatabaseService +} + +func cleanTestServices() serviceSet { + env := &env.Native{} + os.Setenv(api.LogLevel, "info") + env.Configure() + + log := &log.Service{Log: log.NewLogger()} + + db := &postgresql.Service{ + Log: log, + Env: env, + } + + db.Configure() + + return serviceSet{ + env, + log, + db, + } +} + +// randomEmail an example.com email address with 10 random characters +func randomEmail() string { + + len := 10 + bytes := make([]byte, len) + for i := 0; i < len; i++ { + aint := int('a') + zint := int('z') + char := aint + rand.Intn(zint-aint) + bytes[i] = byte(char) + } + + email := string(bytes) + "@example.com" + + return email + +} + +func createTestAccount(db api.DatabaseService) (api.Account, error) { + + email := randomEmail() + + account := api.Account{ + Username: email, + Email: email, + SFType: "SF86", + SFVersion: "2016-11", + } + + _, err := account.Save(db, -1) + if err != nil { + return api.Account{}, err + } + + return account, nil + +} + +func populateAccount(db api.DatabaseService, account api.Account, testCasePath string) error { + + b, err := ioutil.ReadFile(testCasePath) + if err != nil { + return err + } + + sections := make(map[string]map[string]api.Payload) + err = json.Unmarshal(b, §ions) + if err != nil { + return err + } + + for sectionName := range sections { + section := sections[sectionName] + + for subName := range section { + subPayload := section[subName] + + entity, err := subPayload.Entity() + if err != nil { + errstr := fmt.Sprintf("Failed to unpack %s %s ... %s", sectionName, subName, err.Error()) + return errors.New(errstr) + } + + if _, err := entity.Save(db, account.ID); err != nil { + errstr := fmt.Sprintf("Failed to save %s %s ... %s", sectionName, subName, err.Error()) + return errors.New(errstr) + } + } + } + + return nil +} + +// saveJSON calls the save handler with the given json body. +func saveJSON(services serviceSet, json string, accountID int) *gohttp.Response { + + // create request/response + r := httptest.NewRequest("POST", "/me/save", strings.NewReader(json)) + // authenticate user. + authCtx := http.SetAccountIDInRequestContext(r, accountID) + r = r.WithContext(authCtx) + + w := httptest.NewRecorder() + + saveHandler := http.SaveHandler{ + Env: services.env, + Log: services.log, + Database: services.db, + } + + saveHandler.ServeHTTP(w, r) + + resp := w.Result() + + return resp + +} diff --git a/api/postgresql/db.go b/api/postgresql/db.go index dbc123fb7..9b50362c4 100644 --- a/api/postgresql/db.go +++ b/api/postgresql/db.go @@ -146,5 +146,13 @@ func (service *Service) Delete(query interface{}) error { // Select returns the model from the data store func (service *Service) Select(query interface{}) error { - return service.database.Select(query) + err := service.database.Select(query) + if err != nil { + if err.Error() == "pg: no rows in result set" { + return api.DatabaseErrorNotFound("Not found in database") + } else { + return err + } + } + return nil } diff --git a/docker-compose.yml b/docker-compose.yml index e3bf59fc7..a59c3f877 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -10,8 +10,8 @@ services: - ./conf/postgres.conf:/srv/postgresql.conf - ./api/eapp.crt:/srv/server.crt - ./api/eapp.key:/srv/server.key - expose: - - '5432' + ports: + - '5432:5432' networks: - eapp From 20efbfd714d5e2256a307c76c0972d7ffbc2a9ea Mon Sep 17 00:00:00 2001 From: MacRae Linton <55759+macrael@users.noreply.github.com> Date: Thu, 21 Mar 2019 23:24:57 -0700 Subject: [PATCH 02/14] Clear history nos --- api/account.go | 10 ++-- api/collection.go | 16 ++++++- api/history.go | 70 ++++++++++++++++++++++++++++ api/integration/clear_yes_no_test.go | 5 +- 4 files changed, 93 insertions(+), 8 deletions(-) diff --git a/api/account.go b/api/account.go index 09ba14173..b7a5a53f1 100644 --- a/api/account.go +++ b/api/account.go @@ -194,14 +194,16 @@ func (entity *Account) BasicAuthentication(context DatabaseService, password str func (entity *Account) ClearNoBranches(context DatabaseService) error { // Identification.OtherNames - err := ClearIdentificationOtherNamesNos(context, entity.ID) - if err != nil { + if err := ClearIdentificationOtherNamesNos(context, entity.ID); err != nil { return err } // Your History - err = ClearHistoryResidenceNos(context, entity.ID) - if err != nil { + if err := ClearHistoryResidenceNos(context, entity.ID); err != nil { + return err + } + + if err := ClearHistoryEmploymentNos(context, entity.ID); err != nil { return err } diff --git a/api/collection.go b/api/collection.go index 68e68e2a4..d1b19254f 100644 --- a/api/collection.go +++ b/api/collection.go @@ -391,7 +391,7 @@ func (ci CollectionItem) Each(action func(string, string, Entity, error) error) return err } -func (ci CollectionItem) GetItem(key string) (Entity, error) { +func (ci CollectionItem) GetItemValue(key string) (Entity, error) { item, ok := ci.Item[key] if !ok { @@ -404,6 +404,20 @@ func (ci CollectionItem) GetItem(key string) (Entity, error) { } return entity, nil +} + +func (ci *CollectionItem) SetItemValue(key string, value Entity) error { + + payload := value.Marshal() + + js, jsErr := json.Marshal(payload) + if jsErr != nil { + return errors.Wrap(jsErr, "failed to marhsal item value") + } + + ci.Item[key] = js + + return nil } diff --git a/api/history.go b/api/history.go index 297575ef0..ca07ff542 100644 --- a/api/history.go +++ b/api/history.go @@ -345,6 +345,76 @@ func (entity *HistoryEmployment) Find(context DatabaseService) error { return nil } +func ClearHistoryEmploymentNos(context DatabaseService, accountID int) error { + employment := HistoryEmployment{} + _, err := employment.Get(context, accountID) + if err != nil { + if IsDatabaseErrorNotFound(err) { + return nil + } + return errors.Wrap(err, "Failed to clear nos: unable to load residence") + } + + employmentUpdated := false + + if employment.List != nil && employment.List.Branch != nil { + if employment.List.Branch.Value == "No" { + employment.List.Branch.Value = "" + employmentUpdated = true + } + } + + if employment.EmploymentRecord != nil { + if employment.EmploymentRecord.Value == "No" { + employment.EmploymentRecord.Value = "" + employmentUpdated = true + } + } + + // loop through all the records of employment. + if employment.List != nil { + for _, employmentInstance := range employment.List.Items { + reprimandsEntity, repErr := employmentInstance.GetItemValue("Reprimand") + if repErr != nil { + return errors.Wrap(err, "Failed to pull a reprimand from an employment instance") + } + + reprimands := reprimandsEntity.(*Collection) + for _, reprimand := range reprimands.Items { + HasAdditionalEntity, hasAddErr := reprimand.GetItemValue("Has") + if hasAddErr != nil { + return errors.Wrap(err, "Failed to pull Has from a reprimand") + } + + hasAdditional := HasAdditionalEntity.(*Branch) + if hasAdditional.Value == "No" { + hasAdditional.Value = "" + setErr := reprimand.SetItemValue("Has", hasAdditional) + if setErr != nil { + return setErr + } + employmentUpdated = true + } + } + + if employmentUpdated { + setErr := employmentInstance.SetItemValue("Reprimand", reprimands) + if setErr != nil { + return setErr + } + } + } + } + + if employmentUpdated { + if _, err := employment.Save(context, accountID); err != nil { + return errors.Wrap(err, "Unable to save Employment") + } + } + + return nil +} + // HistoryEducation represents the payload for the history education section. type HistoryEducation struct { PayloadHasAttended Payload `json:"HasAttended" sql:"-"` diff --git a/api/integration/clear_yes_no_test.go b/api/integration/clear_yes_no_test.go index edece1c3d..8bc8d00a6 100644 --- a/api/integration/clear_yes_no_test.go +++ b/api/integration/clear_yes_no_test.go @@ -202,7 +202,6 @@ func TestClearHistoryEmployment(t *testing.T) { } // check the record doublecheck is no longer set - if employment.EmploymentRecord.Value != "" { t.Log("employment record was not reset") t.Fail() @@ -210,13 +209,13 @@ func TestClearHistoryEmployment(t *testing.T) { // check that the reprimand is not set in the one entry safeway := employment.List.Items[0] - reprimandEnt, repErr := safeway.GetItem("Reprimand") + reprimandEnt, repErr := safeway.GetItemValue("Reprimand") if repErr != nil { t.Fatal("couldn't get the reprimand", repErr) } reprimands := reprimandEnt.(*api.Collection) - hasReprimandEnt, hasRepErr := reprimands.Items[0].GetItem("Has") + hasReprimandEnt, hasRepErr := reprimands.Items[0].GetItemValue("Has") if hasRepErr != nil { t.Fatal("couldn't get has rep", hasRepErr) } From a07837ae957c17aaf1ce84df7b70cc73416e65e6 Mon Sep 17 00:00:00 2001 From: MacRae Linton <55759+macrael@users.noreply.github.com> Date: Fri, 22 Mar 2019 15:40:05 -0700 Subject: [PATCH 03/14] fix broken build --- api/admin/reject.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/api/admin/reject.go b/api/admin/reject.go index 94ab31b17..f439ad1a3 100644 --- a/api/admin/reject.go +++ b/api/admin/reject.go @@ -1,8 +1,6 @@ package admin import ( - "fmt" - "github.com/pkg/errors" "github.com/18F/e-QIP-prototype/api" From 56f577b85e83f568609a256ce93098d3a06588db Mon Sep 17 00:00:00 2001 From: MacRae Linton <55759+macrael@users.noreply.github.com> Date: Fri, 29 Mar 2019 17:41:41 -0700 Subject: [PATCH 04/14] First step toward having integration tests run in a migrated db. --- api/cmd/dbmigrate/db-migrate-test.sh | 13 ++ api/cmd/dbmigrate/main.go | 176 +++++++++++++++++++++++++++ api/integration/setup.go | 1 + api/migration.go | 5 +- 4 files changed, 193 insertions(+), 2 deletions(-) create mode 100644 api/cmd/dbmigrate/db-migrate-test.sh create mode 100644 api/cmd/dbmigrate/main.go diff --git a/api/cmd/dbmigrate/db-migrate-test.sh b/api/cmd/dbmigrate/db-migrate-test.sh new file mode 100644 index 000000000..99c99e33d --- /dev/null +++ b/api/cmd/dbmigrate/db-migrate-test.sh @@ -0,0 +1,13 @@ +#!/bin/bash + +set -eo pipefail + +go build github.com/18F/e-QIP-prototype/api/cmd/dbmigrate + +./dbmigrate || true + +./dbmigrate -reset -force dbtest_test + +./dbmigrate dbtest_test + +./dbmigrate -migrations_path ./api/migrations dbtest_test diff --git a/api/cmd/dbmigrate/main.go b/api/cmd/dbmigrate/main.go new file mode 100644 index 000000000..e8b2f076c --- /dev/null +++ b/api/cmd/dbmigrate/main.go @@ -0,0 +1,176 @@ +package main + +import ( + "bufio" + "database/sql" + "flag" + "fmt" + "os" + "path/filepath" + "unicode" + + _ "github.com/lib/pq" + "github.com/pkg/errors" + + "github.com/18F/e-QIP-prototype/api" + "github.com/18F/e-QIP-prototype/api/env" +) + +func checkDBNameIsAllowed(dbName string) bool { + for _, r := range dbName { + if !(unicode.IsLetter(r) || r == '_') { + return false + } + } + return true +} + +func resetDB(dbName string, force bool) error { + fmt.Println("Resetting", dbName) + + if !checkDBNameIsAllowed(dbName) || dbName == "" { + return errors.New(fmt.Sprintf("Attempted to reset a db with a strange name: %s", dbName)) + } + + // TODO: get the connection url + connStr := "postgres://postgres@localhost/template1" + db, openErr := sql.Open("postgres", connStr) + if openErr != nil { + return errors.Wrap(openErr, "Error opening connection") + } + + check, checkErr := db.Exec("SELECT 1 AS result FROM pg_database WHERE datname=$1", dbName) + if checkErr != nil { + return errors.Wrap(checkErr, fmt.Sprintf("ERROR Checking for existence of %s", dbName)) + } + + checkCount, _ := check.RowsAffected() + if checkCount != 0 { + // We need to delete the requested db. + + if !force { + fmt.Printf("DANGER: resetting this db will erase all the data in %s permanently, is that what you want? [y/N]: ", dbName) + scanner := bufio.NewScanner(os.Stdin) + scanner.Scan() + text := scanner.Text() + + if scanner.Err() != nil { + return errors.New("Error getting user confirmation.") + } + + fmt.Println(text) + if !(text == "y" || text == "Y" || text == "YES" || text == "yes") { + return errors.New("User disconfirmed reset.") + } + + } + + dropCmd := "DROP DATABASE " + dbName + _, dropErr := db.Exec(dropCmd) + if dropErr != nil { + return dropErr + } + + } + + createCmd := "CREATE DATABASE " + dbName + _, createErr := db.Exec(createCmd) + if createErr != nil { + return errors.Wrap(createErr, "Error Creating db") + } + + return nil +} + +func pathToPattern(path, pattern string) string { + + dir, subject := filepath.Split(path) + if subject == pattern { + return path + } + + if subject == "" { + return "" + } + + return pathToPattern(dir, pattern) +} + +func guessMigrationsPath() string { + + cwd, _ := os.Getwd() + + // 1st. try and see if e-QIP-prototype is in the path + goodPath := pathToPattern(cwd, "e-QIP-prototype") + if goodPath != "" { + migrationsPath := filepath.Join(filepath.Join(goodPath, "api"), "migrations") + return migrationsPath + } + + // If that didn't work, just look for /api + goodPath = pathToPattern(cwd, "api") + if goodPath != "" { + migrationsPath := filepath.Join(goodPath, "migrations") + return migrationsPath + } + + // if that didn't work, we have to guess that we are in api and it's not listed, so just return this. + return filepath.Join(cwd, "migrations") +} + +func runMigrations(dbName string, migrationsPath string) error { + os.Setenv(api.DatabaseName, dbName) + + settings := env.Native{} + settings.Configure() + + apiPath := filepath.Dir(filepath.Clean(migrationsPath)) + + migration := api.Migration{Env: settings} + if migrationErr := migration.Up(apiPath, settings.String(api.GolangEnv), ""); migrationErr != nil { + return errors.Wrap(migrationErr, fmt.Sprintf("Error running migrations in path: %s", migrationsPath)) + } + + return nil +} + +type stackTracer interface { + StackTrace() errors.StackTrace +} + +func main() { + fmt.Println("Hello World") + + shouldReset := flag.Bool("reset", false, "resets the data in the given db by deleting it and re-creating it") + forceReset := flag.Bool("force", false, "skips the interactive dialog triggered by reset") + migrationsPath := flag.String("migrations_path", "", "path to the directory containing migrations. If left out it will be guessed.") + + flag.Parse() + + if len(flag.Args()) != 1 { + fmt.Println("Must pass the db_name as an argument") + flag.Usage() + os.Exit(1) + } + + dbName := flag.Args()[0] + + if *shouldReset { + resetErr := resetDB(dbName, *forceReset) + if resetErr != nil { + fmt.Println(resetErr) + os.Exit(1) + } + } + + if *migrationsPath == "" { + *migrationsPath = guessMigrationsPath() + } + + migrationErr := runMigrations(dbName, *migrationsPath) + if migrationErr != nil { + fmt.Println(migrationErr) + os.Exit(1) + } + +} diff --git a/api/integration/setup.go b/api/integration/setup.go index 47004cae7..6f55cb473 100644 --- a/api/integration/setup.go +++ b/api/integration/setup.go @@ -29,6 +29,7 @@ type serviceSet struct { func cleanTestServices() serviceSet { env := &env.Native{} os.Setenv(api.LogLevel, "info") + os.Setenv(api.DatabaseName, "eapp_test") env.Configure() log := &log.Service{Log: log.NewLogger()} diff --git a/api/migration.go b/api/migration.go index 2057dfc0d..c45acfae0 100644 --- a/api/migration.go +++ b/api/migration.go @@ -5,6 +5,7 @@ package api import ( "path/filepath" + "github.com/pkg/errors" "github.com/truetandem/plucked/migration" ) @@ -17,14 +18,14 @@ type Migration struct { func (service Migration) Up(directory, environment, schema string) error { conf, err := service.databaseConf(directory, environment, schema) if err != nil { - return err + return errors.Wrap(err, "Couldn't determine db Conf") } target, err := migration.NumericComponent(service.Env.String(DbMigrationTarget)) if err != nil { target, err = migration.GetMostRecentDBVersion(conf.MigrationsDir) if err != nil { - return err + return errors.Wrap(err, "Couldn't Get most recent version") } } From b8a2eaec287af49b71eebc0386d94dd03dc98dc6 Mon Sep 17 00:00:00 2001 From: MacRae Linton <55759+macrael@users.noreply.github.com> Date: Tue, 2 Apr 2019 00:27:42 -0700 Subject: [PATCH 05/14] Fix tests to create actual random emails every time. --- api/cmd/dbmigrate/db-migrate-test.sh | 0 api/integration/setup.go | 3 +++ 2 files changed, 3 insertions(+) mode change 100644 => 100755 api/cmd/dbmigrate/db-migrate-test.sh diff --git a/api/cmd/dbmigrate/db-migrate-test.sh b/api/cmd/dbmigrate/db-migrate-test.sh old mode 100644 new mode 100755 diff --git a/api/integration/setup.go b/api/integration/setup.go index 6f55cb473..3a09dc3b8 100644 --- a/api/integration/setup.go +++ b/api/integration/setup.go @@ -9,6 +9,7 @@ import ( "net/http/httptest" "os" "strings" + "time" "github.com/pkg/errors" @@ -51,6 +52,8 @@ func cleanTestServices() serviceSet { // randomEmail an example.com email address with 10 random characters func randomEmail() string { + rand.Seed(time.Now().UTC().UnixNano()) + len := 10 bytes := make([]byte, len) for i := 0; i < len; i++ { From 81c3dabf0427867f8c33ea3b73dd7f6f8955b9ee Mon Sep 17 00:00:00 2001 From: MacRae Linton <55759+macrael@users.noreply.github.com> Date: Tue, 2 Apr 2019 00:40:45 -0700 Subject: [PATCH 06/14] Update makefile to configure test db. --- Makefile | 1 + api/Makefile | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/Makefile b/Makefile index e4be8d336..2c48bbd95 100644 --- a/Makefile +++ b/Makefile @@ -73,6 +73,7 @@ test-react: @docker-compose run --rm js yarn test $(FLAGS) $(FILES) test-go: $(info Running Go test suite) + @docker-compose run --rm api make reset-test-db @docker-compose run --rm api make test # diff --git a/api/Makefile b/api/Makefile index 4cdc19d9c..0b957def2 100644 --- a/api/Makefile +++ b/api/Makefile @@ -5,6 +5,10 @@ all: clean test build test: GOLANG_ENV=test go test -coverprofile=coverage.txt -covermode=atomic -cover $(shell go list ./... | grep -v /vendor/) +reset-test-db: + go build -o bin/dbmigrate ./cmd/dbmigrate + ./bin/dbmigrate -reset -force eapp_test + coverage: # Use -c to remove processed reports so coverage-js won't find it codecov -c -F backend -f coverage.txt -X gcov @@ -21,6 +25,7 @@ clean: .PHONY: cmd cmd: go build -o bin/compare ./cmd/compare + go build -o bin/dbmigrate ./cmd/dbmigrate go build -o bin/flush ./cmd/flush go build -o bin/form ./cmd/form go build -o bin/fuzzer ./cmd/fuzzer From 07192955f9a0e2a561614bce1f7171ed4cb27d3d Mon Sep 17 00:00:00 2001 From: MacRae Linton <55759+macrael@users.noreply.github.com> Date: Tue, 2 Apr 2019 00:54:20 -0700 Subject: [PATCH 07/14] Fix linter errors --- api/admin/reject.go | 2 ++ api/cmd/dbmigrate/main.go | 4 ++-- api/collection.go | 2 ++ api/history.go | 2 ++ api/identification.go | 1 + api/integration/sections/history.go | 3 +++ api/integration/sections/identification.go | 3 +++ 7 files changed, 15 insertions(+), 2 deletions(-) diff --git a/api/admin/reject.go b/api/admin/reject.go index f439ad1a3..ade3fc4a7 100644 --- a/api/admin/reject.go +++ b/api/admin/reject.go @@ -6,11 +6,13 @@ import ( "github.com/18F/e-QIP-prototype/api" ) +// Rejector is used to reject/kickback an application type Rejector struct { DB api.DatabaseService PDF api.PdfService } +// Reject rejects the application for a given account func (r Rejector) Reject(account api.Account) error { err := account.Unlock(r.DB) if err != nil { diff --git a/api/cmd/dbmigrate/main.go b/api/cmd/dbmigrate/main.go index e8b2f076c..615e84d22 100644 --- a/api/cmd/dbmigrate/main.go +++ b/api/cmd/dbmigrate/main.go @@ -55,12 +55,12 @@ func resetDB(dbName string, force bool) error { text := scanner.Text() if scanner.Err() != nil { - return errors.New("Error getting user confirmation.") + return errors.New("error getting user confirmation") } fmt.Println(text) if !(text == "y" || text == "Y" || text == "YES" || text == "yes") { - return errors.New("User disconfirmed reset.") + return errors.New("user disconfirmed reset") } } diff --git a/api/collection.go b/api/collection.go index d1b19254f..d092ef77f 100644 --- a/api/collection.go +++ b/api/collection.go @@ -391,6 +391,7 @@ func (ci CollectionItem) Each(action func(string, string, Entity, error) error) return err } +// GetItemValue returns the entity stored at the key in the collection item func (ci CollectionItem) GetItemValue(key string) (Entity, error) { item, ok := ci.Item[key] @@ -406,6 +407,7 @@ func (ci CollectionItem) GetItemValue(key string) (Entity, error) { return entity, nil } +// SetItemValue sets a value for a key in the CollectionItem func (ci *CollectionItem) SetItemValue(key string, value Entity) error { payload := value.Marshal() diff --git a/api/history.go b/api/history.go index ca07ff542..003363467 100644 --- a/api/history.go +++ b/api/history.go @@ -144,6 +144,7 @@ func (entity *HistoryResidence) Find(context DatabaseService) error { return nil } +// ClearHistoryResidenceNos clears the necessary Nos from the histroy.residence section for kickback func ClearHistoryResidenceNos(context DatabaseService, accountID int) error { residence := HistoryResidence{} _, err := residence.Get(context, accountID) @@ -345,6 +346,7 @@ func (entity *HistoryEmployment) Find(context DatabaseService) error { return nil } +// ClearHistoryEmploymentNos clears Nos from history.employment func ClearHistoryEmploymentNos(context DatabaseService, accountID int) error { employment := HistoryEmployment{} _, err := employment.Get(context, accountID) diff --git a/api/identification.go b/api/identification.go index 5e4ab7144..3aed5183d 100644 --- a/api/identification.go +++ b/api/identification.go @@ -1010,6 +1010,7 @@ func (entity *IdentificationOtherNames) Find(context DatabaseService) error { return nil } +// ClearIdentificationOtherNamesNos clears nos from identifcation.other_names func ClearIdentificationOtherNamesNos(context DatabaseService, accountID int) error { otherNames := IdentificationOtherNames{} _, err := otherNames.Get(context, accountID) diff --git a/api/integration/sections/history.go b/api/integration/sections/history.go index 616ffe8bc..39f5b48fd 100644 --- a/api/integration/sections/history.go +++ b/api/integration/sections/history.go @@ -1,5 +1,6 @@ package sections +// HistResidenceSingle contains a single residence const HistResidenceSingle = ` { "type": "history.residence", @@ -180,6 +181,7 @@ const HistResidenceSingle = ` } ` +// HistResidenceUnfinishedList contains an unfinished list const HistResidenceUnfinishedList = ` { "type": "history.residence", @@ -360,6 +362,7 @@ const HistResidenceUnfinishedList = ` } ` +// HistEmployment contains an employment const HistEmployment = ` { "type": "history.employment", diff --git a/api/integration/sections/identification.go b/api/integration/sections/identification.go index 32f1dbe2d..57584e960 100644 --- a/api/integration/sections/identification.go +++ b/api/integration/sections/identification.go @@ -1,5 +1,6 @@ package sections +// IDOtherNamesNo has no other names const IDOtherNamesNo = ` { "type": "identification.othernames", @@ -26,6 +27,7 @@ const IDOtherNamesNo = ` } ` +// IDOtherNamesYes has other names const IDOtherNamesYes = ` { "type": "identification.othernames", @@ -159,6 +161,7 @@ const IDOtherNamesYes = ` } ` +// IDOtherNamesUnfinishedList has an unfinished list const IDOtherNamesUnfinishedList = ` { "type": "identification.othernames", From a8cd844b6b58f256243436cf15259d40b18f261d Mon Sep 17 00:00:00 2001 From: MacRae Linton <55759+macrael@users.noreply.github.com> Date: Thu, 4 Apr 2019 17:03:58 -0700 Subject: [PATCH 08/14] Configure tests to use TEST_DATABASE_NAME to configure which database to configure to. I also got rid of the database.Configure() method, instead configuring it with a method in the postgres package. This is how all service configuration should work going forward. This neuters the CheckTable() method, since tests should now run against a real database. I also fixed a bug that was exposed by doing all of this. --- .gitignore | 1 + api/cloudfoundry/env_test.go | 2 +- api/cmd/cmd.go | 11 +++++- api/cmd/dbmigrate/main.go | 28 +++++++++++--- api/cmd/server/main.go | 15 ++++++-- api/cmd/sftype/main.go | 10 ++++- api/database.go | 1 - api/env/env.go | 73 ++++++++++++++++++------------------ api/integration/setup.go | 14 +++---- api/migration.go | 14 +++---- api/mock/database.go | 4 -- api/postgresql/db.go | 72 ++++++++++++++++++++++------------- api/postgresql/db_test.go | 33 +++++++++++++--- api/settings.go | 6 +++ api/signature.go | 16 ++++---- 15 files changed, 190 insertions(+), 110 deletions(-) diff --git a/.gitignore b/.gitignore index 59dd3e50a..e8215c043 100644 --- a/.gitignore +++ b/.gitignore @@ -67,6 +67,7 @@ package-lock.json /api/bin/submit /api/bin/transmit /api/bin/unlock +/api/bin/dbmigrate /build/ /doc/ /dist/ diff --git a/api/cloudfoundry/env_test.go b/api/cloudfoundry/env_test.go index deea68ab8..d76c1d23c 100644 --- a/api/cloudfoundry/env_test.go +++ b/api/cloudfoundry/env_test.go @@ -68,7 +68,7 @@ func TestDatabaseDefaults(t *testing.T) { os.Setenv(api.DatabaseURI, "") Configure() - // Test agains the environment variables + // Test against the environment variables expected := "" uri := env.String(api.DatabaseURI) if uri != expected { diff --git a/api/cmd/cmd.go b/api/cmd/cmd.go index 4b3666f0e..ea511131d 100644 --- a/api/cmd/cmd.go +++ b/api/cmd/cmd.go @@ -19,8 +19,15 @@ func Command(log api.LogService, action func(api.DatabaseService, *api.Account)) cloudfoundry.Configure() settings := &env.Native{} settings.Configure() - database := &postgresql.Service{Log: log, Env: settings} - database.Configure() + + dbConf := postgresql.DBConfig{ + User: settings.String(api.DatabaseUser), + Password: settings.String(api.DatabasePassword), + Address: settings.String(api.DatabaseHost), + DBName: settings.String(api.TestDatabaseName), + } + database := postgresql.NewPostgresService(dbConf, log) + flag.Parse() if *flagAll { diff --git a/api/cmd/dbmigrate/main.go b/api/cmd/dbmigrate/main.go index 615e84d22..3e815296d 100644 --- a/api/cmd/dbmigrate/main.go +++ b/api/cmd/dbmigrate/main.go @@ -14,6 +14,7 @@ import ( "github.com/18F/e-QIP-prototype/api" "github.com/18F/e-QIP-prototype/api/env" + "github.com/18F/e-QIP-prototype/api/postgresql" ) func checkDBNameIsAllowed(dbName string) bool { @@ -32,8 +33,18 @@ func resetDB(dbName string, force bool) error { return errors.New(fmt.Sprintf("Attempted to reset a db with a strange name: %s", dbName)) } - // TODO: get the connection url - connStr := "postgres://postgres@localhost/template1" + settings := env.Native{} + settings.Configure() + + dbConf := postgresql.DBConfig{ + User: settings.String(api.DatabaseUser), + Password: settings.String(api.DatabasePassword), + Address: settings.String(api.DatabaseHost), + DBName: "template1", // template1 exists on all default postgres instances. + } + + connStr := postgresql.PostgresConnectURI(dbConf) + db, openErr := sql.Open("postgres", connStr) if openErr != nil { return errors.Wrap(openErr, "Error opening connection") @@ -124,10 +135,19 @@ func runMigrations(dbName string, migrationsPath string) error { settings := env.Native{} settings.Configure() + dbConf := postgresql.DBConfig{ + User: settings.String(api.DatabaseUser), + Password: settings.String(api.DatabasePassword), + Address: settings.String(api.DatabaseHost), + DBName: dbName, + } + + connStr := postgresql.PostgresConnectURI(dbConf) + apiPath := filepath.Dir(filepath.Clean(migrationsPath)) migration := api.Migration{Env: settings} - if migrationErr := migration.Up(apiPath, settings.String(api.GolangEnv), ""); migrationErr != nil { + if migrationErr := migration.Up(connStr, apiPath, settings.String(api.GolangEnv), ""); migrationErr != nil { return errors.Wrap(migrationErr, fmt.Sprintf("Error running migrations in path: %s", migrationsPath)) } @@ -139,8 +159,6 @@ type stackTracer interface { } func main() { - fmt.Println("Hello World") - shouldReset := flag.Bool("reset", false, "resets the data in the given db by deleting it and re-creating it") forceReset := flag.Bool("force", false, "skips the interactive dialog triggered by reset") migrationsPath := flag.String("migrations_path", "", "path to the directory containing migrations. If left out it will be guessed.") diff --git a/api/cmd/server/main.go b/api/cmd/server/main.go index 8b893e693..4ebcae6ee 100644 --- a/api/cmd/server/main.go +++ b/api/cmd/server/main.go @@ -30,8 +30,16 @@ func main() { localClock := clock.New() settings := env.Native{} settings.Configure() - database := &postgresql.Service{Log: logger, Env: settings} - database.Configure() + + dbConf := postgresql.DBConfig{ + User: settings.String(api.DatabaseUser), + Password: settings.String(api.DatabasePassword), + Address: settings.String(api.DatabaseHost), + DBName: settings.String(api.DatabaseName), + } + + database := postgresql.NewPostgresService(dbConf, logger) + token := jwt.Service{Env: settings} xmlsvc := xml.Service{Log: logger, Clock: localClock} pdfsvc := pdf.Service{Log: logger, Env: settings} @@ -42,7 +50,8 @@ func main() { if !*flagSkipMigration { ex, _ := os.Executable() migration := api.Migration{Env: settings} - if err := migration.Up(filepath.Dir(ex), settings.String(api.GolangEnv), ""); err != nil { + connStr := postgresql.PostgresConnectURI(dbConf) + if err := migration.Up(connStr, filepath.Dir(ex), settings.String(api.GolangEnv), ""); err != nil { logger.WarnError(api.WarnFailedMigration, err, api.LogFields{}) } } diff --git a/api/cmd/sftype/main.go b/api/cmd/sftype/main.go index 61cba9635..6ba73116e 100644 --- a/api/cmd/sftype/main.go +++ b/api/cmd/sftype/main.go @@ -23,8 +23,14 @@ func configureDB() api.DatabaseService { settings := &env.Native{} settings.Configure() - db := &postgresql.Service{Log: logger, Env: settings} - db.Configure() + dbConf := postgresql.DBConfig{ + User: os.Getenv(api.DatabaseUser), + Password: os.Getenv(api.DatabasePassword), + Address: os.Getenv(api.DatabaseHost), + DBName: os.Getenv(api.DatabaseName), + } + + db := postgresql.NewPostgresService(dbConf, logger) return db } diff --git a/api/database.go b/api/database.go index 17d51885d..ca6008554 100644 --- a/api/database.go +++ b/api/database.go @@ -22,7 +22,6 @@ func IsDatabaseErrorNotFound(err error) bool { // DatabaseService represents a persisted data storage. type DatabaseService interface { - Configure() CheckTable(entity interface{}) error Raw(query interface{}, params ...interface{}) error Find(query interface{}, callback func(query interface{})) diff --git a/api/env/env.go b/api/env/env.go index e71c751e8..3c15769b2 100644 --- a/api/env/env.go +++ b/api/env/env.go @@ -5,6 +5,7 @@ import ( "net/url" "os" "strconv" + "strings" "github.com/18F/e-QIP-prototype/api" ) @@ -14,10 +15,44 @@ type Native struct{} // Configure the environment. func (env Native) Configure() { + // Setting DatabaseURI overwrites all of the other database environment variables. + if env.Has(api.DatabaseURI) { + + // Parse the address as a URI. If it fails behave as if DatabaseURI is not set + dbString := env.String(api.DatabaseURI) + uri, err := url.Parse(dbString) + if err != nil { + fmt.Printf("ERROR: The %s did not parse: %s\n", api.DatabaseURI, dbString) + } else { + // Remove the leading slash on the path to retrieve the database name + dbName := strings.TrimPrefix(uri.Path, "/") + + // Ignore whether the password was set or not since an empty string suffices + // for the connection options as well. + dbPassword, _ := uri.User.Password() + + if env.Has(api.DatabaseUser) || env.Has(api.DatabasePassword) || + env.Has(api.DatabaseHost) || env.Has(api.DatabaseName) { + fmt.Printf("WARNING: Setting %s is overwriting the values set in %s, %s, %s, and %s.\n", + api.DatabaseURI, api.DatabaseUser, api.DatabasePassword, api.DatabaseHost, api.DatabaseName) + } + + os.Setenv(api.DatabaseUser, uri.User.Username()) + os.Setenv(api.DatabasePassword, dbPassword) + os.Setenv(api.DatabaseHost, uri.Host) + os.Setenv(api.DatabaseName, dbName) + } + } + + // ensure the db variable defaults are set + env.ensure(api.DatabaseUser, "postgres") + env.ensure(api.DatabaseHost, "localhost:5432") + env.ensure(api.DatabaseName, "postgres") + env.ensure(api.TestDatabaseName, "eapp_test") + env.ensure(api.GolangEnv, "development") env.ensure(api.LogLevel, "warning") env.ensure(api.SessionTimeout, "15") - env.ensure(api.DatabaseURI, env.buildDatabaseURI()) env.ensure(api.Port, "3000") env.ensure(api.HashRouting, "0") env.ensure(api.FlushStorage, "0") @@ -65,39 +100,3 @@ func (env Native) ensure(name, value string) { os.Setenv(name, value) } } - -func (env Native) buildDatabaseURI() string { - // By user (+ password) + database + host - uri := &url.URL{Scheme: "postgres"} - username := env.String(api.DatabaseUser) - if username == "" { - username = "postgres" - } - - // Check if there is a password set. If not then we need to create - // the Userinfo structure in a different way so we don't include - // exta colons (:). - pw := env.String(api.DatabasePassword) - if pw == "" { - uri.User = url.User(username) - } else { - uri.User = url.UserPassword(username, pw) - } - - // The database name will be part of the URI path so it needs - // a prefix of "/" - database := env.String(api.DatabaseName) - if database == "" { - database = "postgres" - } - uri.Path = fmt.Sprintf("/%s", database) - - // Host can be either "address + port" or just "address" - host := env.String(api.DatabaseHost) - if host == "" { - host = "localhost:5432" - } - uri.Host = host - - return uri.String() -} diff --git a/api/integration/setup.go b/api/integration/setup.go index 3a09dc3b8..d92029f14 100644 --- a/api/integration/setup.go +++ b/api/integration/setup.go @@ -23,24 +23,24 @@ import ( type serviceSet struct { env api.Settings log api.LogService - // token api.TokenService - db api.DatabaseService + db api.DatabaseService } func cleanTestServices() serviceSet { env := &env.Native{} os.Setenv(api.LogLevel, "info") - os.Setenv(api.DatabaseName, "eapp_test") env.Configure() log := &log.Service{Log: log.NewLogger()} - db := &postgresql.Service{ - Log: log, - Env: env, + dbConf := postgresql.DBConfig{ + User: env.String(api.DatabaseUser), + Password: env.String(api.DatabasePassword), + Address: env.String(api.DatabaseHost), + DBName: env.String(api.TestDatabaseName), } - db.Configure() + db := postgresql.NewPostgresService(dbConf, log) return serviceSet{ env, diff --git a/api/migration.go b/api/migration.go index c45acfae0..ab4ca2c8c 100644 --- a/api/migration.go +++ b/api/migration.go @@ -15,8 +15,8 @@ type Migration struct { } // Up attempts to push any pending updates to the database -func (service Migration) Up(directory, environment, schema string) error { - conf, err := service.databaseConf(directory, environment, schema) +func (service Migration) Up(dbURI, directory, environment, schema string) error { + conf, err := service.databaseConf(dbURI, directory, environment, schema) if err != nil { return errors.Wrap(err, "Couldn't determine db Conf") } @@ -33,8 +33,8 @@ func (service Migration) Up(directory, environment, schema string) error { } // CurrentVersion gets the database current version according to the migration status -func (service Migration) CurrentVersion(directory, environment, schema string) (int64, error) { - conf, err := service.databaseConf(directory, environment, schema) +func (service Migration) CurrentVersion(dbURI, directory, environment, schema string) (int64, error) { + conf, err := service.databaseConf(dbURI, directory, environment, schema) if err != nil { return 0, err } @@ -44,14 +44,12 @@ func (service Migration) CurrentVersion(directory, environment, schema string) ( // databaseConf will generate the configuration in memory using environment variables // instead of the YAML file. This is ideal to reduce the dependencies in production. -func (service Migration) databaseConf(directory, environment, schema string) (*migration.DBConf, error) { - // Pull from database connection string from the environment - uri := service.Env.String(DatabaseURI) +func (service Migration) databaseConf(dbURI, directory, environment, schema string) (*migration.DBConf, error) { return &migration.DBConf{ MigrationsDir: filepath.Join(directory, "migrations"), Env: environment, PgSchema: schema, - Driver: service.databaseDriver(uri), + Driver: service.databaseDriver(dbURI), }, nil } diff --git a/api/mock/database.go b/api/mock/database.go index 425cfd93c..4a8649e21 100644 --- a/api/mock/database.go +++ b/api/mock/database.go @@ -6,10 +6,6 @@ type DatabaseService struct { SelectCount int } -// Configure establishes a new database connection -func (service *DatabaseService) Configure() { -} - // CheckTable ensures a the table exists for the persistor. func (service *DatabaseService) CheckTable(entity interface{}) error { return nil diff --git a/api/postgresql/db.go b/api/postgresql/db.go index 505053d33..58c7eb716 100644 --- a/api/postgresql/db.go +++ b/api/postgresql/db.go @@ -1,13 +1,13 @@ package postgresql import ( + "fmt" "net/url" - "strings" "time" - "github.com/18F/e-QIP-prototype/api" "github.com/go-pg/pg" - "github.com/go-pg/pg/orm" + + "github.com/18F/e-QIP-prototype/api" ) // Service to help abstract the technical implementation per driver used. @@ -17,28 +17,51 @@ type Service struct { database *pg.DB } -// Configure establishes a new database connection -func (service *Service) Configure() { - addr := service.Env.String(api.DatabaseURI) +type DBConfig struct { + User string + Password string + Address string + DBName string +} - // Parse the address as a URI. If it fails return an empty connection - uri, err := url.Parse(addr) - if err != nil { - service.database = pg.Connect(&pg.Options{}) - return +func PostgresConnectURI(conf DBConfig) string { + // By user (+ password) + database + host + uri := &url.URL{Scheme: "postgres"} + username := conf.User + + // Check if there is a password set. If not then we need to create + // the Userinfo structure in a different way so we don't include + // exta colons (:). + pw := conf.Password + if pw == "" { + uri.User = url.User(username) + } else { + uri.User = url.UserPassword(username, pw) } - // Remove the leading slash on the path to retrieve the database name - dbURI := strings.TrimPrefix(uri.Path, "/") + // The database name will be part of the URI path so it needs + // a prefix of "/" + database := conf.DBName + uri.Path = fmt.Sprintf("/%s", database) + + // Host can be either "address + port" or just "address" + host := conf.Address + uri.Host = host + + return uri.String() +} + +// NewPostgresServices returns a configured postgres service +func NewPostgresService(config DBConfig, logger api.LogService) *Service { + service := Service{ + Log: logger, + } - // Ignore whether the password was set or not since an empty string suffices - // for the connection options as well. - pw, _ := uri.User.Password() db := pg.Connect(&pg.Options{ - User: uri.User.Username(), - Password: pw, - Addr: uri.Host, - Database: dbURI, + User: config.User, + Password: config.Password, + Addr: config.Address, + Database: config.DBName, }) // Add logging @@ -53,17 +76,12 @@ func (service *Service) Configure() { }) service.database = db + + return &service } // CheckTable ensures a the table exists for the persistor. func (service *Service) CheckTable(entity interface{}) error { - if service.Env.String(api.GolangEnv) == "test" { - options := &orm.CreateTableOptions{ - Temp: true, - IfNotExists: true, - } - return service.database.CreateTable(entity, options) - } return nil } diff --git a/api/postgresql/db_test.go b/api/postgresql/db_test.go index 41e628b5f..57a2571f4 100644 --- a/api/postgresql/db_test.go +++ b/api/postgresql/db_test.go @@ -9,6 +9,7 @@ import ( "testing" "github.com/18F/e-QIP-prototype/api" + "github.com/18F/e-QIP-prototype/api/env" "github.com/18F/e-QIP-prototype/api/mock" ) @@ -31,10 +32,20 @@ func readBinaryData(filepath string) ([]byte, error) { } func TestCollections(t *testing.T) { - settings := mock.Native{} + settings := env.Native{} settings.Configure() - service := &Service{Log: &mock.LogService{Off: true}, Env: settings} - service.Configure() + + logger := &mock.LogService{Off: true} + + dbConf := DBConfig{ + User: settings.String(api.DatabaseUser), + Password: settings.String(api.DatabasePassword), + Address: settings.String(api.DatabaseHost), + DBName: settings.String(api.TestDatabaseName), + } + + service := NewPostgresService(dbConf, logger) + account := 1 tests := []struct { @@ -269,10 +280,20 @@ func TestPayloadValidate(t *testing.T) { } func TestPayloadPersistence(t *testing.T) { - settings := mock.Native{} + settings := env.Native{} settings.Configure() - service := &Service{Log: &mock.LogService{Off: true}, Env: settings} - service.Configure() + + logger := &mock.LogService{Off: true} + + dbConf := DBConfig{ + User: settings.String(api.DatabaseUser), + Password: settings.String(api.DatabasePassword), + Address: settings.String(api.DatabaseHost), + DBName: settings.String(api.TestDatabaseName), + } + + service := NewPostgresService(dbConf, logger) + api.Geocode = mock.Geocoder{} account := api.Account{ diff --git a/api/settings.go b/api/settings.go index 082f6c3ed..4c604dae2 100644 --- a/api/settings.go +++ b/api/settings.go @@ -137,6 +137,12 @@ const ( // Default: `postgres` DatabaseName = "DATABASE_NAME" + // TestDatabaseName PostgreSQL database instance name for tests + // + // Target: Back-end (api) + // Default: `eapp_test` + TestDatabaseName = "TEST_DATABASE_NAME" + // DatabaseHost PostgreSQL database host name and port. // // Target: Back-end (api) diff --git a/api/signature.go b/api/signature.go index 504a29c08..2ec8e9014 100644 --- a/api/signature.go +++ b/api/signature.go @@ -1,6 +1,8 @@ package api -import "encoding/json" +import ( + "encoding/json" +) // Signature is a basic input. type Signature struct { @@ -109,6 +111,12 @@ func (entity *Signature) Delete(context DatabaseService, account int) (int, erro return entity.ID, err } + if entity.ID != 0 { + if err := context.Delete(entity); err != nil { + return entity.ID, err + } + } + if _, err := entity.Name.Delete(context, account); err != nil { return entity.ID, err } @@ -117,12 +125,6 @@ func (entity *Signature) Delete(context DatabaseService, account int) (int, erro return entity.ID, err } - if entity.ID != 0 { - if err := context.Delete(entity); err != nil { - return entity.ID, err - } - } - return entity.ID, nil } From 04552853f1f51468714684cab5a7862119095ed2 Mon Sep 17 00:00:00 2001 From: MacRae Linton <55759+macrael@users.noreply.github.com> Date: Thu, 4 Apr 2019 17:07:42 -0700 Subject: [PATCH 09/14] Fix linter comment errors --- api/postgresql/db.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/api/postgresql/db.go b/api/postgresql/db.go index 58c7eb716..10fb6a904 100644 --- a/api/postgresql/db.go +++ b/api/postgresql/db.go @@ -17,6 +17,7 @@ type Service struct { database *pg.DB } +// DBConfig contains everything neccecary to setup a postgres db connection type DBConfig struct { User string Password string @@ -24,6 +25,7 @@ type DBConfig struct { DBName string } +// PostgresConnectURI creates a connection string, which is used by the golang sql Open() function func PostgresConnectURI(conf DBConfig) string { // By user (+ password) + database + host uri := &url.URL{Scheme: "postgres"} @@ -51,7 +53,7 @@ func PostgresConnectURI(conf DBConfig) string { return uri.String() } -// NewPostgresServices returns a configured postgres service +// NewPostgresService returns a configured postgres service func NewPostgresService(config DBConfig, logger api.LogService) *Service { service := Service{ Log: logger, From b599071bb3b1385bd763ca2b9a7e0d2decef3b0c Mon Sep 17 00:00:00 2001 From: MacRae Linton <55759+macrael@users.noreply.github.com> Date: Thu, 4 Apr 2019 17:49:34 -0700 Subject: [PATCH 10/14] Remove CheckTable now that tests are running in a separate DB --- api/account.go | 10 -- api/attachment.go | 13 --- api/basicauth_membership.go | 9 -- api/benefit.go | 12 --- api/branch.go | 12 --- api/checkbox.go | 12 --- api/checkboxgroup.go | 12 --- api/citizenship.go | 36 ------- api/civilunion.go | 12 --- api/clearancelevel.go | 12 --- api/collection.go | 32 ------ api/contacts.go | 12 --- api/coowners.go | 12 --- api/country.go | 12 --- api/database.go | 1 - api/datecontrol.go | 12 --- api/daterange.go | 12 --- api/email.go | 12 --- api/employmentactivity.go | 12 --- api/financial.go | 96 ----------------- api/foreign.go | 204 ------------------------------------ api/foreignborndocument.go | 12 --- api/height.go | 12 --- api/history.go | 48 --------- api/identification.go | 84 --------------- api/legal.go | 204 ------------------------------------ api/location.go | 12 --- api/military.go | 74 +++---------- api/mock/database.go | 5 - api/name.go | 12 --- api/notapplicable.go | 12 --- api/number.go | 12 --- api/physicaladdress.go | 12 --- api/postgresql/db.go | 5 - api/psychological.go | 60 ----------- api/radio.go | 12 --- api/reasonleft.go | 12 --- api/relationships.go | 48 --------- api/sentence.go | 12 --- api/signature.go | 12 --- api/ssn.go | 12 --- api/submission.go | 72 ------------- api/substance.go | 132 ----------------------- api/supervisor.go | 12 --- api/telephone.go | 12 --- api/text.go | 12 --- api/textarea.go | 12 --- api/treatment.go | 12 --- 48 files changed, 13 insertions(+), 1480 deletions(-) diff --git a/api/account.go b/api/account.go index 099cc1877..992830c44 100644 --- a/api/account.go +++ b/api/account.go @@ -76,10 +76,6 @@ func (entity *Account) Save(context DatabaseService, account int) (int, error) { return entity.ID, err } - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := context.Save(entity); err != nil { return entity.ID, err } @@ -89,9 +85,6 @@ func (entity *Account) Save(context DatabaseService, account int) (int, error) { // Delete the Account entity. func (entity *Account) Delete(context DatabaseService, account int) (int, error) { - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } if entity.ID != 0 { if err := context.Delete(entity); err != nil { @@ -104,9 +97,6 @@ func (entity *Account) Delete(context DatabaseService, account int) (int, error) // Get the Account entity. func (entity *Account) Get(context DatabaseService, account int) (int, error) { - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } if err := entity.Find(context); err != nil { return entity.ID, err diff --git a/api/attachment.go b/api/attachment.go index 102504e52..c81951e52 100644 --- a/api/attachment.go +++ b/api/attachment.go @@ -42,11 +42,6 @@ func (entity *Attachment) Valid() (bool, error) { // Save the attachment. func (entity *Attachment) Save(context DatabaseService, account int) (int, error) { entity.AccountID = account - - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := context.Save(entity); err != nil { return entity.ID, err } @@ -56,10 +51,6 @@ func (entity *Attachment) Save(context DatabaseService, account int) (int, error // Delete the attachment. func (entity *Attachment) Delete(context DatabaseService, account int) (int, error) { - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if entity.ID != 0 { if err := context.Delete(entity); err != nil { return entity.ID, err @@ -71,10 +62,6 @@ func (entity *Attachment) Delete(context DatabaseService, account int) (int, err // Get the attachment. func (entity *Attachment) Get(context DatabaseService, account int) (int, error) { - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if entity.ID != 0 { if err := context.Select(entity); err != nil { return entity.ID, err diff --git a/api/basicauth_membership.go b/api/basicauth_membership.go index b481e4354..c33ee8ec9 100644 --- a/api/basicauth_membership.go +++ b/api/basicauth_membership.go @@ -17,9 +17,6 @@ type BasicAuthMembership struct { // Save the basic membership. func (entity *BasicAuthMembership) Save(context DatabaseService, account int) (int, error) { - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } if err := context.Save(entity); err != nil { return entity.ID, err @@ -30,9 +27,6 @@ func (entity *BasicAuthMembership) Save(context DatabaseService, account int) (i // Delete the basic membership. func (entity *BasicAuthMembership) Delete(context DatabaseService, account int) (int, error) { - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } if entity.ID != 0 { if err := context.Delete(entity); err != nil { @@ -45,9 +39,6 @@ func (entity *BasicAuthMembership) Delete(context DatabaseService, account int) // Get the basic membership. func (entity *BasicAuthMembership) Get(context DatabaseService, account int) (int, error) { - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } if err := entity.Find(context); err != nil { return entity.ID, err diff --git a/api/benefit.go b/api/benefit.go index df965db3f..eeebb7b3c 100644 --- a/api/benefit.go +++ b/api/benefit.go @@ -216,10 +216,6 @@ func (entity *Benefit) Valid() (bool, error) { func (entity *Benefit) Save(context DatabaseService, account int) (int, error) { entity.AccountID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } @@ -319,10 +315,6 @@ func (entity *Benefit) Save(context DatabaseService, account int) (int, error) { func (entity *Benefit) Delete(context DatabaseService, account int) (int, error) { entity.AccountID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } @@ -400,10 +392,6 @@ func (entity *Benefit) Delete(context DatabaseService, account int) (int, error) func (entity *Benefit) Get(context DatabaseService, account int) (int, error) { entity.AccountID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } diff --git a/api/branch.go b/api/branch.go index ee6c80d4d..66d12f02c 100644 --- a/api/branch.go +++ b/api/branch.go @@ -39,10 +39,6 @@ func (entity *Branch) Valid() (bool, error) { // Save the Branch entity. func (entity *Branch) Save(context DatabaseService, account int) (int, error) { - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := context.Save(entity); err != nil { return entity.ID, err } @@ -52,10 +48,6 @@ func (entity *Branch) Save(context DatabaseService, account int) (int, error) { // Delete the Branch entity. func (entity *Branch) Delete(context DatabaseService, account int) (int, error) { - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if entity.ID != 0 { if err := context.Delete(entity); err != nil { return entity.ID, err @@ -67,10 +59,6 @@ func (entity *Branch) Delete(context DatabaseService, account int) (int, error) // Get the Branch entity. func (entity *Branch) Get(context DatabaseService, account int) (int, error) { - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if entity.ID != 0 { if err := context.Select(entity); err != nil { return entity.ID, err diff --git a/api/checkbox.go b/api/checkbox.go index d91dac602..0bb0a8f44 100644 --- a/api/checkbox.go +++ b/api/checkbox.go @@ -26,10 +26,6 @@ func (entity *Checkbox) Valid() (bool, error) { // Save the checkbox to data storage. func (entity *Checkbox) Save(context DatabaseService, account int) (int, error) { - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := context.Save(entity); err != nil { return entity.ID, err } @@ -39,10 +35,6 @@ func (entity *Checkbox) Save(context DatabaseService, account int) (int, error) // Delete the checkbox from data storage. func (entity *Checkbox) Delete(context DatabaseService, account int) (int, error) { - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if entity.ID != 0 { if err := context.Delete(entity); err != nil { return entity.ID, err @@ -54,10 +46,6 @@ func (entity *Checkbox) Delete(context DatabaseService, account int) (int, error // Get the checkbox from data storage. func (entity *Checkbox) Get(context DatabaseService, account int) (int, error) { - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if entity.ID != 0 { if err := context.Select(entity); err != nil { return entity.ID, err diff --git a/api/checkboxgroup.go b/api/checkboxgroup.go index 28e342e4c..43971d73a 100644 --- a/api/checkboxgroup.go +++ b/api/checkboxgroup.go @@ -25,10 +25,6 @@ func (entity *CheckboxGroup) Valid() (bool, error) { // Save the checkbox group to data storage. func (entity *CheckboxGroup) Save(context DatabaseService, account int) (int, error) { - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := context.Save(entity); err != nil { return entity.ID, err } @@ -38,10 +34,6 @@ func (entity *CheckboxGroup) Save(context DatabaseService, account int) (int, er // Delete the checkbox group to data storage. func (entity *CheckboxGroup) Delete(context DatabaseService, account int) (int, error) { - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if entity.ID != 0 { if err := context.Delete(entity); err != nil { return entity.ID, err @@ -53,10 +45,6 @@ func (entity *CheckboxGroup) Delete(context DatabaseService, account int) (int, // Get the checkbox group to data storage. func (entity *CheckboxGroup) Get(context DatabaseService, account int) (int, error) { - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if entity.ID != 0 { if err := context.Select(entity); err != nil { return entity.ID, err diff --git a/api/citizenship.go b/api/citizenship.go index 5283eb3f0..06b2195cd 100644 --- a/api/citizenship.go +++ b/api/citizenship.go @@ -441,10 +441,6 @@ func (entity *CitizenshipStatus) Valid() (bool, error) { func (entity *CitizenshipStatus) Save(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } @@ -610,10 +606,6 @@ func (entity *CitizenshipStatus) Save(context DatabaseService, account int) (int func (entity *CitizenshipStatus) Delete(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } @@ -731,10 +723,6 @@ func (entity *CitizenshipStatus) Delete(context DatabaseService, account int) (i func (entity *CitizenshipStatus) Get(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if entity.ID != 0 { if err := context.Select(entity); err != nil { return entity.ID, err @@ -1131,10 +1119,6 @@ func (entity *CitizenshipMultiple) Valid() (bool, error) { func (entity *CitizenshipMultiple) Save(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } @@ -1162,10 +1146,6 @@ func (entity *CitizenshipMultiple) Save(context DatabaseService, account int) (i func (entity *CitizenshipMultiple) Delete(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } @@ -1191,10 +1171,6 @@ func (entity *CitizenshipMultiple) Delete(context DatabaseService, account int) func (entity *CitizenshipMultiple) Get(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if entity.ID != 0 { if err := context.Select(entity); err != nil { return entity.ID, err @@ -1292,10 +1268,6 @@ func (entity *CitizenshipPassports) Valid() (bool, error) { func (entity *CitizenshipPassports) Save(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } @@ -1317,10 +1289,6 @@ func (entity *CitizenshipPassports) Save(context DatabaseService, account int) ( func (entity *CitizenshipPassports) Delete(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } @@ -1338,10 +1306,6 @@ func (entity *CitizenshipPassports) Delete(context DatabaseService, account int) func (entity *CitizenshipPassports) Get(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if entity.ID != 0 { if err := context.Select(entity); err != nil { return entity.ID, err diff --git a/api/civilunion.go b/api/civilunion.go index c4dc354ca..78b9432e9 100644 --- a/api/civilunion.go +++ b/api/civilunion.go @@ -371,10 +371,6 @@ func (entity *CivilUnion) Valid() (bool, error) { func (entity *CivilUnion) Save(context DatabaseService, account int) (int, error) { entity.AccountID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } @@ -510,10 +506,6 @@ func (entity *CivilUnion) Save(context DatabaseService, account int) (int, error func (entity *CivilUnion) Delete(context DatabaseService, account int) (int, error) { entity.AccountID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } @@ -592,10 +584,6 @@ func (entity *CivilUnion) Delete(context DatabaseService, account int) (int, err func (entity *CivilUnion) Get(context DatabaseService, account int) (int, error) { entity.AccountID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } diff --git a/api/clearancelevel.go b/api/clearancelevel.go index 01ef4150a..05911684a 100644 --- a/api/clearancelevel.go +++ b/api/clearancelevel.go @@ -72,10 +72,6 @@ func (entity *ClearanceLevel) Valid() (bool, error) { func (entity *ClearanceLevel) Save(context DatabaseService, account int) (int, error) { entity.AccountID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } @@ -103,10 +99,6 @@ func (entity *ClearanceLevel) Save(context DatabaseService, account int) (int, e func (entity *ClearanceLevel) Delete(context DatabaseService, account int) (int, error) { entity.AccountID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } @@ -132,10 +124,6 @@ func (entity *ClearanceLevel) Delete(context DatabaseService, account int) (int, func (entity *ClearanceLevel) Get(context DatabaseService, account int) (int, error) { entity.AccountID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } diff --git a/api/collection.go b/api/collection.go index d092ef77f..b7f201bd4 100644 --- a/api/collection.go +++ b/api/collection.go @@ -86,10 +86,6 @@ func (entity *Collection) Save(context DatabaseService, account int) (int, error entity.Branch = &Branch{} } - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } @@ -121,10 +117,6 @@ func (entity *Collection) Save(context DatabaseService, account int) (int, error func (entity *Collection) Delete(context DatabaseService, account int) (int, error) { entity.AccountID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } @@ -155,10 +147,6 @@ func (entity *Collection) Delete(context DatabaseService, account int) (int, err func (entity *Collection) Get(context DatabaseService, account int) (int, error) { entity.AccountID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } @@ -250,10 +238,6 @@ func (ci *CollectionItem) Valid() (bool, error) { func (ci *CollectionItem) Save(context DatabaseService, account, collectionID, index int) (int, error) { ci.ID = collectionID - if err := context.CheckTable(&CollectionItem{}); err != nil { - return ci.ID, err - } - err := ci.Each(func(name, entityType string, entity Entity, err error) error { // If a named payload was not able to be decoded then skip the saving // bit. @@ -284,10 +268,6 @@ func (ci *CollectionItem) Save(context DatabaseService, account, collectionID, i func (ci *CollectionItem) Delete(context DatabaseService, account, collectionID, index int) (int, error) { ci.ID = collectionID - if err := context.CheckTable(&CollectionItem{}); err != nil { - return ci.ID, err - } - ci.getItemPropertyNames(context) err := ci.Each(func(name, entityType string, entity Entity, err error) error { if err != nil { @@ -301,10 +281,6 @@ func (ci *CollectionItem) Delete(context DatabaseService, account, collectionID, Type: entityType, } - if err := context.CheckTable(entity); err != nil { - return err - } - id, err := entity.Delete(context, account) if err != nil { return err @@ -332,10 +308,6 @@ func (ci *CollectionItem) Delete(context DatabaseService, account, collectionID, func (ci *CollectionItem) Get(context DatabaseService, account, collectionID, index int) (int, error) { ci.ID = collectionID - if err := context.CheckTable(&CollectionItem{}); err != nil { - return ci.ID, err - } - ci.getItemPropertyNames(context) err := ci.Each(func(name, entityType string, entity Entity, err error) error { item := &CollectionItem{ @@ -351,10 +323,6 @@ func (ci *CollectionItem) Get(context DatabaseService, account, collectionID, in entity, _ = transform[item.Type]() entity.SetID(item.ItemID) - if err := context.CheckTable(entity); err != nil { - return err - } - if _, err = entity.Get(context, account); err != nil { return err } diff --git a/api/contacts.go b/api/contacts.go index 6c760cf03..057cc59ea 100644 --- a/api/contacts.go +++ b/api/contacts.go @@ -50,10 +50,6 @@ func (entity *Contacts) Valid() (bool, error) { func (entity *Contacts) Save(context DatabaseService, account int) (int, error) { entity.AccountID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } @@ -75,10 +71,6 @@ func (entity *Contacts) Save(context DatabaseService, account int) (int, error) func (entity *Contacts) Delete(context DatabaseService, account int) (int, error) { entity.AccountID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } @@ -100,10 +92,6 @@ func (entity *Contacts) Delete(context DatabaseService, account int) (int, error func (entity *Contacts) Get(context DatabaseService, account int) (int, error) { entity.AccountID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } diff --git a/api/coowners.go b/api/coowners.go index 87bf27598..6093bff80 100644 --- a/api/coowners.go +++ b/api/coowners.go @@ -50,10 +50,6 @@ func (entity *CoOwners) Valid() (bool, error) { func (entity *CoOwners) Save(context DatabaseService, account int) (int, error) { entity.AccountID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } @@ -75,10 +71,6 @@ func (entity *CoOwners) Save(context DatabaseService, account int) (int, error) func (entity *CoOwners) Delete(context DatabaseService, account int) (int, error) { entity.AccountID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } @@ -100,10 +92,6 @@ func (entity *CoOwners) Delete(context DatabaseService, account int) (int, error func (entity *CoOwners) Get(context DatabaseService, account int) (int, error) { entity.AccountID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } diff --git a/api/country.go b/api/country.go index 0f21b95dd..071124e9b 100644 --- a/api/country.go +++ b/api/country.go @@ -32,10 +32,6 @@ func (entity *Country) Valid() (bool, error) { // Save the country to data storage. func (entity *Country) Save(context DatabaseService, account int) (int, error) { - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := context.Save(entity); err != nil { return entity.ID, err } @@ -45,10 +41,6 @@ func (entity *Country) Save(context DatabaseService, account int) (int, error) { // Delete the country from data storage. func (entity *Country) Delete(context DatabaseService, account int) (int, error) { - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if entity.ID != 0 { if err := context.Delete(entity); err != nil { return entity.ID, err @@ -60,10 +52,6 @@ func (entity *Country) Delete(context DatabaseService, account int) (int, error) // Get the country from data storage. func (entity *Country) Get(context DatabaseService, account int) (int, error) { - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if entity.ID != 0 { if err := context.Select(entity); err != nil { return entity.ID, err diff --git a/api/database.go b/api/database.go index ca6008554..05482f8c0 100644 --- a/api/database.go +++ b/api/database.go @@ -22,7 +22,6 @@ func IsDatabaseErrorNotFound(err error) bool { // DatabaseService represents a persisted data storage. type DatabaseService interface { - CheckTable(entity interface{}) error Raw(query interface{}, params ...interface{}) error Find(query interface{}, callback func(query interface{})) FindAll(model interface{}) error diff --git a/api/datecontrol.go b/api/datecontrol.go index e131b9436..6eb76419b 100644 --- a/api/datecontrol.go +++ b/api/datecontrol.go @@ -71,10 +71,6 @@ func (entity *DateControl) Valid() (bool, error) { // Save the date control to data storage. func (entity *DateControl) Save(context DatabaseService, account int) (int, error) { - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := context.Save(entity); err != nil { return entity.ID, err } @@ -84,10 +80,6 @@ func (entity *DateControl) Save(context DatabaseService, account int) (int, erro // Delete the date control from data storage. func (entity *DateControl) Delete(context DatabaseService, account int) (int, error) { - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if entity.ID != 0 { if err := context.Delete(entity); err != nil { return entity.ID, err @@ -99,10 +91,6 @@ func (entity *DateControl) Delete(context DatabaseService, account int) (int, er // Get the date control from data storage. func (entity *DateControl) Get(context DatabaseService, account int) (int, error) { - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if entity.ID != 0 { if err := context.Select(entity); err != nil { return entity.ID, err diff --git a/api/daterange.go b/api/daterange.go index 73b12fffc..b4e1977c6 100644 --- a/api/daterange.go +++ b/api/daterange.go @@ -75,10 +75,6 @@ func (entity *DateRange) Valid() (bool, error) { func (entity *DateRange) Save(context DatabaseService, account int) (int, error) { entity.AccountID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } @@ -106,10 +102,6 @@ func (entity *DateRange) Save(context DatabaseService, account int) (int, error) func (entity *DateRange) Delete(context DatabaseService, account int) (int, error) { entity.AccountID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } @@ -135,10 +127,6 @@ func (entity *DateRange) Delete(context DatabaseService, account int) (int, erro func (entity *DateRange) Get(context DatabaseService, account int) (int, error) { entity.AccountID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if entity.ID != 0 { if err := context.Select(entity); err != nil { return entity.ID, err diff --git a/api/email.go b/api/email.go index af88a4d91..5f291ded9 100644 --- a/api/email.go +++ b/api/email.go @@ -37,10 +37,6 @@ func (entity *Email) Valid() (bool, error) { // Save the email to data storage. func (entity *Email) Save(context DatabaseService, account int) (int, error) { - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := context.Save(entity); err != nil { return entity.ID, err } @@ -50,10 +46,6 @@ func (entity *Email) Save(context DatabaseService, account int) (int, error) { // Delete the email from data storage. func (entity *Email) Delete(context DatabaseService, account int) (int, error) { - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if entity.ID != 0 { if err := context.Delete(entity); err != nil { return entity.ID, err @@ -65,10 +57,6 @@ func (entity *Email) Delete(context DatabaseService, account int) (int, error) { // Get the email from data storage. func (entity *Email) Get(context DatabaseService, account int) (int, error) { - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if entity.ID != 0 { if err := context.Select(entity); err != nil { return entity.ID, err diff --git a/api/employmentactivity.go b/api/employmentactivity.go index d2aec32cd..0f80da08b 100644 --- a/api/employmentactivity.go +++ b/api/employmentactivity.go @@ -42,10 +42,6 @@ func (entity *EmploymentActivity) Valid() (bool, error) { // Save the employment activity to data storage. func (entity *EmploymentActivity) Save(context DatabaseService, account int) (int, error) { - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := context.Save(entity); err != nil { return entity.ID, err } @@ -55,10 +51,6 @@ func (entity *EmploymentActivity) Save(context DatabaseService, account int) (in // Delete the employment activity from data storage. func (entity *EmploymentActivity) Delete(context DatabaseService, account int) (int, error) { - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if entity.ID != 0 { if err := context.Delete(entity); err != nil { return entity.ID, err @@ -70,10 +62,6 @@ func (entity *EmploymentActivity) Delete(context DatabaseService, account int) ( // Get the employment activity from data storage. func (entity *EmploymentActivity) Get(context DatabaseService, account int) (int, error) { - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if entity.ID != 0 { if err := context.Select(entity); err != nil { return entity.ID, err diff --git a/api/financial.go b/api/financial.go index b1302dd05..53d8eed37 100644 --- a/api/financial.go +++ b/api/financial.go @@ -73,10 +73,6 @@ func (entity *FinancialBankruptcy) Valid() (bool, error) { func (entity *FinancialBankruptcy) Save(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } @@ -104,10 +100,6 @@ func (entity *FinancialBankruptcy) Save(context DatabaseService, account int) (i func (entity *FinancialBankruptcy) Delete(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } @@ -133,10 +125,6 @@ func (entity *FinancialBankruptcy) Delete(context DatabaseService, account int) func (entity *FinancialBankruptcy) Get(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if entity.ID != 0 { if err := context.Select(entity); err != nil { return entity.ID, err @@ -257,10 +245,6 @@ func (entity *FinancialGambling) Valid() (bool, error) { func (entity *FinancialGambling) Save(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } @@ -288,10 +272,6 @@ func (entity *FinancialGambling) Save(context DatabaseService, account int) (int func (entity *FinancialGambling) Delete(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } @@ -317,10 +297,6 @@ func (entity *FinancialGambling) Delete(context DatabaseService, account int) (i func (entity *FinancialGambling) Get(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if entity.ID != 0 { if err := context.Select(entity); err != nil { return entity.ID, err @@ -441,10 +417,6 @@ func (entity *FinancialTaxes) Valid() (bool, error) { func (entity *FinancialTaxes) Save(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } @@ -461,10 +433,6 @@ func (entity *FinancialTaxes) Save(context DatabaseService, account int) (int, e } entity.ListID = listID - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := context.Save(entity); err != nil { return entity.ID, err } @@ -476,10 +444,6 @@ func (entity *FinancialTaxes) Save(context DatabaseService, account int) (int, e func (entity *FinancialTaxes) Delete(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } @@ -505,10 +469,6 @@ func (entity *FinancialTaxes) Delete(context DatabaseService, account int) (int, func (entity *FinancialTaxes) Get(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if entity.ID != 0 { if err := context.Select(entity); err != nil { return entity.ID, err @@ -629,10 +589,6 @@ func (entity *FinancialCard) Valid() (bool, error) { func (entity *FinancialCard) Save(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } @@ -649,10 +605,6 @@ func (entity *FinancialCard) Save(context DatabaseService, account int) (int, er } entity.ListID = listID - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := context.Save(entity); err != nil { return entity.ID, err } @@ -664,10 +616,6 @@ func (entity *FinancialCard) Save(context DatabaseService, account int) (int, er func (entity *FinancialCard) Delete(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } @@ -693,10 +641,6 @@ func (entity *FinancialCard) Delete(context DatabaseService, account int) (int, func (entity *FinancialCard) Get(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if entity.ID != 0 { if err := context.Select(entity); err != nil { return entity.ID, err @@ -817,10 +761,6 @@ func (entity *FinancialCredit) Valid() (bool, error) { func (entity *FinancialCredit) Save(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } @@ -837,10 +777,6 @@ func (entity *FinancialCredit) Save(context DatabaseService, account int) (int, } entity.ListID = listID - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := context.Save(entity); err != nil { return entity.ID, err } @@ -852,10 +788,6 @@ func (entity *FinancialCredit) Save(context DatabaseService, account int) (int, func (entity *FinancialCredit) Delete(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } @@ -881,10 +813,6 @@ func (entity *FinancialCredit) Delete(context DatabaseService, account int) (int func (entity *FinancialCredit) Get(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if entity.ID != 0 { if err := context.Select(entity); err != nil { return entity.ID, err @@ -1005,10 +933,6 @@ func (entity *FinancialDelinquent) Valid() (bool, error) { func (entity *FinancialDelinquent) Save(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } @@ -1036,10 +960,6 @@ func (entity *FinancialDelinquent) Save(context DatabaseService, account int) (i func (entity *FinancialDelinquent) Delete(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } @@ -1065,10 +985,6 @@ func (entity *FinancialDelinquent) Delete(context DatabaseService, account int) func (entity *FinancialDelinquent) Get(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if entity.ID != 0 { if err := context.Select(entity); err != nil { return entity.ID, err @@ -1189,10 +1105,6 @@ func (entity *FinancialNonpayment) Valid() (bool, error) { func (entity *FinancialNonpayment) Save(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } @@ -1220,10 +1132,6 @@ func (entity *FinancialNonpayment) Save(context DatabaseService, account int) (i func (entity *FinancialNonpayment) Delete(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } @@ -1249,10 +1157,6 @@ func (entity *FinancialNonpayment) Delete(context DatabaseService, account int) func (entity *FinancialNonpayment) Get(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if entity.ID != 0 { if err := context.Select(entity); err != nil { return entity.ID, err diff --git a/api/foreign.go b/api/foreign.go index 3daef1539..aa68e6c29 100644 --- a/api/foreign.go +++ b/api/foreign.go @@ -154,10 +154,6 @@ func (entity *ForeignPassport) Valid() (bool, error) { func (entity *ForeignPassport) Save(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } @@ -215,10 +211,6 @@ func (entity *ForeignPassport) Save(context DatabaseService, account int) (int, func (entity *ForeignPassport) Delete(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } @@ -264,10 +256,6 @@ func (entity *ForeignPassport) Delete(context DatabaseService, account int) (int func (entity *ForeignPassport) Get(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if entity.ID != 0 { if err := context.Select(entity); err != nil { return entity.ID, err @@ -440,10 +428,6 @@ func (entity *ForeignContacts) Valid() (bool, error) { func (entity *ForeignContacts) Save(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } @@ -471,10 +455,6 @@ func (entity *ForeignContacts) Save(context DatabaseService, account int) (int, func (entity *ForeignContacts) Delete(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } @@ -500,10 +480,6 @@ func (entity *ForeignContacts) Delete(context DatabaseService, account int) (int func (entity *ForeignContacts) Get(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if entity.ID != 0 { if err := context.Select(entity); err != nil { return entity.ID, err @@ -632,10 +608,6 @@ func (entity *ForeignTravel) Valid() (bool, error) { func (entity *ForeignTravel) Save(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } @@ -669,10 +641,6 @@ func (entity *ForeignTravel) Save(context DatabaseService, account int) (int, er func (entity *ForeignTravel) Delete(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } @@ -702,10 +670,6 @@ func (entity *ForeignTravel) Delete(context DatabaseService, account int) (int, func (entity *ForeignTravel) Get(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if entity.ID != 0 { if err := context.Select(entity); err != nil { return entity.ID, err @@ -830,10 +794,6 @@ func (entity *ForeignActivitiesBenefits) Valid() (bool, error) { func (entity *ForeignActivitiesBenefits) Save(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } @@ -861,10 +821,6 @@ func (entity *ForeignActivitiesBenefits) Save(context DatabaseService, account i func (entity *ForeignActivitiesBenefits) Delete(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } @@ -890,10 +846,6 @@ func (entity *ForeignActivitiesBenefits) Delete(context DatabaseService, account func (entity *ForeignActivitiesBenefits) Get(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if entity.ID != 0 { if err := context.Select(entity); err != nil { return entity.ID, err @@ -1006,10 +958,6 @@ func (entity *ForeignActivitiesDirect) Valid() (bool, error) { func (entity *ForeignActivitiesDirect) Save(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } @@ -1037,10 +985,6 @@ func (entity *ForeignActivitiesDirect) Save(context DatabaseService, account int func (entity *ForeignActivitiesDirect) Delete(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } @@ -1066,10 +1010,6 @@ func (entity *ForeignActivitiesDirect) Delete(context DatabaseService, account i func (entity *ForeignActivitiesDirect) Get(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if entity.ID != 0 { if err := context.Select(entity); err != nil { return entity.ID, err @@ -1182,10 +1122,6 @@ func (entity *ForeignActivitiesIndirect) Valid() (bool, error) { func (entity *ForeignActivitiesIndirect) Save(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } @@ -1213,10 +1149,6 @@ func (entity *ForeignActivitiesIndirect) Save(context DatabaseService, account i func (entity *ForeignActivitiesIndirect) Delete(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } @@ -1242,10 +1174,6 @@ func (entity *ForeignActivitiesIndirect) Delete(context DatabaseService, account func (entity *ForeignActivitiesIndirect) Get(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if entity.ID != 0 { if err := context.Select(entity); err != nil { return entity.ID, err @@ -1358,10 +1286,6 @@ func (entity *ForeignActivitiesRealEstate) Valid() (bool, error) { func (entity *ForeignActivitiesRealEstate) Save(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } @@ -1389,10 +1313,6 @@ func (entity *ForeignActivitiesRealEstate) Save(context DatabaseService, account func (entity *ForeignActivitiesRealEstate) Delete(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } @@ -1418,10 +1338,6 @@ func (entity *ForeignActivitiesRealEstate) Delete(context DatabaseService, accou func (entity *ForeignActivitiesRealEstate) Get(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if entity.ID != 0 { if err := context.Select(entity); err != nil { return entity.ID, err @@ -1534,10 +1450,6 @@ func (entity *ForeignActivitiesSupport) Valid() (bool, error) { func (entity *ForeignActivitiesSupport) Save(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } @@ -1565,10 +1477,6 @@ func (entity *ForeignActivitiesSupport) Save(context DatabaseService, account in func (entity *ForeignActivitiesSupport) Delete(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } @@ -1594,10 +1502,6 @@ func (entity *ForeignActivitiesSupport) Delete(context DatabaseService, account func (entity *ForeignActivitiesSupport) Get(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if entity.ID != 0 { if err := context.Select(entity); err != nil { return entity.ID, err @@ -1710,10 +1614,6 @@ func (entity *ForeignBusinessAdvice) Valid() (bool, error) { func (entity *ForeignBusinessAdvice) Save(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } @@ -1741,10 +1641,6 @@ func (entity *ForeignBusinessAdvice) Save(context DatabaseService, account int) func (entity *ForeignBusinessAdvice) Delete(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } @@ -1770,10 +1666,6 @@ func (entity *ForeignBusinessAdvice) Delete(context DatabaseService, account int func (entity *ForeignBusinessAdvice) Get(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if entity.ID != 0 { if err := context.Select(entity); err != nil { return entity.ID, err @@ -1886,10 +1778,6 @@ func (entity *ForeignBusinessConferences) Valid() (bool, error) { func (entity *ForeignBusinessConferences) Save(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } @@ -1917,10 +1805,6 @@ func (entity *ForeignBusinessConferences) Save(context DatabaseService, account func (entity *ForeignBusinessConferences) Delete(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } @@ -1946,10 +1830,6 @@ func (entity *ForeignBusinessConferences) Delete(context DatabaseService, accoun func (entity *ForeignBusinessConferences) Get(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if entity.ID != 0 { if err := context.Select(entity); err != nil { return entity.ID, err @@ -2062,10 +1942,6 @@ func (entity *ForeignBusinessContact) Valid() (bool, error) { func (entity *ForeignBusinessContact) Save(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } @@ -2093,10 +1969,6 @@ func (entity *ForeignBusinessContact) Save(context DatabaseService, account int) func (entity *ForeignBusinessContact) Delete(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } @@ -2122,10 +1994,6 @@ func (entity *ForeignBusinessContact) Delete(context DatabaseService, account in func (entity *ForeignBusinessContact) Get(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if entity.ID != 0 { if err := context.Select(entity); err != nil { return entity.ID, err @@ -2238,10 +2106,6 @@ func (entity *ForeignBusinessEmployment) Valid() (bool, error) { func (entity *ForeignBusinessEmployment) Save(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } @@ -2269,10 +2133,6 @@ func (entity *ForeignBusinessEmployment) Save(context DatabaseService, account i func (entity *ForeignBusinessEmployment) Delete(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } @@ -2298,10 +2158,6 @@ func (entity *ForeignBusinessEmployment) Delete(context DatabaseService, account func (entity *ForeignBusinessEmployment) Get(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if entity.ID != 0 { if err := context.Select(entity); err != nil { return entity.ID, err @@ -2414,10 +2270,6 @@ func (entity *ForeignBusinessFamily) Valid() (bool, error) { func (entity *ForeignBusinessFamily) Save(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } @@ -2445,10 +2297,6 @@ func (entity *ForeignBusinessFamily) Save(context DatabaseService, account int) func (entity *ForeignBusinessFamily) Delete(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } @@ -2474,10 +2322,6 @@ func (entity *ForeignBusinessFamily) Delete(context DatabaseService, account int func (entity *ForeignBusinessFamily) Get(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if entity.ID != 0 { if err := context.Select(entity); err != nil { return entity.ID, err @@ -2590,10 +2434,6 @@ func (entity *ForeignBusinessPolitical) Valid() (bool, error) { func (entity *ForeignBusinessPolitical) Save(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } @@ -2621,10 +2461,6 @@ func (entity *ForeignBusinessPolitical) Save(context DatabaseService, account in func (entity *ForeignBusinessPolitical) Delete(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } @@ -2650,10 +2486,6 @@ func (entity *ForeignBusinessPolitical) Delete(context DatabaseService, account func (entity *ForeignBusinessPolitical) Get(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if entity.ID != 0 { if err := context.Select(entity); err != nil { return entity.ID, err @@ -2766,10 +2598,6 @@ func (entity *ForeignBusinessSponsorship) Valid() (bool, error) { func (entity *ForeignBusinessSponsorship) Save(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } @@ -2797,10 +2625,6 @@ func (entity *ForeignBusinessSponsorship) Save(context DatabaseService, account func (entity *ForeignBusinessSponsorship) Delete(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } @@ -2826,10 +2650,6 @@ func (entity *ForeignBusinessSponsorship) Delete(context DatabaseService, accoun func (entity *ForeignBusinessSponsorship) Get(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if entity.ID != 0 { if err := context.Select(entity); err != nil { return entity.ID, err @@ -2942,10 +2762,6 @@ func (entity *ForeignBusinessVentures) Valid() (bool, error) { func (entity *ForeignBusinessVentures) Save(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } @@ -2973,10 +2789,6 @@ func (entity *ForeignBusinessVentures) Save(context DatabaseService, account int func (entity *ForeignBusinessVentures) Delete(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } @@ -3002,10 +2814,6 @@ func (entity *ForeignBusinessVentures) Delete(context DatabaseService, account i func (entity *ForeignBusinessVentures) Get(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if entity.ID != 0 { if err := context.Select(entity); err != nil { return entity.ID, err @@ -3118,10 +2926,6 @@ func (entity *ForeignBusinessVoting) Valid() (bool, error) { func (entity *ForeignBusinessVoting) Save(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } @@ -3149,10 +2953,6 @@ func (entity *ForeignBusinessVoting) Save(context DatabaseService, account int) func (entity *ForeignBusinessVoting) Delete(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } @@ -3178,10 +2978,6 @@ func (entity *ForeignBusinessVoting) Delete(context DatabaseService, account int func (entity *ForeignBusinessVoting) Get(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if entity.ID != 0 { if err := context.Select(entity); err != nil { return entity.ID, err diff --git a/api/foreignborndocument.go b/api/foreignborndocument.go index 450f42eef..d7386fb69 100644 --- a/api/foreignborndocument.go +++ b/api/foreignborndocument.go @@ -108,10 +108,6 @@ func (entity *ForeignBornDocument) Valid() (bool, error) { func (entity *ForeignBornDocument) Save(context DatabaseService, account int) (int, error) { entity.AccountID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } @@ -157,10 +153,6 @@ func (entity *ForeignBornDocument) Save(context DatabaseService, account int) (i func (entity *ForeignBornDocument) Delete(context DatabaseService, account int) (int, error) { entity.AccountID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } @@ -198,10 +190,6 @@ func (entity *ForeignBornDocument) Delete(context DatabaseService, account int) func (entity *ForeignBornDocument) Get(context DatabaseService, account int) (int, error) { entity.AccountID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } diff --git a/api/height.go b/api/height.go index 469a0f73e..4f6b66c33 100644 --- a/api/height.go +++ b/api/height.go @@ -36,10 +36,6 @@ func (entity *Height) Valid() (bool, error) { // Save the height to data storage. func (entity *Height) Save(context DatabaseService, account int) (int, error) { - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := context.Save(entity); err != nil { return entity.ID, err } @@ -49,10 +45,6 @@ func (entity *Height) Save(context DatabaseService, account int) (int, error) { // Delete the height from data storage. func (entity *Height) Delete(context DatabaseService, account int) (int, error) { - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if entity.ID != 0 { if err := context.Delete(entity); err != nil { return entity.ID, err @@ -64,10 +56,6 @@ func (entity *Height) Delete(context DatabaseService, account int) (int, error) // Get the height from data storage. func (entity *Height) Get(context DatabaseService, account int) (int, error) { - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if entity.ID != 0 { if err := context.Select(entity); err != nil { return entity.ID, err diff --git a/api/history.go b/api/history.go index 003363467..eda470d97 100644 --- a/api/history.go +++ b/api/history.go @@ -51,10 +51,6 @@ func (entity *HistoryResidence) Valid() (bool, error) { func (entity *HistoryResidence) Save(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } @@ -76,10 +72,6 @@ func (entity *HistoryResidence) Save(context DatabaseService, account int) (int, func (entity *HistoryResidence) Delete(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } @@ -101,10 +93,6 @@ func (entity *HistoryResidence) Delete(context DatabaseService, account int) (in func (entity *HistoryResidence) Get(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if entity.ID != 0 { if err := context.Select(entity); err != nil { return entity.ID, err @@ -231,10 +219,6 @@ func (entity *HistoryEmployment) Valid() (bool, error) { func (entity *HistoryEmployment) Save(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } @@ -262,10 +246,6 @@ func (entity *HistoryEmployment) Save(context DatabaseService, account int) (int func (entity *HistoryEmployment) Delete(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } @@ -291,10 +271,6 @@ func (entity *HistoryEmployment) Delete(context DatabaseService, account int) (i func (entity *HistoryEmployment) Get(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if entity.ID != 0 { if err := context.Select(entity); err != nil { return entity.ID, err @@ -490,10 +466,6 @@ func (entity *HistoryEducation) Valid() (bool, error) { func (entity *HistoryEducation) Save(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } @@ -527,10 +499,6 @@ func (entity *HistoryEducation) Save(context DatabaseService, account int) (int, func (entity *HistoryEducation) Delete(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } @@ -560,10 +528,6 @@ func (entity *HistoryEducation) Delete(context DatabaseService, account int) (in func (entity *HistoryEducation) Get(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if entity.ID != 0 { if err := context.Select(entity); err != nil { return entity.ID, err @@ -688,10 +652,6 @@ func (entity *HistoryFederal) Valid() (bool, error) { func (entity *HistoryFederal) Save(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } @@ -719,10 +679,6 @@ func (entity *HistoryFederal) Save(context DatabaseService, account int) (int, e func (entity *HistoryFederal) Delete(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } @@ -748,10 +704,6 @@ func (entity *HistoryFederal) Delete(context DatabaseService, account int) (int, func (entity *HistoryFederal) Get(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if entity.ID != 0 { if err := context.Select(entity); err != nil { return entity.ID, err diff --git a/api/identification.go b/api/identification.go index 3aed5183d..461195798 100644 --- a/api/identification.go +++ b/api/identification.go @@ -51,10 +51,6 @@ func (entity *IdentificationName) Valid() (bool, error) { func (entity *IdentificationName) Save(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } @@ -76,10 +72,6 @@ func (entity *IdentificationName) Save(context DatabaseService, account int) (in func (entity *IdentificationName) Delete(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } @@ -101,10 +93,6 @@ func (entity *IdentificationName) Delete(context DatabaseService, account int) ( func (entity *IdentificationName) Get(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if entity.ID != 0 { if err := context.Select(entity); err != nil { return entity.ID, err @@ -189,10 +177,6 @@ func (entity *IdentificationBirthPlace) Valid() (bool, error) { func (entity *IdentificationBirthPlace) Save(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } @@ -214,10 +198,6 @@ func (entity *IdentificationBirthPlace) Save(context DatabaseService, account in func (entity *IdentificationBirthPlace) Delete(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } @@ -239,10 +219,6 @@ func (entity *IdentificationBirthPlace) Delete(context DatabaseService, account func (entity *IdentificationBirthPlace) Get(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if entity.ID != 0 { if err := context.Select(entity); err != nil { return entity.ID, err @@ -339,10 +315,6 @@ func (entity *IdentificationBirthDate) Valid() (bool, error) { func (entity *IdentificationBirthDate) Save(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } @@ -370,10 +342,6 @@ func (entity *IdentificationBirthDate) Save(context DatabaseService, account int func (entity *IdentificationBirthDate) Delete(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } @@ -399,10 +367,6 @@ func (entity *IdentificationBirthDate) Delete(context DatabaseService, account i func (entity *IdentificationBirthDate) Get(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if entity.ID != 0 { if err := context.Select(entity); err != nil { return entity.ID, err @@ -509,10 +473,6 @@ func (entity *IdentificationSSN) Valid() (bool, error) { func (entity *IdentificationSSN) Save(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } @@ -534,10 +494,6 @@ func (entity *IdentificationSSN) Save(context DatabaseService, account int) (int func (entity *IdentificationSSN) Delete(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } @@ -559,10 +515,6 @@ func (entity *IdentificationSSN) Delete(context DatabaseService, account int) (i func (entity *IdentificationSSN) Get(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if entity.ID != 0 { if err := context.Select(entity); err != nil { return entity.ID, err @@ -685,10 +637,6 @@ func (entity *IdentificationContacts) Valid() (bool, error) { func (entity *IdentificationContacts) Save(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } @@ -722,10 +670,6 @@ func (entity *IdentificationContacts) Save(context DatabaseService, account int) func (entity *IdentificationContacts) Delete(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } @@ -755,10 +699,6 @@ func (entity *IdentificationContacts) Delete(context DatabaseService, account in func (entity *IdentificationContacts) Get(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if entity.ID != 0 { if err := context.Select(entity); err != nil { return entity.ID, err @@ -891,10 +831,6 @@ func (entity *IdentificationOtherNames) Valid() (bool, error) { func (entity *IdentificationOtherNames) Save(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } @@ -922,10 +858,6 @@ func (entity *IdentificationOtherNames) Save(context DatabaseService, account in func (entity *IdentificationOtherNames) Delete(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } @@ -951,10 +883,6 @@ func (entity *IdentificationOtherNames) Delete(context DatabaseService, account func (entity *IdentificationOtherNames) Get(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } @@ -1176,10 +1104,6 @@ func (entity *IdentificationPhysical) Valid() (bool, error) { func (entity *IdentificationPhysical) Save(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } @@ -1231,10 +1155,6 @@ func (entity *IdentificationPhysical) Save(context DatabaseService, account int) func (entity *IdentificationPhysical) Delete(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } @@ -1276,10 +1196,6 @@ func (entity *IdentificationPhysical) Delete(context DatabaseService, account in func (entity *IdentificationPhysical) Get(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } diff --git a/api/legal.go b/api/legal.go index 41cc4964a..4be87456e 100644 --- a/api/legal.go +++ b/api/legal.go @@ -63,10 +63,6 @@ func (entity *LegalCourt) Valid() (bool, error) { func (entity *LegalCourt) Save(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } @@ -94,10 +90,6 @@ func (entity *LegalCourt) Save(context DatabaseService, account int) (int, error func (entity *LegalCourt) Delete(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } @@ -123,10 +115,6 @@ func (entity *LegalCourt) Delete(context DatabaseService, account int) (int, err func (entity *LegalCourt) Get(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if entity.ID != 0 { if err := context.Select(entity); err != nil { return entity.ID, err @@ -239,10 +227,6 @@ func (entity *LegalPoliceOffenses) Valid() (bool, error) { func (entity *LegalPoliceOffenses) Save(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } @@ -270,10 +254,6 @@ func (entity *LegalPoliceOffenses) Save(context DatabaseService, account int) (i func (entity *LegalPoliceOffenses) Delete(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } @@ -299,10 +279,6 @@ func (entity *LegalPoliceOffenses) Delete(context DatabaseService, account int) func (entity *LegalPoliceOffenses) Get(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if entity.ID != 0 { if err := context.Select(entity); err != nil { return entity.ID, err @@ -415,10 +391,6 @@ func (entity *LegalPoliceAdditionalOffenses) Valid() (bool, error) { func (entity *LegalPoliceAdditionalOffenses) Save(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } @@ -446,10 +418,6 @@ func (entity *LegalPoliceAdditionalOffenses) Save(context DatabaseService, accou func (entity *LegalPoliceAdditionalOffenses) Delete(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } @@ -475,10 +443,6 @@ func (entity *LegalPoliceAdditionalOffenses) Delete(context DatabaseService, acc func (entity *LegalPoliceAdditionalOffenses) Get(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if entity.ID != 0 { if err := context.Select(entity); err != nil { return entity.ID, err @@ -590,10 +554,6 @@ func (entity *LegalPoliceDomesticViolence) Valid() (bool, error) { func (entity *LegalPoliceDomesticViolence) Save(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } @@ -621,10 +581,6 @@ func (entity *LegalPoliceDomesticViolence) Save(context DatabaseService, account func (entity *LegalPoliceDomesticViolence) Delete(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } @@ -650,10 +606,6 @@ func (entity *LegalPoliceDomesticViolence) Delete(context DatabaseService, accou func (entity *LegalPoliceDomesticViolence) Get(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if entity.ID != 0 { if err := context.Select(entity); err != nil { return entity.ID, err @@ -766,10 +718,6 @@ func (entity *LegalInvestigationsDebarred) Valid() (bool, error) { func (entity *LegalInvestigationsDebarred) Save(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } @@ -797,10 +745,6 @@ func (entity *LegalInvestigationsDebarred) Save(context DatabaseService, account func (entity *LegalInvestigationsDebarred) Delete(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } @@ -826,10 +770,6 @@ func (entity *LegalInvestigationsDebarred) Delete(context DatabaseService, accou func (entity *LegalInvestigationsDebarred) Get(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if entity.ID != 0 { if err := context.Select(entity); err != nil { return entity.ID, err @@ -942,10 +882,6 @@ func (entity *LegalInvestigationsHistory) Valid() (bool, error) { func (entity *LegalInvestigationsHistory) Save(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } @@ -973,10 +909,6 @@ func (entity *LegalInvestigationsHistory) Save(context DatabaseService, account func (entity *LegalInvestigationsHistory) Delete(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } @@ -1002,10 +934,6 @@ func (entity *LegalInvestigationsHistory) Delete(context DatabaseService, accoun func (entity *LegalInvestigationsHistory) Get(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if entity.ID != 0 { if err := context.Select(entity); err != nil { return entity.ID, err @@ -1118,10 +1046,6 @@ func (entity *LegalInvestigationsRevoked) Valid() (bool, error) { func (entity *LegalInvestigationsRevoked) Save(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } @@ -1149,10 +1073,6 @@ func (entity *LegalInvestigationsRevoked) Save(context DatabaseService, account func (entity *LegalInvestigationsRevoked) Delete(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } @@ -1178,10 +1098,6 @@ func (entity *LegalInvestigationsRevoked) Delete(context DatabaseService, accoun func (entity *LegalInvestigationsRevoked) Get(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if entity.ID != 0 { if err := context.Select(entity); err != nil { return entity.ID, err @@ -1294,10 +1210,6 @@ func (entity *LegalTechnologyManipulating) Valid() (bool, error) { func (entity *LegalTechnologyManipulating) Save(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } @@ -1325,10 +1237,6 @@ func (entity *LegalTechnologyManipulating) Save(context DatabaseService, account func (entity *LegalTechnologyManipulating) Delete(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } @@ -1354,10 +1262,6 @@ func (entity *LegalTechnologyManipulating) Delete(context DatabaseService, accou func (entity *LegalTechnologyManipulating) Get(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if entity.ID != 0 { if err := context.Select(entity); err != nil { return entity.ID, err @@ -1470,10 +1374,6 @@ func (entity *LegalTechnologyUnauthorized) Valid() (bool, error) { func (entity *LegalTechnologyUnauthorized) Save(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } @@ -1501,10 +1401,6 @@ func (entity *LegalTechnologyUnauthorized) Save(context DatabaseService, account func (entity *LegalTechnologyUnauthorized) Delete(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } @@ -1530,10 +1426,6 @@ func (entity *LegalTechnologyUnauthorized) Delete(context DatabaseService, accou func (entity *LegalTechnologyUnauthorized) Get(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if entity.ID != 0 { if err := context.Select(entity); err != nil { return entity.ID, err @@ -1646,10 +1538,6 @@ func (entity *LegalTechnologyUnlawful) Valid() (bool, error) { func (entity *LegalTechnologyUnlawful) Save(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } @@ -1677,10 +1565,6 @@ func (entity *LegalTechnologyUnlawful) Save(context DatabaseService, account int func (entity *LegalTechnologyUnlawful) Delete(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } @@ -1706,10 +1590,6 @@ func (entity *LegalTechnologyUnlawful) Delete(context DatabaseService, account i func (entity *LegalTechnologyUnlawful) Get(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if entity.ID != 0 { if err := context.Select(entity); err != nil { return entity.ID, err @@ -1822,10 +1702,6 @@ func (entity *LegalAssociationsActivitiesToOverthrow) Valid() (bool, error) { func (entity *LegalAssociationsActivitiesToOverthrow) Save(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } @@ -1853,10 +1729,6 @@ func (entity *LegalAssociationsActivitiesToOverthrow) Save(context DatabaseServi func (entity *LegalAssociationsActivitiesToOverthrow) Delete(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } @@ -1882,10 +1754,6 @@ func (entity *LegalAssociationsActivitiesToOverthrow) Delete(context DatabaseSer func (entity *LegalAssociationsActivitiesToOverthrow) Get(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if entity.ID != 0 { if err := context.Select(entity); err != nil { return entity.ID, err @@ -1998,10 +1866,6 @@ func (entity *LegalAssociationsAdvocating) Valid() (bool, error) { func (entity *LegalAssociationsAdvocating) Save(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } @@ -2029,10 +1893,6 @@ func (entity *LegalAssociationsAdvocating) Save(context DatabaseService, account func (entity *LegalAssociationsAdvocating) Delete(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } @@ -2058,10 +1918,6 @@ func (entity *LegalAssociationsAdvocating) Delete(context DatabaseService, accou func (entity *LegalAssociationsAdvocating) Get(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if entity.ID != 0 { if err := context.Select(entity); err != nil { return entity.ID, err @@ -2174,10 +2030,6 @@ func (entity *LegalAssociationsEngagedInTerrorism) Valid() (bool, error) { func (entity *LegalAssociationsEngagedInTerrorism) Save(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } @@ -2205,10 +2057,6 @@ func (entity *LegalAssociationsEngagedInTerrorism) Save(context DatabaseService, func (entity *LegalAssociationsEngagedInTerrorism) Delete(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } @@ -2234,10 +2082,6 @@ func (entity *LegalAssociationsEngagedInTerrorism) Delete(context DatabaseServic func (entity *LegalAssociationsEngagedInTerrorism) Get(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if entity.ID != 0 { if err := context.Select(entity); err != nil { return entity.ID, err @@ -2350,10 +2194,6 @@ func (entity *LegalAssociationsMembershipOverthrow) Valid() (bool, error) { func (entity *LegalAssociationsMembershipOverthrow) Save(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } @@ -2381,10 +2221,6 @@ func (entity *LegalAssociationsMembershipOverthrow) Save(context DatabaseService func (entity *LegalAssociationsMembershipOverthrow) Delete(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } @@ -2410,10 +2246,6 @@ func (entity *LegalAssociationsMembershipOverthrow) Delete(context DatabaseServi func (entity *LegalAssociationsMembershipOverthrow) Get(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if entity.ID != 0 { if err := context.Select(entity); err != nil { return entity.ID, err @@ -2526,10 +2358,6 @@ func (entity *LegalAssociationsMembershipViolence) Valid() (bool, error) { func (entity *LegalAssociationsMembershipViolence) Save(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } @@ -2557,10 +2385,6 @@ func (entity *LegalAssociationsMembershipViolence) Save(context DatabaseService, func (entity *LegalAssociationsMembershipViolence) Delete(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } @@ -2586,10 +2410,6 @@ func (entity *LegalAssociationsMembershipViolence) Delete(context DatabaseServic func (entity *LegalAssociationsMembershipViolence) Get(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if entity.ID != 0 { if err := context.Select(entity); err != nil { return entity.ID, err @@ -2702,10 +2522,6 @@ func (entity *LegalAssociationsTerrorismAssociation) Valid() (bool, error) { func (entity *LegalAssociationsTerrorismAssociation) Save(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } @@ -2733,10 +2549,6 @@ func (entity *LegalAssociationsTerrorismAssociation) Save(context DatabaseServic func (entity *LegalAssociationsTerrorismAssociation) Delete(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } @@ -2762,10 +2574,6 @@ func (entity *LegalAssociationsTerrorismAssociation) Delete(context DatabaseServ func (entity *LegalAssociationsTerrorismAssociation) Get(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if entity.ID != 0 { if err := context.Select(entity); err != nil { return entity.ID, err @@ -2878,10 +2686,6 @@ func (entity *LegalAssociationsTerroristOrganization) Valid() (bool, error) { func (entity *LegalAssociationsTerroristOrganization) Save(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } @@ -2909,10 +2713,6 @@ func (entity *LegalAssociationsTerroristOrganization) Save(context DatabaseServi func (entity *LegalAssociationsTerroristOrganization) Delete(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } @@ -2938,10 +2738,6 @@ func (entity *LegalAssociationsTerroristOrganization) Delete(context DatabaseSer func (entity *LegalAssociationsTerroristOrganization) Get(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if entity.ID != 0 { if err := context.Select(entity); err != nil { return entity.ID, err diff --git a/api/location.go b/api/location.go index 4d5b79ae1..88c632fe3 100644 --- a/api/location.go +++ b/api/location.go @@ -63,10 +63,6 @@ func (entity *Location) Marshal() Payload { // Save the location to data storage. func (entity *Location) Save(context DatabaseService, account int) (int, error) { - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := context.Save(entity); err != nil { return entity.ID, err } @@ -76,10 +72,6 @@ func (entity *Location) Save(context DatabaseService, account int) (int, error) // Delete the location from data storage. func (entity *Location) Delete(context DatabaseService, account int) (int, error) { - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if entity.ID != 0 { if err := context.Delete(entity); err != nil { return entity.ID, err @@ -91,10 +83,6 @@ func (entity *Location) Delete(context DatabaseService, account int) (int, error // Get the location from data storage. func (entity *Location) Get(context DatabaseService, account int) (int, error) { - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if entity.ID != 0 { if err := context.Select(entity); err != nil { return entity.ID, err diff --git a/api/military.go b/api/military.go index 4cbd6d5bc..f3832bc88 100644 --- a/api/military.go +++ b/api/military.go @@ -4,25 +4,25 @@ import "encoding/json" // MilitarySelective represents the payload for the military service section. type MilitarySelective struct { - PayloadWasBornAfter Payload `json:"WasBornAfter" sql:"-"` - PayloadHasRegistered Payload `json:"HasRegistered" sql:"-"` - PayloadRegistrationNumber Payload `json:"RegistrationNumber" sql:"-"` - PayloadExplanation Payload `json:"Explanation" sql:"-"` + PayloadWasBornAfter Payload `json:"WasBornAfter" sql:"-"` + PayloadHasRegistered Payload `json:"HasRegistered" sql:"-"` + PayloadRegistrationNumber Payload `json:"RegistrationNumber" sql:"-"` + PayloadExplanation Payload `json:"Explanation" sql:"-"` PayloadHasRegisteredNotApplicable Payload `json:"HasRegisteredNotApplicable" sql:"-"` // Validator specific fields - WasBornAfter *Branch `json:"-"` - HasRegistered *Branch `json:"-"` - RegistrationNumber *Text `json:"-"` - Explanation *Textarea `json:"-"` + WasBornAfter *Branch `json:"-"` + HasRegistered *Branch `json:"-"` + RegistrationNumber *Text `json:"-"` + Explanation *Textarea `json:"-"` HasRegisteredNotApplicable *NotApplicable `json:"-"` // Persister specific fields - ID int `json:"-"` - WasBornAfterID int `json:"-" pg:", fk:WasBornAfter"` - HasRegisteredID int `json:"-" pg:", fk:HasRegistered"` - RegistrationNumberID int `json:"-" pg:", fk:RegistrationNumber"` - ExplanationID int `json:"-" pg:", fk:Explanation"` + ID int `json:"-"` + WasBornAfterID int `json:"-" pg:", fk:WasBornAfter"` + HasRegisteredID int `json:"-" pg:", fk:HasRegistered"` + RegistrationNumberID int `json:"-" pg:", fk:RegistrationNumber"` + ExplanationID int `json:"-" pg:", fk:Explanation"` HasRegisteredNotApplicableID int `json:"-" pg:", fk:HasRegisteredNotApplicable"` } @@ -123,10 +123,6 @@ func (entity *MilitarySelective) Valid() (bool, error) { func (entity *MilitarySelective) Save(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } @@ -172,10 +168,6 @@ func (entity *MilitarySelective) Save(context DatabaseService, account int) (int func (entity *MilitarySelective) Delete(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } @@ -213,10 +205,6 @@ func (entity *MilitarySelective) Delete(context DatabaseService, account int) (i func (entity *MilitarySelective) Get(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if entity.ID != 0 { if err := context.Select(entity); err != nil { return entity.ID, err @@ -373,10 +361,6 @@ func (entity *MilitaryHistory) Valid() (bool, error) { func (entity *MilitaryHistory) Save(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } @@ -404,10 +388,6 @@ func (entity *MilitaryHistory) Save(context DatabaseService, account int) (int, func (entity *MilitaryHistory) Delete(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } @@ -433,10 +413,6 @@ func (entity *MilitaryHistory) Delete(context DatabaseService, account int) (int func (entity *MilitaryHistory) Get(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if entity.ID != 0 { if err := context.Select(entity); err != nil { return entity.ID, err @@ -557,10 +533,6 @@ func (entity *MilitaryDisciplinary) Valid() (bool, error) { func (entity *MilitaryDisciplinary) Save(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } @@ -588,10 +560,6 @@ func (entity *MilitaryDisciplinary) Save(context DatabaseService, account int) ( func (entity *MilitaryDisciplinary) Delete(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } @@ -617,10 +585,6 @@ func (entity *MilitaryDisciplinary) Delete(context DatabaseService, account int) func (entity *MilitaryDisciplinary) Get(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if entity.ID != 0 { if err := context.Select(entity); err != nil { return entity.ID, err @@ -723,10 +687,6 @@ func (entity *MilitaryForeign) Valid() (bool, error) { func (entity *MilitaryForeign) Save(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } @@ -748,10 +708,6 @@ func (entity *MilitaryForeign) Save(context DatabaseService, account int) (int, func (entity *MilitaryForeign) Delete(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } @@ -773,10 +729,6 @@ func (entity *MilitaryForeign) Delete(context DatabaseService, account int) (int func (entity *MilitaryForeign) Get(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if entity.ID != 0 { if err := context.Select(entity); err != nil { return entity.ID, err diff --git a/api/mock/database.go b/api/mock/database.go index 4a8649e21..986a59a28 100644 --- a/api/mock/database.go +++ b/api/mock/database.go @@ -6,11 +6,6 @@ type DatabaseService struct { SelectCount int } -// CheckTable ensures a the table exists for the persistor. -func (service *DatabaseService) CheckTable(entity interface{}) error { - return nil -} - // Raw executes a string of SQL. func (service *DatabaseService) Raw(query interface{}, params ...interface{}) error { return nil diff --git a/api/name.go b/api/name.go index 80a69f14e..b0235ccf1 100644 --- a/api/name.go +++ b/api/name.go @@ -65,10 +65,6 @@ func (entity *Name) Valid() (bool, error) { // Save the name to data storage. func (entity *Name) Save(context DatabaseService, account int) (int, error) { - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := context.Save(entity); err != nil { return entity.ID, err } @@ -78,10 +74,6 @@ func (entity *Name) Save(context DatabaseService, account int) (int, error) { // Delete the name from data storage. func (entity *Name) Delete(context DatabaseService, account int) (int, error) { - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if entity.ID != 0 { if err := context.Delete(entity); err != nil { return entity.ID, err @@ -93,10 +85,6 @@ func (entity *Name) Delete(context DatabaseService, account int) (int, error) { // Get the name from data storage. func (entity *Name) Get(context DatabaseService, account int) (int, error) { - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if entity.ID != 0 { if err := context.Select(entity); err != nil { return entity.ID, err diff --git a/api/notapplicable.go b/api/notapplicable.go index c898ed8fd..410b56f25 100644 --- a/api/notapplicable.go +++ b/api/notapplicable.go @@ -25,10 +25,6 @@ func (entity *NotApplicable) Valid() (bool, error) { // Save the entity to data storage. func (entity *NotApplicable) Save(context DatabaseService, account int) (int, error) { - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := context.Save(entity); err != nil { return entity.ID, err } @@ -38,10 +34,6 @@ func (entity *NotApplicable) Save(context DatabaseService, account int) (int, er // Delete the entity from data storage. func (entity *NotApplicable) Delete(context DatabaseService, account int) (int, error) { - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if entity.ID != 0 { if err := context.Delete(entity); err != nil { return entity.ID, err @@ -53,10 +45,6 @@ func (entity *NotApplicable) Delete(context DatabaseService, account int) (int, // Get the entity from data storage. func (entity *NotApplicable) Get(context DatabaseService, account int) (int, error) { - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if entity.ID != 0 { if err := context.Select(entity); err != nil { return entity.ID, err diff --git a/api/number.go b/api/number.go index 0e57dc14d..811c9dba3 100644 --- a/api/number.go +++ b/api/number.go @@ -37,10 +37,6 @@ func (entity *Number) Valid() (bool, error) { // Save the number to data storage. func (entity *Number) Save(context DatabaseService, account int) (int, error) { - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := context.Save(entity); err != nil { return entity.ID, err } @@ -50,10 +46,6 @@ func (entity *Number) Save(context DatabaseService, account int) (int, error) { // Delete the number from data storage. func (entity *Number) Delete(context DatabaseService, account int) (int, error) { - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if entity.ID != 0 { if err := context.Delete(entity); err != nil { return entity.ID, err @@ -65,10 +57,6 @@ func (entity *Number) Delete(context DatabaseService, account int) (int, error) // Get the number from data storage. func (entity *Number) Get(context DatabaseService, account int) (int, error) { - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if entity.ID != 0 { if err := context.Select(entity); err != nil { return entity.ID, err diff --git a/api/physicaladdress.go b/api/physicaladdress.go index 973d7e5e0..e59ba8fbd 100644 --- a/api/physicaladdress.go +++ b/api/physicaladdress.go @@ -82,10 +82,6 @@ func (entity *PhysicalAddress) Valid() (bool, error) { func (entity *PhysicalAddress) Save(context DatabaseService, account int) (int, error) { entity.AccountID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } @@ -119,10 +115,6 @@ func (entity *PhysicalAddress) Save(context DatabaseService, account int) (int, func (entity *PhysicalAddress) Delete(context DatabaseService, account int) (int, error) { entity.AccountID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } @@ -152,10 +144,6 @@ func (entity *PhysicalAddress) Delete(context DatabaseService, account int) (int func (entity *PhysicalAddress) Get(context DatabaseService, account int) (int, error) { entity.AccountID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } diff --git a/api/postgresql/db.go b/api/postgresql/db.go index 10fb6a904..92e34e984 100644 --- a/api/postgresql/db.go +++ b/api/postgresql/db.go @@ -82,11 +82,6 @@ func NewPostgresService(config DBConfig, logger api.LogService) *Service { return &service } -// CheckTable ensures a the table exists for the persistor. -func (service *Service) CheckTable(entity interface{}) error { - return nil -} - // Raw executes a string of SQL. func (service *Service) Raw(query interface{}, params ...interface{}) error { _, err := service.database.Exec(query, params...) diff --git a/api/psychological.go b/api/psychological.go index ef3db0e65..a44712d5e 100644 --- a/api/psychological.go +++ b/api/psychological.go @@ -73,10 +73,6 @@ func (entity *PsychologicalCompetence) Valid() (bool, error) { func (entity *PsychologicalCompetence) Save(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } @@ -104,10 +100,6 @@ func (entity *PsychologicalCompetence) Save(context DatabaseService, account int func (entity *PsychologicalCompetence) Delete(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } @@ -133,10 +125,6 @@ func (entity *PsychologicalCompetence) Delete(context DatabaseService, account i func (entity *PsychologicalCompetence) Get(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if entity.ID != 0 { if err := context.Select(entity); err != nil { return entity.ID, err @@ -257,10 +245,6 @@ func (entity *PsychologicalConsultations) Valid() (bool, error) { func (entity *PsychologicalConsultations) Save(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } @@ -288,10 +272,6 @@ func (entity *PsychologicalConsultations) Save(context DatabaseService, account func (entity *PsychologicalConsultations) Delete(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } @@ -317,10 +297,6 @@ func (entity *PsychologicalConsultations) Delete(context DatabaseService, accoun func (entity *PsychologicalConsultations) Get(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if entity.ID != 0 { if err := context.Select(entity); err != nil { return entity.ID, err @@ -491,10 +467,6 @@ func (entity *PsychologicalDiagnoses) Valid() (bool, error) { func (entity *PsychologicalDiagnoses) Save(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } @@ -540,10 +512,6 @@ func (entity *PsychologicalDiagnoses) Save(context DatabaseService, account int) func (entity *PsychologicalDiagnoses) Delete(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } @@ -581,10 +549,6 @@ func (entity *PsychologicalDiagnoses) Delete(context DatabaseService, account in func (entity *PsychologicalDiagnoses) Get(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if entity.ID != 0 { if err := context.Select(entity); err != nil { return entity.ID, err @@ -741,10 +705,6 @@ func (entity *PsychologicalHospitalizations) Valid() (bool, error) { func (entity *PsychologicalHospitalizations) Save(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } @@ -772,10 +732,6 @@ func (entity *PsychologicalHospitalizations) Save(context DatabaseService, accou func (entity *PsychologicalHospitalizations) Delete(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } @@ -801,10 +757,6 @@ func (entity *PsychologicalHospitalizations) Delete(context DatabaseService, acc func (entity *PsychologicalHospitalizations) Get(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if entity.ID != 0 { if err := context.Select(entity); err != nil { return entity.ID, err @@ -995,10 +947,6 @@ func (entity *PsychologicalExisting) Valid() (bool, error) { func (entity *PsychologicalExisting) Save(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } @@ -1050,10 +998,6 @@ func (entity *PsychologicalExisting) Save(context DatabaseService, account int) func (entity *PsychologicalExisting) Delete(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } @@ -1095,10 +1039,6 @@ func (entity *PsychologicalExisting) Delete(context DatabaseService, account int func (entity *PsychologicalExisting) Get(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if entity.ID != 0 { if err := context.Select(entity); err != nil { return entity.ID, err diff --git a/api/radio.go b/api/radio.go index abd8d2cb4..83d10f031 100644 --- a/api/radio.go +++ b/api/radio.go @@ -26,10 +26,6 @@ func (entity *Radio) Valid() (bool, error) { // Save the radio to data storage. func (entity *Radio) Save(context DatabaseService, account int) (int, error) { - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := context.Save(entity); err != nil { return entity.ID, err } @@ -39,10 +35,6 @@ func (entity *Radio) Save(context DatabaseService, account int) (int, error) { // Delete the radio from data storage. func (entity *Radio) Delete(context DatabaseService, account int) (int, error) { - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if entity.ID != 0 { if err := context.Delete(entity); err != nil { return entity.ID, err @@ -54,10 +46,6 @@ func (entity *Radio) Delete(context DatabaseService, account int) (int, error) { // Get the radio from data storage. func (entity *Radio) Get(context DatabaseService, account int) (int, error) { - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if entity.ID != 0 { if err := context.Select(entity); err != nil { return entity.ID, err diff --git a/api/reasonleft.go b/api/reasonleft.go index 772a7edac..ecef51558 100644 --- a/api/reasonleft.go +++ b/api/reasonleft.go @@ -80,10 +80,6 @@ func (entity *ReasonLeft) Valid() (bool, error) { func (entity *ReasonLeft) Save(context DatabaseService, account int) (int, error) { entity.AccountID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } @@ -117,10 +113,6 @@ func (entity *ReasonLeft) Save(context DatabaseService, account int) (int, error func (entity *ReasonLeft) Delete(context DatabaseService, account int) (int, error) { entity.AccountID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } @@ -150,10 +142,6 @@ func (entity *ReasonLeft) Delete(context DatabaseService, account int) (int, err func (entity *ReasonLeft) Get(context DatabaseService, account int) (int, error) { entity.AccountID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } diff --git a/api/relationships.go b/api/relationships.go index 567e053e9..71b2f9b38 100644 --- a/api/relationships.go +++ b/api/relationships.go @@ -92,10 +92,6 @@ func (entity *RelationshipsMarital) Valid() (bool, error) { func (entity *RelationshipsMarital) Save(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } @@ -129,10 +125,6 @@ func (entity *RelationshipsMarital) Save(context DatabaseService, account int) ( func (entity *RelationshipsMarital) Delete(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } @@ -162,10 +154,6 @@ func (entity *RelationshipsMarital) Delete(context DatabaseService, account int) func (entity *RelationshipsMarital) Get(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if entity.ID != 0 { if err := context.Select(entity); err != nil { return entity.ID, err @@ -291,10 +279,6 @@ func (entity *RelationshipsCohabitants) Valid() (bool, error) { func (entity *RelationshipsCohabitants) Save(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } @@ -322,10 +306,6 @@ func (entity *RelationshipsCohabitants) Save(context DatabaseService, account in func (entity *RelationshipsCohabitants) Delete(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } @@ -351,10 +331,6 @@ func (entity *RelationshipsCohabitants) Delete(context DatabaseService, account func (entity *RelationshipsCohabitants) Get(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if entity.ID != 0 { if err := context.Select(entity); err != nil { return entity.ID, err @@ -453,10 +429,6 @@ func (entity *RelationshipsPeople) Valid() (bool, error) { func (entity *RelationshipsPeople) Save(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } @@ -478,10 +450,6 @@ func (entity *RelationshipsPeople) Save(context DatabaseService, account int) (i func (entity *RelationshipsPeople) Delete(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } @@ -503,10 +471,6 @@ func (entity *RelationshipsPeople) Delete(context DatabaseService, account int) func (entity *RelationshipsPeople) Get(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if entity.ID != 0 { if err := context.Select(entity); err != nil { return entity.ID, err @@ -594,10 +558,6 @@ func (entity *RelationshipsRelatives) Valid() (bool, error) { func (entity *RelationshipsRelatives) Save(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } @@ -619,10 +579,6 @@ func (entity *RelationshipsRelatives) Save(context DatabaseService, account int) func (entity *RelationshipsRelatives) Delete(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } @@ -644,10 +600,6 @@ func (entity *RelationshipsRelatives) Delete(context DatabaseService, account in func (entity *RelationshipsRelatives) Get(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if entity.ID != 0 { if err := context.Select(entity); err != nil { return entity.ID, err diff --git a/api/sentence.go b/api/sentence.go index 9800eeeee..9a8d3aacb 100644 --- a/api/sentence.go +++ b/api/sentence.go @@ -148,10 +148,6 @@ func (entity *Sentence) Valid() (bool, error) { func (entity *Sentence) Save(context DatabaseService, account int) (int, error) { entity.AccountID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } @@ -209,10 +205,6 @@ func (entity *Sentence) Save(context DatabaseService, account int) (int, error) func (entity *Sentence) Delete(context DatabaseService, account int) (int, error) { entity.AccountID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } @@ -258,10 +250,6 @@ func (entity *Sentence) Delete(context DatabaseService, account int) (int, error func (entity *Sentence) Get(context DatabaseService, account int) (int, error) { entity.AccountID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } diff --git a/api/signature.go b/api/signature.go index 2ec8e9014..fe3b25c9c 100644 --- a/api/signature.go +++ b/api/signature.go @@ -72,10 +72,6 @@ func (entity *Signature) Valid() (bool, error) { func (entity *Signature) Save(context DatabaseService, account int) (int, error) { entity.AccountID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } @@ -103,10 +99,6 @@ func (entity *Signature) Save(context DatabaseService, account int) (int, error) func (entity *Signature) Delete(context DatabaseService, account int) (int, error) { entity.AccountID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } @@ -132,10 +124,6 @@ func (entity *Signature) Delete(context DatabaseService, account int) (int, erro func (entity *Signature) Get(context DatabaseService, account int) (int, error) { entity.AccountID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if entity.ID != 0 { if err := context.Select(entity); err != nil { return entity.ID, err diff --git a/api/ssn.go b/api/ssn.go index 95ddfcf02..bce8f05bf 100644 --- a/api/ssn.go +++ b/api/ssn.go @@ -87,10 +87,6 @@ func (entity *SSN) Valid() (bool, error) { // Save the SSN to data storage. func (entity *SSN) Save(context DatabaseService, account int) (int, error) { - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := context.Save(entity); err != nil { return entity.ID, err } @@ -100,10 +96,6 @@ func (entity *SSN) Save(context DatabaseService, account int) (int, error) { // Delete the SSN from data storage. func (entity *SSN) Delete(context DatabaseService, account int) (int, error) { - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if entity.ID != 0 { if err := context.Delete(entity); err != nil { return entity.ID, err @@ -115,10 +107,6 @@ func (entity *SSN) Delete(context DatabaseService, account int) (int, error) { // Get the SSN from data storage. func (entity *SSN) Get(context DatabaseService, account int) (int, error) { - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if entity.ID != 0 { if err := context.Select(entity); err != nil { return entity.ID, err diff --git a/api/submission.go b/api/submission.go index a5f0a45d4..706899a7d 100644 --- a/api/submission.go +++ b/api/submission.go @@ -121,10 +121,6 @@ func (entity *Submission) Save(context DatabaseService, account int) (int, error } entity.Hash = hash - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } @@ -170,10 +166,6 @@ func (entity *Submission) Save(context DatabaseService, account int) (int, error func (entity *Submission) Delete(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } @@ -211,10 +203,6 @@ func (entity *Submission) Delete(context DatabaseService, account int) (int, err func (entity *Submission) Get(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if entity.ID != 0 { if err := context.Select(entity); err != nil { return entity.ID, err @@ -353,10 +341,6 @@ func (entity *SubmissionAdditionalComments) Valid() (bool, error) { func (entity *SubmissionAdditionalComments) Save(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } @@ -378,10 +362,6 @@ func (entity *SubmissionAdditionalComments) Save(context DatabaseService, accoun func (entity *SubmissionAdditionalComments) Delete(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } @@ -403,10 +383,6 @@ func (entity *SubmissionAdditionalComments) Delete(context DatabaseService, acco func (entity *SubmissionAdditionalComments) Get(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if entity.ID != 0 { if err := context.Select(entity); err != nil { return entity.ID, err @@ -497,10 +473,6 @@ func (entity *SubmissionGeneral) Valid() (bool, error) { func (entity *SubmissionGeneral) Save(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } @@ -522,10 +494,6 @@ func (entity *SubmissionGeneral) Save(context DatabaseService, account int) (int func (entity *SubmissionGeneral) Delete(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } @@ -547,10 +515,6 @@ func (entity *SubmissionGeneral) Delete(context DatabaseService, account int) (i func (entity *SubmissionGeneral) Get(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if entity.ID != 0 { if err := context.Select(entity); err != nil { return entity.ID, err @@ -641,10 +605,6 @@ func (entity *SubmissionMedical) Valid() (bool, error) { func (entity *SubmissionMedical) Save(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } @@ -666,10 +626,6 @@ func (entity *SubmissionMedical) Save(context DatabaseService, account int) (int func (entity *SubmissionMedical) Delete(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } @@ -691,10 +647,6 @@ func (entity *SubmissionMedical) Delete(context DatabaseService, account int) (i func (entity *SubmissionMedical) Get(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if entity.ID != 0 { if err := context.Select(entity); err != nil { return entity.ID, err @@ -785,10 +737,6 @@ func (entity *SubmissionCredit) Valid() (bool, error) { func (entity *SubmissionCredit) Save(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } @@ -810,10 +758,6 @@ func (entity *SubmissionCredit) Save(context DatabaseService, account int) (int, func (entity *SubmissionCredit) Delete(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } @@ -835,10 +779,6 @@ func (entity *SubmissionCredit) Delete(context DatabaseService, account int) (in func (entity *SubmissionCredit) Get(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if entity.ID != 0 { if err := context.Select(entity); err != nil { return entity.ID, err @@ -929,10 +869,6 @@ func (entity *SubmissionAttachments) Valid() (bool, error) { func (entity *SubmissionAttachments) Save(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } @@ -954,10 +890,6 @@ func (entity *SubmissionAttachments) Save(context DatabaseService, account int) func (entity *SubmissionAttachments) Delete(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } @@ -979,10 +911,6 @@ func (entity *SubmissionAttachments) Delete(context DatabaseService, account int func (entity *SubmissionAttachments) Get(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if entity.ID != 0 { if err := context.Select(entity); err != nil { return entity.ID, err diff --git a/api/substance.go b/api/substance.go index cfe0b9efa..406d36888 100644 --- a/api/substance.go +++ b/api/substance.go @@ -71,10 +71,6 @@ func (entity *SubstanceDrugUsage) Valid() (bool, error) { func (entity *SubstanceDrugUsage) Save(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } @@ -102,10 +98,6 @@ func (entity *SubstanceDrugUsage) Save(context DatabaseService, account int) (in func (entity *SubstanceDrugUsage) Delete(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } @@ -131,10 +123,6 @@ func (entity *SubstanceDrugUsage) Delete(context DatabaseService, account int) ( func (entity *SubstanceDrugUsage) Get(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if entity.ID != 0 { if err := context.Select(entity); err != nil { return entity.ID, err @@ -255,10 +243,6 @@ func (entity *SubstanceDrugPurchase) Valid() (bool, error) { func (entity *SubstanceDrugPurchase) Save(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } @@ -286,10 +270,6 @@ func (entity *SubstanceDrugPurchase) Save(context DatabaseService, account int) func (entity *SubstanceDrugPurchase) Delete(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } @@ -315,10 +295,6 @@ func (entity *SubstanceDrugPurchase) Delete(context DatabaseService, account int func (entity *SubstanceDrugPurchase) Get(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if entity.ID != 0 { if err := context.Select(entity); err != nil { return entity.ID, err @@ -439,10 +415,6 @@ func (entity *SubstanceDrugClearance) Valid() (bool, error) { func (entity *SubstanceDrugClearance) Save(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } @@ -470,10 +442,6 @@ func (entity *SubstanceDrugClearance) Save(context DatabaseService, account int) func (entity *SubstanceDrugClearance) Delete(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } @@ -499,10 +467,6 @@ func (entity *SubstanceDrugClearance) Delete(context DatabaseService, account in func (entity *SubstanceDrugClearance) Get(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if entity.ID != 0 { if err := context.Select(entity); err != nil { return entity.ID, err @@ -623,10 +587,6 @@ func (entity *SubstanceDrugPublicSafety) Valid() (bool, error) { func (entity *SubstanceDrugPublicSafety) Save(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } @@ -654,10 +614,6 @@ func (entity *SubstanceDrugPublicSafety) Save(context DatabaseService, account i func (entity *SubstanceDrugPublicSafety) Delete(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } @@ -683,10 +639,6 @@ func (entity *SubstanceDrugPublicSafety) Delete(context DatabaseService, account func (entity *SubstanceDrugPublicSafety) Get(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if entity.ID != 0 { if err := context.Select(entity); err != nil { return entity.ID, err @@ -807,10 +759,6 @@ func (entity *SubstanceDrugMisuse) Valid() (bool, error) { func (entity *SubstanceDrugMisuse) Save(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } @@ -838,10 +786,6 @@ func (entity *SubstanceDrugMisuse) Save(context DatabaseService, account int) (i func (entity *SubstanceDrugMisuse) Delete(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } @@ -867,10 +811,6 @@ func (entity *SubstanceDrugMisuse) Delete(context DatabaseService, account int) func (entity *SubstanceDrugMisuse) Get(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if entity.ID != 0 { if err := context.Select(entity); err != nil { return entity.ID, err @@ -991,10 +931,6 @@ func (entity *SubstanceDrugOrdered) Valid() (bool, error) { func (entity *SubstanceDrugOrdered) Save(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } @@ -1022,10 +958,6 @@ func (entity *SubstanceDrugOrdered) Save(context DatabaseService, account int) ( func (entity *SubstanceDrugOrdered) Delete(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } @@ -1051,10 +983,6 @@ func (entity *SubstanceDrugOrdered) Delete(context DatabaseService, account int) func (entity *SubstanceDrugOrdered) Get(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if entity.ID != 0 { if err := context.Select(entity); err != nil { return entity.ID, err @@ -1175,10 +1103,6 @@ func (entity *SubstanceDrugVoluntary) Valid() (bool, error) { func (entity *SubstanceDrugVoluntary) Save(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } @@ -1206,10 +1130,6 @@ func (entity *SubstanceDrugVoluntary) Save(context DatabaseService, account int) func (entity *SubstanceDrugVoluntary) Delete(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } @@ -1235,10 +1155,6 @@ func (entity *SubstanceDrugVoluntary) Delete(context DatabaseService, account in func (entity *SubstanceDrugVoluntary) Get(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if entity.ID != 0 { if err := context.Select(entity); err != nil { return entity.ID, err @@ -1359,10 +1275,6 @@ func (entity *SubstanceAlcoholNegative) Valid() (bool, error) { func (entity *SubstanceAlcoholNegative) Save(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } @@ -1390,10 +1302,6 @@ func (entity *SubstanceAlcoholNegative) Save(context DatabaseService, account in func (entity *SubstanceAlcoholNegative) Delete(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } @@ -1419,10 +1327,6 @@ func (entity *SubstanceAlcoholNegative) Delete(context DatabaseService, account func (entity *SubstanceAlcoholNegative) Get(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if entity.ID != 0 { if err := context.Select(entity); err != nil { return entity.ID, err @@ -1543,10 +1447,6 @@ func (entity *SubstanceAlcoholOrdered) Valid() (bool, error) { func (entity *SubstanceAlcoholOrdered) Save(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } @@ -1574,10 +1474,6 @@ func (entity *SubstanceAlcoholOrdered) Save(context DatabaseService, account int func (entity *SubstanceAlcoholOrdered) Delete(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } @@ -1603,10 +1499,6 @@ func (entity *SubstanceAlcoholOrdered) Delete(context DatabaseService, account i func (entity *SubstanceAlcoholOrdered) Get(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if entity.ID != 0 { if err := context.Select(entity); err != nil { return entity.ID, err @@ -1727,10 +1619,6 @@ func (entity *SubstanceAlcoholVoluntary) Valid() (bool, error) { func (entity *SubstanceAlcoholVoluntary) Save(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } @@ -1758,10 +1646,6 @@ func (entity *SubstanceAlcoholVoluntary) Save(context DatabaseService, account i func (entity *SubstanceAlcoholVoluntary) Delete(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } @@ -1787,10 +1671,6 @@ func (entity *SubstanceAlcoholVoluntary) Delete(context DatabaseService, account func (entity *SubstanceAlcoholVoluntary) Get(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if entity.ID != 0 { if err := context.Select(entity); err != nil { return entity.ID, err @@ -1911,10 +1791,6 @@ func (entity *SubstanceAlcoholAdditional) Valid() (bool, error) { func (entity *SubstanceAlcoholAdditional) Save(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } @@ -1942,10 +1818,6 @@ func (entity *SubstanceAlcoholAdditional) Save(context DatabaseService, account func (entity *SubstanceAlcoholAdditional) Delete(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } @@ -1971,10 +1843,6 @@ func (entity *SubstanceAlcoholAdditional) Delete(context DatabaseService, accoun func (entity *SubstanceAlcoholAdditional) Get(context DatabaseService, account int) (int, error) { entity.ID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if entity.ID != 0 { if err := context.Select(entity); err != nil { return entity.ID, err diff --git a/api/supervisor.go b/api/supervisor.go index 545b254dd..3198d532f 100644 --- a/api/supervisor.go +++ b/api/supervisor.go @@ -130,10 +130,6 @@ func (entity *Supervisor) Valid() (bool, error) { func (entity *Supervisor) Save(context DatabaseService, account int) (int, error) { entity.AccountID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } @@ -185,10 +181,6 @@ func (entity *Supervisor) Save(context DatabaseService, account int) (int, error func (entity *Supervisor) Delete(context DatabaseService, account int) (int, error) { entity.AccountID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } @@ -230,10 +222,6 @@ func (entity *Supervisor) Delete(context DatabaseService, account int) (int, err func (entity *Supervisor) Get(context DatabaseService, account int) (int, error) { entity.AccountID = account - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } diff --git a/api/telephone.go b/api/telephone.go index 3af9dcc78..1e41bfcbd 100644 --- a/api/telephone.go +++ b/api/telephone.go @@ -74,10 +74,6 @@ func (entity *Telephone) Valid() (bool, error) { // Save the telephone to data storage. func (entity *Telephone) Save(context DatabaseService, account int) (int, error) { - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := context.Save(entity); err != nil { return entity.ID, err } @@ -87,10 +83,6 @@ func (entity *Telephone) Save(context DatabaseService, account int) (int, error) // Delete the telephone from data storage. func (entity *Telephone) Delete(context DatabaseService, account int) (int, error) { - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if entity.ID != 0 { if err := context.Delete(entity); err != nil { return entity.ID, err @@ -102,10 +94,6 @@ func (entity *Telephone) Delete(context DatabaseService, account int) (int, erro // Get the telephone from data storage. func (entity *Telephone) Get(context DatabaseService, account int) (int, error) { - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if entity.ID != 0 { if err := context.Select(entity); err != nil { return entity.ID, err diff --git a/api/text.go b/api/text.go index 4942db65a..2bb7f7a17 100644 --- a/api/text.go +++ b/api/text.go @@ -34,10 +34,6 @@ func (entity *Text) Valid() (bool, error) { // Save the text to data storage. func (entity *Text) Save(context DatabaseService, account int) (int, error) { - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := context.Save(entity); err != nil { return entity.ID, err } @@ -47,10 +43,6 @@ func (entity *Text) Save(context DatabaseService, account int) (int, error) { // Delete the text from data storage. func (entity *Text) Delete(context DatabaseService, account int) (int, error) { - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if entity.ID != 0 { if err := context.Delete(entity); err != nil { return entity.ID, err @@ -62,10 +54,6 @@ func (entity *Text) Delete(context DatabaseService, account int) (int, error) { // Get the text from data storage. func (entity *Text) Get(context DatabaseService, account int) (int, error) { - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if entity.ID != 0 { if err := context.Select(entity); err != nil { return entity.ID, err diff --git a/api/textarea.go b/api/textarea.go index d52856676..51317165c 100644 --- a/api/textarea.go +++ b/api/textarea.go @@ -34,10 +34,6 @@ func (entity *Textarea) Valid() (bool, error) { // Save the textarea to data storage. func (entity *Textarea) Save(context DatabaseService, account int) (int, error) { - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := context.Save(entity); err != nil { return entity.ID, err } @@ -47,10 +43,6 @@ func (entity *Textarea) Save(context DatabaseService, account int) (int, error) // Delete the textarea from data storage. func (entity *Textarea) Delete(context DatabaseService, account int) (int, error) { - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if entity.ID != 0 { if err := context.Delete(entity); err != nil { return entity.ID, err @@ -62,10 +54,6 @@ func (entity *Textarea) Delete(context DatabaseService, account int) (int, error // Get the textarea from data storage. func (entity *Textarea) Get(context DatabaseService, account int) (int, error) { - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if entity.ID != 0 { if err := context.Select(entity); err != nil { return entity.ID, err diff --git a/api/treatment.go b/api/treatment.go index c9e06fded..f3e15c827 100644 --- a/api/treatment.go +++ b/api/treatment.go @@ -85,10 +85,6 @@ func (entity *Treatment) Valid() (bool, error) { // Save the treatment to data storage. func (entity *Treatment) Save(context DatabaseService, account int) (int, error) { - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } @@ -120,10 +116,6 @@ func (entity *Treatment) Save(context DatabaseService, account int) (int, error) // Delete the treatment from data storage. func (entity *Treatment) Delete(context DatabaseService, account int) (int, error) { - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if err := entity.Find(context); err != nil { return entity.ID, err } @@ -151,10 +143,6 @@ func (entity *Treatment) Delete(context DatabaseService, account int) (int, erro // Get the treatment from data storage. func (entity *Treatment) Get(context DatabaseService, account int) (int, error) { - if err := context.CheckTable(entity); err != nil { - return entity.ID, err - } - if entity.ID != 0 { if err := context.Select(entity); err != nil { return entity.ID, err From 34349d43cffc280adf1e0972fa29017f836047ed Mon Sep 17 00:00:00 2001 From: MacRae Linton <55759+macrael@users.noreply.github.com> Date: Thu, 4 Apr 2019 17:21:57 -0700 Subject: [PATCH 11/14] Add TEST_DATABASE_NAME config docs. --- docs/CONFIGURATION.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/docs/CONFIGURATION.md b/docs/CONFIGURATION.md index 818df3de7..9b5bf7330 100644 --- a/docs/CONFIGURATION.md +++ b/docs/CONFIGURATION.md @@ -30,6 +30,7 @@ When running the application using the provided [docker-compose.yml](docker-comp | [`DATABASE_USER`](#database_user) | | | X | | [`DATABASE_PASSWORD`](#database_password) | | | X | | [`DATABASE_NAME`](#database_name) | | | X | +| [`TEST_DATABASE_NAME`](#database_name) | | | X | | [`DATABASE_HOST`](#database_host) | | | X | | [`CORS_ALLOWED`](#cors_allowed) | X | | X | | [`FLUSH_STORAGE`](#flush_storage) | | | X | @@ -194,6 +195,13 @@ PostgreSQL database instance name. **Target** - Back-end (api)
**Default** - `postgres`
+## `TEST_DATABASE_NAME` + +PostgreSQL database instance name for running any tests that require a database. + +**Target** - Back-end (api)
+**Default** - `eapp_test`
+ ## `DATABASE_HOST` PostgreSQL database host name and port. From a1a81cccae1da297baf0b6e5b5774a8540e1ab61 Mon Sep 17 00:00:00 2001 From: MacRae Linton <55759+macrael@users.noreply.github.com> Date: Mon, 22 Apr 2019 15:37:56 -0700 Subject: [PATCH 12/14] Split out dbreset from dbmigrate and require passing path to migration directory. --- api/Makefile | 4 +- api/cmd/dbmigrate/db-migrate-test.sh | 5 +- api/cmd/dbmigrate/main.go | 122 ++------------------------- api/cmd/dbreset/db-reset-test.sh | 9 ++ api/cmd/dbreset/main.go | 115 +++++++++++++++++++++++++ 5 files changed, 135 insertions(+), 120 deletions(-) create mode 100755 api/cmd/dbreset/db-reset-test.sh create mode 100644 api/cmd/dbreset/main.go diff --git a/api/Makefile b/api/Makefile index 0b957def2..507d8720d 100644 --- a/api/Makefile +++ b/api/Makefile @@ -7,7 +7,9 @@ test: reset-test-db: go build -o bin/dbmigrate ./cmd/dbmigrate - ./bin/dbmigrate -reset -force eapp_test + go build -o bin/dbreset ./cmd/dbreset + ./bin/dbreset -force eapp_test + ./bin/dbmigrate -migrations_path ./migrations eapp_test coverage: # Use -c to remove processed reports so coverage-js won't find it diff --git a/api/cmd/dbmigrate/db-migrate-test.sh b/api/cmd/dbmigrate/db-migrate-test.sh index 99c99e33d..ba0636dcd 100755 --- a/api/cmd/dbmigrate/db-migrate-test.sh +++ b/api/cmd/dbmigrate/db-migrate-test.sh @@ -3,11 +3,10 @@ set -eo pipefail go build github.com/18F/e-QIP-prototype/api/cmd/dbmigrate +go build github.com/18F/e-QIP-prototype/api/cmd/dbreset ./dbmigrate || true -./dbmigrate -reset -force dbtest_test - -./dbmigrate dbtest_test +./dbreset -force dbtest_test ./dbmigrate -migrations_path ./api/migrations dbtest_test diff --git a/api/cmd/dbmigrate/main.go b/api/cmd/dbmigrate/main.go index 3e815296d..555c48e05 100644 --- a/api/cmd/dbmigrate/main.go +++ b/api/cmd/dbmigrate/main.go @@ -1,15 +1,11 @@ package main import ( - "bufio" - "database/sql" "flag" "fmt" "os" "path/filepath" - "unicode" - _ "github.com/lib/pq" "github.com/pkg/errors" "github.com/18F/e-QIP-prototype/api" @@ -17,82 +13,6 @@ import ( "github.com/18F/e-QIP-prototype/api/postgresql" ) -func checkDBNameIsAllowed(dbName string) bool { - for _, r := range dbName { - if !(unicode.IsLetter(r) || r == '_') { - return false - } - } - return true -} - -func resetDB(dbName string, force bool) error { - fmt.Println("Resetting", dbName) - - if !checkDBNameIsAllowed(dbName) || dbName == "" { - return errors.New(fmt.Sprintf("Attempted to reset a db with a strange name: %s", dbName)) - } - - settings := env.Native{} - settings.Configure() - - dbConf := postgresql.DBConfig{ - User: settings.String(api.DatabaseUser), - Password: settings.String(api.DatabasePassword), - Address: settings.String(api.DatabaseHost), - DBName: "template1", // template1 exists on all default postgres instances. - } - - connStr := postgresql.PostgresConnectURI(dbConf) - - db, openErr := sql.Open("postgres", connStr) - if openErr != nil { - return errors.Wrap(openErr, "Error opening connection") - } - - check, checkErr := db.Exec("SELECT 1 AS result FROM pg_database WHERE datname=$1", dbName) - if checkErr != nil { - return errors.Wrap(checkErr, fmt.Sprintf("ERROR Checking for existence of %s", dbName)) - } - - checkCount, _ := check.RowsAffected() - if checkCount != 0 { - // We need to delete the requested db. - - if !force { - fmt.Printf("DANGER: resetting this db will erase all the data in %s permanently, is that what you want? [y/N]: ", dbName) - scanner := bufio.NewScanner(os.Stdin) - scanner.Scan() - text := scanner.Text() - - if scanner.Err() != nil { - return errors.New("error getting user confirmation") - } - - fmt.Println(text) - if !(text == "y" || text == "Y" || text == "YES" || text == "yes") { - return errors.New("user disconfirmed reset") - } - - } - - dropCmd := "DROP DATABASE " + dbName - _, dropErr := db.Exec(dropCmd) - if dropErr != nil { - return dropErr - } - - } - - createCmd := "CREATE DATABASE " + dbName - _, createErr := db.Exec(createCmd) - if createErr != nil { - return errors.Wrap(createErr, "Error Creating db") - } - - return nil -} - func pathToPattern(path, pattern string) string { dir, subject := filepath.Split(path) @@ -107,28 +27,6 @@ func pathToPattern(path, pattern string) string { return pathToPattern(dir, pattern) } -func guessMigrationsPath() string { - - cwd, _ := os.Getwd() - - // 1st. try and see if e-QIP-prototype is in the path - goodPath := pathToPattern(cwd, "e-QIP-prototype") - if goodPath != "" { - migrationsPath := filepath.Join(filepath.Join(goodPath, "api"), "migrations") - return migrationsPath - } - - // If that didn't work, just look for /api - goodPath = pathToPattern(cwd, "api") - if goodPath != "" { - migrationsPath := filepath.Join(goodPath, "migrations") - return migrationsPath - } - - // if that didn't work, we have to guess that we are in api and it's not listed, so just return this. - return filepath.Join(cwd, "migrations") -} - func runMigrations(dbName string, migrationsPath string) error { os.Setenv(api.DatabaseName, dbName) @@ -159,12 +57,16 @@ type stackTracer interface { } func main() { - shouldReset := flag.Bool("reset", false, "resets the data in the given db by deleting it and re-creating it") - forceReset := flag.Bool("force", false, "skips the interactive dialog triggered by reset") migrationsPath := flag.String("migrations_path", "", "path to the directory containing migrations. If left out it will be guessed.") flag.Parse() + if *migrationsPath == "" { + fmt.Println("Must pass -migrations_path explicitly") + flag.Usage() + os.Exit(1) + } + if len(flag.Args()) != 1 { fmt.Println("Must pass the db_name as an argument") flag.Usage() @@ -173,18 +75,6 @@ func main() { dbName := flag.Args()[0] - if *shouldReset { - resetErr := resetDB(dbName, *forceReset) - if resetErr != nil { - fmt.Println(resetErr) - os.Exit(1) - } - } - - if *migrationsPath == "" { - *migrationsPath = guessMigrationsPath() - } - migrationErr := runMigrations(dbName, *migrationsPath) if migrationErr != nil { fmt.Println(migrationErr) diff --git a/api/cmd/dbreset/db-reset-test.sh b/api/cmd/dbreset/db-reset-test.sh new file mode 100755 index 000000000..60f3e1dcf --- /dev/null +++ b/api/cmd/dbreset/db-reset-test.sh @@ -0,0 +1,9 @@ +#!/bin/bash + +set -eo pipefail + +go build github.com/18F/e-QIP-prototype/api/cmd/dbreset + +./dbreset || true + +./dbreset -force dbtest_test diff --git a/api/cmd/dbreset/main.go b/api/cmd/dbreset/main.go new file mode 100644 index 000000000..84d2e1dbd --- /dev/null +++ b/api/cmd/dbreset/main.go @@ -0,0 +1,115 @@ +package main + +import ( + "bufio" + "database/sql" + "flag" + "fmt" + "os" + "unicode" + + _ "github.com/lib/pq" + "github.com/pkg/errors" + + "github.com/18F/e-QIP-prototype/api" + "github.com/18F/e-QIP-prototype/api/env" + "github.com/18F/e-QIP-prototype/api/postgresql" +) + +func checkDBNameIsAllowed(dbName string) bool { + for _, r := range dbName { + if !(unicode.IsLetter(r) || r == '_') { + return false + } + } + return true +} + +func resetDB(dbName string, force bool) error { + fmt.Println("Resetting", dbName) + + if !checkDBNameIsAllowed(dbName) || dbName == "" { + return errors.New(fmt.Sprintf("Attempted to reset a db with a strange name: %s", dbName)) + } + + settings := env.Native{} + settings.Configure() + + dbConf := postgresql.DBConfig{ + User: settings.String(api.DatabaseUser), + Password: settings.String(api.DatabasePassword), + Address: settings.String(api.DatabaseHost), + DBName: "template1", // template1 exists on all default postgres instances. + } + + connStr := postgresql.PostgresConnectURI(dbConf) + + db, openErr := sql.Open("postgres", connStr) + if openErr != nil { + return errors.Wrap(openErr, "Error opening connection") + } + + check, checkErr := db.Exec("SELECT 1 AS result FROM pg_database WHERE datname=$1", dbName) + if checkErr != nil { + return errors.Wrap(checkErr, fmt.Sprintf("ERROR Checking for existence of %s", dbName)) + } + + checkCount, _ := check.RowsAffected() + if checkCount != 0 { + // We need to delete the requested db. + + if !force { + fmt.Printf("DANGER: resetting this db will erase all the data in %s permanently, is that what you want? [y/N]: ", dbName) + scanner := bufio.NewScanner(os.Stdin) + scanner.Scan() + text := scanner.Text() + + if scanner.Err() != nil { + return errors.New("error getting user confirmation") + } + + fmt.Println(text) + if !(text == "y" || text == "Y" || text == "YES" || text == "yes") { + return errors.New("user disconfirmed reset") + } + + } + + dropCmd := "DROP DATABASE " + dbName + _, dropErr := db.Exec(dropCmd) + if dropErr != nil { + return dropErr + } + + } + + createCmd := "CREATE DATABASE " + dbName + _, createErr := db.Exec(createCmd) + if createErr != nil { + return errors.Wrap(createErr, "Error Creating db") + } + + return nil +} + +func main() { + forceReset := flag.Bool("force", false, "skips the interactive dialog triggered by reset") + flag.Parse() + + if len(flag.Args()) != 1 { + fmt.Println("Must pass the db_name as an argument") + flag.Usage() + os.Exit(1) + } + + dbName := flag.Args()[0] + + resetErr := resetDB(dbName, *forceReset) + if resetErr != nil { + fmt.Println(resetErr) + os.Exit(1) + } + + fmt.Println("HI THERE") + +} From beebcac9e827527c4e34e4db4b9dda3b97ee3ccf Mon Sep 17 00:00:00 2001 From: MacRae Linton <55759+macrael@users.noreply.github.com> Date: Mon, 22 Apr 2019 16:34:29 -0700 Subject: [PATCH 13/14] Pull ID and History sections out of the /sections go files and into stand alone json files. Some reoganization begins to make sense. Further sections will be reorganized as we move forward. --- .gitignore | 1 + api/integration/clear_yes_no_test.go | 42 +- api/integration/sections/history.go | 732 ------------------ api/integration/sections/identification.go | 296 ------- api/integration/setup.go | 9 + api/pdf/pdf_test.go | 16 +- api/postgresql/db_test.go | 44 +- .../{ => history}/history-education.json | 0 .../history/history-employment-full.json | 365 +++++++++ .../{ => history}/history-employment.json | 0 .../{ => history}/history-federal.json | 0 .../history-residence-unfinished-list.json | 177 +++++ .../{ => history}/history-residence.json | 0 .../identification-birth.json | 0 .../identification-birthdate.json | 0 .../identification-birthplace.json | 0 .../identification-contacts.json | 0 .../identification-eyecolor.json | 0 .../identification-height.json | 0 .../identification-name.json | 0 .../identification-othernames-no.json | 23 + .../identification-othernames-unfinished.json | 130 ++++ .../identification-othernames.json | 0 .../identification-physical.json | 0 .../identification-sex.json | 0 .../identification-ssn.json | 0 .../identification-weight.json | 0 api/xml/xml_test.go | 46 +- 28 files changed, 793 insertions(+), 1088 deletions(-) delete mode 100644 api/integration/sections/history.go delete mode 100644 api/integration/sections/identification.go rename api/testdata/{ => history}/history-education.json (100%) create mode 100644 api/testdata/history/history-employment-full.json rename api/testdata/{ => history}/history-employment.json (100%) rename api/testdata/{ => history}/history-federal.json (100%) create mode 100644 api/testdata/history/history-residence-unfinished-list.json rename api/testdata/{ => history}/history-residence.json (100%) rename api/testdata/{ => identification}/identification-birth.json (100%) rename api/testdata/{ => identification}/identification-birthdate.json (100%) rename api/testdata/{ => identification}/identification-birthplace.json (100%) rename api/testdata/{ => identification}/identification-contacts.json (100%) rename api/testdata/{ => identification}/identification-eyecolor.json (100%) rename api/testdata/{ => identification}/identification-height.json (100%) rename api/testdata/{ => identification}/identification-name.json (100%) create mode 100644 api/testdata/identification/identification-othernames-no.json create mode 100644 api/testdata/identification/identification-othernames-unfinished.json rename api/testdata/{ => identification}/identification-othernames.json (100%) rename api/testdata/{ => identification}/identification-physical.json (100%) rename api/testdata/{ => identification}/identification-sex.json (100%) rename api/testdata/{ => identification}/identification-ssn.json (100%) rename api/testdata/{ => identification}/identification-weight.json (100%) diff --git a/.gitignore b/.gitignore index e8215c043..4edffe48f 100644 --- a/.gitignore +++ b/.gitignore @@ -68,6 +68,7 @@ package-lock.json /api/bin/transmit /api/bin/unlock /api/bin/dbmigrate +/api/bin/dbreset /build/ /doc/ /dist/ diff --git a/api/integration/clear_yes_no_test.go b/api/integration/clear_yes_no_test.go index 8bc8d00a6..2e6efb1e0 100644 --- a/api/integration/clear_yes_no_test.go +++ b/api/integration/clear_yes_no_test.go @@ -5,7 +5,6 @@ import ( "github.com/18F/e-QIP-prototype/api" "github.com/18F/e-QIP-prototype/api/admin" - "github.com/18F/e-QIP-prototype/api/integration/sections" ) func TestClearEmptyAccount(t *testing.T) { @@ -39,7 +38,12 @@ func TestClearInformation(t *testing.T) { } // Test top level no - resp := saveJSON(services, sections.IDOtherNamesNo, account.ID) + otherNo, err := readTestData("../testdata/identification/identification-othernames-no.json") + if err != nil { + t.Fatal("Bad Test Data", err) + } + + resp := saveJSON(services, otherNo, account.ID) if resp.StatusCode != 200 { t.Fatal("Failed to save topLevelNoJSON", resp.StatusCode) } @@ -63,7 +67,12 @@ func TestClearInformation(t *testing.T) { } // Test list no - resp = saveJSON(services, sections.IDOtherNamesYes, account.ID) + listNo, err := readTestData("../testdata/identification/identification-othernames.json") + if err != nil { + t.Fatal("Bad Test Data", err) + } + + resp = saveJSON(services, listNo, account.ID) if resp.StatusCode != 200 { t.Fatal("Failed to save listNoJSON", resp.StatusCode) } @@ -87,8 +96,12 @@ func TestClearInformation(t *testing.T) { } // test list unset + unifishedList, err := readTestData("../testdata/identification/identification-othernames-unfinished.json") + if err != nil { + t.Fatal("Bad Test Data", err) + } - resp = saveJSON(services, sections.IDOtherNamesUnfinishedList, account.ID) + resp = saveJSON(services, unifishedList, account.ID) if resp.StatusCode != 200 { t.Fatal("Failed to save unfinishedListJSON", resp.StatusCode) } @@ -121,8 +134,13 @@ func TestClearHistoryResidence(t *testing.T) { t.Fatal("couldn't create account", err) } + residenceSingle, err := readTestData("../testdata/history/history-residence.json") + if err != nil { + t.Fatal("Bad Test Data", err) + } + // TEST complete list - resp := saveJSON(services, sections.HistResidenceSingle, account.ID) + resp := saveJSON(services, residenceSingle, account.ID) if resp.StatusCode != 200 { t.Fatal("Failed to save HistResidenceSingle", resp.StatusCode) } @@ -145,8 +163,13 @@ func TestClearHistoryResidence(t *testing.T) { t.Fatal("residences was not reset") } + residenceUnfinished, err := readTestData("../testdata/history/history-residence-unfinished-list.json") + if err != nil { + t.Fatal("Bad Test Data", err) + } + // TEST incomplete list - resp = saveJSON(services, sections.HistResidenceUnfinishedList, account.ID) + resp = saveJSON(services, residenceUnfinished, account.ID) if resp.StatusCode != 200 { t.Fatal("Failed to save HistResidenceSingle", resp.StatusCode) } @@ -175,8 +198,13 @@ func TestClearHistoryEmployment(t *testing.T) { t.Fatal("couldn't create account", err) } + employmentSection, err := readTestData("../testdata/history/history-employment-full.json") + if err != nil { + t.Fatal("Bad Test Data", err) + } + // TEST complete list - resp := saveJSON(services, sections.HistEmployment, account.ID) + resp := saveJSON(services, employmentSection, account.ID) if resp.StatusCode != 200 { t.Fatal("Failed to save HistResidenceSingle", resp.StatusCode) } diff --git a/api/integration/sections/history.go b/api/integration/sections/history.go deleted file mode 100644 index 39f5b48fd..000000000 --- a/api/integration/sections/history.go +++ /dev/null @@ -1,732 +0,0 @@ -package sections - -// HistResidenceSingle contains a single residence -const HistResidenceSingle = ` -{ - "type": "history.residence", - "props": { - "List": { - "type": "collection", - "props": { - "branch": { - "type": "branch", - "props": { - "value": "No" - } - }, - "items": [ - { - "Item": { - "Address": { - "type": "location", - "props": { - "layout": "Address", - "street": "316 Washington Ave", - "city": "Wheeling", - "state": "WV", - "zipcode": "26003", - "country": "United States", - "validated": true - } - }, - "Comments": { - "type": "textarea", - "props": { - "value": "" - } - }, - "Dates": { - "type": "daterange", - "props": { - "from": { - "type": "datecontrol", - "props": { - "month": "12", - "day": "13", - "year": "1990", - "estimated": false - } - }, - "to": { - "type": "datecontrol", - "props": { - "month": "8", - "day": "24", - "year": "2018", - "estimated": false - } - }, - "present": true - } - }, - "ReferenceAddress": { - "type": "location", - "props": { - "layout": "Address", - "street": "317 WASHINGTON AVE", - "city": "WHEELING", - "state": "WV", - "zipcode": "26003", - "country": "United States", - "validated": true - } - }, - "ReferenceEmail": { - "type": "email", - "props": { - "value": "ashley.Emily@testemail.com" - } - }, - "ReferenceEmailNotApplicable": { - "type": "notapplicable", - "props": { - "applicable": false - } - }, - "ReferenceLastContact": { - "type": "datecontrol", - "props": { - "month": "08", - "day": "01", - "year": "2018", - "estimated": false - } - }, - "ReferenceName": { - "type": "name", - "props": { - "first": "Ashley", - "firstInitialOnly": false, - "middle": "", - "middleInitialOnly": false, - "noMiddleName": true, - "last": "Emily", - "suffix": "", - "suffixOther": "" - } - }, - "ReferencePhoneDay": { - "type": "telephone", - "props": { - "timeOfDay": "Both", - "type": "Domestic", - "numberType": "", - "number": "7245555551", - "extension": "", - "noNumber": false - } - }, - "ReferencePhoneEvening": { - "type": "telephone", - "props": { - "timeOfDay": "Both", - "type": "Domestic", - "numberType": "", - "number": "7245555551", - "extension": "", - "noNumber": false - } - }, - "ReferencePhoneMobile": { - "type": "telephone", - "props": { - "timeOfDay": "Both", - "type": "Domestic", - "numberType": "", - "number": "7245555551", - "extension": "", - "noNumber": false - } - }, - "ReferenceRelationship": { - "type": "checkboxgroup", - "props": { - "values": [ - "Neighbor", - "Friend" - ] - } - }, - "ReferenceRelationshipComments": { - "type": "checkboxgroup", - "props": { - "values": null - } - }, - "ReferenceRelationshipOther": { - "type": "text", - "props": { - "value": "" - } - }, - "Role": { - "type": "radio", - "props": { - "value": "Own", - "checked": true - } - }, - "RoleOther": { - "type": "text", - "props": { - "value": "" - } - } - } - } - ] - } - } - } -} -` - -// HistResidenceUnfinishedList contains an unfinished list -const HistResidenceUnfinishedList = ` -{ - "type": "history.residence", - "props": { - "List": { - "type": "collection", - "props": { - "branch": { - "type": "branch", - "props": { - "value": "" - } - }, - "items": [ - { - "Item": { - "Address": { - "type": "location", - "props": { - "layout": "Address", - "street": "316 Washington Ave", - "city": "Wheeling", - "state": "WV", - "zipcode": "26003", - "country": "United States", - "validated": true - } - }, - "Comments": { - "type": "textarea", - "props": { - "value": "" - } - }, - "Dates": { - "type": "daterange", - "props": { - "from": { - "type": "datecontrol", - "props": { - "month": "12", - "day": "13", - "year": "1990", - "estimated": false - } - }, - "to": { - "type": "datecontrol", - "props": { - "month": "8", - "day": "24", - "year": "2018", - "estimated": false - } - }, - "present": true - } - }, - "ReferenceAddress": { - "type": "location", - "props": { - "layout": "Address", - "street": "317 WASHINGTON AVE", - "city": "WHEELING", - "state": "WV", - "zipcode": "26003", - "country": "United States", - "validated": true - } - }, - "ReferenceEmail": { - "type": "email", - "props": { - "value": "ashley.Emily@testemail.com" - } - }, - "ReferenceEmailNotApplicable": { - "type": "notapplicable", - "props": { - "applicable": false - } - }, - "ReferenceLastContact": { - "type": "datecontrol", - "props": { - "month": "08", - "day": "01", - "year": "2018", - "estimated": false - } - }, - "ReferenceName": { - "type": "name", - "props": { - "first": "Ashley", - "firstInitialOnly": false, - "middle": "", - "middleInitialOnly": false, - "noMiddleName": true, - "last": "Emily", - "suffix": "", - "suffixOther": "" - } - }, - "ReferencePhoneDay": { - "type": "telephone", - "props": { - "timeOfDay": "Both", - "type": "Domestic", - "numberType": "", - "number": "7245555551", - "extension": "", - "noNumber": false - } - }, - "ReferencePhoneEvening": { - "type": "telephone", - "props": { - "timeOfDay": "Both", - "type": "Domestic", - "numberType": "", - "number": "7245555551", - "extension": "", - "noNumber": false - } - }, - "ReferencePhoneMobile": { - "type": "telephone", - "props": { - "timeOfDay": "Both", - "type": "Domestic", - "numberType": "", - "number": "7245555551", - "extension": "", - "noNumber": false - } - }, - "ReferenceRelationship": { - "type": "checkboxgroup", - "props": { - "values": [ - "Neighbor", - "Friend" - ] - } - }, - "ReferenceRelationshipComments": { - "type": "checkboxgroup", - "props": { - "values": null - } - }, - "ReferenceRelationshipOther": { - "type": "text", - "props": { - "value": "" - } - }, - "Role": { - "type": "radio", - "props": { - "value": "Own", - "checked": true - } - }, - "RoleOther": { - "type": "text", - "props": { - "value": "" - } - } - } - } - ] - } - } - } -} -` - -// HistEmployment contains an employment -const HistEmployment = ` -{ - "type": "history.employment", - "props": { - "List": { - "type": "collection", - "props": { - "branch": { - "type": "branch", - "props": { - "value": "No" - } - }, - "items": [ - { - "Item": { - "Additional": { - "type": "collection", - "props": { - "branch": { - "type": "" - }, - "items": [ - { - "Item": { - "DatesEmployed": { - "type": "daterange", - "props": { - "from": { - "type": "datecontrol", - "props": { - "month": "", - "day": "", - "year": "", - "estimated": false - } - }, - "to": { - "type": "datecontrol", - "props": { - "month": "", - "day": "", - "year": "", - "estimated": false - } - }, - "present": false - } - }, - "Has": { - "type": "branch", - "props": { - "value": "No" - } - }, - "Position": { - "type": "text", - "props": { - "value": "" - } - }, - "Supervisor": { - "type": "text", - "props": { - "value": "" - } - } - } - } - ] - } - }, - "Address": { - "type": "location", - "props": { - "layout": "Address", - "street": "345 NATIONAL RD", - "city": "WHEELING", - "state": "WV", - "zipcode": "26003", - "country": "United States", - "validated": true - } - }, - "Dates": { - "type": "daterange", - "props": { - "from": { - "type": "datecontrol", - "props": { - "month": "06", - "day": "12", - "year": "2006", - "estimated": false - } - }, - "to": { - "type": "datecontrol", - "props": { - "month": "8", - "day": "24", - "year": "2018", - "estimated": false - } - }, - "present": true - } - }, - "DutyStation": { - "type": "text", - "props": { - "value": "" - } - }, - "Employment": { - "type": "text", - "props": { - "value": "FBI" - } - }, - "EmploymentActivity": { - "type": "employmentactivity", - "props": { - "value": "OtherFederal" - } - }, - "PhysicalAddress": { - "type": "physicaladdress", - "props": { - "HasDifferentAddress": { - "type": "branch", - "props": { - "value": "No" - } - }, - "Address": { - "type": "location", - "props": { - "layout": "", - "country": "" - } - }, - "Telephone": { - "type": "telephone", - "props": { - "timeOfDay": "", - "type": "", - "numberType": "", - "number": "", - "extension": "", - "noNumber": false - } - } - } - }, - "ReasonLeft": { - "type": "reasonleft", - "props": { - "Comments": { - "type": "textarea", - "props": { - "value": "" - } - }, - "Reasons": { - "type": "collection", - "props": { - "branch": { - "type": "" - }, - "items": [ - { - "Item": { - "Date": { - "type": "datecontrol", - "props": { - "month": "", - "day": "", - "year": "", - "estimated": false - } - }, - "Has": { - "type": "branch", - "props": { - "value": "No" - } - }, - "Reason": { - "type": "textarea", - "props": { - "value": "" - } - }, - "Text": { - "type": "textarea", - "props": { - "value": "" - } - } - } - } - ] - } - }, - "ReasonDescription": { - "type": "textarea", - "props": { - "value": "" - } - } - } - }, - "ReferenceAddress": { - "type": "location", - "props": { - "layout": "", - "country": "" - } - }, - "ReferenceName": { - "type": "name", - "props": { - "first": "", - "firstInitialOnly": false, - "middle": "", - "middleInitialOnly": false, - "noMiddleName": false, - "last": "", - "suffix": "", - "suffixOther": "" - } - }, - "ReferencePhone": { - "type": "telephone", - "props": { - "timeOfDay": "", - "type": "", - "numberType": "", - "number": "", - "extension": "", - "noNumber": false - } - }, - "Reprimand": { - "type": "collection", - "props": { - "branch": { - "type": "" - }, - "items": [ - { - "Item": { - "Date": { - "type": "datecontrol", - "props": { - "month": "", - "day": "", - "year": "", - "estimated": false - } - }, - "Has": { - "type": "branch", - "props": { - "value": "No" - } - }, - "Text": { - "type": "textarea", - "props": { - "value": "" - } - } - } - } - ] - } - }, - "Status": { - "type": "radio", - "props": { - "value": "FullTime" - } - }, - "Supervisor": { - "type": "supervisor", - "props": { - "SupervisorName": { - "type": "text", - "props": { - "value": "Gail Shannon" - } - }, - "Title": { - "type": "text", - "props": { - "value": "Lead Analyst" - } - }, - "Email": { - "type": "email", - "props": { - "value": "gail.shannon@testemail.gov" - } - }, - "EmailNotApplicable": { - "type": "notapplicable", - "props": { - "applicable": true - } - }, - "Address": { - "type": "location", - "props": { - "layout": "Address", - "street": "345 NATIONAL RD", - "city": "WHEELING", - "state": "WV", - "zipcode": "26003", - "country": "United States" - } - }, - "Telephone": { - "type": "telephone", - "props": { - "timeOfDay": "Both", - "type": "Domestic", - "numberType": "", - "number": "3163170345", - "extension": "067", - "noNumber": false - } - } - } - }, - "Telephone": { - "type": "telephone", - "props": { - "timeOfDay": "Both", - "type": "Domestic", - "numberType": "", - "number": "3163170345", - "extension": "", - "noNumber": false - } - }, - "Title": { - "type": "text", - "props": { - "value": "Analyst" - } - } - } - } - ] - } - }, - "EmploymentRecord": { - "type": "branch", - "props": { - "value": "No" - } - } - } -} - ` diff --git a/api/integration/sections/identification.go b/api/integration/sections/identification.go deleted file mode 100644 index 57584e960..000000000 --- a/api/integration/sections/identification.go +++ /dev/null @@ -1,296 +0,0 @@ -package sections - -// IDOtherNamesNo has no other names -const IDOtherNamesNo = ` -{ - "type": "identification.othernames", - "props": { - "HasOtherNames": { - "type": "branch", - "props": { - "value": "No" - } - }, - "List": { - "type": "collection", - "props": { - "branch": { - "type": "branch", - "props": { - "value": "" - } - }, - "items": [] - } - } - } -} -` - -// IDOtherNamesYes has other names -const IDOtherNamesYes = ` -{ - "type": "identification.othernames", - "props": { - "HasOtherNames": { - "type": "branch", - "props": { - "value": "Yes" - } - }, - "List": { - "type": "collection", - "props": { - "branch": { - "type": "branch", - "props": { - "value": "No" - } - }, - "items": [ - { - "Item": { - "DatesUsed": { - "type": "daterange", - "props": { - "from": { - "type": "datecontrol", - "props": { - "month": "01", - "day": "02", - "year": "1992", - "estimated": false - } - }, - "to": { - "type": "datecontrol", - "props": { - "month": "01", - "day": "01", - "year": "1993", - "estimated": false - } - }, - "present": false - } - }, - "MaidenName": { - "type": "radio", - "props": { - "value": "No" - } - }, - "Name": { - "type": "name", - "props": { - "first": "Kirk", - "firstInitialOnly": false, - "middle": "Enzo", - "middleInitialOnly": false, - "noMiddleName": false, - "last": "James", - "suffix": "", - "suffixOther": "" - } - }, - "Reason": { - "type": "textarea", - "props": { - "value": "For a good reason." - } - } - } - }, - { - "Item": { - "DatesUsed": { - "type": "daterange", - "props": { - "from": { - "type": "datecontrol", - "props": { - "month": "01", - "day": "01", - "year": "1996", - "estimated": false - } - }, - "to": { - "type": "datecontrol", - "props": { - "month": "01", - "day": "01", - "year": "1997", - "estimated": false - } - }, - "present": false - } - }, - "MaidenName": { - "type": "radio", - "props": { - "value": "No" - } - }, - "Name": { - "type": "name", - "props": { - "first": "Kirk", - "firstInitialOnly": false, - "middle": "Enzo", - "middleInitialOnly": false, - "noMiddleName": false, - "last": "Riker", - "suffix": "", - "suffixOther": "" - } - }, - "Reason": { - "type": "textarea", - "props": { - "value": "Another good reason." - } - } - } - } - ] - } - } - } -} - ` - -// IDOtherNamesUnfinishedList has an unfinished list -const IDOtherNamesUnfinishedList = ` -{ - "type": "identification.othernames", - "props": { - "HasOtherNames": { - "type": "branch", - "props": { - "value": "Yes" - } - }, - "List": { - "type": "collection", - "props": { - "branch": { - "type": "branch", - "props": { - "value": "No" - } - }, - "items": [ - { - "Item": { - "DatesUsed": { - "type": "daterange", - "props": { - "from": { - "type": "datecontrol", - "props": { - "month": "01", - "day": "02", - "year": "1992", - "estimated": false - } - }, - "to": { - "type": "datecontrol", - "props": { - "month": "01", - "day": "01", - "year": "1993", - "estimated": false - } - }, - "present": false - } - }, - "MaidenName": { - "type": "radio", - "props": { - "value": "No" - } - }, - "Name": { - "type": "name", - "props": { - "first": "Kirk", - "firstInitialOnly": false, - "middle": "Enzo", - "middleInitialOnly": false, - "noMiddleName": false, - "last": "James", - "suffix": "", - "suffixOther": "" - } - }, - "Reason": { - "type": "textarea", - "props": { - "value": "For a good reason." - } - } - } - }, - { - "Item": { - "DatesUsed": { - "type": "daterange", - "props": { - "from": { - "type": "datecontrol", - "props": { - "month": "01", - "day": "01", - "year": "1996", - "estimated": false - } - }, - "to": { - "type": "datecontrol", - "props": { - "month": "01", - "day": "01", - "year": "1997", - "estimated": false - } - }, - "present": false - } - }, - "MaidenName": { - "type": "radio", - "props": { - "value": "No" - } - }, - "Name": { - "type": "name", - "props": { - "first": "Kirk", - "firstInitialOnly": false, - "middle": "Enzo", - "middleInitialOnly": false, - "noMiddleName": false, - "last": "Riker", - "suffix": "", - "suffixOther": "" - } - }, - "Reason": { - "type": "textarea", - "props": { - "value": "Another good reason." - } - } - } - } - ] - } - } - } -} -` diff --git a/api/integration/setup.go b/api/integration/setup.go index d92029f14..73d4246e6 100644 --- a/api/integration/setup.go +++ b/api/integration/setup.go @@ -124,6 +124,15 @@ func populateAccount(db api.DatabaseService, account api.Account, testCasePath s return nil } +// readTestData pulls in test data as a string +func readTestData(filepath string) (string, error) { + b, err := ioutil.ReadFile(filepath) + if err != nil { + return "", err + } + return string(b), nil +} + // saveJSON calls the save handler with the given json body. func saveJSON(services serviceSet, json string, accountID int) *gohttp.Response { diff --git a/api/pdf/pdf_test.go b/api/pdf/pdf_test.go index 2135fa24e..96e9850bd 100644 --- a/api/pdf/pdf_test.go +++ b/api/pdf/pdf_test.go @@ -69,19 +69,19 @@ func TestPackage(t *testing.T) { func applicationData(t *testing.T) map[string]interface{} { return map[string]interface{}{ "Identification": map[string]interface{}{ - "ApplicantName": readSectionData("identification-name.json", t), - "Contacts": readSectionData("identification-contacts.json", t), - "OtherNames": readSectionData("identification-othernames.json", t), - "ApplicantBirthDate": readSectionData("identification-birthdate.json", t), - "ApplicantBirthPlace": readSectionData("identification-birthplace.json", t), - "ApplicantSSN": readSectionData("identification-ssn.json", t), - "Physical": readSectionData("identification-physical.json", t), + "ApplicantName": readSectionData("identification/identification-name.json", t), + "Contacts": readSectionData("identification/identification-contacts.json", t), + "OtherNames": readSectionData("identification/identification-othernames.json", t), + "ApplicantBirthDate": readSectionData("identification/identification-birthdate.json", t), + "ApplicantBirthPlace": readSectionData("identification/identification-birthplace.json", t), + "ApplicantSSN": readSectionData("identification/identification-ssn.json", t), + "Physical": readSectionData("identification/identification-physical.json", t), }, "Submission": map[string]interface{}{ "Releases": readSectionData("submission.json", t), }, "History": map[string]interface{}{ - "Residence": readSectionData("history-residence.json", t), + "Residence": readSectionData("history/history-residence.json", t), }, } } diff --git a/api/postgresql/db_test.go b/api/postgresql/db_test.go index 57a2571f4..4820b1d3b 100644 --- a/api/postgresql/db_test.go +++ b/api/postgresql/db_test.go @@ -140,13 +140,13 @@ func TestPayloadValidate(t *testing.T) { {Data: "testdata/textarea.json"}, // Section: Identification - {Data: "testdata/identification-birthdate.json"}, - {Data: "testdata/identification-birthplace.json"}, - {Data: "testdata/identification-contacts.json"}, - {Data: "testdata/identification-name.json"}, - {Data: "testdata/identification-othernames.json"}, - {Data: "testdata/identification-physical.json"}, - {Data: "testdata/identification-ssn.json"}, + {Data: "testdata/identification/identification-birthdate.json"}, + {Data: "testdata/identification/identification-birthplace.json"}, + {Data: "testdata/identification/identification-contacts.json"}, + {Data: "testdata/identification/identification-name.json"}, + {Data: "testdata/identification/identification-othernames.json"}, + {Data: "testdata/identification/identification-physical.json"}, + {Data: "testdata/identification/identification-ssn.json"}, // Section: Financial {Data: "testdata/financial-bankruptcy.json"}, @@ -158,10 +158,10 @@ func TestPayloadValidate(t *testing.T) { {Data: "testdata/financial-nonpayment.json"}, // Section: Your history - {Data: "testdata/history-residence.json"}, - {Data: "testdata/history-employment.json"}, - {Data: "testdata/history-education.json"}, - {Data: "testdata/history-federal.json"}, + {Data: "testdata/history/history-residence.json"}, + {Data: "testdata/history/history-employment.json"}, + {Data: "testdata/history/history-education.json"}, + {Data: "testdata/history/history-federal.json"}, // Section: Relationships {Data: "testdata/relationships-status-marital.json"}, @@ -319,13 +319,13 @@ func TestPayloadPersistence(t *testing.T) { Data string }{ // Section: Identification - {Data: "testdata/identification-birthdate.json"}, - {Data: "testdata/identification-birthplace.json"}, - {Data: "testdata/identification-contacts.json"}, - {Data: "testdata/identification-name.json"}, - {Data: "testdata/identification-othernames.json"}, - {Data: "testdata/identification-physical.json"}, - {Data: "testdata/identification-ssn.json"}, + {Data: "testdata/identification/identification-birthdate.json"}, + {Data: "testdata/identification/identification-birthplace.json"}, + {Data: "testdata/identification/identification-contacts.json"}, + {Data: "testdata/identification/identification-name.json"}, + {Data: "testdata/identification/identification-othernames.json"}, + {Data: "testdata/identification/identification-physical.json"}, + {Data: "testdata/identification/identification-ssn.json"}, // Section: Financial {Data: "testdata/financial-bankruptcy.json"}, @@ -337,10 +337,10 @@ func TestPayloadPersistence(t *testing.T) { {Data: "testdata/financial-nonpayment.json"}, // Section: Your history - {Data: "testdata/history-residence.json"}, - {Data: "testdata/history-employment.json"}, - {Data: "testdata/history-education.json"}, - {Data: "testdata/history-federal.json"}, + {Data: "testdata/history/history-residence.json"}, + {Data: "testdata/history/history-employment.json"}, + {Data: "testdata/history/history-education.json"}, + {Data: "testdata/history/history-federal.json"}, // Section: Relationships {Data: "testdata/relationships-status-marital.json"}, diff --git a/api/testdata/history-education.json b/api/testdata/history/history-education.json similarity index 100% rename from api/testdata/history-education.json rename to api/testdata/history/history-education.json diff --git a/api/testdata/history/history-employment-full.json b/api/testdata/history/history-employment-full.json new file mode 100644 index 000000000..f0433d819 --- /dev/null +++ b/api/testdata/history/history-employment-full.json @@ -0,0 +1,365 @@ +{ + "type": "history.employment", + "props": { + "List": { + "type": "collection", + "props": { + "branch": { + "type": "branch", + "props": { + "value": "No" + } + }, + "items": [ + { + "Item": { + "Additional": { + "type": "collection", + "props": { + "branch": { + "type": "" + }, + "items": [ + { + "Item": { + "DatesEmployed": { + "type": "daterange", + "props": { + "from": { + "type": "datecontrol", + "props": { + "month": "", + "day": "", + "year": "", + "estimated": false + } + }, + "to": { + "type": "datecontrol", + "props": { + "month": "", + "day": "", + "year": "", + "estimated": false + } + }, + "present": false + } + }, + "Has": { + "type": "branch", + "props": { + "value": "No" + } + }, + "Position": { + "type": "text", + "props": { + "value": "" + } + }, + "Supervisor": { + "type": "text", + "props": { + "value": "" + } + } + } + } + ] + } + }, + "Address": { + "type": "location", + "props": { + "layout": "Address", + "street": "345 NATIONAL RD", + "city": "WHEELING", + "state": "WV", + "zipcode": "26003", + "country": "United States", + "validated": true + } + }, + "Dates": { + "type": "daterange", + "props": { + "from": { + "type": "datecontrol", + "props": { + "month": "06", + "day": "12", + "year": "2006", + "estimated": false + } + }, + "to": { + "type": "datecontrol", + "props": { + "month": "8", + "day": "24", + "year": "2018", + "estimated": false + } + }, + "present": true + } + }, + "DutyStation": { + "type": "text", + "props": { + "value": "" + } + }, + "Employment": { + "type": "text", + "props": { + "value": "FBI" + } + }, + "EmploymentActivity": { + "type": "employmentactivity", + "props": { + "value": "OtherFederal" + } + }, + "PhysicalAddress": { + "type": "physicaladdress", + "props": { + "HasDifferentAddress": { + "type": "branch", + "props": { + "value": "No" + } + }, + "Address": { + "type": "location", + "props": { + "layout": "", + "country": "" + } + }, + "Telephone": { + "type": "telephone", + "props": { + "timeOfDay": "", + "type": "", + "numberType": "", + "number": "", + "extension": "", + "noNumber": false + } + } + } + }, + "ReasonLeft": { + "type": "reasonleft", + "props": { + "Comments": { + "type": "textarea", + "props": { + "value": "" + } + }, + "Reasons": { + "type": "collection", + "props": { + "branch": { + "type": "" + }, + "items": [ + { + "Item": { + "Date": { + "type": "datecontrol", + "props": { + "month": "", + "day": "", + "year": "", + "estimated": false + } + }, + "Has": { + "type": "branch", + "props": { + "value": "No" + } + }, + "Reason": { + "type": "textarea", + "props": { + "value": "" + } + }, + "Text": { + "type": "textarea", + "props": { + "value": "" + } + } + } + } + ] + } + }, + "ReasonDescription": { + "type": "textarea", + "props": { + "value": "" + } + } + } + }, + "ReferenceAddress": { + "type": "location", + "props": { + "layout": "", + "country": "" + } + }, + "ReferenceName": { + "type": "name", + "props": { + "first": "", + "firstInitialOnly": false, + "middle": "", + "middleInitialOnly": false, + "noMiddleName": false, + "last": "", + "suffix": "", + "suffixOther": "" + } + }, + "ReferencePhone": { + "type": "telephone", + "props": { + "timeOfDay": "", + "type": "", + "numberType": "", + "number": "", + "extension": "", + "noNumber": false + } + }, + "Reprimand": { + "type": "collection", + "props": { + "branch": { + "type": "" + }, + "items": [ + { + "Item": { + "Date": { + "type": "datecontrol", + "props": { + "month": "", + "day": "", + "year": "", + "estimated": false + } + }, + "Has": { + "type": "branch", + "props": { + "value": "No" + } + }, + "Text": { + "type": "textarea", + "props": { + "value": "" + } + } + } + } + ] + } + }, + "Status": { + "type": "radio", + "props": { + "value": "FullTime" + } + }, + "Supervisor": { + "type": "supervisor", + "props": { + "SupervisorName": { + "type": "text", + "props": { + "value": "Gail Shannon" + } + }, + "Title": { + "type": "text", + "props": { + "value": "Lead Analyst" + } + }, + "Email": { + "type": "email", + "props": { + "value": "gail.shannon@testemail.gov" + } + }, + "EmailNotApplicable": { + "type": "notapplicable", + "props": { + "applicable": true + } + }, + "Address": { + "type": "location", + "props": { + "layout": "Address", + "street": "345 NATIONAL RD", + "city": "WHEELING", + "state": "WV", + "zipcode": "26003", + "country": "United States" + } + }, + "Telephone": { + "type": "telephone", + "props": { + "timeOfDay": "Both", + "type": "Domestic", + "numberType": "", + "number": "3163170345", + "extension": "067", + "noNumber": false + } + } + } + }, + "Telephone": { + "type": "telephone", + "props": { + "timeOfDay": "Both", + "type": "Domestic", + "numberType": "", + "number": "3163170345", + "extension": "", + "noNumber": false + } + }, + "Title": { + "type": "text", + "props": { + "value": "Analyst" + } + } + } + } + ] + } + }, + "EmploymentRecord": { + "type": "branch", + "props": { + "value": "No" + } + } + } +} diff --git a/api/testdata/history-employment.json b/api/testdata/history/history-employment.json similarity index 100% rename from api/testdata/history-employment.json rename to api/testdata/history/history-employment.json diff --git a/api/testdata/history-federal.json b/api/testdata/history/history-federal.json similarity index 100% rename from api/testdata/history-federal.json rename to api/testdata/history/history-federal.json diff --git a/api/testdata/history/history-residence-unfinished-list.json b/api/testdata/history/history-residence-unfinished-list.json new file mode 100644 index 000000000..2534733ac --- /dev/null +++ b/api/testdata/history/history-residence-unfinished-list.json @@ -0,0 +1,177 @@ +{ + "type": "history.residence", + "props": { + "List": { + "type": "collection", + "props": { + "branch": { + "type": "branch", + "props": { + "value": "" + } + }, + "items": [ + { + "Item": { + "Address": { + "type": "location", + "props": { + "layout": "Address", + "street": "316 Washington Ave", + "city": "Wheeling", + "state": "WV", + "zipcode": "26003", + "country": "United States", + "validated": true + } + }, + "Comments": { + "type": "textarea", + "props": { + "value": "" + } + }, + "Dates": { + "type": "daterange", + "props": { + "from": { + "type": "datecontrol", + "props": { + "month": "12", + "day": "13", + "year": "1990", + "estimated": false + } + }, + "to": { + "type": "datecontrol", + "props": { + "month": "8", + "day": "24", + "year": "2018", + "estimated": false + } + }, + "present": true + } + }, + "ReferenceAddress": { + "type": "location", + "props": { + "layout": "Address", + "street": "317 WASHINGTON AVE", + "city": "WHEELING", + "state": "WV", + "zipcode": "26003", + "country": "United States", + "validated": true + } + }, + "ReferenceEmail": { + "type": "email", + "props": { + "value": "ashley.Emily@testemail.com" + } + }, + "ReferenceEmailNotApplicable": { + "type": "notapplicable", + "props": { + "applicable": false + } + }, + "ReferenceLastContact": { + "type": "datecontrol", + "props": { + "month": "08", + "day": "01", + "year": "2018", + "estimated": false + } + }, + "ReferenceName": { + "type": "name", + "props": { + "first": "Ashley", + "firstInitialOnly": false, + "middle": "", + "middleInitialOnly": false, + "noMiddleName": true, + "last": "Emily", + "suffix": "", + "suffixOther": "" + } + }, + "ReferencePhoneDay": { + "type": "telephone", + "props": { + "timeOfDay": "Both", + "type": "Domestic", + "numberType": "", + "number": "7245555551", + "extension": "", + "noNumber": false + } + }, + "ReferencePhoneEvening": { + "type": "telephone", + "props": { + "timeOfDay": "Both", + "type": "Domestic", + "numberType": "", + "number": "7245555551", + "extension": "", + "noNumber": false + } + }, + "ReferencePhoneMobile": { + "type": "telephone", + "props": { + "timeOfDay": "Both", + "type": "Domestic", + "numberType": "", + "number": "7245555551", + "extension": "", + "noNumber": false + } + }, + "ReferenceRelationship": { + "type": "checkboxgroup", + "props": { + "values": [ + "Neighbor", + "Friend" + ] + } + }, + "ReferenceRelationshipComments": { + "type": "checkboxgroup", + "props": { + "values": null + } + }, + "ReferenceRelationshipOther": { + "type": "text", + "props": { + "value": "" + } + }, + "Role": { + "type": "radio", + "props": { + "value": "Own", + "checked": true + } + }, + "RoleOther": { + "type": "text", + "props": { + "value": "" + } + } + } + } + ] + } + } + } +} diff --git a/api/testdata/history-residence.json b/api/testdata/history/history-residence.json similarity index 100% rename from api/testdata/history-residence.json rename to api/testdata/history/history-residence.json diff --git a/api/testdata/identification-birth.json b/api/testdata/identification/identification-birth.json similarity index 100% rename from api/testdata/identification-birth.json rename to api/testdata/identification/identification-birth.json diff --git a/api/testdata/identification-birthdate.json b/api/testdata/identification/identification-birthdate.json similarity index 100% rename from api/testdata/identification-birthdate.json rename to api/testdata/identification/identification-birthdate.json diff --git a/api/testdata/identification-birthplace.json b/api/testdata/identification/identification-birthplace.json similarity index 100% rename from api/testdata/identification-birthplace.json rename to api/testdata/identification/identification-birthplace.json diff --git a/api/testdata/identification-contacts.json b/api/testdata/identification/identification-contacts.json similarity index 100% rename from api/testdata/identification-contacts.json rename to api/testdata/identification/identification-contacts.json diff --git a/api/testdata/identification-eyecolor.json b/api/testdata/identification/identification-eyecolor.json similarity index 100% rename from api/testdata/identification-eyecolor.json rename to api/testdata/identification/identification-eyecolor.json diff --git a/api/testdata/identification-height.json b/api/testdata/identification/identification-height.json similarity index 100% rename from api/testdata/identification-height.json rename to api/testdata/identification/identification-height.json diff --git a/api/testdata/identification-name.json b/api/testdata/identification/identification-name.json similarity index 100% rename from api/testdata/identification-name.json rename to api/testdata/identification/identification-name.json diff --git a/api/testdata/identification/identification-othernames-no.json b/api/testdata/identification/identification-othernames-no.json new file mode 100644 index 000000000..5a3e2779c --- /dev/null +++ b/api/testdata/identification/identification-othernames-no.json @@ -0,0 +1,23 @@ +{ + "type": "identification.othernames", + "props": { + "HasOtherNames": { + "type": "branch", + "props": { + "value": "No" + } + }, + "List": { + "type": "collection", + "props": { + "branch": { + "type": "branch", + "props": { + "value": "" + } + }, + "items": [] + } + } + } +} diff --git a/api/testdata/identification/identification-othernames-unfinished.json b/api/testdata/identification/identification-othernames-unfinished.json new file mode 100644 index 000000000..931588b73 --- /dev/null +++ b/api/testdata/identification/identification-othernames-unfinished.json @@ -0,0 +1,130 @@ +{ + "type": "identification.othernames", + "props": { + "HasOtherNames": { + "type": "branch", + "props": { + "value": "Yes" + } + }, + "List": { + "type": "collection", + "props": { + "branch": { + "type": "branch", + "props": { + "value": "No" + } + }, + "items": [ + { + "Item": { + "DatesUsed": { + "type": "daterange", + "props": { + "from": { + "type": "datecontrol", + "props": { + "month": "01", + "day": "02", + "year": "1992", + "estimated": false + } + }, + "to": { + "type": "datecontrol", + "props": { + "month": "01", + "day": "01", + "year": "1993", + "estimated": false + } + }, + "present": false + } + }, + "MaidenName": { + "type": "radio", + "props": { + "value": "No" + } + }, + "Name": { + "type": "name", + "props": { + "first": "Kirk", + "firstInitialOnly": false, + "middle": "Enzo", + "middleInitialOnly": false, + "noMiddleName": false, + "last": "James", + "suffix": "", + "suffixOther": "" + } + }, + "Reason": { + "type": "textarea", + "props": { + "value": "For a good reason." + } + } + } + }, + { + "Item": { + "DatesUsed": { + "type": "daterange", + "props": { + "from": { + "type": "datecontrol", + "props": { + "month": "01", + "day": "01", + "year": "1996", + "estimated": false + } + }, + "to": { + "type": "datecontrol", + "props": { + "month": "01", + "day": "01", + "year": "1997", + "estimated": false + } + }, + "present": false + } + }, + "MaidenName": { + "type": "radio", + "props": { + "value": "No" + } + }, + "Name": { + "type": "name", + "props": { + "first": "Kirk", + "firstInitialOnly": false, + "middle": "Enzo", + "middleInitialOnly": false, + "noMiddleName": false, + "last": "Riker", + "suffix": "", + "suffixOther": "" + } + }, + "Reason": { + "type": "textarea", + "props": { + "value": "Another good reason." + } + } + } + } + ] + } + } + } +} diff --git a/api/testdata/identification-othernames.json b/api/testdata/identification/identification-othernames.json similarity index 100% rename from api/testdata/identification-othernames.json rename to api/testdata/identification/identification-othernames.json diff --git a/api/testdata/identification-physical.json b/api/testdata/identification/identification-physical.json similarity index 100% rename from api/testdata/identification-physical.json rename to api/testdata/identification/identification-physical.json diff --git a/api/testdata/identification-sex.json b/api/testdata/identification/identification-sex.json similarity index 100% rename from api/testdata/identification-sex.json rename to api/testdata/identification/identification-sex.json diff --git a/api/testdata/identification-ssn.json b/api/testdata/identification/identification-ssn.json similarity index 100% rename from api/testdata/identification-ssn.json rename to api/testdata/identification/identification-ssn.json diff --git a/api/testdata/identification-weight.json b/api/testdata/identification/identification-weight.json similarity index 100% rename from api/testdata/identification-weight.json rename to api/testdata/identification/identification-weight.json diff --git a/api/xml/xml_test.go b/api/xml/xml_test.go index 8c418e836..e0589d0b8 100644 --- a/api/xml/xml_test.go +++ b/api/xml/xml_test.go @@ -34,14 +34,14 @@ func TestPackage(t *testing.T) { Data map[string]interface{} }{ {Schema: "identification.xml", Data: application}, - {Schema: "identification-name.xml", Data: r("identification-name.json")}, - {Schema: "identification-birth.xml", Data: r("identification-birth.json")}, - {Schema: "identification-eyecolor.xml", Data: r("identification-eyecolor.json")}, - {Schema: "identification-height.xml", Data: r("identification-height.json")}, - {Schema: "identification-othernames.xml", Data: r("identification-othernames.json")}, - {Schema: "identification-ssn.xml", Data: r("identification-ssn.json")}, - {Schema: "identification-sex.xml", Data: r("identification-sex.json")}, - {Schema: "identification-weight.xml", Data: r("identification-weight.json")}, + {Schema: "identification-name.xml", Data: r("identification/identification-name.json")}, + {Schema: "identification-birth.xml", Data: r("identification/identification-birth.json")}, + {Schema: "identification-eyecolor.xml", Data: r("identification/identification-eyecolor.json")}, + {Schema: "identification-height.xml", Data: r("identification/identification-height.json")}, + {Schema: "identification-othernames.xml", Data: r("identification/identification-othernames.json")}, + {Schema: "identification-ssn.xml", Data: r("identification/identification-ssn.json")}, + {Schema: "identification-sex.xml", Data: r("identification/identification-sex.json")}, + {Schema: "identification-weight.xml", Data: r("identification/identification-weight.json")}, {Schema: "financial.xml", Data: application}, {Schema: "financial-bankruptcy.xml", Data: r("financial-bankruptcy.json")}, {Schema: "financial-card.xml", Data: r("financial-card.json")}, @@ -51,10 +51,10 @@ func TestPackage(t *testing.T) { {Schema: "financial-nonpayment.xml", Data: r("financial-nonpayment.json")}, {Schema: "financial-taxes.xml", Data: r("financial-taxes.json")}, {Schema: "history.xml", Data: application}, - {Schema: "history-education.xml", Data: r("history-education.json")}, - {Schema: "history-employment.xml", Data: r("history-employment.json")}, - {Schema: "history-federal.xml", Data: r("history-federal.json")}, - {Schema: "history-residence.xml", Data: r("history-residence.json")}, + {Schema: "history-education.xml", Data: r("history/history-education.json")}, + {Schema: "history-employment.xml", Data: r("history/history-employment.json")}, + {Schema: "history-federal.xml", Data: r("history/history-federal.json")}, + {Schema: "history-residence.xml", Data: r("history/history-residence.json")}, {Schema: "relationships.xml", Data: application}, {Schema: "relatives-and-associates.xml", Data: r("relationships-relatives.json")}, {Schema: "spouse-cohabitants.xml", Data: r("relationships-status-cohabitant.json")}, @@ -382,21 +382,21 @@ func formatXML(t *testing.T, snippet string) []byte { // applicationData loads a fully-populated, valid SF-86 form with test data func applicationData(t *testing.T) map[string]interface{} { return newForm(t, - "identification-name.json", - "identification-contacts.json", - "identification-othernames.json", - "identification-birthdate.json", - "identification-birthplace.json", - "identification-ssn.json", - "identification-physical.json", + "identification/identification-name.json", + "identification/identification-contacts.json", + "identification/identification-othernames.json", + "identification/identification-birthdate.json", + "identification/identification-birthplace.json", + "identification/identification-ssn.json", + "identification/identification-physical.json", "relationships-status-marital.json", "relationships-status-cohabitant.json", "relationships-people.json", "relationships-relatives.json", - "history-education.json", - "history-employment.json", - "history-federal.json", - "history-residence.json", + "history/history-education.json", + "history/history-employment.json", + "history/history-federal.json", + "history/history-residence.json", "citizenship-status.json", "citizenship-multiple.json", "citizenship-passports.json", From 5869a9974f12f7e219a3b755a70f954ba69222a2 Mon Sep 17 00:00:00 2001 From: MacRae Linton <55759+macrael@users.noreply.github.com> Date: Tue, 23 Apr 2019 13:26:36 -0700 Subject: [PATCH 14/14] Update dbreset to quote identifiers. I'm leaving in the db check just so that we don't create tables that are wierd by accident. --- api/cmd/dbreset/main.go | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/api/cmd/dbreset/main.go b/api/cmd/dbreset/main.go index 84d2e1dbd..acb4f2f6a 100644 --- a/api/cmd/dbreset/main.go +++ b/api/cmd/dbreset/main.go @@ -8,7 +8,7 @@ import ( "os" "unicode" - _ "github.com/lib/pq" + "github.com/lib/pq" "github.com/pkg/errors" "github.com/18F/e-QIP-prototype/api" @@ -48,6 +48,7 @@ func resetDB(dbName string, force bool) error { if openErr != nil { return errors.Wrap(openErr, "Error opening connection") } + defer db.Close() check, checkErr := db.Exec("SELECT 1 AS result FROM pg_database WHERE datname=$1", dbName) if checkErr != nil { @@ -75,7 +76,7 @@ func resetDB(dbName string, force bool) error { } - dropCmd := "DROP DATABASE " + dbName + dropCmd := "DROP DATABASE " + pq.QuoteIdentifier(dbName) _, dropErr := db.Exec(dropCmd) if dropErr != nil { return dropErr @@ -83,7 +84,7 @@ func resetDB(dbName string, force bool) error { } - createCmd := "CREATE DATABASE " + dbName + createCmd := "CREATE DATABASE " + pq.QuoteIdentifier(dbName) _, createErr := db.Exec(createCmd) if createErr != nil { return errors.Wrap(createErr, "Error Creating db") @@ -110,6 +111,4 @@ func main() { os.Exit(1) } - fmt.Println("HI THERE") - }