Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[API] Visit patch request to start next stage #7479

Merged
merged 8 commits into from
Oct 27, 2021
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ requesting a new account and will be displayed in the User Accounts module (PR #
#### API
- Creation of a new version of the API under development (v0.0.4-dev) (PR #6944)
- Deletion of support for the oldest version of the API (v0.0.2) (PR #6944)
- Addition of a PATCH request for /candidates/$CandID/$VisitLabel to start next stage when the payload contains a "Visit" stage with "In Progress" as Status, when the current status of the Visit stage is "Not Started". (PR #7479)
#### Candidate Parameters
- Consents may now be grouped in UI of consent tab (PR #6042, PR #6044)
#### API Documentation (**New Module**)
Expand Down
2 changes: 1 addition & 1 deletion modules/api/docs/LorisRESTAPI.md
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ The JSON object is of the form:
}
```

A PUT of the same format but with only the Meta fields will create the VisitLabel
A PUT request with only the Meta fields will create the VisitLabel
for this candidate, in an unstarted stage if the Visit label provided is valid.

PATCH is not supported for Visit Labels.
Expand Down
21 changes: 19 additions & 2 deletions modules/api/docs/LorisRESTAPI_v0.0.4-dev.md
Original file line number Diff line number Diff line change
Expand Up @@ -416,10 +416,27 @@ The JSON object is of the form:
}
```

A PUT of the same format but with only the Meta fields will create the VisitLabel
A PUT request with only the Meta fields will create the VisitLabel
for this candidate, in an unstarted stage if the Visit label provided is valid.

PATCH is not supported for Visit Labels.
A PATCH request of the form:
```js
{
"CandID" : 317604,
"Visit" : 'Visit 01',
"Site" : 'DCC',
"Battery" : 'Stale',
"Project" : 'Pumpernickel',
"Stages" : {
"Visit" : {
"Date" : "YYYY-MM-DD",
"Status" : "In Progress"
}
}
}
```
will update the Visit stage date and status and start the next stage if the Visit stage
is 'Not Started' and the CandID and Visit label provided are valid.

It will return a 404 Not Found if the visit label does not exist for this candidate
(as well as anything under the /candidates/$CandID/$VisitLabel hierarchy)
Expand Down
11 changes: 9 additions & 2 deletions modules/api/php/endpoints/candidate/candidate.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ class Candidate extends Endpoint implements \LORIS\Middleware\ETagCalculator
}

// Delegate to sub-endpoints
$visit_label = array_shift($pathparts);
$visit_label = urldecode(array_shift($pathparts));
$newrequest = $request
->withAttribute('pathparts', $pathparts);

Expand All @@ -112,7 +112,14 @@ class Candidate extends Endpoint implements \LORIS\Middleware\ETagCalculator
$visit = null;
}

$handler = new Visit\Visit(
$version = $request->getAttribute("LORIS-API-Version");
$subendpoint = __NAMESPACE__ . '\\' . 'Visit\Visit';

if ($version == 'v0.0.4-dev') {
$subendpoint = __NAMESPACE__ . '\\' .'Visit\Visit_0_0_4_Dev';
}

$handler = new $subendpoint(
$this->_candidate,
$visit
);
Expand Down
3 changes: 1 addition & 2 deletions modules/api/php/endpoints/candidate/visit/visit.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ class Visit extends Endpoint implements \LORIS\Middleware\ETagCalculator
{
return [
'v0.0.3',
'v0.0.4-dev',
];
}

Expand Down Expand Up @@ -215,7 +214,7 @@ class Visit extends Endpoint implements \LORIS\Middleware\ETagCalculator

if ($visitinfo['CandID'] !== $this->_candidate->getCandID()) {
return new \LORIS\Http\Response\JSON\BadRequest(
'CandID do not match this candidate'
'CandID does not match this candidate'
);
}

Expand Down
Loading