Skip to content

Commit

Permalink
Add missing swagger documentation from controllers
Browse files Browse the repository at this point in the history
  • Loading branch information
Skippyoftedal committed Apr 7, 2024
1 parent 8d146f1 commit e101490
Show file tree
Hide file tree
Showing 6 changed files with 148 additions and 120 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ public class AuthenticationController {
@ApiResponse(responseCode = "500", description = "Unknown internal server error.")
})
@PostMapping("/register")
public ResponseEntity<AuthenticationDto> registerUser(@RequestBody RegistrationDto registrationDto) {
public ResponseEntity<AuthenticationDto> registerUser(
@RequestBody RegistrationDto registrationDto) {
log.info("Attempting to register user: {}", registrationDto.getUsername());
AuthenticationDto authenticationDto = authenticationService.registerUser(registrationDto);
log.info("User {} registered successfully.", registrationDto.getUsername());
Expand All @@ -71,6 +72,7 @@ public ResponseEntity<AuthenticationDto> registerUser(@RequestBody RegistrationD
schema = @Schema(implementation = AuthenticationDto.class))}
),
@ApiResponse(responseCode = "401", description = "User is unauthorized to log in"),
@ApiResponse(responseCode = "500", description = "Internal server error", content = @Content)
})
@PostMapping("/login")
public ResponseEntity<AuthenticationDto> loginUser(@RequestBody LoginRequestDto loginRequestDto) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
import edu.ntnu.idatt2105.quizapp.dto.FeedbackDto;
import edu.ntnu.idatt2105.quizapp.services.FeedbackService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
Expand Down Expand Up @@ -33,8 +35,12 @@ public class FeedbackController {
* @param feedbackDto The feedback DTO containing feedback information.
* @return ResponseEntity indicating the status of the feedback submission.
*/

@Operation(summary = "Submit user feedbacks")
@ApiResponse(responseCode = "200", description = "Feedback successfully submitted.")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "Feedback successfully submitted."),
@ApiResponse(responseCode = "500", description = "Internal server error", content = @Content)
})
@PostMapping(path = "/submit")
public ResponseEntity<Void> submitFeedback(@RequestBody FeedbackDto feedbackDto) {
log.info("Feedback received from {}.", feedbackDto.getEmail());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,11 @@ public class UserController {
* @return ResponseEntity indicating the status of the edit request.
*/
@Operation(summary = "Change user information")
@ApiResponse(responseCode = "200", description = "User information successfully updated.")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "User information successfully updated."),
@ApiResponse(responseCode = "500", description = "Unknown internal server error.", content
= @Content)
})
@PutMapping()
public ResponseEntity<Void> editUserInformation(@RequestBody EditUserDto editUserDto,
Principal principal) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import edu.ntnu.idatt2105.quizapp.model.quiz.Category;
import edu.ntnu.idatt2105.quizapp.services.quiz.CategoryService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import java.util.List;
Expand Down Expand Up @@ -35,16 +37,18 @@ public class CategoryController {
*/
@Operation(summary = "Get all possible categories")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "Successfully retrieved all categories"),
@ApiResponse(responseCode = "500", description = "Internal server error")
@ApiResponse(responseCode = "200", description = "Successfully retrieved all categories",
content = {
@Content(mediaType = "application/json",
schema = @Schema(implementation = List.class))}),
@ApiResponse(responseCode = "500", description = "Internal server error", content = @Content)
})
@GetMapping("/categories")
public ResponseEntity<List<String>> getAllCategories(
@RequestParam(defaultValue = "0") int page,
@RequestParam(defaultValue = "10") int size
) {

log.info("page: {}, size: {}", page, size);
List<String> receivedCategories =
categoryService.getAllPossibleCategories(Pageable.ofSize(size).withPage(page))
.stream()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import edu.ntnu.idatt2105.quizapp.dto.quiz.QuizAttemptDto;
import edu.ntnu.idatt2105.quizapp.services.quiz.QuizAttemptService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import java.security.Principal;
import lombok.RequiredArgsConstructor;
Expand Down Expand Up @@ -37,6 +38,7 @@ public class QuizAttemptController {
*/
@Operation(summary = "Submit quiz attempt")
@ApiResponse(responseCode = "200", description = "Attempts successfully submitted.")
@ApiResponse(responseCode = "500", description = "Internal server error", content = @Content)
@PostMapping()
public ResponseEntity<Void> submitAttempt(@RequestBody QuizAttemptDto quizAttemptDto,
Principal principal) {
Expand Down
Loading

0 comments on commit e101490

Please sign in to comment.