callicoder / spring-security-react-ant-design-polls-app

Full Stack Polls App built using Spring Boot, Spring Security, JWT, React, and Ant Design
https://www.callicoder.com/spring-boot-spring-security-jwt-mysql-react-app-part-1/
1.76k stars 1.07k forks source link

Issues testing the create poll api in postman #72

Closed Kordedekehine closed 2 years ago

Kordedekehine commented 2 years ago

As a beginner,I've been coding along the tutorial until I finished and I realize I can't test the create poll API.

The PollRequest class @Data public class PollRequestDto {

private String question;

private List<ChoiceRequestDto> choices;

private PollLengthOfTimeDto pollLength;

}

The choices class

@Data public class ChoiceRequestDto {

private String opinion;

}

The pollLenght class

@Data @NoArgsConstructor

public class PollLengthOfTimeDto {

private Integer days;

private Integer hours;

}

These is the controller code:

@PostMapping //@PreAuthorize("hasRole('USER')") public ResponseEntity<?> createPoll(@Valid @RequestBody PollRequestDto pollRequest) { Poll poll = pollService.createPoll(pollRequest);

    URI location = ServletUriComponentsBuilder
            .fromCurrentRequest().path("/{pollId}")
            .buildAndExpand(poll.getId()).toUri();

    return ResponseEntity.created(location)
            .body(new ApiResponse(true, "Poll Created Successfully"));
}

And these is how I've been testing it in the postman: Screenshot (166)

Kordedekehine commented 2 years ago

Can someone help me with this question? I can't send out the PollLength request. It's not working

Kordedekehine commented 2 years ago

SOLVED

{ "question": "Who is the next president of the country", "choices": [ { "opinion": "buhari" }, { "opinion": "atiku" }, { "opinion": "obi" } ], "pollLength": { "days": 2, "hours": 2 }

}