-
Notifications
You must be signed in to change notification settings - Fork 8
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
Desafio Finalizado #1
base: main
Are you sure you want to change the base?
Conversation
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.
Parabéns pela entrega! 👏 🚀
@PostMapping | ||
public String salvar(@Valid ReceitaForm receitaForm, BindingResult result, RedirectAttributes attributes) { | ||
if (result.hasErrors()) { | ||
return "cadastro-receita"; |
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.
Retornar algum tipo de erro informando o que houve de errado seria uma alternativa melhor
|
||
@PostMapping | ||
public String salvar(@Valid ReceitaForm receitaForm, BindingResult result, RedirectAttributes attributes) { | ||
if (result.hasErrors()) { |
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.
Legal usar o BindingResult
import java.util.List; | ||
|
||
@Data | ||
@NoArgsConstructor |
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.
Se vc não tem um outro construtor definido, não precisa do @NoArgsConstructor
@Data | ||
@NoArgsConstructor | ||
public class ReceitaForm { | ||
@NotNull @NotEmpty |
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.
Tem uma @NotBlank
para esse caso
@NotNull @Min(1) @Max(50) | ||
private Integer rendimento; | ||
|
||
@NotEmpty |
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.
Para validar os elementos internos vc pode usar o @Valid
aqui
@NoArgsConstructor | ||
public class Ingredientes { | ||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) |
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.
mantenha o padrão de quebrar uma linha entre os atributos, fica mais legível
private Medida medida; | ||
|
||
public Ingredientes(String nome, Integer quantidade, Medida medida) { | ||
setNome(nome); |
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.
bom reaproveitamento dos setters 👍
@GeneratedValue(strategy = javax.persistence.GenerationType.IDENTITY) | ||
private Long id; | ||
private String nome; | ||
@Lob |
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.
Geralmente se usa essa annotation para gravar um arquivo mesmo, não o link para o arquivo. Está geralmente associado a um byte[]
private Integer rendimento; | ||
@OneToMany(cascade = CascadeType.ALL) | ||
private List<Ingredientes> ingredientes; | ||
private LocalDateTime dataPublicacao = LocalDateTime.now(); |
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.
vc pode usar a annotation @CreationTimestamp
} | ||
} | ||
|
||
|
||
function isValid(nome, quantidade, medida) { | ||
return nome != "" && nome != null && quantidade >= 1 && quantidade <= 1000 && medida != "Selecione um tipo de medida..."; |
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.
o ideal seria utilizar um form validation e mostrar ao usuário onde ele está errando
No description provided.