# GET userPost

<figure><img src="https://406443198-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fo9WUNENo2kA7OHYOg3Tr%2Fuploads%2Fc36SU1KBSGBClJyjB21j%2Fimage.png?alt=media&#x26;token=887cdd6a-2e46-488e-82a1-0d5484195cd5" alt=""><figcaption></figcaption></figure>

**Controller**

```java
@GetMapping(value = "/{id}/posts")
public ResponseEntity<List<PostDTO>> getUserPosts(@PathVariable String id) {
    List<PostDTO> obj = userService.getUsersPosts(id);
    return ResponseEntity.ok().body(obj);
}
```

**Service**

```java
public List<PostDTO> getUsersPosts(String id) {
    User user = getEntityById(id);
    return user.getPosts().stream()
            .map(PostDTO::new).toList();
}
```
