diff --git a/Dockerfile-local b/Dockerfile-local index 49162000..b6dd77fe 100644 --- a/Dockerfile-local +++ b/Dockerfile-local @@ -1,4 +1,4 @@ -FROM golang:1.17-stretch as build +FROM golang:1.18-stretch as build RUN apt-get update && apt-get upgrade -y diff --git a/Dockerfile.local b/Dockerfile.local index ba4ec51b..a270516e 100644 --- a/Dockerfile.local +++ b/Dockerfile.local @@ -1,8 +1,8 @@ -FROM golang:1.17-stretch AS base +FROM golang:1.18-stretch AS base ENV GOCACHE=/go/.go/cache GOPATH=/go/.go/path TZ=Europe/London -RUN GOBIN=/bin go get github.com/cespare/reflex +RUN GOBIN=/bin go install github.com/cespare/reflex@latest # Map between the working directories of dev and live RUN ln -s /go /dp-dataset-api diff --git a/features/private_datasets.feature b/features/private_datasets.feature index 245774ae..d58b7157 100644 --- a/features/private_datasets.feature +++ b/features/private_datasets.feature @@ -44,7 +44,7 @@ Feature: Private Dataset API forbidden - dataset already exists """ - Scenario: Adding canonical and subtopic fields to a dataset + Scenario: Adding survey field to a dataset Given I have these datasets: """ [ @@ -56,14 +56,7 @@ Feature: Private Dataset API When I PUT "/datasets/population-estimates" """ { - "canonical_topic": { - "id": "canonical-topic-ID", - "title": "Canonical topic title" - }, - "sub_topics": [{ - "id": "subtopic-ID", - "title": "Subtopic title" - }] + "survey": "mockSurvey" } """ Then the HTTP status code should be "200" @@ -71,17 +64,59 @@ Feature: Private Dataset API """ { "id": "population-estimates", - "canonical_topic": { - "id": "canonical-topic-ID", - "title": "Canonical topic title" - }, - "sub_topics": [{ - "id": "subtopic-ID", - "title": "Subtopic title" - }] + "survey": "mockSurvey" } """ + Scenario: Adding topic fields to a dataset + Given I have these datasets: + """ + [ + { + "id": "population-estimates" + } + ] + """ + When I PUT "/datasets/population-estimates" + """ + { + "canonical_topic": "canonical-topic-ID", + "subtopics": ["subtopic-ID"] + } + """ + Then the HTTP status code should be "200" + And the document in the database for id "population-estimates" should be: + """ + { + "id": "population-estimates", + "canonical_topic": "canonical-topic-ID", + "subtopics": ["subtopic-ID"] + } + """ + + Scenario: Removing a survey from a dataset + Given I have these datasets: + """ + [ + { + "id": "population-estimates", + "survey": "mockSurvey" + } + ] + """ + When I PUT "/datasets/population-estimates" + """ + { + "survey": "" + } + """ + Then the document in the database for id "population-estimates" should be: + """ + { + "id": "population-estimates" + } + """ + Scenario: GET /datasets Given I have these datasets: """ @@ -119,14 +154,8 @@ Feature: Private Dataset API [ { "id": "population-estimates", - "canonical_topic": { - "id": "canonical-topic-ID", - "title": "Canonical topic title" - }, - "sub_topics": [{ - "id": "subtopic-ID", - "title": "Subtopic title" - }] + "canonical_topic": "canonical-topic-ID", + "subtopics": ["subtopic-ID"] } ] """ @@ -139,25 +168,13 @@ Feature: Private Dataset API "id": "population-estimates", "next": { "id": "population-estimates", - "canonical_topic": { - "id": "canonical-topic-ID", - "title": "Canonical topic title" - }, - "sub_topics": [{ - "id": "subtopic-ID", - "title": "Subtopic title" - }] + "canonical_topic": "canonical-topic-ID", + "subtopics": ["subtopic-ID"] }, "current": { "id": "population-estimates", - "canonical_topic": { - "id": "canonical-topic-ID", - "title": "Canonical topic title" - }, - "sub_topics": [{ - "id": "subtopic-ID", - "title": "Subtopic title" - }] + "canonical_topic": "canonical-topic-ID", + "subtopics": ["subtopic-ID"] } }], "limit": 20, diff --git a/features/public_datasets.feature b/features/public_datasets.feature index e7c7113f..0a3b1b80 100644 --- a/features/public_datasets.feature +++ b/features/public_datasets.feature @@ -45,7 +45,7 @@ Feature: Dataset API } """ - Scenario: Adding canonical and subtopic fields to a dataset + Scenario: Adding topic and survey fields to a dataset Given I have these datasets: """ [ @@ -57,14 +57,9 @@ Feature: Dataset API When I PUT "/datasets/population-estimates" """ { - "canonical_topic": { - "id": "canonical-topic-ID", - "title": "Canonical topic title" - }, - "sub_topics": [{ - "id": "subtopic-ID", - "title": "Subtopic title" - }] + "canonical_topic": "canonical-topic-ID", + "subtopics": ["subtopic-ID"], + "survey": "mockSurvey" } """ Then the HTTP status code should be "405" diff --git a/models/dataset.go b/models/dataset.go index c3d10b90..ffd96bc0 100644 --- a/models/dataset.go +++ b/models/dataset.go @@ -110,13 +110,9 @@ type Dataset struct { Type string `bson:"type,omitempty" json:"type,omitempty"` NomisReferenceURL string `bson:"nomis_reference_url,omitempty" json:"nomis_reference_url,omitempty"` IsBasedOn *IsBasedOn `bson:"is_based_on,omitempty" json:"is_based_on,omitempty"` - CanonicalTopic *Topic `bson:"canonical_topic,omitempty" json:"canonical_topic,omitempty"` - SubTopics []Topic `bson:"sub_topics,omitempty" json:"sub_topics,omitempty"` -} - -type Topic struct { - ID string `bson:"id,omitempty" json:"id,omitempty"` - Title string `bson:"title,omitempty" json:"title,omitempty"` + CanonicalTopic string `bson:"canonical_topic,omitempty" json:"canonical_topic,omitempty"` + Subtopics []string `bson:"subtopics,omitempty" json:"subtopics,omitempty"` + Survey string `bson:"survey,omitempty" json:"survey,omitempty"` } // DatasetLinks represents a list of specific links related to the dataset resource diff --git a/models/dataset_test.go b/models/dataset_test.go index 6ab90e48..5c9b1d60 100644 --- a/models/dataset_test.go +++ b/models/dataset_test.go @@ -176,8 +176,9 @@ func TestCreateDataset(t *testing.T) { So(dataset.URI, ShouldEqual, "http://localhost:22000/datasets/123/breadcrumbs") So(dataset.Type, ShouldEqual, "filterable") So(dataset.NomisReferenceURL, ShouldEqual, "") - So(dataset.CanonicalTopic, ShouldResemble, &canonicalTopic) - So(dataset.SubTopics[0], ShouldResemble, subtopic) + So(dataset.CanonicalTopic, ShouldResemble, canonicalTopic) + So(dataset.Subtopics[0], ShouldResemble, subtopic) + So(dataset.Survey, ShouldEqual, survey) }) }) diff --git a/models/test_data.go b/models/test_data.go index 48437915..feabe38b 100644 --- a/models/test_data.go +++ b/models/test_data.go @@ -43,15 +43,11 @@ var relatedDatasets = GeneralDetails{ Title: "Census Age", } -var canonicalTopic = Topic{ - ID: "canonicalTopicID", - Title: "Canonical topic title", -} +var canonicalTopic = "canonicalTopicID" -var subtopic = Topic{ - ID: "subtopicID", - Title: "Subtopic title", -} +var subtopic = "subtopicID" + +var survey = "mockSurvey" // Create a fully populated dataset object to use in testing. func createTestDataset() *Dataset { @@ -90,8 +86,9 @@ func createTestDataset() *Dataset { URI: "http://localhost:22000/datasets/123/breadcrumbs", Type: "filterable", NomisReferenceURL: "", - CanonicalTopic: &canonicalTopic, - SubTopics: []Topic{subtopic}, + CanonicalTopic: canonicalTopic, + Subtopics: []string{subtopic}, + Survey: survey, } } @@ -128,8 +125,9 @@ func expectedDataset() Dataset { URI: "http://localhost:22000/datasets/123/breadcrumbs", Type: "filterable", NomisReferenceURL: "", - CanonicalTopic: &canonicalTopic, - SubTopics: []Topic{subtopic}, + CanonicalTopic: canonicalTopic, + Subtopics: []string{subtopic}, + Survey: survey, } } diff --git a/mongo/dataset_store.go b/mongo/dataset_store.go index 6fbc294c..1a307035 100644 --- a/mongo/dataset_store.go +++ b/mongo/dataset_store.go @@ -414,12 +414,16 @@ func createDatasetUpdateQuery(ctx context.Context, id string, dataset *models.Da updates["next.nomis_reference_url"] = dataset.NomisReferenceURL } - if dataset.CanonicalTopic != nil { + if dataset.CanonicalTopic != "" { updates["next.canonical_topic"] = dataset.CanonicalTopic } - if dataset.SubTopics != nil { - updates["next.sub_topics"] = dataset.SubTopics + if len(dataset.Subtopics) > 0 { + updates["next.subtopics"] = dataset.Subtopics + } + + if dataset.Survey != "" { + updates["next.survey"] = dataset.Survey } log.Info(ctx, "built update query for dataset resource", log.Data{"dataset_id": id, "dataset": dataset, "updates": updates}) diff --git a/mongo/dataset_test.go b/mongo/dataset_test.go index 0e38d119..9ad330ad 100644 --- a/mongo/dataset_test.go +++ b/mongo/dataset_test.go @@ -179,18 +179,11 @@ func TestDatasetUpdateQuery(t *testing.T) { Title: "some dataset title", } - canonicalTopic := models.Topic{ - ID: "canonicalTopicID", - Title: "Canonical topic title", - } + canonicalTopic := "canonicalTopicID" + + subtopics := []string{"secondaryTopic1ID", "secondaryTopic2ID"} - subTopics := []models.Topic{{ - ID: "secondaryTopic1ID", - Title: "Secondary topic 1 title", - }, { - ID: "secondaryTopic2ID", - Title: "Secondary topic 2 title", - }} + survey := "mockSurvey" var methodologies, publications, relatedDatasets []models.GeneralDetails methodologies = append(methodologies, methodology) @@ -222,8 +215,9 @@ func TestDatasetUpdateQuery(t *testing.T) { "next.uri": "http://ons.gov.uk/datasets/123/landing-page", "next.type": "nomis", "next.nomis_reference_url": "https://www.nomisweb.co.uk/census/2011/ks106ew", - "next.canonical_topic": &canonicalTopic, - "next.sub_topics": subTopics, + "next.canonical_topic": canonicalTopic, + "next.subtopics": subtopics, + "next.survey": survey, } dataset := &models.Dataset{ @@ -254,8 +248,9 @@ func TestDatasetUpdateQuery(t *testing.T) { URI: "http://ons.gov.uk/datasets/123/landing-page", Type: "nomis", NomisReferenceURL: "https://www.nomisweb.co.uk/census/2011/ks106ew", - CanonicalTopic: &canonicalTopic, - SubTopics: subTopics, + CanonicalTopic: canonicalTopic, + Subtopics: subtopics, + Survey: survey, } selector := createDatasetUpdateQuery(testContext, "123", dataset, models.CreatedState)