Skip to content

Instantly share code, notes, and snippets.

View httpmurilo's full-sized avatar
💭
I may be slow to respond.

Murilo httpmurilo

💭
I may be slow to respond.
View GitHub Profile
@httpmurilo
httpmurilo / ControllerCustomerTests.java
Created January 22, 2022 20:25
ControllerCustomerTests
@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());
}
@httpmurilo
httpmurilo / Hateoas.json
Created January 22, 2022 19:54
Retorno
{
"_embedded": {
"customers": [
{
"_links": {
"self": {
"href": "http://localhost:8080/customer/1"
},
"customer": {
"href": "http://localhost:8080/customer/1"
@httpmurilo
httpmurilo / Customer.java
Created January 22, 2022 19:50
Customer
package io.murilo.store.model;
import javax.persistence.*;
@Entity
@Table
public class Customer {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@httpmurilo
httpmurilo / CustomerRepository.java
Created January 22, 2022 19:49
CustomerRepository
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;
@httpmurilo
httpmurilo / class.cs
Created September 11, 2020 12:05
Valida Cpf
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;
@httpmurilo
httpmurilo / class.cs
Created August 13, 2020 16:22
Limpar acentos especiais
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]);
}
@httpmurilo
httpmurilo / Dockerfile
Created July 3, 2020 15:33
Dockerfile ASP.NET Core
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
[HttpGet("{id}")]
public IActionResult RetornarAutorPorId(int id)
{
return Ok (_context.Autores.Where(x => x.Id == id));
}
[HttpGet]
public IActionResult RetornarTodosAutores()
{
return Ok(_context.Autores.ToList());
}
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;}