Clyde/frontend/src/rest/forum.js

49 lines
1.3 KiB
JavaScript
Raw Normal View History

2024-04-09 23:41:24 +02:00
/*******************************************************
* File: forum.js
* Author: Anthony Debucquoy
* Scope: Extension messagerie
* Description: Forum related functions and calls
*******************************************************/
2024-04-05 08:57:19 +02:00
import { ref } from 'vue'
import { restGet, restPost, restDelete, restPatch } from './restConsumer.js'
/**
* List forums of a course
*/
export async function getForumsOfCourse(id){
2024-04-09 17:27:26 +02:00
ForumsOfCurrentCourse.value = await restGet("/forums/" + id)
2024-04-05 08:57:19 +02:00
}
export const ForumsOfCurrentCourse = ref();
2024-04-09 17:27:26 +02:00
export function createForum(id, name){
restPost("/forums/" + id, {name: name}).then(_ => getForumsOfCourse(id));
}
2024-04-05 08:57:19 +02:00
/**
* List post of a specified forum
*/
export async function getPostsOfForum(id){
2024-04-09 23:41:24 +02:00
PostsOfCurrentForum.value = await restGet("/forum/" + id);
}
export function createPost(id, subject, content){
restPost("/forum/" + id, {subject: subject, content: content}).then(_ => getPostsOfForum(id));
2024-04-05 08:57:19 +02:00
}
export const PostsOfCurrentForum = ref();
/**
* Get a post and its responses
*/
export async function fetchPost(id){
2024-04-09 23:41:24 +02:00
fetchedPost.value = await restGet("/forum/post/" + id);
}
export function sendAnswer(id, content){
restPost("/forum/post/" + id, {content: content}).then(_ => fetchPost(id))
2024-04-05 08:57:19 +02:00
}
export const fetchedPost = ref();