> 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/entidades-e-mapeamento/post.md).

# Post

O Post já terá os seus atributos + o comentário e o autor do post.

Para que Posts fiquem referenciados no User conforme pode ser visto no UML, criaremos no User uma lista de posts (public), com a anotação @DBRef(lazy = true).

```java
@Document(collection = "posts") 
@Getter 
@Setter 
@NoArgsConstructor 
public class Post {
    @Id
    private String id;
    private Instant moment;
    private String title;
    private String body;
    
    private Author author;
    
    @Setter(AccessLevel.NONE)
    private List<Comment> comments = new ArrayList<>();
    
    public Post(String id, Instant moment, String title, String body, Author author) {
        this.id = id;
        this.moment = moment;
        this.title = title;
        this.body = body;
        this.author = author;
    }
}
```

Criar também, PostRepository.
