Base générale d'UI
This commit is contained in:
24
client/src/util/api.js
Normal file
24
client/src/util/api.js
Normal file
@ -0,0 +1,24 @@
|
||||
|
||||
export class APIClient {
|
||||
|
||||
saveBoard(board) {
|
||||
return fetch(`/api/boards`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify(board)
|
||||
})
|
||||
.then(res => res.json())
|
||||
;
|
||||
}
|
||||
|
||||
fetchBoards() {
|
||||
return fetch(`/api/boards`)
|
||||
.then(res => res.json())
|
||||
;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export const api = new APIClient();
|
@ -1,7 +1,65 @@
|
||||
|
||||
export class GiteaUnauthorizedError extends Error {
|
||||
constructor(...args) {
|
||||
super(...args)
|
||||
Error.captureStackTrace(this, GiteaUnauthorizedError)
|
||||
}
|
||||
}
|
||||
|
||||
export class GiteaClient {
|
||||
|
||||
constructor() {
|
||||
|
||||
fetchIssues(project) {
|
||||
return fetch(`/gitea/api/v1/repos/${project}/issues`)
|
||||
.then(this.assertAuthorization)
|
||||
.then(res => res.json())
|
||||
;
|
||||
}
|
||||
|
||||
fetchUserProjects() {
|
||||
return fetch(`/gitea/api/v1/user/repos`)
|
||||
.then(this.assertOk)
|
||||
.then(this.assertAuthorization)
|
||||
.then(res => res.json())
|
||||
;
|
||||
}
|
||||
|
||||
addIssueLabel(project, issueNumber, labelID) {
|
||||
return fetch(`/gitea/api/v1/repos/${project}/issues/${issueNumber}/labels`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify({ labels: [labelID] }),
|
||||
})
|
||||
.then(this.assertOk)
|
||||
.then(this.assertAuthorization)
|
||||
.then(res => res.json())
|
||||
}
|
||||
|
||||
fetchProjectLabels(project) {
|
||||
return fetch(`/gitea/api/v1/repos/${project}/labels`)
|
||||
.then(this.assertOk)
|
||||
.then(this.assertAuthorization)
|
||||
.then(res => res.json())
|
||||
;
|
||||
}
|
||||
|
||||
removeIssueLabel(project, issueNumber, labelID) {
|
||||
return fetch(`/gitea/api/v1/repos/${project}/issues/${issueNumber}/labels/${labelID}`, {
|
||||
method: 'DELETE'
|
||||
})
|
||||
.then(this.assertOk)
|
||||
.then(this.assertAuthorization)
|
||||
}
|
||||
|
||||
assertOk(res) {
|
||||
if (!res.ok) return Promise.reject(new Error('Request failed'));
|
||||
return res;
|
||||
}
|
||||
|
||||
assertAuthorization(res) {
|
||||
if (res.status === 401 || res.status === 404) return Promise.reject(new GiteaUnauthorizedError());
|
||||
return res;
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user