-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
133 additions
and
0 deletions.
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
src/main/java/ailtonbsj/sauteweb/sauteapi/model/Autorizacao.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package ailtonbsj.sauteweb.sauteapi.model; | ||
|
||
import javax.persistence.CascadeType; | ||
import javax.persistence.Column; | ||
import javax.persistence.Entity; | ||
import javax.persistence.ManyToOne; | ||
|
||
import lombok.Getter; | ||
import lombok.Setter; | ||
|
||
@Entity | ||
@Getter | ||
@Setter | ||
public class Autorizacao extends EntityBase { | ||
String numero; | ||
|
||
@ManyToOne(optional = false, cascade = CascadeType.DETACH) | ||
Professor professor; | ||
|
||
@ManyToOne(optional = false, cascade = CascadeType.DETACH) | ||
Processo processo; | ||
|
||
@Column(nullable = false) | ||
String referendum; | ||
} |
39 changes: 39 additions & 0 deletions
39
src/main/java/ailtonbsj/sauteweb/sauteapi/model/EntityBase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package ailtonbsj.sauteweb.sauteapi.model; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
import javax.persistence.Column; | ||
import javax.persistence.GeneratedValue; | ||
import javax.persistence.GenerationType; | ||
import javax.persistence.Id; | ||
import javax.persistence.MappedSuperclass; | ||
import javax.persistence.PrePersist; | ||
|
||
import com.fasterxml.jackson.annotation.JsonFormat; | ||
|
||
import lombok.Getter; | ||
import lombok.Setter; | ||
|
||
@MappedSuperclass | ||
@Getter | ||
@Setter | ||
public class EntityBase { | ||
@Id | ||
@GeneratedValue(strategy = GenerationType.AUTO) | ||
Long id; | ||
|
||
@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); | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
src/main/java/ailtonbsj/sauteweb/sauteapi/repository/AutorizacaoRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package ailtonbsj.sauteweb.sauteapi.repository; | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
import ailtonbsj.sauteweb.sauteapi.model.Autorizacao; | ||
|
||
public interface AutorizacaoRepository extends JpaRepository<Autorizacao, Long> { | ||
} |
61 changes: 61 additions & 0 deletions
61
src/main/java/ailtonbsj/sauteweb/sauteapi/rest/AutorizacaoController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package ailtonbsj.sauteweb.sauteapi.rest; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
import org.springframework.beans.BeanUtils; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.web.bind.annotation.CrossOrigin; | ||
import org.springframework.web.bind.annotation.DeleteMapping; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PatchMapping; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
import org.springframework.web.server.ResponseStatusException; | ||
|
||
import ailtonbsj.sauteweb.sauteapi.model.Autorizacao; | ||
import ailtonbsj.sauteweb.sauteapi.repository.AutorizacaoRepository; | ||
import ailtonbsj.sauteweb.sauteapi.utils.Utils; | ||
|
||
@RestController | ||
@RequestMapping("/api/autorizacao") | ||
@CrossOrigin("http://localhost:4200") | ||
public class AutorizacaoController { | ||
|
||
@Autowired | ||
AutorizacaoRepository rep; | ||
|
||
@PostMapping | ||
public Long save(@RequestBody Autorizacao autorizacao) { | ||
return rep.save(autorizacao).getId(); | ||
} | ||
|
||
@GetMapping | ||
public Iterable<Autorizacao> findAll() { | ||
return rep.findAll(); | ||
} | ||
|
||
@GetMapping("{id}") | ||
public Autorizacao findById(@PathVariable Long id) { | ||
return rep.findById(id).orElseThrow( | ||
() -> new ResponseStatusException(HttpStatus.NOT_FOUND)); | ||
} | ||
|
||
@PatchMapping | ||
public Long update(@RequestBody Autorizacao autorizacao) { | ||
Autorizacao ent = this.findById(autorizacao.getId()); | ||
autorizacao.setId(null); | ||
BeanUtils.copyProperties(autorizacao, ent, Utils.getNullPropertyNames(autorizacao)); | ||
ent.setUpdatedAt(LocalDateTime.now()); | ||
return rep.save(ent).getId(); | ||
} | ||
|
||
@DeleteMapping("{id}") | ||
public void deleteById(@PathVariable Long id) { | ||
rep.deleteById(id); | ||
} | ||
|
||
} |