This file contains hidden or 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
using Faculdade.Api.Model; | |
using Microsoft.EntityFrameworkCore; | |
namespace Faculdade.Api.Data | |
{ | |
public class DataContext: DbContext | |
{ | |
public DataContext(DbContextOptions<DataContext> options) : base(options) | |
{} | |
public DbSet<Autor> Autores {get;set;} |
This file contains hidden or 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
[HttpGet] | |
public IActionResult RetornarTodosAutores() | |
{ | |
return Ok(_context.Autores.ToList()); | |
} |
This file contains hidden or 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
[HttpGet("{id}")] | |
public IActionResult RetornarAutorPorId(int id) | |
{ | |
return Ok (_context.Autores.Where(x => x.Id == id)); | |
} |
This file contains hidden or 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
FROM mcr.microsoft.com/dotnet/core/aspnet:3.0-buster-slim AS base | |
WORKDIR /app | |
FROM mcr.microsoft.com/dotnet/core/sdk:3.0-buster AS build | |
WORKDIR /src | |
COPY Faculdade.csproj /src/Faculdade.csproj | |
RUN dotnet restore | |
COPY . . | |
RUN dotnet publish -c Release -o /pub |
This file contains hidden or 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
public string ObterStringSemAcentosECaracteresEspeciais(string str) | |
{ | |
/** Troca os caracteres acentuados por não acentuados **/ | |
string[] acentos = new string[] { "ç", "Ç", "á", "é", "í", "ó", "ú", "ý", "Á", "É", "Í", "Ó", "Ú", "Ý", "à", "è", "ì", "ò", "ù", "À", "È", "Ì", "Ò", "Ù", "ã", "õ", "ñ", "ä", "ë", "ï", "ö", "ü", "ÿ", "Ä", "Ë", "Ï", "Ö", "Ü", "Ã", "Õ", "Ñ", "â", "ê", "î", "ô", "û", "Â", "Ê", "Î", "Ô", "Û" }; | |
string[] semAcento = new string[] { "c", "C", "a", "e", "i", "o", "u", "y", "A", "E", "I", "O", "U", "Y", "a", "e", "i", "o", "u", "A", "E", "I", "O", "U", "a", "o", "n", "a", "e", "i", "o", "u", "y", "A", "E", "I", "O", "U", "A", "O", "N", "a", "e", "i", "o", "u", "A", "E", "I", "O", "U" }; | |
for (int i = 0; i < acentos.Length; i++) | |
{ | |
str = str.Replace(acentos[i], semAcento[i]); | |
} |
This file contains hidden or 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
bool isCpfMurilo(string cpf) | |
{ | |
var valor = cpf.Replace(".", ""); | |
valor = valor.Replace("-", ""); | |
var igual = true; | |
for (var i = 1; i < 11 && igual; i++) | |
if (valor[i] != valor[0]) | |
igual = false; |
This file contains hidden or 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
package io.murilo.store.repository; | |
import io.murilo.store.model.Customer; | |
import org.springframework.data.jpa.repository.JpaRepository; | |
import org.springframework.data.repository.query.Param; | |
import org.springframework.data.rest.core.annotation.RepositoryRestResource; | |
import java.util.List; | |
import java.util.Optional; |
This file contains hidden or 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
package io.murilo.store.model; | |
import javax.persistence.*; | |
@Entity | |
@Table | |
public class Customer { | |
@Id | |
@GeneratedValue(strategy = GenerationType.IDENTITY) |
This file contains hidden or 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
{ | |
"_embedded": { | |
"customers": [ | |
{ | |
"_links": { | |
"self": { | |
"href": "http://localhost:8080/customer/1" | |
}, | |
"customer": { | |
"href": "http://localhost:8080/customer/1" |
This file contains hidden or 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
@Order(1) | |
@Test | |
void testPostAction() throws Exception { | |
mvc.perform(MockMvcRequestBuilders | |
.post("/customer") | |
.content(jsonString(new Customer("Antony", 12, true))) | |
.contentType(MediaType.APPLICATION_JSON)) | |
.andExpect(status().isCreated()); | |
} |