-
Notifications
You must be signed in to change notification settings - Fork 1
feature: add modeled classes #11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 2 commits
2a7d7db
cb362ae
c2d430d
c2c4eee
dd77918
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| package com.java.dojo.recipes.entities; | ||
|
|
||
| import javax.persistence.Entity; | ||
| import javax.persistence.Table; | ||
|
|
||
| import lombok.AllArgsConstructor; | ||
| import lombok.Builder; | ||
| import lombok.Data; | ||
| import lombok.EqualsAndHashCode; | ||
| import lombok.NoArgsConstructor; | ||
|
|
||
| @AllArgsConstructor | ||
| @NoArgsConstructor | ||
| @Data | ||
| @Entity | ||
| @Builder | ||
| @EqualsAndHashCode(of = "id") | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Por qual motivo vc usou essa annotation do equals e hash code ? Segundo o time do lombok: Will soon be marked @deprecated; use the @EqualsAndHashCode.Include annotation together with @EqualsAndHashCode(onlyExplicitlyIncluded = true). Ela usando "of" vai ser deprecada em breve,,,
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Cara não manjo muito de lombok kkk
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Não sabia disso, vou corrigir dps |
||
| @Table(name = "comment") | ||
| public class Comment { | ||
| private Long id; | ||
| private Long post_id; | ||
| private String username; | ||
| private String content; | ||
| private String data; | ||
|
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| package com.java.dojo.recipes.entities; | ||
|
|
||
| import javax.persistence.Entity; | ||
| import javax.persistence.Table; | ||
|
|
||
| import lombok.AllArgsConstructor; | ||
| import lombok.Builder; | ||
| import lombok.Data; | ||
| import lombok.EqualsAndHashCode; | ||
| import lombok.NoArgsConstructor; | ||
|
|
||
| @AllArgsConstructor | ||
| @NoArgsConstructor | ||
| @Data | ||
| @Entity | ||
| @Builder | ||
| @EqualsAndHashCode(of = "id") | ||
| @Table(name = "post") | ||
| public class Post { | ||
|
|
||
| private Long id; | ||
| private Long user_id; | ||
| private String username; | ||
| private String imageUrl; | ||
| private String title; | ||
| private String content; | ||
| private String data; | ||
|
|
||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| package com.java.dojo.recipes.entities; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
|
|
||
| import javax.persistence.Entity; | ||
|
|
||
| import lombok.AllArgsConstructor; | ||
| import lombok.Builder; | ||
| import lombok.Getter; | ||
| import lombok.Setter; | ||
|
|
||
| @Entity | ||
| @Getter | ||
| @Setter | ||
| @AllArgsConstructor | ||
| @Builder | ||
| public class Recipe { | ||
|
pedroluiznogueira marked this conversation as resolved.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. precisamos de um |
||
|
|
||
| private List<String> ingredients = new ArrayList<>(); | ||
| private List<String> preparingMode = new ArrayList<>(); | ||
|
|
||
|
Comment on lines
+26
to
+28
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| package com.java.dojo.recipes.entities; | ||
|
|
||
| import javax.persistence.Entity; | ||
| import javax.persistence.Table; | ||
|
|
||
| import lombok.AllArgsConstructor; | ||
| import lombok.Builder; | ||
| import lombok.Data; | ||
| import lombok.EqualsAndHashCode; | ||
| import lombok.NoArgsConstructor; | ||
|
|
||
| @AllArgsConstructor | ||
| @NoArgsConstructor | ||
| @Data | ||
| @Entity | ||
| @Builder | ||
| @EqualsAndHashCode(of = "id") | ||
| @Table(name = "user") | ||
| public class User { | ||
|
|
||
| private Long id; | ||
| private String name; | ||
| private String surname; | ||
| private String email; | ||
| private String password; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| spring.datasource.url=jdbc:h2:mem:testdb | ||
| spring.datasource.username=sa | ||
| spring.datasource.password= | ||
| spring.h2.console.enabled=true | ||
| spring.h2.console.path=/h2-console |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,3 @@ | ||
|
|
||
| spring.profiles.active=test | ||
| spring.jpa.open-in-view=false | ||
| spring.jpa.properties.hibernate.jdbc.time_zone=UTC |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isso serve para todas as classes:
Eu acho que a gente não deveria usar @DaTa nas entidades do JPA por que tem algumas chances de ter conflitos no futuro, essa annotation gera @tostring, @EqualsAndHashCode, @requiredargsconstructor e também @Getter e @Setter.
Tem um artigo legal falando sobre os "riscos" de algumas anotações do JPA com Lombok:
https://thorben-janssen.com/lombok-hibernate-how-to-avoid-common-pitfalls/
Em relação ao @AllArgsConstructor eu acho que a gente poderia colocar acesso private nele, visto que a gente vai usar o @builder então não vamos utilizar em outras partes da aplicação um construtor com os parametros da classes, mas o builder pattern:
@AllArgsConstructor(access = AccessLevel.PRIVATE)Eu acho que a gente pode colocar o id dessas classes pra serem auto generated, assim cada objeto salvo gera um id automaticamente... uma forma seria:
@Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id;There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bem demais Pedrão, eu também não manjo muito de utilizar o lombok mas vou correr atrás pra ficar por dentro!