From 112acbc9d22e766ac5fec62004671b857ade34ea Mon Sep 17 00:00:00 2001 From: Ada Werefox Date: Tue, 29 Apr 2025 15:54:54 -0700 Subject: [PATCH] Updates to align frontend with API paths. --- public/css/main.css | 3 ++ src/components/DeleteFunction.vue | 27 +++++++++++ src/components/UpdateFunction.vue | 59 ++++++++++++++++++++++++ src/ts/authorization.ts | 2 +- src/ts/function_tags.ts | 12 ++--- src/ts/functions.ts | 74 +++++++++++++++++++++++++++++-- src/ts/groups.ts | 4 +- src/ts/user_info.ts | 2 +- src/views/UserDashboard.vue | 33 +++++++++++++- 9 files changed, 201 insertions(+), 15 deletions(-) create mode 100644 src/components/DeleteFunction.vue create mode 100644 src/components/UpdateFunction.vue diff --git a/public/css/main.css b/public/css/main.css index 583995b..d572e02 100644 --- a/public/css/main.css +++ b/public/css/main.css @@ -211,6 +211,9 @@ .my-auto { margin-block: auto; } + .mb-4 { + margin-bottom: calc(var(--spacing) * 4); + } .ml-2 { margin-left: calc(var(--spacing) * 2); } diff --git a/src/components/DeleteFunction.vue b/src/components/DeleteFunction.vue new file mode 100644 index 0000000..7ae30bb --- /dev/null +++ b/src/components/DeleteFunction.vue @@ -0,0 +1,27 @@ + + + diff --git a/src/components/UpdateFunction.vue b/src/components/UpdateFunction.vue new file mode 100644 index 0000000..37e7260 --- /dev/null +++ b/src/components/UpdateFunction.vue @@ -0,0 +1,59 @@ + + + diff --git a/src/ts/authorization.ts b/src/ts/authorization.ts index 14327f8..932a416 100644 --- a/src/ts/authorization.ts +++ b/src/ts/authorization.ts @@ -1,5 +1,5 @@ export function isLoggedIn(): Promise { - return fetch('http://localhost:31337/get/user/authorized', { + return fetch('http://localhost:31337/user/authorized', { credentials: 'include', }) .then((res) => { diff --git a/src/ts/function_tags.ts b/src/ts/function_tags.ts index 673e09c..420a63b 100644 --- a/src/ts/function_tags.ts +++ b/src/ts/function_tags.ts @@ -1,13 +1,15 @@ import { reactive, ref } from 'vue' export const function_tags_store = reactive({ - function_tags: ref([] as Array<{ - name: string - }>,), + function_tags: ref( + [] as Array<{ + name: string + }>, + ), }) export function update_function_tags() { - fetch('http://localhost:31337/get/all/function-tags', { + fetch('http://localhost:31337/all/function-tags', { credentials: 'include', }) .then((res) => { @@ -22,7 +24,7 @@ export function update_function_tags() { } export function add_function_tag(function_tag_name: string) { - const post_url = new URL('http://localhost:31337/post/function-tag') + const post_url = new URL('http://localhost:31337/function-tag') const search_params = new URLSearchParams() search_params.append('name', function_tag_name) post_url.search = search_params.toString() diff --git a/src/ts/functions.ts b/src/ts/functions.ts index 3b7b874..5236d5b 100644 --- a/src/ts/functions.ts +++ b/src/ts/functions.ts @@ -22,14 +22,15 @@ export const functions_store = reactive({ ), }) -export function update_functions() { - fetch('http://localhost:31337/get/all/functions', { +export function get_functions() { + fetch('http://localhost:31337/all/functions', { credentials: 'include', }) .then((res) => { res .json() .then((functionsjson) => { + console.log(functionsjson) functions_store.functions = functionsjson.functions }) .catch(() => {}) @@ -37,12 +38,77 @@ export function update_functions() { .catch(() => {}) } +export function update_function( + function_name: string, + function_tags: string[], + function_requirements: string[], +) { + const post_url = new URL('http://localhost:31337/function') + const search_params = new URLSearchParams() + search_params.append('name', function_name) + function_tags.forEach((tag) => { + search_params.append('tags', tag) + }) + if (function_requirements.length > 0 && function_requirements[0] != 'undefined') { + function_requirements.forEach((requirement) => { + search_params.append('requirements', requirement) + }) + } + post_url.search = search_params.toString() + fetch(post_url, { + credentials: 'include', + method: 'PUT', + body: JSON.stringify({ + name: function_name, + tags: function_tags, + requirements: function_requirements, + }), + headers: { + 'Content-Type': 'application/json', + }, + }) + .then((res) => { + if (res.status === 400) { + console.log('Function submitted is invalid.') + } else if (res.status === 401) { + console.log("You aren't logged in.") + } else { + get_functions() + } + }) + .catch(() => {}) +} + +export function delete_function(function_name: string) { + const delete_url = new URL('http://localhost:31337/function') + const search_params = new URLSearchParams() + search_params.append('name', function_name) + delete_url.search = search_params.toString() + fetch(delete_url, { + credentials: 'include', + method: 'DELETE', + body: JSON.stringify({ + name: function_name, + }), + }) + .then((res) => { + if (res.status === 400) { + console.log('Function submitted is invalid.') + } else if (res.status === 401) { + console.log("You aren't logged in.") + } else { + get_functions() + } + }) + .catch(() => {}) +} + export function add_function( function_name: string, function_tags: string[], function_requirements: string[], ) { - const post_url = new URL('http://localhost:31337/post/function') + const post_url = new URL('http://localhost:31337/function') const search_params = new URLSearchParams() search_params.append('name', function_name) function_tags.forEach((tag) => { @@ -72,7 +138,7 @@ export function add_function( } else if (res.status === 401) { console.log("You aren't logged in.") } else { - update_functions() + get_functions() } }) .catch(() => {}) diff --git a/src/ts/groups.ts b/src/ts/groups.ts index a4fcf42..811424f 100644 --- a/src/ts/groups.ts +++ b/src/ts/groups.ts @@ -9,7 +9,7 @@ export const groups_store = reactive({ }) export function update_groups() { - fetch('http://localhost:31337/get/all/groups', { + fetch('http://localhost:31337/all/groups', { credentials: 'include', }) .then((res) => { @@ -24,7 +24,7 @@ export function update_groups() { } export function add_group(group: string) { - fetch('http://localhost:31337/post/group?name=' + group, { + fetch('http://localhost:31337/group?name=' + group, { credentials: 'include', method: 'POST', body: JSON.stringify({ name: group }), diff --git a/src/ts/user_info.ts b/src/ts/user_info.ts index 4678de0..f218441 100644 --- a/src/ts/user_info.ts +++ b/src/ts/user_info.ts @@ -9,7 +9,7 @@ export const user_store = reactive({ }) export function update_info() { - fetch('http://localhost:31337/get/user/info', { + fetch('http://localhost:31337/user/info', { credentials: 'include', }) .then((res) => { diff --git a/src/views/UserDashboard.vue b/src/views/UserDashboard.vue index 5294ba3..c1a9bd2 100644 --- a/src/views/UserDashboard.vue +++ b/src/views/UserDashboard.vue @@ -6,15 +6,17 @@ import ListFunctionTags from '@/components/ListFunctionTags.vue' import AddGroup from '@/components/AddGroup.vue' import AddFunction from '@/components/AddFunction.vue' import AddFunctionTag from '@/components/AddFunctionTag.vue' +import DeleteFunction from '@/components/DeleteFunction.vue' import { onMounted } from 'vue' import { update_info } from '@/ts/user_info' import { update_groups } from '@/ts/groups' -import { update_functions } from '@/ts/functions' +import { get_functions } from '@/ts/functions' import { update_function_tags } from '@/ts/function_tags' +import UpdateFunction from '@/components/UpdateFunction.vue' onMounted(update_info) onMounted(update_groups) -onMounted(update_functions) +onMounted(get_functions) onMounted(update_function_tags) @@ -67,8 +69,35 @@ onMounted(update_function_tags)
+
+
+

> CREATE

+
+
+
+
+
+

> UPDATE

+
+
+ +
+
+
+
+

> DELETE

+
+
+ +