Skip to content
Snippets Groups Projects
Commit 0749df43 authored by thomas.blanc.2@etu.univ-amu.fr's avatar thomas.blanc.2@etu.univ-amu.fr
Browse files

Fixed date & api refactor part1

parent faaa2a66
No related branches found
No related tags found
No related merge requests found
export const api = {
async search (name, tags, param, sort, size, page) {
var url = this.$serverurl + 'search'
const params = new URLSearchParams()
if (name != null) params.append('name', name)
if (tags != null) params.append('tags', tags)
if (param != null) params.append('param', param)
if (sort != null) params.append('sort', sort)
params.append('size', size)
params.append('page', page)
console.log('get models ' + this.paramSearch + ' + ' + this.paramPerf + ' + ' + this.paramTags)
url += '?' + params
const response = await fetch(url)
try {
return await response.json()
} catch (error) {
return null
}
},
async getTags () {
const url = this.$serverurl + 'tags'
const response = await fetch(url)
try {
return await response.json()
} catch (error) {
return null
}
},
async getUser () {
const token = await localStorage.getItem('token')
const url = this.$serverurl + 'user'
try {
const response = await fetch(url, { headers: { Authorization: 'Bearer ' + token } })
return await response.json()
} catch (error) {
return null
}
},
async addNewCategory (name) {
const url = this.$serverurl + 'tags/category'
const token = await localStorage.getItem('token')
try {
const response = await fetch(
url, {
method: 'POST',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
Authorization: 'Bearer ' + token
},
body: JSON.stringify({
name: name
})
}
)
return await response.json()
} catch (error) {
return null
}
},
async addNewTag (tag, categoryId) {
const url = this.$serverurl + 'tags'
const token = await localStorage.getItem('token')
try {
const response = await fetch(
url, {
method: 'POST',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
Authorization: 'Bearer ' + token
},
body: JSON.stringify({
name: tag,
categoryId: categoryId
})
}
)
return await response.json()
} catch (error) {
return null
}
},
async getUserList () {
const token = await localStorage.getItem('token')
const url = this.$serverurl + 'user/list'
try {
const response = await fetch(url, { headers: { Authorization: 'Bearer ' + token } })
return await response.json()
} catch (error) {
return null
}
},
async getModelList () {
const token = await localStorage.getItem('token')
const url = this.$serverurl + 'models/list'
try {
const response = await fetch(url, { headers: { Authorization: 'Bearer ' + token } })
return await response.json()
} catch (error) {
return null
}
},
async getUserModels () {
const token = await localStorage.getItem('token')
const url = this.$serverurl + 'models'
try {
const response = await fetch(url, { headers: { Authorization: 'Bearer ' + token } })
return await response.json()
} catch (error) {
return null
}
},
async getModel (id) {
const url = this.$serverurl + 'models' + '?id=' + id
const response = await fetch(url)
try {
return await response.json()
} catch (error) {
return null
}
},
async removeModel (id) {
const token = await localStorage.getItem('token')
const url = this.$serverurl + 'models' + '?id=' + id
try {
await fetch(url, {
method: 'DELETE',
headers: {
Authorization: 'Bearer ' + token
}
})
return true
} catch (error) {
return false
}
},
async removeTag (id) {
const token = await localStorage.getItem('token')
const url = this.$serverurl + 'tags' + '?id=' + id
try {
await fetch(url, {
method: 'DELETE',
headers: {
Authorization: 'Bearer ' + token
}
})
return true
} catch (error) {
return false
}
},
async removeCategory (id) {
const token = await localStorage.getItem('token')
const url = this.$serverurl + 'tags/category' + '?id=' + id
try {
await fetch(url, {
method: 'DELETE',
headers: {
Authorization: 'Bearer ' + token
}
})
return true
} catch (error) {
return false
}
},
async removeUser (id) {
const token = await localStorage.getItem('token')
const url = this.$serverurl + 'user' + '?id=' + id
try {
await fetch(url, {
method: 'DELETE',
headers: {
Authorization: 'Bearer ' + token
}
})
return true
} catch (error) {
return false
}
},
async login (username, password) {
const url = this.$serverurl + 'login'
try {
const response = await fetch(
url, {
method: 'POST',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json'
},
body: JSON.stringify({
username: username,
password: password
})
}
)
return await response.json()
} catch (error) {
return null
}
},
async register (username, email, password) {
const url = this.$serverurl + 'user/signup'
try {
const response = await fetch(
url, {
method: 'POST',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json'
},
body: JSON.stringify({
email: email,
username: username,
password: password
})
}
)
return await response.json()
} catch (error) {
return null
}
}
}
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
<b-menu> <b-menu>
<div> <div>
<b-menu-list v-for="category in tags" v-bind:key="category.name" :label="category.name"> <b-menu-list v-for="category in tags" v-bind:key="category.name" :label="category.name">
<div v-for="tag in category.tags" v-bind:key="tag" class="field"> <div v-for="tag in category.tags" v-bind:key="tag.name" class="field">
<b-checkbox <b-checkbox
:native-value="tag.name" :native-value="tag.name"
v-model="checkboxGroup" v-model="checkboxGroup"
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
<p> <p>
<strong>{{model.name}}</strong> <strong>{{model.name}}</strong>
<br> <br>
<small>{{model.author.username}}</small> - <small>{{new Date(model.modificationDate).toLocaleDateString()}}</small> <small>{{model.author.username}}</small> - <small>{{new Date(model.lastModified).toLocaleDateString()}}</small>
<br> <br>
{{model.shortDescription}} {{model.shortDescription}}
</p> </p>
......
...@@ -10,11 +10,11 @@ ...@@ -10,11 +10,11 @@
</b-table-column> </b-table-column>
<b-table-column field="date" label="Last modification" centered sortable> <b-table-column field="date" label="Last modification" centered sortable>
{{ new Date(props.row.modificationDate).toLocaleDateString() }} {{ new Date(props.row.lastModified).toLocaleDateString() }}
</b-table-column> </b-table-column>
<b-table-column field="date" label="Added" centered sortable> <b-table-column field="date" label="Added" centered sortable>
{{ new Date(props.row.addedDate).toLocaleDateString() }} {{ new Date(props.row.added).toLocaleDateString() }}
</b-table-column> </b-table-column>
<b-table-column label="" centered> <b-table-column label="" centered>
......
...@@ -9,7 +9,7 @@ Vue.use(Buefy) ...@@ -9,7 +9,7 @@ Vue.use(Buefy)
Vue.config.productionTip = false Vue.config.productionTip = false
// Vue.prototype.$serverurl = process.env.VUE_APP_SERVER_URL // Vue.prototype.$serverurl = process.env.VUE_APP_SERVER_URL
Vue.prototype.$serverurl = '/' Vue.prototype.$serverurl = 'https://mozen.gltronic.ovh/'
new Vue({ new Vue({
router, router,
......
...@@ -22,9 +22,9 @@ ...@@ -22,9 +22,9 @@
<h1 class="title is-4">{{model.votes}} votes <b-button size="is-small" icon-left="heart-outline" style="top:-2px"/></h1> <h1 class="title is-4">{{model.votes}} votes <b-button size="is-small" icon-left="heart-outline" style="top:-2px"/></h1>
<small>Author: </small><strong>{{model.author.username}}</strong> <small>Author: </small><strong>{{model.author.username}}</strong>
<br> <br>
<small>Added: </small><strong>{{new Date(model.addedDate).toLocaleDateString()}}</strong> <small>Added: </small><strong>{{new Date(model.added).toLocaleDateString()}}</strong>
<br> <br>
<small>Last modification: </small><strong>{{new Date(model.modificationDate).toLocaleDateString()}}</strong> <small>Last modification: </small><strong>{{new Date(model.lastModified).toLocaleDateString()}}</strong>
<br> <br>
<br> <br>
<b-button type="is-primary" size="is-medium" icon-left="download"> <b-button type="is-primary" size="is-medium" icon-left="download">
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment