-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow updates of single data sets #934
- Loading branch information
Showing
6 changed files
with
193 additions
and
57 deletions.
There are no files selected for viewing
30 changes: 30 additions & 0 deletions
30
grails-app/controllers/au/org/ala/ecodata/DataSetSummaryController.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package au.org.ala.ecodata | ||
|
||
import org.apache.http.HttpStatus | ||
|
||
class DataSetSummaryController { | ||
|
||
static responseFormats = ['json', 'xml'] | ||
static allowedMethods = [update:['POST', 'PUT']] | ||
|
||
ProjectService projectService | ||
|
||
/** Updates a single dataset for a project */ | ||
def update(String projectId) { | ||
Map dataSet = request.JSON | ||
|
||
if (!projectId && !dataSet.projectId) { | ||
respond status: 400, message: "projectId is required" | ||
return | ||
} | ||
|
||
projectId = projectId || dataSet.projectId | ||
|
||
if (dataSet.projectId && dataSet.projectId != projectId) { | ||
respond status: HttpStatus.SC_BAD_REQUEST, message: "projectId must match the data set projectId" | ||
return | ||
} | ||
|
||
respond projectService.updateDataSet(projectId, dataSet) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
src/test/groovy/au/org/ala/ecodata/DataSetSummaryControllerSpec.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package au.org.ala.ecodata | ||
|
||
import grails.testing.web.controllers.ControllerUnitTest | ||
import org.apache.http.HttpStatus | ||
import spock.lang.Specification | ||
|
||
class DataSetSummaryControllerSpec extends Specification implements ControllerUnitTest<DataSetSummaryController> { | ||
|
||
ProjectService projectService = Mock(ProjectService) | ||
def setup() { | ||
controller.projectService = projectService | ||
} | ||
|
||
def cleanup() { | ||
} | ||
|
||
void "The update method delegates to the projectService"() { | ||
setup: | ||
String projectId = 'p1' | ||
Map dataSetSummary = [dataSetId:'d1', name:'Data set 1'] | ||
|
||
when: | ||
request.json = dataSetSummary | ||
controller.update(projectId) | ||
|
||
then: | ||
1 * projectService.updateDataSet(projectId, dataSetSummary) >> [status:'ok'] | ||
response.json == ['status':'ok'] | ||
|
||
} | ||
|
||
void "A project id must be specified either in the path or as part of the data set summary"() { | ||
setup: | ||
Map dataSetSummary = [dataSetId: 'd1', name: 'Data set 1'] | ||
|
||
when: | ||
request.json = dataSetSummary | ||
controller.update() | ||
|
||
then: | ||
0 * projectService.updateDataSet(_, _) | ||
response.status == HttpStatus.SC_BAD_REQUEST | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters