PUT problems with Spring data JPA

Asked

Viewed 23 times

2

I’m using Controller architecture, DTO, Repositoy, Service

Use Postman to test the requests, I can do POST on User normally and when I do GET Postman returns me

{
    "id": 3,
    "nome": "Arthur",
    "cpf": "281.590.328-89",
    "cnh": "35214349616",
    "telefone": "(61) 99805-2147",
    "email": "[email protected]",
    "senha": "1234",
    "perfil": "alugador",
    "endereco": {
        "id": 3,
        "logradouro": "Quadra SHPS Quadra 502",
        "bairro": "Setor Habitacional Pôr do Sol (Ceilândia)",
        "numero": 927,
        "complemento": " ",
        "cidade": "Brasília",
        "estado": "DF"
    }
}

I do POST on Car passing User id and GET returns me:

{
    "id": 4,
    "usuarioRegistrador": {
        "id": 3,
        "nome": "Arthur",
        "cpf": "281.590.328-89",
        "cnh": "35214349616",
        "telefone": "(61) 99805-2147",
        "email": "[email protected]",
        "senha": "1234",
        "perfil": "alugador",
        "endereco": {
            "id": 3,
            "logradouro": "Quadra SHPS Quadra 502",
            "bairro": "Setor Habitacional Pôr do Sol (Ceilândia)",
            "numero": 927,
            "complemento": " ",
            "cidade": "Brasília",
            "estado": "DF"
        }
    },
    "kmsRodados": 555.0,
    "documentoCarro": "555",
    "tipoCombustivel": "55",
    "marca": "CAMARO",
    "modelo": "GOL BOLA",
    "placa": "TTT-1555",
    "valorCarro": 363636.0,
    "estaAlugado": true
}

When I do a POST on Rent, passing User id and Car id, GET returns me "carro":null

Can someone help me?

{
    "id": 7,
    "usuarioCliente": {
        "id": 3,
        "nome": "Arthur",
        "cpf": "281.590.328-89",
        "cnh": "35214349616",
        "telefone": "(61) 99805-2147",
        "email": "[email protected]",
        "senha": "1234",
        "perfil": "alugador",
        "endereco": {
            "id": 3,
            "logradouro": "Quadra SHPS Quadra 502",
            "bairro": "Setor Habitacional Pôr do Sol (Ceilândia)",
            "numero": 927,
            "complemento": " ",
            "cidade": "Brasília",
            "estado": "DF"
        }
    },
    "carro": null,
    "retirada": "2009-08-07",
    "entrega": "2019-08-04",
    "valor": 99.0
}

1 answer

1


check if in DTO, vc is passing the car public Static Rentals convertibleEntityEmDto(Rentals) { Rent dto = new Rent(); dto.setId(aluguel.getId()); dto.setEntrega(rent.getEntrega()); dto.setCarro(rental.getCarro()); dto.setUsuarioClient(rental.getUsuarioClient()); dto.setRetaken(rental.getRetaken()); dto.setValor(rental.getValor()); Return dto; }

public static Aluguel converteDtoEmEntidade(AluguelDto dto) {
    Aluguel aluguel = new Aluguel();
    aluguel.setCarro(dto.getCarro());
    aluguel.setId(dto.getId());
    aluguel.setEntrega(dto.getEntrega());
    aluguel.setRetirada(dto.getRetirada());
    aluguel.setValor(dto.getValor());
    aluguel.setUsuarioCliente(dto.getUsuarioCliente());
    return aluguel;
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.