Skip to content

Commit

Permalink
chore: Normalize API URLs to end in /. Use template strings.
Browse files Browse the repository at this point in the history
  • Loading branch information
jpmckinney committed Aug 14, 2023
1 parent 523f19b commit 9b80960
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 61 deletions.
6 changes: 3 additions & 3 deletions backend/api/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@
TemplateView.as_view(template_name="swagger-ui.html", extra_context={"schema_url": "openapi-schema"}),
name="swagger-ui",
),
path("dataset-filter-items", views.dataset_filter_items, name="dataset-filter-items"),
path("dataset-filter-items/", views.dataset_filter_items, name="dataset-filter-items"),
path(
"dataset-distinct-values/<dataset_id>/<field>",
"dataset-distinct-values/<dataset_id>/<field>/",
views.dataset_distinct_values,
name="dataset-distinct-values",
),
path(
"dataset-distinct-values/<dataset_id>/<field>/<query>",
"dataset-distinct-values/<dataset_id>/<field>/<query>/",
views.dataset_distinct_values,
name="dataset-distinct-values-query",
),
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/components/DatasetFilterModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ export default {
this.isSubmitting = true;
axios
.post(
CONFIG.apiBaseUrl + CONFIG.apiEndpoints.createDatasetFilter.replace(/{id}/g, this.dataset.id),
`${CONFIG.apiBaseUrl}${CONFIG.apiEndpoints.createDatasetFilter.replace(/{id}/g, this.dataset.id)}`,
this.datasetFilterMessage()
)
.then(response => {
Expand Down Expand Up @@ -211,7 +211,7 @@ export default {
this.gettingCountsToken = axios.CancelToken.source();
axios
.post(CONFIG.apiBaseUrl + CONFIG.apiEndpoints.datasetFilterItems, {
.post(`${CONFIG.apiBaseUrl}${CONFIG.apiEndpoints.datasetFilterItems}`, {
dataset_id_original: parseInt(this.dataset.id),
filter_message: this.datasetFilterMessage()
}, {
Expand Down
3 changes: 1 addition & 2 deletions frontend/src/components/DatasetPicker.vue
Original file line number Diff line number Diff line change
Expand Up @@ -184,9 +184,8 @@ export default {
return result;
};
var url = CONFIG.apiBaseUrl + CONFIG.apiEndpoints.dataset;
axios
.get(url)
.get(`${CONFIG.apiBaseUrl}${CONFIG.apiEndpoints.dataset}`)
.then(response => {
this.datasets = buildDatasetsTree(response["data"], null);
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/DatasetReportModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ export default {
}
axios
.post(CONFIG.apiBaseUrl + CONFIG.apiEndpoints.createDatasetReport, data)
.post(`${CONFIG.apiBaseUrl}${CONFIG.apiEndpoints.createDatasetReport}`, data)
.then(response => {
if (response.data.failed_tags.length == 0) this.failedTags = null;
else this.failedTags = response.data.failed_tags;
Expand Down
22 changes: 3 additions & 19 deletions frontend/src/components/DatasetValuesMultiselect.vue
Original file line number Diff line number Diff line change
Expand Up @@ -90,25 +90,9 @@ export default {
}
this.isLoading = true;
this.options = [];
var url = null;
if (query != "") {
url =
CONFIG.apiBaseUrl +
CONFIG.apiEndpoints.datasetDistinctValues +
"/" +
this.datasetId +
"/" +
this.jsonPath +
"/" +
query;
} else {
url =
CONFIG.apiBaseUrl +
CONFIG.apiEndpoints.datasetDistinctValues +
"/" +
this.datasetId +
"/" +
this.jsonPath;
var url = `${CONFIG.apiBaseUrl}${CONFIG.apiEndpoints.datasetDistinctValues}/${this.datasetId}/${this.jsonPath}/`;
if (query) {
url += `${query}/`;
}
this.cancelToken = axios.CancelToken.source();
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ var config = {
timeVarianceLevelReport: "datasets/{id}/time_based_report/",
fieldLevelDetail: "datasets/{id}/field_level/{name}/",
resourceLevelDetail: "datasets/{id}/compiled_release_level/{name}/",
datasetFilterItems: "dataset-filter-items",
datasetDistinctValues: "dataset-distinct-values",
datasetFilterItems: "dataset-filter-items/",
datasetDistinctValues: "dataset-distinct-values/",
// POST
createDatasetFilter: "datasets/{id}/filter/",
createDatasetReport: "generate-report"
Expand Down
52 changes: 20 additions & 32 deletions frontend/src/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -266,11 +266,9 @@ export default new Vuex.Store({
},
actions: {
loadDataset({ dispatch, commit }, datasetId) {
var url = CONFIG.apiBaseUrl + CONFIG.apiEndpoints.dataset + datasetId;

return new Promise(resolve => {
axios
.get(url)
.get(`${CONFIG.apiBaseUrl}${CONFIG.apiEndpoints.dataset}${datasetId}`)
.then(response => {
dispatch("resetDatasetEnv");
commit("setDataset", response["data"]);
Expand All @@ -291,10 +289,9 @@ export default new Vuex.Store({
loadResourceLevelStats({ commit, state }) {
return new Promise(resolve => {
commit("setResourceLevelStats", null);
var url =
CONFIG.apiBaseUrl + CONFIG.apiEndpoints.resourceLevelReport.replace(/{id}/g, state.dataset.id);
var formatted = CONFIG.apiEndpoints.resourceLevelReport.replace(/{id}/g, state.dataset.id);
axios
.get(url)
.get(`${CONFIG.apiBaseUrl}${formatted}`)
.then(function (response) {
var data = [];
for (var key in response["data"]) {
Expand All @@ -315,13 +312,11 @@ export default new Vuex.Store({

if (checkDetail != null && !checkDetail.examplesLoaded) {
if (state.dataset != null && checkName != null) {
var url =
CONFIG.apiBaseUrl +
CONFIG.apiEndpoints.resourceLevelDetail
.replace(/{id}/g, state.dataset.id)
.replace(/{name}/g, checkName);
var formatted = CONFIG.apiEndpoints.resourceLevelDetail
.replace(/{id}/g, state.dataset.id)
.replace(/{name}/g, checkName);
axios
.get(url)
.get(`${CONFIG.apiBaseUrl}${formatted}`)
.then(function (response) {
response["data"]["examples_filled"] = true;
commit("setResourceLevelCheckDetail", {
Expand All @@ -340,10 +335,9 @@ export default new Vuex.Store({
loadDatasetLevelStats({ commit, state }) {
return new Promise(resolve => {
commit("setDatasetLevelStats", null);
var url =
CONFIG.apiBaseUrl + CONFIG.apiEndpoints.datasetLevelReport.replace(/{id}/g, state.dataset.id);
var formatted = CONFIG.apiEndpoints.datasetLevelReport.replace(/{id}/g, state.dataset.id);
axios
.get(url)
.get(`${CONFIG.apiBaseUrl}${formatted}`)
.then(function (response) {
var data = [];
for (var key in response["data"]) {
Expand All @@ -365,9 +359,9 @@ export default new Vuex.Store({
dataItem = state.dataItems.find(item => item.id === itemId);
}
if (dataItem == null) {
var url = CONFIG.apiBaseUrl + CONFIG.apiEndpoints.dataItem.replace(/{id}/g, itemId);
var formatted = CONFIG.apiEndpoints.dataItem.replace(/{id}/g, itemId);
axios
.get(url)
.get(`${CONFIG.apiBaseUrl}${formatted}`)
.then(function (response) {
commit("addDataItem", response["data"]);
resolve();
Expand All @@ -384,8 +378,6 @@ export default new Vuex.Store({
return new Promise(resolve => {
commit("setFieldLevelStats", null);

var url = CONFIG.apiBaseUrl + CONFIG.apiEndpoints.fieldLevelReport.replace(/{id}/g, state.dataset.id);

var okShare = function (item) {
var result = (item.passed_count / item.total_count) * 100;
return isNaN(result) ? 0 : result;
Expand All @@ -396,8 +388,9 @@ export default new Vuex.Store({
return isNaN(result) ? 0 : result;
};

var formatted = CONFIG.apiEndpoints.fieldLevelReport.replace(/{id}/g, state.dataset.id);
axios
.get(url)
.get(`${CONFIG.apiBaseUrl}${formatted}`)
.then(function (response) {
var data = [];
for (var key in response["data"]) {
Expand Down Expand Up @@ -427,19 +420,15 @@ export default new Vuex.Store({

if (checkDetail == null || (checkDetail != null && !checkDetail.examplesLoaded)) {
if (state.dataset != null && path != null) {
var url =
CONFIG.apiBaseUrl +
CONFIG.apiEndpoints.fieldLevelDetail
.replace(/{id}/g, state.dataset.id)
.replace(/{name}/g, path);

var aaa = path;
var formatted = CONFIG.apiEndpoints.fieldLevelDetail
.replace(/{id}/g, state.dataset.id)
.replace(/{name}/g, path);
axios
.get(url)
.get(`${CONFIG.apiBaseUrl}${formatted}`)
.then(function (response) {
response["data"]["examples_filled"] = true;
commit("setFieldLevelCheckDetail", {
path: aaa,
path: path,
data: response["data"]
});
})
Expand All @@ -452,10 +441,9 @@ export default new Vuex.Store({
loadTimeVarianceLevelStats({ commit, state }) {
return new Promise(resolve => {
commit("setTimeVarianceLevelStats", null);
var url =
CONFIG.apiBaseUrl + CONFIG.apiEndpoints.timeVarianceLevelReport.replace(/{id}/g, state.dataset.id);
var formatted = CONFIG.apiEndpoints.timeVarianceLevelReport.replace(/{id}/g, state.dataset.id);
axios
.get(url)
.get(`${CONFIG.apiBaseUrl}${formatted}`)
.then(function (response) {
var data = [];
for (var key in response["data"]) {
Expand Down

0 comments on commit 9b80960

Please sign in to comment.