> For the complete documentation index, see [llms.txt](https://olavo-moreira.gitbook.io/studies/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://olavo-moreira.gitbook.io/studies/workshop-mongodb/endpoints/posts/get-userpost.md).

# GET userPost

<figure><img src="/files/oTKZRPMdFq9TYbIwvQqT" 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();
}
```
