Skip to content

Commit 29542ae

Browse files
Tariq HookTariq Hook
Tariq Hook
authored and
Tariq Hook
committed
updates
1 parent 24e7dcb commit 29542ae

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

WaterTrackerAPI/src/main/java/com/codedifferently/watertrackerapi/domain/userProfiles/controllers/UserProfileController.java

+7
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,13 @@ public ResponseEntity<Iterable<UserProfileDTO>> getFollowers(@PathVariable("id")
6565
return new ResponseEntity<>(followers, HttpStatus.OK);
6666
}
6767

68+
@GetMapping("{id}/following")
69+
public ResponseEntity<Iterable<UserProfileDTO>> getFollowing(@PathVariable("id") String userId){
70+
Iterable<UserProfileDTO> following = userProfileService.getFollowing(userId);
71+
return new ResponseEntity<>(following, HttpStatus.OK);
72+
}
73+
74+
6875
@PostMapping("follow")
6976
public ResponseEntity follow(@RequestBody Map<String,String> data){
7077
String userId = data.get("userId");

WaterTrackerAPI/src/main/java/com/codedifferently/watertrackerapi/domain/userProfiles/services/UserProfileService.java

+2
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,6 @@ public interface UserProfileService {
1717
void follow(String userId, String followerId) throws ResourceNotFoundException;
1818
void unfollow(String userId, String followerId) throws ResourceNotFoundException;
1919
Iterable<UserProfileDTO> getFollowers(String id) throws ResourceNotFoundException;
20+
Iterable<UserProfileDTO> getFollowing(String id) throws ResourceNotFoundException;
2021
}
22+

WaterTrackerAPI/src/main/java/com/codedifferently/watertrackerapi/domain/userProfiles/services/UserProfileServiceImpl.java

+7-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import lombok.extern.slf4j.Slf4j;
1111
import org.springframework.beans.factory.annotation.Autowired;
1212
import org.springframework.stereotype.Service;
13-
1413
import java.util.ArrayList;
1514
import java.util.List;
1615
import java.util.Optional;
@@ -110,6 +109,13 @@ public Iterable<UserProfileDTO> getFollowers(String id) throws ResourceNotFoundE
110109
return convertToDtoList(followers);
111110
}
112111

112+
@Override
113+
public Iterable<UserProfileDTO> getFollowing(String id) throws ResourceNotFoundException {
114+
UserProfile user = retrieveById(id);
115+
Set<UserProfile> following = user.getFollowing();
116+
return convertToDtoList(following);
117+
}
118+
113119
private Iterable<UserProfileDTO> convertToDtoList(Iterable<UserProfile> profiles){
114120
List<UserProfileDTO> userProfileDTOS = new ArrayList<>();
115121
for (UserProfile userProfile:profiles) {

0 commit comments

Comments
 (0)