@@ -43,6 +43,12 @@ public FriendService(FriendsRepository friendsRepository,
4343
4444 public String sendFriendRequest (String userEmail , String friendEmail ) {
4545
46+ if (userEmail == null || userEmail .isBlank ())
47+ throw new RuntimeException ("UserEmail is required" );
48+
49+ if (friendEmail == null || friendEmail .isBlank ())
50+ throw new RuntimeException ("FriendEmail is required" );
51+
4652 if (userEmail .equalsIgnoreCase (friendEmail )) {
4753 return "You cannot send a friend request to yourself." ;
4854 }
@@ -76,6 +82,13 @@ public String sendFriendRequest(String userEmail, String friendEmail) {
7682 }
7783
7884 public String respondFriendRequest (String userEmail , String requesterEmail , boolean accept ) {
85+
86+ if (userEmail == null || userEmail .isBlank ())
87+ throw new RuntimeException ("UserEmail is required" );
88+
89+ if (requesterEmail == null || requesterEmail .isBlank ())
90+ throw new RuntimeException ("RequesterEmail is required" );
91+
7992 if (userEmail .equalsIgnoreCase (requesterEmail )) {
8093 return "Invalid operation." ;
8194 }
@@ -133,6 +146,10 @@ public String respondFriendRequest(String userEmail, String requesterEmail, bool
133146 }
134147
135148 public List <UserOutput > getFriends (String userEmail ) {
149+
150+ if (userEmail == null || userEmail .isBlank ())
151+ throw new RuntimeException ("UserEmail is required" );
152+
136153 User user = userRepository .findByEmail (userEmail ).orElseThrow (() -> new RuntimeException ("User not found" ));
137154
138155 List <Friends > sent = friendsRepository .findByUserAndStatus (user , "accepted" );
@@ -148,8 +165,7 @@ public List<UserOutput> getFriends(String userEmail) {
148165 f .getEmail (),
149166 preview
150167 );
151- })
152- .collect (Collectors .toList ());
168+ }).collect (Collectors .toList ());
153169
154170 friendsList .addAll (received .stream ()
155171 .map (friend -> {
@@ -161,13 +177,19 @@ public List<UserOutput> getFriends(String userEmail) {
161177 f .getEmail (),
162178 preview
163179 );
164- })
165- .toList ());
180+ }).toList ());
166181
167182 return friendsList ;
168183 }
169184
170185 public String blockFriend (String userEmail , String friendEmail ) {
186+
187+ if (userEmail == null || userEmail .isBlank ())
188+ throw new RuntimeException ("UserEmail is required" );
189+
190+ if (friendEmail == null || friendEmail .isBlank ())
191+ throw new RuntimeException ("FriendEmail is required" );
192+
171193 if (userEmail .equalsIgnoreCase (friendEmail )) {
172194 return "You cannot block yourself." ;
173195 }
@@ -191,6 +213,10 @@ public String blockFriend(String userEmail, String friendEmail) {
191213
192214
193215 public List <UserOutput > getIncomingPendingRequests (String userEmail ) {
216+
217+ if (userEmail == null || userEmail .isBlank ())
218+ throw new RuntimeException ("UserEmail is required" );
219+
194220 User user = userRepository .findByEmail (userEmail )
195221 .orElseThrow (() -> new RuntimeException ("User not found" ));
196222
@@ -207,6 +233,10 @@ public List<UserOutput> getIncomingPendingRequests(String userEmail) {
207233 }
208234
209235 public List <UserOutput > getOutgoingPendingRequests (String userEmail ) {
236+
237+ if (userEmail == null || userEmail .isBlank ())
238+ throw new RuntimeException ("UserEmail is required" );
239+
210240 User user = userRepository .findByEmail (userEmail )
211241 .orElseThrow (() -> new RuntimeException ("User not found" ));
212242
@@ -217,12 +247,19 @@ public List<UserOutput> getOutgoingPendingRequests(String userEmail) {
217247 f .getFriend ().getId (),
218248 f .getFriend ().getUsername (),
219249 f .getFriend ().getEmail (),
220- f .getUser ().getAvatarUrl ()
250+ f .getFriend ().getAvatarUrl ()
221251 ))
222252 .collect (Collectors .toList ());
223253 }
224254
225255 public String unblockUser (String userEmail , String blockedUserEmail ) {
256+
257+ if (userEmail == null || userEmail .isBlank ())
258+ throw new RuntimeException ("UserEmail is required" );
259+
260+ if (blockedUserEmail == null || blockedUserEmail .isBlank ())
261+ throw new RuntimeException ("BlockedUserEmail is required" );
262+
226263 if (userEmail .equalsIgnoreCase (blockedUserEmail )) {
227264 return "You cannot unblock yourself." ;
228265 }
@@ -242,9 +279,12 @@ public String unblockUser(String userEmail, String blockedUserEmail) {
242279 }
243280
244281 public String removeFriend (String userEmail , String friendEmail ) {
245- if (userEmail == null || friendEmail == null ) {
246- throw new RuntimeException ("Both userEmail and friendEmail are required" );
247- }
282+
283+ if (userEmail == null || userEmail .isBlank ())
284+ throw new RuntimeException ("UserEmail is required" );
285+
286+ if (friendEmail == null || friendEmail .isBlank ())
287+ throw new RuntimeException ("FriendEmail is required" );
248288
249289 if (userEmail .equalsIgnoreCase (friendEmail )) {
250290 return "Invalid operation: cannot remove yourself." ;
0 commit comments