-
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
5 changed files
with
120 additions
and
1 deletion.
There are no files selected for viewing
42 changes: 42 additions & 0 deletions
42
src/main/java/ailtonbsj/sauteweb/sauteapi/model/NivelEscolar.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,42 @@ | ||
package ailtonbsj.sauteweb.sauteapi.model; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
import javax.persistence.Column; | ||
import javax.persistence.Entity; | ||
import javax.persistence.GeneratedValue; | ||
import javax.persistence.GenerationType; | ||
import javax.persistence.Id; | ||
import javax.persistence.PrePersist; | ||
|
||
import com.fasterxml.jackson.annotation.JsonFormat; | ||
|
||
import lombok.Getter; | ||
import lombok.Setter; | ||
|
||
@Entity | ||
@Getter | ||
@Setter | ||
public class NivelEscolar { | ||
@Id | ||
@GeneratedValue(strategy = GenerationType.AUTO) | ||
private Long id; | ||
|
||
@Column | ||
private String nivelEscolar; | ||
|
||
@Column | ||
@JsonFormat(pattern = "dd/MM/yyyy HH:mm") | ||
private LocalDateTime createdAt; | ||
|
||
@Column | ||
@JsonFormat(pattern = "dd/MM/yyyy 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/NivelEscolarRepository.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.NivelEscolar; | ||
|
||
public interface NivelEscolarRepository extends JpaRepository<NivelEscolar, Long> { | ||
} |
58 changes: 58 additions & 0 deletions
58
src/main/java/ailtonbsj/sauteweb/sauteapi/rest/NivelEscolarController.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,58 @@ | ||
package ailtonbsj.sauteweb.sauteapi.rest; | ||
|
||
import java.time.LocalDateTime; | ||
import java.util.List; | ||
|
||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.http.HttpStatus; | ||
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.NivelEscolar; | ||
import ailtonbsj.sauteweb.sauteapi.repository.NivelEscolarRepository; | ||
|
||
@RestController | ||
@RequestMapping("/api/nivelescolar") | ||
public class NivelEscolarController { | ||
|
||
@Autowired | ||
private NivelEscolarRepository repository; | ||
|
||
@GetMapping | ||
public List<NivelEscolar> index() { | ||
return repository.findAll(); | ||
} | ||
|
||
@PostMapping | ||
public NivelEscolar store(@RequestBody NivelEscolar nivelEscolar) { | ||
return repository.save(nivelEscolar); | ||
} | ||
|
||
@GetMapping("{id}") | ||
public NivelEscolar show(@PathVariable Long id) { | ||
return repository.findById(id).orElseThrow( | ||
() -> new ResponseStatusException(HttpStatus.NOT_FOUND)); | ||
} | ||
|
||
@PatchMapping | ||
public NivelEscolar update(@RequestBody NivelEscolar nivelEscolar) { | ||
NivelEscolar ent = repository.findById(nivelEscolar.getId()).orElseThrow( | ||
() -> new ResponseStatusException(HttpStatus.NOT_FOUND)); | ||
ent.setNivelEscolar(nivelEscolar.getNivelEscolar()); | ||
ent.setUpdatedAt(LocalDateTime.now()); | ||
return repository.save(ent); | ||
} | ||
|
||
@DeleteMapping("{id}") | ||
public void destroy(@PathVariable Long id) { | ||
repository.deleteById(id); | ||
} | ||
|
||
} |
This file was deleted.
Oops, something went wrong.
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,12 @@ | ||
spring: | ||
datasource: | ||
url: jdbc:mysql://localhost:3306/saute | ||
username: root | ||
password: YOUR_PASS | ||
jpa: | ||
show-sql: true | ||
hibernate: | ||
ddl-auto: update | ||
properties: | ||
hibernate: | ||
dialect: org.hibernate.dialect.MySQL8Dialect |