Skip to content

Eliminate code duplication requests between Upsert and Insert #3287

Draft
aaronburtle wants to merge 2 commits intomainfrom
dev/aaronburtle/FactorOutCodeDuplicationInInsertAndUpsert
Draft

Eliminate code duplication requests between Upsert and Insert #3287
aaronburtle wants to merge 2 commits intomainfrom
dev/aaronburtle/FactorOutCodeDuplicationInInsertAndUpsert

Conversation

@aaronburtle
Copy link
Contributor

Why make this change?

Closes #3209

What is this change?

Allow Upserts coming from REST requests to fall through to the Insert logic when auto-generated primary keys are missing. This eliminates code duplication between these two ops in the SqlMutationEngine

Add a test to cover the case when we have a PUT/PATCH with keys provided in the request body.

How was this tested?

New test was added to ensure complete coverage over the scenarios introduced with the keyless PUT/PATCH change.

Sample Request(s)

PUT that updates existing row (expects 200 OK):

PUT https://localhost:5001/api/magazine
Content-Type: application/json

{
    "id": 1,
    "title": "Updated Vogue",
    "issue_number": 9999
}

PUT that inserts new row (expects 201 Created):

PUT https://localhost:5001/api/magazine
Content-Type: application/json

{
    "id": 5001,
    "title": "Brand New Magazine",
    "issue_number": 42
}

PATCH that updates existing row (expects 200 OK):

PATCH https://localhost:5001/api/magazine
Content-Type: application/json

{
    "id": 1,
    "title": "Updated Vogue"
}

PATCH that inserts new row (expects 201 Created):

PATCH https://localhost:5001/api/magazine
Content-Type: application/json

{
    "id": 5001,
    "title": "Brand New Magazine"
}

@aaronburtle
Copy link
Contributor Author

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 6 pipeline(s).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Code duplication in Upsert and Insert operations

1 participant