Skip to content
Snippets Groups Projects
Commit 49bdb42b authored by Madeleine Stenberg Jonassen's avatar Madeleine Stenberg Jonassen
Browse files

Merge branch 'main' into 'overview-ui'

# Conflicts:
#   FullstackProsjekt/src/frontend/src/views/OverviewQuizView.vue
parents a11ec963 4c5e7a83
No related branches found
No related tags found
1 merge request!16overview ui
Pipeline #267964 passed
image: maven:eclipse-temurin
before_script:
- cd FullstackProsjekt
stages: stages:
- ".pre"
- build - build
- test - test
- deploy - package
- ".post"
build-job: build:
stage: build stage: build
script: script:
- echo "Compiling the code..." - mvn compile
- echo "Compile complete."
unit-test-job: test:
stage: test stage: test
script: script:
- echo "Running unit tests... This will take about 60 seconds." - mvn clean test
- sleep 60
- echo "Code coverage is 90%" package:
lint-test-job: stage: package
stage: test
script:
- echo "Linting code... This will take about 10 seconds."
- sleep 10
- echo "No lint issues found."
deploy-job:
stage: deploy
environment: production
script: script:
- echo "Deploying application..." - mvn clean package
- echo "Application successfully deployed."
...@@ -71,6 +71,9 @@ ...@@ -71,6 +71,9 @@
<plugin> <plugin>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId> <artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<mainClass>edu.ntnu.idatt2105.FullstackProsjektApplication</mainClass>
</configuration>
</plugin> </plugin>
</plugins> </plugins>
</build> </build>
......
import axios from 'axios';
export const apiClient = axios.create({
baseURL: '/api',
//TODO: set api URL
});
\ No newline at end of file
export const getToken = () => {
return localStorage.getItem('token');
}
export const setToken = (token) => {
localStorage.setItem('token', token);
}
export const removeToken = () => {
localStorage.removeItem('token');
}
\ No newline at end of file
...@@ -2,12 +2,17 @@ ...@@ -2,12 +2,17 @@
import NewQuestionModel from "@/components/shared/NewQuestionModel.vue"; import NewQuestionModel from "@/components/shared/NewQuestionModel.vue";
import {ref} from "vue"; import {ref} from "vue";
import router from "@/router/index.js"; import router from "@/router/index.js";
import {apiClient} from "@/api.js";
const quizId = ref(null); //TODO: set quiz id when routing here
const createdQuestion = ref(null); const createdQuestion = ref(null);
const newAnswers = ref([]); const newAnswers = ref([]);
const showNewQuestionModal = ref(false); const showNewQuestionModal = ref(false);
const selectedAnswer = ref(null); const selectedAnswer = ref(null);
const existingQuestions = ref([]);
let answerId = 1; let answerId = 1;
const errorMsg = ''; //TODO: display error to user
function createQuestion() { function createQuestion() {
...@@ -51,7 +56,19 @@ function answerCount() { ...@@ -51,7 +56,19 @@ function answerCount() {
} }
} }
function submitQuestion() { async function getExistingQuestions() {
try {
const response = await apiClient.get(`/quizzes/${quizId.value}/questions`); // Fetch questions for a specific quiz
existingQuestions.value = response.data; // Update existingQuestions with the fetched questions
} catch (error) {
console.error('Error fetching existing questions:', error);
// Optionally, you can handle error response here
alert('An error occurred while fetching existing questions');
}
}
async function submitQuestion() {
//TODO: proper error handling
if(!createdQuestion.value){ if(!createdQuestion.value){
alert('Question cannot be empty'); alert('Question cannot be empty');
return false return false
...@@ -60,11 +77,18 @@ function submitQuestion() { ...@@ -60,11 +77,18 @@ function submitQuestion() {
alert('Fill all inputs before submitting') alert('Fill all inputs before submitting')
return false return false
} }
//Supposed to send request to backend with a finnished Question with id and such
router.post('/questions',{ try {
await apiClient.post('questions', {
//TODO: find quizID, send this too
question: createdQuestion.value, question: createdQuestion.value,
correctAnswer: selectedAnswer.value,
answers: newAnswers.value answers: newAnswers.value
}) });
} catch (error) {
//TODO: proper error handling
this.errorMsg = 'Error logging in';
}
} }
</script> </script>
......
<script> <script>
import axios from "axios"; //import Svg from "@/assets/Svg.vue";
import Svg from "@/assets/Svg.vue"; import {setToken} from "@/tokenController.js";
import {apiClient} from "@/api.js";
export default { export default {
name: 'Login', //name: 'Login',
components: {Svg}, //components: {Svg},
data() { data() {
return { return {
email: '', email: '',
password: '', password: '',
showPassword: false // Add showPassword property showPassword: false, // Add showPassword property
errorMsg: '', //TODO: display error to user
} }
}, },
methods: { methods: {
async handleSubmit() { async handleSubmit() {
const response = await axios.post('login', { try {
await apiClient.post('/login', {
email: this.email, email: this.email,
password: this.password password: this.password
}).then(response => {
setToken(response.data.token); //TODO: check token name
}); });
localStorage.setItem('token', response.data.token) } catch (error) {
//TODO: proper error handling
this.errorMsg = 'Error logging in';
}
}, },
togglePasswordVisibility() { togglePasswordVisibility() {
this.showPassword = !this.showPassword; this.showPassword = !this.showPassword;
......
...@@ -52,6 +52,17 @@ ...@@ -52,6 +52,17 @@
<script> <script>
import { defineComponent } from "vue"; import { defineComponent } from "vue";
import Svg from "@/assets/Svg.vue"; import Svg from "@/assets/Svg.vue";
import {apiClient} from "@/api.js";
import {ref} from "vue";
getQuizzes();
const quizzes = ref([]);
async function getQuizzes() {
//TODO: try/catch
const response = await apiClient.get('/quizzes/${quizId.value}');
quizzes.value = response.data; //TODO: create parsing method
}
export default defineComponent({ export default defineComponent({
components: { Svg }, components: { Svg },
...@@ -84,7 +95,6 @@ export default defineComponent({ ...@@ -84,7 +95,6 @@ export default defineComponent({
}); });
</script> </script>
<style> <style>
.overViewQuestion-page{ .overViewQuestion-page{
padding: 50px; padding: 50px;
......
<script> <script>
import Svg from '../assets/Svg.vue' //import Svg from '../assets/Svg.vue'
import axios from "axios"; import {apiClient} from "@/api.js";
export default { export default {
name: 'Register', name: 'Register',
data(){ data(){
...@@ -10,20 +10,28 @@ ...@@ -10,20 +10,28 @@
last_name:'', last_name:'',
email:'', email:'',
password:'', password:'',
password_confirm:'' password_confirm:'',
errorMsg: '', //TODO: display error to user
} }
}, },
methods:{ methods:{
async handleSubmit(e) { async handleSubmit() {
const response = await axios.post('signup', { //TODO: use interceptor to check matching password, send one password
try {
await apiClient.post('/api/auth/register', {
first_name: this.first_name, first_name: this.first_name,
last_name: this.last_name, last_name: this.last_name,
email: this.email, email: this.email,
password: this.password, password: this.password
password_confirm: this.password_confirm //password_confirm: this.password_confirm
}); }).then(response => {
//TODO: display successful registration to user
this.$router.push('/login') this.$router.push('/login')
});
} catch (error) {
//TODO: proper error handling
this.errorMsg = 'Error signing up';
}
} }
} }
} }
......
import { ref } from 'vue';
export const user = ref({
userId: null,
email: null,
});
// Function to set user data
export function setUser(userId, userEmail) {
user.value = {
userId: userId,
email: userEmail
};
}
export function clearUser() {
user.value = {
userId: null,
email: null,
};
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment