Skip to content
This repository has been archived by the owner on Sep 29, 2024. It is now read-only.

Commit

Permalink
Merge pull request #941 from SE-TINF22B6/backend
Browse files Browse the repository at this point in the history
Hotfix: User cannot follow itself + corrected profile data endpoint
  • Loading branch information
Nahlam4 authored Jun 12, 2024
2 parents 1727e13 + 92037ef commit f5cb268
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 6 deletions.
1 change: 1 addition & 0 deletions src/main/java/de/tinf22b6/dhbwhub/mapper/UserMapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public static UserInformationProposal mapToUserInformationProposal(User user, in
return new UserInformationProposal(
user.getId(),
user.getAccount().getUsername(),
user.getAccount().getEmail(),
user.getAccount().getPicture(),
followerAmount,
user.getAge(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ public class UserInformationProposal {

private String username;

private String email;

private Picture picture;

private int amountFollower;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import java.util.Collections;
import java.util.List;
import java.util.Objects;

@Service
public class FriendshipServiceImpl implements FriendshipService {
Expand Down Expand Up @@ -52,6 +53,10 @@ public List<FriendlistProposal> getFriendlist(Long id) {

@Override
public FriendlistProposal followUser(FollowUserProposal proposal) {
if (Objects.equals(proposal.getRequesterId(), proposal.getReceiverId())) {
throw new RuntimeException("User cannot follow itself");
}

User requester = userRepository.find(proposal.getRequesterId());
if (requester == null) {
throw new NoSuchEntryException(String.format("%s with ID %d does not exist", User.class.getSimpleName(), proposal.getRequesterId()));
Expand Down
12 changes: 7 additions & 5 deletions src/main/web/src/services/ProfileDataService.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {getJWT, getUserId, getUsername} from "./AuthService";
import config from "../config/config";

interface UserData {
userId: number;
username: string;
email: string;
picture: {
Expand All @@ -27,20 +28,21 @@ export const fetchUserData = async (): Promise<UserData | null> => {
const userId: number | null = getUserId();

try {
const response: Response = await fetch(`${config.apiUrl}user/${userId}`, {
const response: Response = await fetch(`${config.apiUrl}user/user-information/${userId}`, {
headers: getHeaders()
});

if (response.ok) {
const data = await response.json();
const userData: UserData = {
username: data.account.username ?? "",
email: data.account.email ?? "",
picture: data.account.picture ? data.account.picture : { id: 0, name: '', imageData: '' },
userId: data.userId ?? 0,
username: data.username ?? "",
email: data.email ?? "",
picture: data.picture ? data.picture : { id: 0, name: '', imageData: '' },
amountFollower: data.amountFollower ?? 0,
age: data.age ?? '',
description: data.description ?? '',
course: data.course?.name ?? ''
course: data.course ?? ''
};
console.log("Successful fetching of userdata", userData);
return userData;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ protected ProfileInformationProposal createProfileInformationProposal() {
}

protected UserInformationProposal createUserInformationProposal() {
return new UserInformationProposal(1L ,"test name", createDefaultPicture(), 12, 12, "Beschreibung 1", "TINF22B6");
return new UserInformationProposal(1L ,"test name", "adsa@gmail.com", createDefaultPicture(), 12, 12, "Beschreibung 1", "TINF22B6");
}

protected UpdateAgeProposal createUpdateAgeProposal() {
Expand Down

0 comments on commit f5cb268

Please sign in to comment.