Clean up destroy routine

This commit is contained in:
James Cole 2022-02-28 17:06:01 +01:00
parent 22a6e34279
commit b9536dfe4e
No known key found for this signature in database
GPG Key ID: B49A324B7EAD6D80
26 changed files with 188 additions and 368 deletions

View File

@ -1,28 +0,0 @@
/*
* post.js
* Copyright (c) 2022 james@firefly-iii.org
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
import {api} from "boot/axios";
export default class Destroy {
destroy(identifier) {
let url = '/api/v1/accounts/' + identifier;
return api.delete(url);
}
}

View File

@ -18,18 +18,34 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
import {api} from "boot/axios";
import Api from "src/api/root/api";
export default class Get {
get(identifier, date) {
let url = '/api/v1/accounts/' + identifier;
if(!date) {
return api.get(url);
}
return api.get(url, {params: {date: date}});
export default class Get extends Api {
constructor() {
super('accounts'); // call the super class constructor and pass in the name parameter
}
transactions(identifier, page, cacheKey) {
let url = '/api/v1/accounts/' + identifier + '/transactions';
return api.get(url, {params: {page: page, cache: cacheKey}});
/**
*
* @param identifier
* @param date
* @returns {Promise<AxiosResponse<any>>}
*/
get(identifier, date) {
let params = {date: date};
if(!date) {
return this.apiGet(identifier);
}
return this.apiGet(identifier, params);
}
/**
*
* @param identifier
* @param page
* @returns {Promise<AxiosResponse<any>>}
*/
transactions(identifier, page) {
return this.apiGetChildren('transactions', identifier, page);
}
}

View File

@ -19,10 +19,27 @@
*/
import {api} from "boot/axios";
import Api from "src/api/root/api";
export default class List extends Api{
constructor() {
super('accounts');
}
export default class List {
list(type, page, cacheKey) {
let url = '/api/v1/accounts';
return api.get(url, {params: {page: page, cache: cacheKey, type: type}});
// console.log('list');
//
//
// let params = {
// type: type,
// page: page
// }
// this.apiList(page, params).then((response) => {
// console.log('response OK');
// }).catch((err) => {
// console.error('api list failed');
// });
}
}

View File

@ -1,28 +0,0 @@
/*
* post.js
* Copyright (c) 2022 james@firefly-iii.org
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
import {api} from "boot/axios";
export default class Destroy {
destroy(identifier) {
let url = 'api/v1/budgets/' + identifier;
return api.delete(url);
}
}

View File

@ -1,28 +0,0 @@
/*
* post.js
* Copyright (c) 2022 james@firefly-iii.org
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
import {api} from "boot/axios";
export default class Destroy {
destroy(identifier) {
let url = '/api/v1/categories/' + identifier;
return api.delete(url);
}
}

View File

@ -1,28 +0,0 @@
/*
* post.js
* Copyright (c) 2022 james@firefly-iii.org
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
import {api} from "boot/axios";
export default class Destroy {
destroy(identifier) {
let url = '/api/v1/currencies/' + identifier;
return api.delete(url);
}
}

View File

@ -1,5 +1,5 @@
/*
* post.js
* destroy.js
* Copyright (c) 2022 james@firefly-iii.org
*
* This file is part of Firefly III (https://github.com/firefly-iii).
@ -18,11 +18,10 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
import {api} from "boot/axios";
import Api from "src/api/root/api";
export default class Destroy {
destroy(identifier) {
let url = '/api/v1/rules/' + identifier;
return api.delete(url);
export default class Destroy extends Api {
constructor(path) {
super(path);
}
}

View File

@ -1,28 +0,0 @@
/*
* post.js
* Copyright (c) 2022 james@firefly-iii.org
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
import {api} from "boot/axios";
export default class Destroy {
destroy(identifier) {
let url = '/api/v1/object_groups/' + identifier;
return api.delete(url);
}
}

View File

@ -1,28 +0,0 @@
/*
* post.js
* Copyright (c) 2022 james@firefly-iii.org
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
import {api} from "boot/axios";
export default class Destroy {
destroy(identifier) {
let url = '/api/v1/piggy_banks/' + identifier;
return api.delete(url);
}
}

View File

@ -1,28 +0,0 @@
/*
* post.js
* Copyright (c) 2022 james@firefly-iii.org
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
import {api} from "boot/axios";
export default class Destroy {
destroy(identifier) {
let url = '/api/v1/recurrences/' + identifier;
return api.delete(url);
}
}

View File

@ -0,0 +1,104 @@
import {api} from "boot/axios";
/**
*
*/
export default class Api {
root = '/api/v1/';
path = '';
constructor(path) {
this.path = path;
}
apiPath() {
return this.root + this.path;
}
apiPathId(identifier) {
return this.root + this.path + '/' + identifier;
}
/**
*
* @param identifier
* @param params
* @returns {Promise<AxiosResponse<any>>}
*/
apiGet(identifier, params) {
let url = this.apiPathId(identifier);
if (params) {
return api.get(url, {params: params});
}
return api.get(url);
}
destroy(identifier) {
let url = this.apiPathId(identifier);
return api.delete(url);
}
apiPathChildren(identifier, type) {
return this.apiPathId(identifier) + '/' + type;
}
apiGetChildren(type, identifier, page) {
let url = this.apiPathChildren(identifier, type);
let cacheKey = 'still-todo';
// needs a cache key. Based on type.
return api.get(url, {params: {page: page, cache: cacheKey}});
}
/**
*
* @param page
* @param params
* @returns {Promise<AxiosResponse<any>>}
*/
apiList(page, params) {
let type = 'transactions';
let identifier = '1';
let cacheKey = 'still-todo';
let url = this.apiPathChildren(identifier, type);
// needs a cache key. Based on type.
return api.get(url, {params: {page: page, cache: cacheKey}});
// let identifier = 'abc';
// // test:
// let type= 'expense';
// let type ='accounts';
//
// this.store.getters["fireflyiii/getScopedCacheKey"](type);
// let cacheKey = 'def';
// let url = this.apiPath();
//
// // needs a cache key. Based on type.
// return api.get(url, {params: {page: page, cache: cacheKey}});
//
//
// console.log('apiList');
// let cacheKey;
//
// //let $q = useQuasar();
// //const store = useStore();
// cacheKey = 'OK';
// console.log('path: ' + this.path);
// //cacheKey = $store.getters["fireflyiii/getScopedCacheKey"](this.path);
// //store.getters["fireflyiii/getScopedCacheKey"](this.path)
// let cache = {
// cache: cacheKey
// };
// let merged = {...params, ...cache};
// console.log(merged);
// let url = this.apiPath();
// console.log(url);
// return api.get(url, {params: merged});
}
}

View File

@ -1,28 +0,0 @@
/*
* post.js
* Copyright (c) 2022 james@firefly-iii.org
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
import {api} from "boot/axios";
export default class Destroy {
destroy(identifier) {
let url = '/api/v1/rule_groups/' + identifier;
return api.delete(url);
}
}

View File

@ -1,28 +0,0 @@
/*
* post.js
* Copyright (c) 2022 james@firefly-iii.org
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
import {api} from "boot/axios";
export default class Destroy {
destroy(identifier) {
let url = '/api/v1/bills/' + identifier;
return api.delete(url);
}
}

View File

@ -1,28 +0,0 @@
/*
* post.js
* Copyright (c) 2022 james@firefly-iii.org
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
import {api} from "boot/axios";
export default class Destroy {
destroy(identifier) {
let url = '/api/v1/transactions/' + identifier;
return api.delete(url);
}
}

View File

@ -1,28 +0,0 @@
/*
* post.js
* Copyright (c) 2022 james@firefly-iii.org
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
import {api} from "boot/axios";
export default class Destroy {
destroy(identifier) {
let url = '/api/v1/webhooks/' + identifier;
return api.delete(url);
}
}

View File

@ -5,7 +5,6 @@
:rows="rows"
:columns="columns"
row-key="id"
@request="onRequest"
v-model:pagination="pagination"
:loading="loading"
class="q-ma-md"
@ -75,7 +74,7 @@
<script>
import {mapGetters, useStore} from "vuex";
import List from "../../api/accounts/list";
import Destroy from "../../api/accounts/destroy";
import Destroy from "../../api/generic/destroy";
export default {
name: 'Index',
@ -144,10 +143,11 @@ export default {
});
},
destroyAccount: function (id) {
let destr = new Destroy;
destr.destroy(id).then(() => {
this.$store.dispatch('fireflyiii/refreshCacheKey');
this.triggerUpdate();
(new Destroy('accounts')).destroy(id).then(() => {
this.rows= [];
this.$store.dispatch('fireflyiii/refreshCacheKey').then(() => {
this.triggerUpdate();
});
});
},
updateBreadcrumbs: function () {
@ -169,14 +169,15 @@ export default {
return string.replace(NON_ALPHANUM, '').toUpperCase().replace(EVERY_FOUR_CHARS, "$1 ");
},
triggerUpdate: function () {
if (this.loading) {
this.rows= [];
if (true === this.loading) {
return;
}
if (null === this.range.start || null === this.range.end) {
return;
}
this.loading = true;
const list = new List();
const list = new List;
this.rows = [];
list.list(this.type, this.page, this.getCacheKey).then(
(response) => {
@ -198,8 +199,10 @@ export default {
}
this.loading = false;
}
)
;
).catch((err) => {
console.error('Error loading list');
console.error(err);
});
}
}
}

View File

@ -95,7 +95,7 @@ export default {
const parser = new Parser;
this.rows = [];
get.transactions(this.id, this.page, this.getCacheKey).then(
get.transactions(this.id, this.page).then(
(response) => {
let resp = parser.parseResponse(response);

View File

@ -68,7 +68,7 @@
<script>
import {mapGetters, useStore} from "vuex";
import Destroy from "../../api/budgets/destroy";
import Destroy from "../../api/generic/destroy";
import List from "../../api/budgets/list";
export default {
@ -135,8 +135,7 @@ export default {
});
},
destroyBudget: function (id) {
let destr = new Destroy;
destr.destroy(id).then(() => {
(new Destroy('budgets')).destroy(id).then(() => {
this.$store.dispatch('fireflyiii/refreshCacheKey');
this.triggerUpdate();
});

View File

@ -68,7 +68,7 @@
<script>
import {mapGetters, useStore} from "vuex";
import Destroy from "../../api/categories/destroy";
import Destroy from "../../api/generic/destroy";
import List from "../../api/categories/list";
export default {
@ -135,8 +135,7 @@ export default {
});
},
destroyCategory: function (id) {
let destr = new Destroy;
destr.destroy(id).then(() => {
(new Destroy('categories')).destroy(id).then(() => {
this.$store.dispatch('fireflyiii/refreshCacheKey');
this.triggerUpdate();
});

View File

@ -68,7 +68,7 @@
<script>
import {mapGetters, useStore} from "vuex";
import Destroy from "../../api/currencies/destroy";
import Destroy from "../../api/generic/destroy";
import List from "../../api/currencies/list";
export default {
@ -137,8 +137,7 @@ export default {
});
},
destroyCurrency: function (code) {
let destr = new Destroy;
destr.destroy(code).then(() => {
(new Destroy('currencies')).destroy(code).then(() => {
this.$store.dispatch('fireflyiii/refreshCacheKey');
this.triggerUpdate();
});

View File

@ -52,7 +52,7 @@
<script>
import {mapGetters, useStore} from "vuex";
import Destroy from "../../api/groups/destroy";
import Destroy from "../../api/generic/destroy";
import List from "../../api/groups/list";
export default {
@ -119,9 +119,8 @@ export default {
// TODO needs error catch.
});
},
destroyGroup: function (code) {
let destr = new Destroy;
destr.destroy(code).then(() => {
destroyGroup: function (identifier) {
(new Destroy('object_groups')).destroy(identifier).then(() => {
this.$store.dispatch('fireflyiii/refreshCacheKey');
this.triggerUpdate();
});

View File

@ -65,7 +65,7 @@
<script>
import {mapGetters, useStore} from "vuex";
import Destroy from "../../api/piggy-banks/destroy";
import Destroy from "../../api/generic/destroy";
import List from "../../api/piggy-banks/list";
export default {
@ -131,8 +131,7 @@ export default {
});
},
destroyPiggyBank: function (id) {
let destr = new Destroy;
destr.destroy(id).then(() => {
(new Destroy('piggy_banks')).destroy(id).then(() => {
this.$store.dispatch('fireflyiii/refreshCacheKey');
this.triggerUpdate();
});

View File

@ -65,7 +65,7 @@
<script>
import {mapGetters, useStore} from "vuex";
import Destroy from "../../api/recurring/destroy";
import Destroy from "../../api/generic/destroy";
import List from "../../api/recurring/list";
export default {
@ -132,8 +132,7 @@ export default {
});
},
destroyRecurring: function (id) {
let destr = new Destroy;
destr.destroy(id).then(() => {
(new Destroy('recurrences')).destroy(id).then(() => {
this.$store.dispatch('fireflyiii/refreshCacheKey');
this.triggerUpdate();
});

View File

@ -80,8 +80,7 @@
import {mapGetters} from "vuex";
import List from "../../api/rule-groups/list";
import Get from "../../api/rule-groups/get";
import Destroy from "../../api/rule-groups/destroy";
import DestroyRule from "../../api/rules/destroy";
import Destroy from "../../api/generic/destroy";
export default {
name: 'Index',
@ -142,15 +141,13 @@ export default {
});
},
destroyRuleGroup: function (id) {
let destr = new Destroy;
destr.destroy(id).then(() => {
(new Destroy('rule_groups')).destroy(id).then(() => {
this.$store.dispatch('fireflyiii/refreshCacheKey');
this.triggerUpdate();
});
},
destroyRule: function (id) {
let destr = new DestroyRule;
destr.destroy(id).then(() => {
(new Destroy('rules')).destroy(id).then(() => {
this.$store.dispatch('fireflyiii/refreshCacheKey');
this.triggerUpdate();
});

View File

@ -67,7 +67,7 @@
<script>
import {mapGetters, useStore} from "vuex";
import List from "../../api/subscriptions/list";
import Destroy from "../../api/subscriptions/destroy";
import Destroy from "../../api/generic/destroy";
export default {
name: 'Index',
@ -127,8 +127,7 @@ export default {
});
},
destroySubscription: function (id) {
let destr = new Destroy;
destr.destroy(id).then(() => {
(new Destroy('bills')).destroy(id).then(() => {
this.$store.dispatch('fireflyiii/refreshCacheKey');
this.triggerUpdate();
});

View File

@ -66,7 +66,7 @@
<script>
import {mapGetters} from "vuex";
import Destroy from "../../api/webhooks/destroy";
import Destroy from "../../api/generic/destroy";
import List from "../../api/webhooks/list";
export default {
@ -119,8 +119,7 @@ export default {
});
},
destroyWebhook: function (id) {
let destr = new Destroy;
destr.destroy(id).then(() => {
(new Destroy('webhooks')).destroy(id).then(() => {
this.$store.dispatch('fireflyiii/refreshCacheKey');
this.triggerUpdate();
});