No mapping for POST. 404 Not Found

74 Views Asked by At

Please help if you have any idea why it's not working. I have been trying to test it with Postman for hours but no luck. I am trying to test my API with Postman but every time I try to send a post I get the same error, "No mapping for POST /api/v1/cont/parties".

PartyController:

package controllers;

import assemblers.PartyModelAssembler;
import dto.PartyDto;
import model.Party;
import org.modelmapper.ModelMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.hateoas.CollectionModel;
import org.springframework.hateoas.EntityModel;
import org.springframework.hateoas.IanaLinkRelations;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import services.IPartyService;

import java.util.List;

@RestController
@RequestMapping("api/v1/cont")
public class PartyController {

    @Autowired
    private ModelMapper modelMapper;

    @Autowired
    private IPartyService partyService;

    @Autowired
    private PartyModelAssembler partyModelAssembler;

    public PartyController() { super();}

    @PostMapping("/parties")
    public ResponseEntity<EntityModel<PartyDto>> newParty (@RequestBody PartyDto partyDto){
        Party partyRequest = modelMapper.map(partyDto, Party.class);
        Party newParty = partyService.createParty(partyRequest);

        EntityModel<PartyDto> partyEntityModel = partyModelAssembler
                .toModel(modelMapper.map(newParty, PartyDto.class));

        return ResponseEntity.created(partyEntityModel.getRequiredLink(IanaLinkRelations.SELF).toUri())
                .body(partyEntityModel);
    }

}

This is the Controller that has the request and the mappings.

The URL I'm using in postman is:

http://localhost:8080/api/v1/cont/parties

I double-checked the URL I'm sending in Postman and in my Controller class but still did not work.

0

There are 0 best solutions below