Skip to content

Commit

Permalink
Creating Insituicao route
Browse files Browse the repository at this point in the history
  • Loading branch information
ailtonbsj committed Aug 29, 2022
1 parent 34e0ce4 commit 2f7370c
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 1 deletion.
67 changes: 67 additions & 0 deletions src/main/java/ailtonbsj/sauteweb/sauteapi/model/Instituicao.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package ailtonbsj.sauteweb.sauteapi.model;

import java.time.LocalDate;
import java.time.LocalDateTime;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Embedded;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.PrePersist;

import com.fasterxml.jackson.annotation.JsonFormat;

import lombok.Getter;
import lombok.Setter;

@Entity
@Setter
@Getter
public class Instituicao {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
Long id;

String instituicao;

@ManyToOne(cascade = CascadeType.DETACH)
NivelEscolar nivelEscolar;

@Embedded
Endereco endereco;

String email;

String dependencia;

String entidade;

String credenciamento;

@JsonFormat(pattern = "yyyy-MM-dd")
LocalDate validadeCredenciamento;

String recredenciamento;

@JsonFormat(pattern = "yyyy-MM-dd")
LocalDate validadeRecredenciamento;

@Column(nullable = false)
@JsonFormat(pattern = "yyyy-MM-dd'T'HH:mm")
private LocalDateTime createdAt;

@Column(nullable = false)
@JsonFormat(pattern = "yyyy-MM-dd'T'HH:mm")
private LocalDateTime updatedAt;

@PrePersist
public void beforeSave() {
LocalDateTime now = LocalDateTime.now();
setCreatedAt(now);
setUpdatedAt(now);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package ailtonbsj.sauteweb.sauteapi.repository;

import org.springframework.data.jpa.repository.JpaRepository;

import ailtonbsj.sauteweb.sauteapi.model.Instituicao;

public interface InstituicaoRepository extends JpaRepository<Instituicao, Long> {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package ailtonbsj.sauteweb.sauteapi.rest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import ailtonbsj.sauteweb.sauteapi.model.Instituicao;
import ailtonbsj.sauteweb.sauteapi.repository.InstituicaoRepository;

@RestController
@RequestMapping("/instituicao")
public class InstituicaoController {

@Autowired
private InstituicaoRepository rep;

public Instituicao save(@RequestBody Instituicao instituicao) {
return rep.save(instituicao);
}
}
2 changes: 1 addition & 1 deletion src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ spring:
jpa:
show-sql: true
hibernate:
ddl-auto: update
ddl-auto: create
properties:
hibernate:
dialect: org.hibernate.dialect.MySQL8Dialect

0 comments on commit 2f7370c

Please sign in to comment.