Skip to content

Commit 02dacb4

Browse files
committed
refactored api calls to use new api, instead of the django user and pass
1 parent a66c9fa commit 02dacb4

File tree

8 files changed

+44
-91
lines changed

8 files changed

+44
-91
lines changed

ui/src/components/Bruckarte/GuestsTable.vue

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
</template>
4141

4242
<script>
43-
import axios from 'axios'
43+
import { api } from '@/plugins/api'
4444
export default {
4545
name: 'GuestsTable',
4646
props: {
@@ -70,24 +70,21 @@ export default {
7070
loggg() {
7171
},
7272
created() {
73-
axios.get(process.env.VUE_APP_BASE_URL + '/guests/?search=Brucoši&search_fields=tag',)
73+
api.get('/guests/?search=Brucoši&search_fields=tag')
7474
.then(response => {
7575
this.guests = response.data;
7676
7777
})
7878
},
7979
changeBought(guest, changenum) {
80-
axios.put(process.env.VUE_APP_BASE_URL + '/guests/' + guest.id + '/',
81-
{ bought: changenum },
82-
{ auth: { username: process.env.VUE_APP_DJANGO_USER, password: process.env.VUE_APP_DJANGO_PASS } }
83-
)
80+
api.put('/guests/' + guest.id + '/', { bought: changenum })
8481
.then(() => {
8582
this.created();
8683
})
8784
8885
},
8986
searchGuest() {
90-
axios.get(process.env.VUE_APP_BASE_URL + '/guests/?search=Brucoši ' + this.search + "&search_fields=tag&search_fields=name&search_fields=surname",)
87+
api.get('/guests/?search=Brucoši ' + this.search + '&search_fields=tag&search_fields=name&search_fields=surname')
9188
.then(response => {
9289
this.guests = response.data;
9390
})

ui/src/views/AdminViews/BandKontaktView.vue

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
<script>
6161
import Sidebar from '@/components/NavbarAndFooter/Sidebar.vue'
6262
63-
import axios from 'axios'
63+
import { api } from '@/plugins/api'
6464
6565
export default {
6666
name: 'GuestsAdd',
@@ -93,7 +93,7 @@ export default {
9393
window.open(tel);
9494
},
9595
created() {
96-
axios.get(process.env.VUE_APP_BASE_URL + '/contact/',)
96+
api.get('/contact/')
9797
.then(response => {
9898
this.bandcontacts = response.data;
9999
this.len = this.bandcontacts.length;
@@ -112,9 +112,8 @@ export default {
112112
113113
postBandContact() {
114114
if (this.bandName && this.bookerName && this.bookerPhone) {
115-
axios.post(process.env.VUE_APP_BASE_URL + '/contact/',
116-
{ bandName: this.bandName, bookerName: this.bookerName, bookerPhone: this.bookerPhone },
117-
{ auth: { username: process.env.VUE_APP_DJANGO_USER, password: process.env.VUE_APP_DJANGO_PASS } }
115+
api.post('/contact/',
116+
{ bandName: this.bandName, bookerName: this.bookerName, bookerPhone: this.bookerPhone }
118117
)
119118
.then(() => {
120119
this.bookerName = "";
@@ -125,9 +124,7 @@ export default {
125124
}
126125
},
127126
deleteBandContact(bandcontact) {
128-
axios.delete(process.env.VUE_APP_BASE_URL + '/contact/' + bandcontact.id + '/',
129-
{ auth: { username: process.env.VUE_APP_DJANGO_USER, password: process.env.VUE_APP_DJANGO_PASS } }
130-
)
127+
api.delete('/contact/' + bandcontact.id + '/')
131128
.then(() => {
132129
this.created();
133130
})

ui/src/views/AdminViews/CjenikView.vue

Lines changed: 10 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@
9191
<script>
9292
import Sidebar from '@/components/NavbarAndFooter/Sidebar.vue'
9393
94-
import axios from 'axios'
94+
import { api } from '@/plugins/api'
9595
9696
export default {
9797
name: 'GuestsAdd',
@@ -126,7 +126,7 @@ export default {
126126
async created() {
127127
this.artikli = [];
128128
this.tags.forEach(async element => {
129-
const resp = await axios.get(process.env.VUE_APP_BASE_URL + '/cjenik/?ordering=order&search=' + element + '&search_fields=tag',)
129+
const resp = await api.get('/cjenik/?ordering=order&search=' + element + '&search_fields=tag')
130130
if (resp.data.length != 0) {
131131
resp.data.forEach(element => {
132132
this.artikli.push(element)
@@ -142,13 +142,8 @@ export default {
142142
143143
if (curIndex != "0") {
144144
if (artikl.tag == nextArtikl.tag) {
145-
await axios.put(process.env.VUE_APP_BASE_URL + '/cjenik/' + artikl.id + '/',
146-
{ order: nextArtikl.order },
147-
{ auth: { username: process.env.VUE_APP_DJANGO_USER, password: process.env.VUE_APP_DJANGO_PASS } })
148-
149-
await axios.put(process.env.VUE_APP_BASE_URL + '/cjenik/' + nextArtikl.id + '/',
150-
{ order: artikl.order },
151-
{ auth: { username: process.env.VUE_APP_DJANGO_USER, password: process.env.VUE_APP_DJANGO_PASS } })
145+
await api.put('/cjenik/' + artikl.id + '/', { order: nextArtikl.order })
146+
await api.put('/cjenik/' + nextArtikl.id + '/', { order: artikl.order })
152147
}
153148
window.location.reload();
154149
}
@@ -160,13 +155,8 @@ export default {
160155
161156
if (nextIndex != this.artikli.length) {
162157
if (artikl.tag == nextArtikl.tag) {
163-
await axios.put(process.env.VUE_APP_BASE_URL + '/cjenik/' + artikl.id + '/',
164-
{ order: nextArtikl.order },
165-
{ auth: { username: process.env.VUE_APP_DJANGO_USER, password: process.env.VUE_APP_DJANGO_PASS } })
166-
167-
await axios.put(process.env.VUE_APP_BASE_URL + '/cjenik/' + nextArtikl.id + '/',
168-
{ order: artikl.order },
169-
{ auth: { username: process.env.VUE_APP_DJANGO_USER, password: process.env.VUE_APP_DJANGO_PASS } })
158+
await api.put('/cjenik/' + artikl.id + '/', { order: nextArtikl.order })
159+
await api.put('/cjenik/' + nextArtikl.id + '/', { order: artikl.order })
170160
}
171161
this.created()
172162
}
@@ -187,7 +177,7 @@ export default {
187177
},
188178
189179
async postArtikl() {
190-
const resp = await axios.get(process.env.VUE_APP_BASE_URL + '/cjenik/?ordering=order&search=' + this.selectedTag + '&search_fields=tag',)
180+
const resp = await api.get('/cjenik/?ordering=order&search=' + this.selectedTag + '&search_fields=tag')
191181
let nextOrder = "00";
192182
193183
let cjenik = resp.data;
@@ -207,18 +197,15 @@ export default {
207197
}
208198
}
209199
210-
axios.post(process.env.VUE_APP_BASE_URL + '/cjenik/',
211-
{ name: this.name, tag: this.selectedTag, order: nextOrder, priceEUR: this.priceEUR, volume: this.volume },
212-
{ auth: { username: process.env.VUE_APP_DJANGO_USER, password: process.env.VUE_APP_DJANGO_PASS } }
200+
api.post('/cjenik/',
201+
{ name: this.name, tag: this.selectedTag, order: nextOrder, priceEUR: this.priceEUR, volume: this.volume }
213202
).then(() => {
214203
this.created()
215204
})
216205
217206
},
218207
deleteArtikl(artikl) {
219-
axios.delete(process.env.VUE_APP_BASE_URL + '/cjenik/' + artikl.id + '/',
220-
{ auth: { username: process.env.VUE_APP_DJANGO_USER, password: process.env.VUE_APP_DJANGO_PASS } }
221-
)
208+
api.delete('/cjenik/' + artikl.id + '/')
222209
.then(() => {
223210
this.created()
224211
})

ui/src/views/AdminViews/SponsorsListView.vue

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
import SponsorsTable from '@/components/AdminPanel/SponsorsTable.vue'
2323
import Sidebar from '@/components/NavbarAndFooter/Sidebar.vue'
2424
25-
import axios from 'axios'
25+
import { api } from '@/plugins/api'
2626
export default {
2727
name: 'SponsorsView',
2828
components: {
@@ -49,8 +49,8 @@ export default {
4949
5050
async sendMail() {
5151
if (window.confirm("Klikom na OK šaljete mail SVIM sponzorima!!!")) {
52-
const resp = await axios.get(process.env.VUE_APP_BASE_URL + '/sponsors/')
53-
const res = await axios.get(process.env.VUE_APP_BASE_URL + '/mailer/')
52+
const resp = await api.get('/sponsors/')
53+
const res = await api.get('/mailer/')
5454
5555
let emails = []
5656
resp.data.forEach(elementy => {
@@ -96,26 +96,20 @@ export default {
9696
to_mail: e
9797
})
9898
})
99-
await axios.post(process.env.VUE_APP_BASE_URL + '/mailer/',
99+
await api.post('/mailer/',
100100
{
101101
subject: "[KSET] Link za uređivanje popisa za 42. Brucošijadu FER-a",
102102
template: "sponsors_email",
103103
message: msg,
104104
name: element.name,
105105
link: "https://brucosijada.kset.org/sponzori/" + element.slug,
106106
to_mail: email.join(", ")
107-
},
108-
{ auth: { username: process.env.VUE_APP_DJANGO_USER, password: process.env.VUE_APP_DJANGO_PASS } }
107+
}
109108
)
110109
}
111110
});
112111
113-
await axios.post(process.env.VUE_APP_BASE_URL + '/mailer/send_mail/',
114-
{
115-
emails: emails
116-
},
117-
{ auth: { username: process.env.VUE_APP_DJANGO_USER, password: process.env.VUE_APP_DJANGO_PASS } }
118-
)
112+
await api.post('/mailer/send_mail/', { emails: emails })
119113
120114
}
121115
}

ui/src/views/AdminViews/TranslationsView.vue

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
</template>
3333

3434
<script>
35-
import axios from 'axios'
35+
import { api } from '@/plugins/api'
3636
import Sidebar from '@/components/NavbarAndFooter/Sidebar.vue'
3737
import translationsStore from "@/store/translationsStore.js";
3838
@@ -54,9 +54,8 @@ export default {
5454
},
5555
methods: {
5656
async postTranslation() {
57-
await axios.post(process.env.VUE_APP_BASE_URL + '/translations/',
58-
{ key: this.key, value: this.value },
59-
{ auth: { username: process.env.VUE_APP_DJANGO_USER, password: process.env.VUE_APP_DJANGO_PASS } }
57+
await api.post('/translations/',
58+
{ key: this.key, value: this.value }
6059
)
6160
6261
this.key = "";
@@ -66,23 +65,19 @@ export default {
6665
},
6766
async deleteTranslation(translation) {
6867
console.log(translation)
69-
await axios.delete(process.env.VUE_APP_BASE_URL + '/translations/' + translation.id + '/',
70-
{ auth: { username: process.env.VUE_APP_DJANGO_USER, password: process.env.VUE_APP_DJANGO_PASS } }
71-
)
68+
await api.delete('/translations/' + translation.id + '/')
7269
await translationsStore.dispatch("fetchTranslations")
7370
},
7471
async changeTranslationValue(translation) {
7572
let changeVal = event.target.innerHTML.replace(/<(?!br\s*\/?)[^>]+>/gi, '').replace('<br>', '\n\n')
76-
await axios.put(process.env.VUE_APP_BASE_URL + '/translations/' + translation.id + '/',
77-
{ value: changeVal },
78-
{ auth: { username: process.env.VUE_APP_DJANGO_USER, password: process.env.VUE_APP_DJANGO_PASS } }
73+
await api.put('/translations/' + translation.id + '/',
74+
{ value: changeVal }
7975
)
8076
},
8177
async changeTranslationKey(translation) {
8278
let changeKey = event.target.innerHTML.replace(/<(?!br\s*\/?)[^>]+>/gi, '').replace('<br>', '\n\n')
83-
await axios.put(process.env.VUE_APP_BASE_URL + '/translations/' + translation.id + '/',
84-
{ key: changeKey },
85-
{ auth: { username: process.env.VUE_APP_DJANGO_USER, password: process.env.VUE_APP_DJANGO_PASS } }
79+
await api.put('/translations/' + translation.id + '/',
80+
{ key: changeKey }
8681
)
8782
},
8883
changeValue() {

ui/src/views/AdminViews/VisibilityView.vue

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ export default {
306306
try {
307307
// Send email
308308
await api.post(
309-
`${process.env.VUE_APP_BASE_URL}/mailer/send_mail/`,
309+
'/mailer/send_mail/',
310310
{
311311
emails: [
312312
{
@@ -318,12 +318,6 @@ export default {
318318
to_mail: email,
319319
},
320320
],
321-
},
322-
{
323-
auth: {
324-
username: process.env.VUE_APP_DJANGO_USER,
325-
password: process.env.VUE_APP_DJANGO_PASS,
326-
},
327321
}
328322
);
329323

ui/src/views/BruciWebViews/IgricaView.vue

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939

4040
<script>
4141
import Footer from '@/components/NavbarAndFooter/Footer.vue'
42-
import axios from 'axios';
42+
import { api } from '@/plugins/api';
4343
import translationsStore from '@/store/translationsStore';
4444
import visibilityStore from '@/store/visibilityStore';
4545
import debounce from 'lodash/debounce';
@@ -73,7 +73,7 @@ export default {
7373
methods: {
7474
async fetchLeaderboardData() {
7575
try {
76-
const response = await axios.get(process.env.VUE_APP_BASE_URL + '/gameLeaderboard/?ordering=-score');
76+
const response = await api.get('/gameLeaderboard/?ordering=-score');
7777
this.leaderboardData = response.data.slice(0, 20);;
7878
} catch (error) {
7979
console.error('Error fetching leaderboard data:', error);
@@ -85,35 +85,28 @@ export default {
8585
},
8686
async sendScoreToBackend(scoreData) {
8787
88-
const response = await axios.get(process.env.VUE_APP_BASE_URL + '/gameLeaderboard/?search=' +
88+
const response = await api.get('/gameLeaderboard/?search=' +
8989
scoreData.mail + '&search_fields=email');
9090
9191
if (response.data.length > 0) {
9292
let user = response.data[0];
9393
if (user.score < scoreData.score) {
94-
await axios.delete(process.env.VUE_APP_BASE_URL + '/gameLeaderboard/' + user.id + '/',
95-
{ auth: { username: process.env.VUE_APP_DJANGO_USER, password: process.env.VUE_APP_DJANGO_PASS } });
96-
await axios.post(process.env.VUE_APP_BASE_URL + '/gameLeaderboard/', {
94+
await api.delete('/gameLeaderboard/' + user.id + '/');
95+
await api.post('/gameLeaderboard/', {
9796
name: scoreData.nickname,
9897
email: scoreData.mail,
9998
score: scoreData.score
100-
}, {
101-
auth: { username: process.env.VUE_APP_DJANGO_USER, password: process.env.VUE_APP_DJANGO_PASS }
10299
});
103100
} else {
104-
await axios.put(process.env.VUE_APP_BASE_URL + '/gameLeaderboard/' + user.id + '/', {
101+
await api.put('/gameLeaderboard/' + user.id + '/', {
105102
name: scoreData.nickname
106-
}, {
107-
auth: { username: process.env.VUE_APP_DJANGO_USER, password: process.env.VUE_APP_DJANGO_PASS }
108103
});
109104
}
110105
} else {
111-
await axios.post(process.env.VUE_APP_BASE_URL + '/gameLeaderboard/', {
106+
await api.post('/gameLeaderboard/', {
112107
name: scoreData.nickname,
113108
email: scoreData.mail,
114109
score: scoreData.score
115-
}, {
116-
auth: { username: process.env.VUE_APP_DJANGO_USER, password: process.env.VUE_APP_DJANGO_PASS }
117110
});
118111
}
119112

ui/src/views/BruciWebViews/SponsorsPageView.vue

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ import Footer from '@/components/NavbarAndFooter/Footer.vue'
8686
import NavbarBweb from '@/components/NavbarAndFooter/NavbarBweb.vue'
8787
import store from '@/store/visibilityStore'
8888
import { publicApi } from "@/plugins/publicApi";
89+
import { api } from "@/plugins/api";
8990
9091
export default {
9192
components: { Footer, NavbarBweb },
@@ -142,13 +143,8 @@ export default {
142143
this.guestsEnabled = 0;
143144
144145
145-
const resp = await axios.put(process.env.VUE_APP_BASE_URL + "/sponsors/" + this.sponsorsInstance.id + "/", formData,
146-
{ auth: { username: process.env.VUE_APP_DJANGO_USER, password: process.env.VUE_APP_DJANGO_PASS } },
147-
{
148-
headers: {
149-
"Content-Type": "multipart/form-data"
150-
151-
}
146+
const resp = await api.put("/sponsors/" + this.sponsorsInstance.id + "/", formData, {
147+
headers: { "Content-Type": "multipart/form-data" }
152148
})
153149
154150
console.log("posted")

0 commit comments

Comments
 (0)