Skip to content
Snippets Groups Projects
Commit f727cb2b authored by VIktorGrev's avatar VIktorGrev
Browse files

fix: Fixing profile picture with update user

parent 7a0b2bd0
Branches ImageInStorage
No related tags found
1 merge request!52feat: Adding upload img and update password
Pipeline #280848 failed
......@@ -16,7 +16,46 @@
"Bearer Authentication": []
}
],
"tags": [
{
"name": "Friend",
"description": "API for managing friend relationships"
}
],
"paths": {
"/api/friends/{friendId}": {
"put": {
"tags": [
"Friend"
],
"summary": "Accept a friend request",
"description": "Accepts a friend request from another user.",
"operationId": "acceptFriendRequest",
"parameters": [
{
"name": "friendId",
"in": "path",
"required": true,
"schema": {
"type": "integer",
"format": "int64"
}
}
],
"responses": {
"200": {
"description": "Friend request successfully accepted",
"content": {
"*/*": {
"schema": {
"type": "object"
}
}
}
}
}
}
},
"/bank/v1/transaction/norwegian-domestic-payment-to-self": {
"post": {
"tags": [
......@@ -269,6 +308,32 @@
}
}
},
"/api/friends/{userId}": {
"post": {
"tags": [
"Friend"
],
"summary": "Send a friend request",
"description": "Sends a new friend request to another user.",
"operationId": "addFriendRequest",
"parameters": [
{
"name": "userId",
"in": "path",
"required": true,
"schema": {
"type": "integer",
"format": "int64"
}
}
],
"responses": {
"201": {
"description": "Friend request successfully created"
}
}
}
},
"/api/budget/update/{budgetId}": {
"post": {
"tags": [
......@@ -469,22 +534,22 @@
"required": true
},
"responses": {
"201": {
"description": "Successfully signed up",
"409": {
"description": "Email already exists",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/AuthenticationResponse"
"$ref": "#/components/schemas/ExceptionResponse"
}
}
}
},
"409": {
"description": "Email already exists",
"201": {
"description": "Successfully signed up",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/ExceptionResponse"
"$ref": "#/components/schemas/AuthenticationResponse"
}
}
}
......@@ -522,8 +587,8 @@
}
}
},
"401": {
"description": "Invalid credentials",
"404": {
"description": "User not found",
"content": {
"application/json": {
"schema": {
......@@ -532,8 +597,8 @@
}
}
},
"404": {
"description": "User not found",
"401": {
"description": "Invalid credentials",
"content": {
"application/json": {
"schema": {
......@@ -911,23 +976,23 @@
}
],
"responses": {
"200": {
"description": "Successfully retrieved the image",
"404": {
"description": "Image not found",
"content": {
"*/*": {
"schema": {
"type": "string",
"format": "binary"
"$ref": "#/components/schemas/ExceptionResponse"
}
}
}
},
"404": {
"description": "Image not found",
"200": {
"description": "Successfully retrieved the image",
"content": {
"*/*": {
"schema": {
"$ref": "#/components/schemas/ExceptionResponse"
"type": "string",
"format": "binary"
}
}
}
......@@ -979,6 +1044,56 @@
}
}
},
"/api/friends": {
"get": {
"tags": [
"Friend"
],
"summary": "Get all friends",
"description": "Returns a list of all friends.",
"operationId": "getFriends",
"responses": {
"200": {
"description": "Successfully retrieved list of friends",
"content": {
"*/*": {
"schema": {
"type": "array",
"items": {
"$ref": "#/components/schemas/UserDTO"
}
}
}
}
}
}
}
},
"/api/friends/requests": {
"get": {
"tags": [
"Friend"
],
"summary": "Get friend requests",
"description": "Returns a list of all users who have sent a friend request.",
"operationId": "getFriendRequests",
"responses": {
"200": {
"description": "Successfully retrieved friend requests",
"content": {
"*/*": {
"schema": {
"type": "array",
"items": {
"$ref": "#/components/schemas/UserDTO"
}
}
}
}
}
}
}
},
"/api/budget": {
"get": {
"tags": [
......@@ -1723,22 +1838,22 @@
"enabled": {
"type": "boolean"
},
"username": {
"type": "string"
},
"authorities": {
"type": "array",
"items": {
"$ref": "#/components/schemas/GrantedAuthority"
}
},
"username": {
"type": "string"
},
"accountNonExpired": {
"accountNonLocked": {
"type": "boolean"
},
"credentialsNonExpired": {
"type": "boolean"
},
"accountNonLocked": {
"accountNonExpired": {
"type": "boolean"
}
}
......
......@@ -50,6 +50,7 @@ export type { UserUpdateDTO } from './models/UserUpdateDTO';
export { AccountControllerService } from './services/AccountControllerService';
export { AuthenticationService } from './services/AuthenticationService';
export { BankProfileControllerService } from './services/BankProfileControllerService';
export { FriendService } from './services/FriendService';
export { GoalService } from './services/GoalService';
export { ImageService } from './services/ImageService';
export { LeaderboardService } from './services/LeaderboardService';
......
......@@ -24,11 +24,11 @@ export type User = {
streak?: Streak;
configuration?: Configuration;
enabled?: boolean;
authorities?: Array<GrantedAuthority>;
username?: string;
accountNonExpired?: boolean;
credentialsNonExpired?: boolean;
authorities?: Array<GrantedAuthority>;
accountNonLocked?: boolean;
credentialsNonExpired?: boolean;
accountNonExpired?: boolean;
};
export namespace User {
export enum role {
......
/* generated using openapi-typescript-codegen -- do not edit */
/* istanbul ignore file */
/* tslint:disable */
/* eslint-disable */
import type { UserDTO } from '../models/UserDTO';
import type { CancelablePromise } from '../core/CancelablePromise';
import { OpenAPI } from '../core/OpenAPI';
import { request as __request } from '../core/request';
export class FriendService {
/**
* Accept a friend request
* Accepts a friend request from another user.
* @returns any Friend request successfully accepted
* @throws ApiError
*/
public static acceptFriendRequest({
friendId,
}: {
friendId: number,
}): CancelablePromise<Record<string, any>> {
return __request(OpenAPI, {
method: 'PUT',
url: '/api/friends/{friendId}',
path: {
'friendId': friendId,
},
});
}
/**
* Send a friend request
* Sends a new friend request to another user.
* @returns any Friend request successfully created
* @throws ApiError
*/
public static addFriendRequest({
userId,
}: {
userId: number,
}): CancelablePromise<any> {
return __request(OpenAPI, {
method: 'POST',
url: '/api/friends/{userId}',
path: {
'userId': userId,
},
});
}
/**
* Get all friends
* Returns a list of all friends.
* @returns UserDTO Successfully retrieved list of friends
* @throws ApiError
*/
public static getFriends(): CancelablePromise<Array<UserDTO>> {
return __request(OpenAPI, {
method: 'GET',
url: '/api/friends',
});
}
/**
* Get friend requests
* Returns a list of all users who have sent a friend request.
* @returns UserDTO Successfully retrieved friend requests
* @throws ApiError
*/
public static getFriendRequests(): CancelablePromise<Array<UserDTO>> {
return __request(OpenAPI, {
method: 'GET',
url: '/api/friends/requests',
});
}
}
<script setup lang="ts">
import { ref } from "vue";
import { ref, onMounted } from "vue";
import { useRouter } from "vue-router";
import { useUserInfoStore } from "../../stores/UserStore";
import { UserService } from "@/api";
let numberOfHistory = 6;
let cardTitles = ["Spain tour", "Food waste", "Coffee", "Concert", "New book", "Pretty clothes"]
let firstname = ref("");
let lastname = ref("");
let imageID = ref(12)
const imageUrl = ref(`http://localhost:8080/api/images/${imageID.value}`);
let firstname = ref();
let lastname = ref();
const imageUrl = ref(`../src/assets/userprofile.png`);
const router = useRouter();
const userStore = useUserInfoStore();
firstname.value = userStore.firstname;
lastname.value = userStore.lastname;
async function setupForm() {
try {
const response = await UserService.getUser();
console.log(response.firstName)
firstname.value = response.firstName;
lastname.value = response.lastName;
imageUrl.value = "http://localhost:8080/api/images/" + response.profileImage;
} catch (err) {
console.error(err)
}
}
onMounted(() => {
setupForm()
})
const toRoadmap = () => {
router.push('/');
......
......@@ -12,7 +12,7 @@ const passwordRef = ref('')
const formRef = ref()
let samePasswords = ref(true)
const iconSrc = ref('https://bootdey.com/img/Content/avatar/avatar7.png');
const iconSrc = ref('../src/assets/userprofile.png');
const fileInputRef = ref();
const handleFirstNameInputEvent = (newValue: any) => {
......@@ -36,14 +36,16 @@ const handleFileChange = (event: any) => {
};
const uploadImage = async (file: any) => {
const formData = { file: new Blob([file])}
const formData = { file: new Blob([file]) }
try {
const response = await ImageService.uploadImage({formData});
console.log('Image uploaded:', response);
const response = await ImageService.uploadImage({ formData });
iconSrc.value = "http://localhost:8080/api/images/" + response;
const updateUserPayload: UserUpdateDTO = {
profileImage: response,
};
UserService.update({ requestBody: updateUserPayload })
} catch (error) {
console.error('Failed to upload image:', error);
}
......@@ -51,13 +53,15 @@ const uploadImage = async (file: any) => {
async function setupForm() {
try {
let response = await UserService.getUser();
const response = await UserService.getUser();
console.log(response.firstName)
firstNameRef.value = response.firstName;
if (response.lastName != null) {
surnameRef.value = response.lastName;
}
console.log(response.profileImage)
iconSrc.value = "http://localhost:8080/api/images/" + response.profileImage;
} catch (err) {
console.error(err)
}
......@@ -94,10 +98,12 @@ onMounted(() => {
<hr>
<form @submit.prevent="handleSubmit" novalidate>
<div class="user-avatar">
<input type="file" ref="fileInputRef" @change="handleFileChange" accept=".jpg, .jpeg, .png" style="display: none;" />
<img :src="iconSrc" alt="User Avatar">
<input type="file" ref="fileInputRef" @change="handleFileChange" accept=".jpg, .jpeg, .png"
style="display: none;" />
<img :src="iconSrc" alt="User Avatar" style="width: 300px">
<div class="mt-2">
<button type="button" class="btn btn-primary" @click="triggerFileUpload"><img src="@/assets/icons/download.svg"> Upload Image</button>
<button type="button" class="btn btn-primary" @click="triggerFileUpload"><img
src="@/assets/icons/download.svg"> Upload Image</button>
</div>
</div>
<div class="form-group">
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment