Skip to content

Commit

Permalink
Merge pull request #455 from softwareconstruction240/server-communicator
Browse files Browse the repository at this point in the history
Frontend: refactor server calls into a ServerCommunicator
  • Loading branch information
webecke authored Nov 8, 2024
2 parents eedbfc8 + 53a7fb8 commit 7fb354c
Show file tree
Hide file tree
Showing 15 changed files with 377 additions and 465 deletions.
51 changes: 0 additions & 51 deletions src/main/java/edu/byu/cs/controller/AdminController.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,57 +45,6 @@ public class AdminController {

};

public static final Route userPatch = (req, res) -> {
String netId = req.params(":netId");

UserDao userDao = DaoService.getUserDao();
User user;
try {
user = userDao.getUser(netId);
} catch (DataAccessException e) {
LOGGER.error("Error getting user", e);
halt(500);
return null;
}

if (user == null) {
halt(404, "user not found");
return null;
}

try {
String firstName = req.queryParams("firstName");
if (firstName != null)
userDao.setFirstName(user.netId(), firstName);

String lastName = req.queryParams("lastName");
if (lastName != null)
userDao.setLastName(user.netId(), lastName);

String repoUrl = req.queryParams("repoUrl");
if (repoUrl != null)
userDao.setRepoUrl(user.netId(), repoUrl);

String role = req.queryParams("role");
if (role != null) {
try {
userDao.setRole(user.netId(), User.Role.valueOf(role.toUpperCase()));
} catch (IllegalArgumentException e) {
halt(400, "invalid role. must be one of: STUDENT, ADMIN");
return null;
}
}
} catch (DataAccessException e) {
LOGGER.error("Error updating user", e);
halt(500);
return null;
}

res.status(204);

return "";
};

public static final Route testModeGet = (req, res) -> {
User latestTestStudent;
try {
Expand Down
2 changes: 0 additions & 2 deletions src/main/java/edu/byu/cs/server/Server.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,6 @@ public static int setupEndpoints(int port) {

get("/users", usersGet);

patch("/user/:netId", userPatch);

post("/submit", adminRepoSubmitPost);

path("/submissions", () -> {
Expand Down
9 changes: 7 additions & 2 deletions src/main/resources/frontend/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import BannerMessage from '@/components/BannerMessage.vue'
import PopUp from '@/components/PopUp.vue'
import RepoEditor from '@/components/RepoEditor.vue'
import AboutPage from '@/components/AboutPage.vue'
import { ServerError } from '@/network/ServerError'
const greeting = computed(() => {
if (useAuthStore().isLoggedIn) {
Expand All @@ -23,9 +24,13 @@ const logOut = async () => {
await logoutPost()
useAuthStore().user = null
} catch (e) {
alert(e)
if (e instanceof ServerError){
alert(e.message)
} else {
alert(e)
}
}
router.push({name: "login"})
await router.push({ name: "login" })
}
onMounted( async () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script setup lang="ts">
import { computed, onBeforeMount, onMounted, ref } from 'vue'
import { computed } from 'vue'
import { useAuthStore } from '@/stores/auth'
import { useAppConfigStore } from '@/stores/appConfig'
Expand Down
5 changes: 1 addition & 4 deletions src/main/resources/frontend/src/components/RepoEditor.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script setup lang="ts">
import { isPlausibleRepoUrl } from '@/utils/utils'
import { defineEmits, onMounted, reactive } from 'vue'
import { defineEmits, reactive } from 'vue'
import { adminUpdateRepoPatch, studentUpdateRepoPatch } from '@/services/userService'
import type { User } from '@/types/types'
import { useAuthStore } from '@/stores/auth'
Expand Down Expand Up @@ -42,9 +42,6 @@ const submitAndCheckRepo = async (sendEmit: (event: any) => void) => {
sendEmit('repoEditSuccess')
}
onMounted( () => {
console.log(user)
})
</script>

<template>
Expand Down

This file was deleted.

This file was deleted.

Loading

0 comments on commit 7fb354c

Please sign in to comment.