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