diff --git a/spec.json b/spec.json index a86e9275db55936df12b800a4318eea02621ff20..6528f8560d283391d0035b987bd98a6f00dd5dd3 100644 --- a/spec.json +++ b/spec.json @@ -411,14 +411,6 @@ } ], "responses": { - "201": { - "description": "Item purchased and added to inventory successfully", - "content": { - "application/json": { - - } - } - }, "403": { "description": "Insufficient points to purchase the item", "content": { @@ -428,6 +420,14 @@ } } } + }, + "201": { + "description": "Item purchased and added to inventory successfully", + "content": { + "application/json": { + + } + } } } } @@ -814,22 +814,22 @@ "required": true }, "responses": { - "409": { - "description": "Email already exists", + "201": { + "description": "Successfully signed up", "content": { "application/json": { "schema": { - "$ref": "#/components/schemas/ExceptionResponse" + "$ref": "#/components/schemas/AuthenticationResponse" } } } }, - "201": { - "description": "Successfully signed up", + "409": { + "description": "Email already exists", "content": { "application/json": { "schema": { - "$ref": "#/components/schemas/AuthenticationResponse" + "$ref": "#/components/schemas/ExceptionResponse" } } } diff --git a/src/api/core/OpenAPI.ts b/src/api/core/OpenAPI.ts index b33daf25d0e3518d35dc91aac288e991b8a7c160..213c15d4a7b840e8d13a35f74c2618c13b7c9398 100644 --- a/src/api/core/OpenAPI.ts +++ b/src/api/core/OpenAPI.ts @@ -20,7 +20,7 @@ export type OpenAPIConfig = { }; export const OpenAPI: OpenAPIConfig = { - BASE: import.meta.env.VITE_APP_API_URL, + BASE: 'http://localhost:8080', VERSION: '3.0', WITH_CREDENTIALS: false, CREDENTIALS: 'include', diff --git a/src/components/UserProfile/ExternalProfile.vue b/src/components/UserProfile/ExternalProfile.vue index 3852752e2e3d7889edfec0f7f4862375072fc5e5..2737d695b9955782811eeb0dfe958f2772591f85 100644 --- a/src/components/UserProfile/ExternalProfile.vue +++ b/src/components/UserProfile/ExternalProfile.vue @@ -6,13 +6,10 @@ import {UserService, BadgeService, GoalService, type GoalDTO, type BadgeDTO, Fri import { ItemService } from "@/api"; import handleUnknownError from '@/components/Exceptions/unkownErrorHandler' -let numberOfHistory = 6; -let cardTitles = ["Spain tour", "Food waste", "Coffee", "Concert", "New book", "Pretty clothes"] let firstname = ref(); let lastname = ref(); const imageUrl = ref(`../src/assets/userprofile.png`); -let hasHistory = ref(true) let hasBadges = ref(false) let hasInventory = ref(false) @@ -24,30 +21,8 @@ const backgroundName = ref(""); const points = ref(0 as any); const streak = ref(0 as any); - -let goalName = ref(''); -let goalDescription = ref(''); -let targetAmount = ref(''); -let targetDate = ref(''); -let createdAt = ref(''); -let goals = ref<GoalDTO[]>([]) - -async function getGoals() { - try { - goals.value = await GoalService.getGoals(); - console.log("number of goals: ", goals.value.length) - console.log('The id of a goal: ', goals.value[0]) - if (goals.value.length > 0) { - hasHistory.value = true - } else { - hasHistory.value = false - console.log('No history') - } - }catch (error){ - handleUnknownError(error) - console.error("Something went wrong", error) - } -} +const isFriend = ref(false); +const isRequestSent = ref(false); async function setupForm() { try { @@ -75,9 +50,20 @@ async function setupForm() { } } +const checkIfFriend = async () => { + let id = route.params.id as any; + const response = await FriendService.getFriends(); + response.forEach((friend) => { + if (friend.id == id) { + isFriend.value = true; + } + }); +}; + const getInventory = async () => { try { - const response = await ItemService.getInventory(); + let id = route.params.id as any + const response = await ItemService.getInventoryByUserId({ userId: id }); inventory.value = response; if (inventory.value.length > 0) { hasInventory.value = true @@ -93,7 +79,8 @@ const getInventory = async () => { const getBadges = async () => { try { - const responseBadge = await BadgeService.getBadgesUnlockedByUser(); + let id = route.params.id as any + const responseBadge = await BadgeService.getBadgesUnlockedByUser({ userId: id }); badges.value = responseBadge; if (badges.value.length > 0) { hasBadges.value = true @@ -107,16 +94,9 @@ const getBadges = async () => { } } -const selectItem = (item: any) => { - backgroundName.value = item.itemName; - useUserInfoStore().setUserInfo({ - roadBackground: item.imageId, - }) -} - onMounted(() => { setupForm() - getGoals() + checkIfFriend() }) const toRoadmap = () => { @@ -126,6 +106,7 @@ const toRoadmap = () => { const addFriend = () => { let id = route.params.id as any; const response = FriendService.addFriendRequest({ userId: id }); + isRequestSent.value = true; }; const removeFriend = () => { @@ -152,11 +133,30 @@ const removeFriend = () => { <div class="p-3 text-black" style="background-color: #f8f9fa;"> <div class="d-flex justify-content-end text-center py-1"> <div style="width: 100%; display: flex; justify-content: start"> - <button data-cy="toUpdate" type="button" data-mdb-button-init data-mdb-ripple-init class="btn btn-outline-primary" - data-mdb-ripple-color="dark" style="z-index: 1; height: 40px; margin-left: 17px" id="toUpdate" @click="addFriend"> - Rediger profil - </button> - + <button + v-if="!isFriend && !isRequestSent" + @click="addFriend" + class="btn btn-success mx-3" + style="height: 40px;" + > + Legg til venn + </button> + <button + v-else-if="isRequestSent" + class="btn btn-secondary mx-2" + style="height: 40px;" + disabled + > + Forespørsel sendt + </button> + <button + v-else + @click="removeFriend" + class="btn btn-danger mx-3" + style="height: 40px;" + > + Fjern venn + </button> </div> <div> <p class="mb-1 h2" data-cy="points">{{ points }} <img src="@/assets/items/pigcoin.png" style="width: 4rem"></p> @@ -176,7 +176,7 @@ const removeFriend = () => { <h1 class="mt-1 text-start badges-text">Lageret ditt</h1> <div v-if="hasInventory" class="scrolling-wrapper-badges row flex-row flex-nowrap mt-2 pb-2 pt-2"> <div v-for="product in inventory" :key="product.id" class="card text-center" - style="width: 12rem; border: none; cursor: pointer; margin: 1rem; border: 2px solid black" @click="selectItem(product)"> + style="width: 12rem; border: none; cursor: pointer; margin: 1rem; border: 2px solid black"> <img :src="`http://localhost:8080/api/images/${product.imageId}`" class="card-img-top" alt="..." /> <div class="card-body"> @@ -184,8 +184,7 @@ const removeFriend = () => { </div> </div> </div> - <div v-else>Du har ingen ting på lageret ditt, gå til butikken for å kjøpe!</div> - <div v-if="backgroundName" class="text-success">You selected the background: <strong>{{ backgroundName }}!</strong></div> + <div v-else>Ingen gjenstander</div> </div> </div> </div> diff --git a/src/components/UserProfile/MyProfile.vue b/src/components/UserProfile/MyProfile.vue index 6f4e2ab6c80dd4dda4b2f471bcf64e9c8e1c76a2..9cb7f0d66b2353d85e62f98afb91776c51942dd9 100644 --- a/src/components/UserProfile/MyProfile.vue +++ b/src/components/UserProfile/MyProfile.vue @@ -3,14 +3,17 @@ import {ref, onMounted} from "vue"; import { useRouter } from "vue-router"; import { useUserInfoStore } from "@/stores/UserStore"; import {UserService, BadgeService, GoalService, type GoalDTO, type BadgeDTO} from "@/api"; -import { ItemService } from "@/api"; +import { ItemService, type UserUpdateDTO } from "@/api"; import handleUnknownError from '@/components/Exceptions/unkownErrorHandler' +import bannerImage from '@/assets/banners/stacked.svg'; let numberOfHistory = 6; let cardTitles = ["Spain tour", "Food waste", "Coffee", "Concert", "New book", "Pretty clothes"] let firstname = ref(); let lastname = ref(); const imageUrl = ref(`../src/assets/userprofile.png`); +const bannerImageUrl = ref(bannerImage); + let hasHistory = ref(true) let hasBadges = ref(false) @@ -23,12 +26,6 @@ const backgroundName = ref(""); const points = ref(0 as any); const streak = ref(0 as any); - -let goalName = ref(''); -let goalDescription = ref(''); -let targetAmount = ref(''); -let targetDate = ref(''); -let createdAt = ref(''); let goals = ref<GoalDTO[]>([]) async function getGoals() { @@ -90,7 +87,7 @@ const getInventory = async () => { const getBadges = async () => { try { - const responseBadge = await BadgeService.getBadgesUnlockedByUser(); + const responseBadge = await BadgeService.getBadgesUnlockedByActiveUser(); badges.value = responseBadge; if (badges.value.length > 0) { hasBadges.value = true @@ -106,9 +103,13 @@ const getBadges = async () => { const selectItem = (item: any) => { backgroundName.value = item.itemName; - useUserInfoStore().setUserInfo({ - roadBackground: item.imageId, - }) + let imageId = item.imageId; + //const bannerImagePayload: UserUpdateDTO = { + // bannerImage: imageId as any, + // }; + //UserService.update({ requestBody: bannerImagePayload }) + //bannerImageUrl.value = `http://localhost:8080/api/images/${imageId}`; + } onMounted(() => { @@ -136,7 +137,7 @@ const toUpdateUserSettings = () => { <div class="row d-flex justify-content-center align-items-center h-100"> <div class="col 12"> <div class="card"> - <div class="rounded-top text-white d-flex flex-row bg-primary" style="height:200px;" id="banner"> + <div class="rounded-top text-white d-flex flex-row bg-primary" :style="{ height: '200px', backgroundImage: `url(${bannerImageUrl})` }"> <div class=" d-flex flex-column align-items-center justify-content-center"> <img :src="imageUrl" alt="Generisk plassholderbilde" class="img-fluid img-thumbnail" style="width: 150px; height:150px; margin-left: 25px; margin-right: 15px;">