Skip to content

Commit 802c72f

Browse files
committed
feat: api controller poc
1 parent 84a4300 commit 802c72f

5 files changed

Lines changed: 47 additions & 7 deletions

File tree

css/autocurrency-style.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/Controller/ApiController.php

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,26 @@ class ApiController extends OCSController {
2121
*
2222
* 200: Data returned
2323
*/
24+
// #[NoAdminRequired]
25+
// #[ApiRoute(verb: 'GET', url: '/api')]
26+
// public function index(): DataResponse {
27+
// return new DataResponse(
28+
// ['message' => 'Hello world!']
29+
// );
30+
// }
31+
32+
/**
33+
* Get current cron information
34+
*
35+
* @return DataResponse<Http::STATUS_OK, array{last_update:string,interval:int}, array{}>
36+
*
37+
* 200: Data returned
38+
*/
2439
#[NoAdminRequired]
25-
#[ApiRoute(verb: 'GET', url: '/api')]
26-
public function index(): DataResponse {
40+
#[ApiRoute(verb: 'GET', url: '/api/cron')]
41+
public function getCronInfo(): DataResponse {
2742
return new DataResponse(
28-
['message' => 'Hello world!']
43+
['last_update' => '2021-09-01 00:00:00', 'interval' => 24]
2944
);
3045
}
3146
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"npm": "^10.0.0"
99
},
1010
"scripts": {
11-
"dev": "vite",
11+
"dev": "vite build --watch",
1212
"build": "vue-tsc -b && vite build",
1313
"preview": "vite preview",
1414
"lint": "eslint src",

src/App.vue

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
:options="intervals"
1010
input-label="Currency conversion rate update interval"
1111
required
12+
:disabled="interval == null"
1213
/>
1314
<div class="submit-buttons">
1415
<NcButton native-type="submit">Save</NcButton>
@@ -24,6 +25,7 @@
2425
import NcAppSettingsSection from '@nextcloud/vue/dist/Components/NcAppSettingsSection.js'
2526
import NcSelect from '@nextcloud/vue/dist/Components/NcSelect.js'
2627
import NcButton from '@nextcloud/vue/dist/Components/NcButton.js'
28+
import axios from '@nextcloud/axios'
2729
2830
export default {
2931
name: 'App',
@@ -47,9 +49,26 @@ export default {
4749
}
4850
},
4951
created() {
50-
this.interval = this.getIntervalByValue(24).label
52+
// this.interval = this.getIntervalByValue(24).label
53+
this.fetchSettings()
5154
},
5255
methods: {
56+
async fetchSettings() {
57+
try {
58+
const resp = await axios.get('/cron')
59+
const data = resp.data.ocs.data
60+
console.debug('[DEBUG] Settings fetched', data)
61+
const interval = this.getIntervalByValue(data.interval)
62+
if (interval) {
63+
console.debug('[DEBUG] Interval found', interval)
64+
this.interval = interval.label
65+
} else {
66+
console.warn('Invalid interval value', data.interval)
67+
}
68+
} catch (e) {
69+
console.error('Failed to fetch settings', e)
70+
}
71+
},
5372
getIntervalByValue(value) {
5473
return this.intervalOptions.find((x) => x.value === value)
5574
},

src/main.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
import App from './App.vue'
22
import './style.scss'
33
import { createApp } from 'vue'
4+
import axios from '@nextcloud/axios'
5+
import { generateUrl, generateOcsUrl } from '@nextcloud/router'
46

5-
console.log('Mounting AutoCurrency Settings')
7+
const baseURL = generateOcsUrl('/apps/autocurrency/api')
8+
axios.defaults.baseURL = baseURL
9+
10+
console.log('[DEBUG] Mounting AutoCurrency Settings')
11+
console.log('[DEBUG] Base URL:', baseURL)
612
createApp(App).mount('#autocurrency-settings')

0 commit comments

Comments
 (0)