diff --git a/src/main/java/de/tinf22b6/dhbwhub/mapper/UserMapper.java b/src/main/java/de/tinf22b6/dhbwhub/mapper/UserMapper.java index d847e263..c3b2cc9f 100644 --- a/src/main/java/de/tinf22b6/dhbwhub/mapper/UserMapper.java +++ b/src/main/java/de/tinf22b6/dhbwhub/mapper/UserMapper.java @@ -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(), diff --git a/src/main/java/de/tinf22b6/dhbwhub/proposal/simplified_models/UserInformationProposal.java b/src/main/java/de/tinf22b6/dhbwhub/proposal/simplified_models/UserInformationProposal.java index fd488e95..f03a8c07 100644 --- a/src/main/java/de/tinf22b6/dhbwhub/proposal/simplified_models/UserInformationProposal.java +++ b/src/main/java/de/tinf22b6/dhbwhub/proposal/simplified_models/UserInformationProposal.java @@ -15,6 +15,8 @@ public class UserInformationProposal { private String username; + private String email; + private Picture picture; private int amountFollower; diff --git a/src/main/java/de/tinf22b6/dhbwhub/service/FriendshipServiceImpl.java b/src/main/java/de/tinf22b6/dhbwhub/service/FriendshipServiceImpl.java index 066ff9ab..bd609061 100644 --- a/src/main/java/de/tinf22b6/dhbwhub/service/FriendshipServiceImpl.java +++ b/src/main/java/de/tinf22b6/dhbwhub/service/FriendshipServiceImpl.java @@ -17,6 +17,7 @@ import java.util.Collections; import java.util.List; +import java.util.Objects; @Service public class FriendshipServiceImpl implements FriendshipService { @@ -52,6 +53,10 @@ public List 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())); diff --git a/src/main/web/src/services/ProfileDataService.tsx b/src/main/web/src/services/ProfileDataService.tsx index d5d74b86..a0182d5d 100644 --- a/src/main/web/src/services/ProfileDataService.tsx +++ b/src/main/web/src/services/ProfileDataService.tsx @@ -2,6 +2,7 @@ import {getJWT, getUserId, getUsername} from "./AuthService"; import config from "../config/config"; interface UserData { + userId: number; username: string; email: string; picture: { @@ -27,20 +28,21 @@ export const fetchUserData = async (): Promise => { 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; diff --git a/src/test/java/de/tinf22b6/dhbwhub/AbstractApplicationTest.java b/src/test/java/de/tinf22b6/dhbwhub/AbstractApplicationTest.java index df86a49b..b408c8bd 100644 --- a/src/test/java/de/tinf22b6/dhbwhub/AbstractApplicationTest.java +++ b/src/test/java/de/tinf22b6/dhbwhub/AbstractApplicationTest.java @@ -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() {