#Spring REST API problem

1 messages · Page 1 of 1 (latest)

silk nexusBOT
#

<@&1004656351647117403> please have a look, thanks.

feral charm
#

Thats what i got in POSTMAN http://localhost:8080/api/v1/quizzes/create-with-questions?authorId=1

#
@Slf4j
@RestController
@RequestMapping("/api/v1/quizzes")
public class QuizController {

    @Autowired
    private QuizService quizService;

    @PostMapping("/create")
    public ResponseEntity<Response> createQuiz(@RequestBody CreateQuizDTO createQuizDTO, @RequestParam int authorId) {
        Quiz newQuiz = quizService.createQuiz(createQuizDTO, authorId);
        Response response = Response.builder().data(newQuiz).build();
        return ResponseEntity.ok(response);
    }

    @PostMapping("/create-with-questions")
    public ResponseEntity<Response> createQuizWithQuestions(
            @RequestBody CreateQuizDTO createQuizDTO,
            @RequestParam int authorId,
            @RequestBody List<CreateQuestionDTO> createQuestionDTOs)
    {
        Quiz newQuiz = quizService.createQuizWithQuestions(createQuizDTO, authorId, createQuestionDTOs);
        Response response = Response.builder().data(newQuiz).build();
        return ResponseEntity.ok(response);

    }
// Some other endpoints
#

And thats the response :C

#
package com.patrykstk.javatestpro.dto;

import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@NoArgsConstructor
public class CreateAnswerDTO {
    private String text;
    private boolean correct;
}

package com.patrykstk.javatestpro.dto;

import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@NoArgsConstructor
public class CreateCodeBlockDTO {
    private String code;
}
package com.patrykstk.javatestpro.dto;

import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@NoArgsConstructor
public class CreateQuestionImageDTO {
    private byte[] imageData;
}
package com.patrykstk.javatestpro.dto;

import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.List;

@Data
@NoArgsConstructor
public class CreateQuestionDTO {
    private String text;
    private CreateCodeBlockDTO codeBlock;
    private List<CreateQuestionImageDTO> images;
    private List<CreateAnswerDTO> answers;
}
package com.patrykstk.javatestpro.dto;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.Random;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class CreateQuizDTO {
    private String title;
    private String description;
    private int timeInHours;
    private int timeInMinutes;
    private int timeInSeconds;
    private int authorId;  

    public CreateQuizDTO(String title, String description, int timeInHours, int timeInMinutes, int timeInSeconds) {
        this.title = title;
        this.description = description;
        this.timeInHours = timeInHours;
        this.timeInMinutes = timeInMinutes;
        this.timeInSeconds = timeInSeconds;
    }

    public int generateJoinCode() {
        Random random = new Random();
        int randomNumber = random.nextInt(90000000) + 10000000;
        return randomNumber;
    }
}