Skip to content
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

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Open

Desafio Finalizado #1

wants to merge 10 commits into from

Conversation

Jand-S
Copy link

@Jand-S Jand-S commented Dec 1, 2021

No description provided.

Copy link

@gcestaro gcestaro left a 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";
Copy link

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()) {
Copy link

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
Copy link

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
Copy link

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
Copy link

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)
Copy link

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);
Copy link

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
Copy link

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();
Copy link

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...";
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants