Skip to content

Commit

Permalink
Documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
akingeniero committed Mar 24, 2023
1 parent 73ecd7b commit 0401151
Show file tree
Hide file tree
Showing 4 changed files with 228 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
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 app.security.jwt.AuthResponse;
import app.security.jwt.LoginRequest;
Expand All @@ -23,7 +28,12 @@ public class LoginRestController {

@Autowired
private UserLoginService userService;

@Operation(summary = "Login")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "Login successful", content = {
@Content(mediaType = "application/json", schema = @Schema(implementation = AuthResponse.class)) }),
@ApiResponse(responseCode = "400", description = "Bad request", content = @Content),
@ApiResponse(responseCode = "401", description = "Unauthorized", content = @Content) })
@PostMapping("/login")
public ResponseEntity<AuthResponse> login(
@CookieValue(name = "accessToken", required = false) String accessToken,
Expand All @@ -32,7 +42,11 @@ public ResponseEntity<AuthResponse> login(

return userService.login(loginRequest, accessToken, refreshToken);
}

@Operation(summary = "Logout")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "Logout successful", content = {
@Content(mediaType = "application/json", schema = @Schema(implementation = AuthResponse.class)) }),
@ApiResponse(responseCode = "400", description = "Bad request", content = @Content)})
@PostMapping("/logout")
public ResponseEntity<AuthResponse> logOut(HttpServletRequest request, HttpServletResponse response) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,13 @@ public class GameRestController {

@Autowired
private ReviewService reviewService;

@Operation(summary = "Get a page of games")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "Found the games",
content = { @Content(mediaType = "application/json",
schema = @Schema(implementation = Game.class)) }),
@ApiResponse(responseCode = "404", description = "Games not found",
content = @Content) })
@GetMapping("/")
public ResponseEntity<Page<Game>> getGames() {
Page<Game> findGames = gameService.findGames(PageRequest.of(0, 6));
Expand All @@ -51,12 +57,24 @@ public ResponseEntity<Page<Game>> getGames() {
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
}
}

@Operation(summary = "Get more games")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "Found the games",
content = { @Content(mediaType = "application/json",
schema = @Schema(implementation = Game.class)) }),
@ApiResponse(responseCode = "404", description = "Games not found",
content = @Content) })
@GetMapping("/moreIndexGames/{page}")
public Page<Game> getMoreIndexGames(@PathVariable int page) {
return gameService.getMoreIndexGames(page);
}

@Operation(summary = "Get a page of games by name or category")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "Found the games by name or category",
content = { @Content(mediaType = "application/json",
schema = @Schema(implementation = Game.class)) }),
@ApiResponse(responseCode = "404", description = "Games not found",
content = @Content) })
@GetMapping("/search")
public ResponseEntity<Page<Game>> search(String name, String category) {
Page<Game> searchGames = gameService.getSearchGames(0, name, category);
Expand All @@ -66,7 +84,13 @@ public ResponseEntity<Page<Game>> search(String name, String category) {
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
}
}

@Operation(summary = "Get more games by name or category")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "Found the games by name or category",
content = { @Content(mediaType = "application/json",
schema = @Schema(implementation = Game.class)) }),
@ApiResponse(responseCode = "404", description = "Games not found",
content = @Content) })
@GetMapping("/moreFoundGames/{page}")
public Page<Game> getMoreFoundGames(@PathVariable int page, String category, String name) {
return gameService.getSearchGames(page, name, category);
Expand All @@ -83,7 +107,17 @@ public ResponseEntity<Game> newGameProcess(Game game, MultipartFile imageField,
URI location = fromCurrentRequest().path("/{id}").buildAndExpand(game.getId()).toUri();
return ResponseEntity.created(location).body(saveNewGame);
}

@Operation(summary = "Get a game by its id")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "Found the game",
content = { @Content(mediaType = "application/json",
schema = @Schema(implementation = GameDetails.class)) }),
@ApiResponse(responseCode = "400", description = "Invalid id supplied",
content = @Content),
@ApiResponse(responseCode = "404", description = "Game not found",
content = @Content),
@ApiResponse(responseCode = "401", description = "Unauthorized",
content = @Content)})
@GetMapping("/{id}")
public ResponseEntity<GameDetails> gameDetails(@PathVariable long id) {
Optional<Game> opGame = gameService.findById(id);
Expand All @@ -95,25 +129,61 @@ public ResponseEntity<GameDetails> gameDetails(@PathVariable long id) {
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
}
}

@Operation(summary = "Delete a game")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "Game deleted",
content = { @Content(mediaType = "application/json",
schema = @Schema(implementation = Game.class)) }),
@ApiResponse(responseCode = "400", description = "Invalid id supplied",
content = @Content),
@ApiResponse(responseCode = "404", description = "Game not found",
content = @Content),
@ApiResponse(responseCode = "401", description = "Unauthorized",
content = @Content) })
// Delete a game
@DeleteMapping("/{id}")
public ResponseEntity<Game> deleteGame(@PathVariable long id) {
return gameService.deleteById(id);
}

@Operation(summary = "Edit a game")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "Game edited",
content = { @Content(mediaType = "application/json",
schema = @Schema(implementation = Game.class)) }),
@ApiResponse(responseCode = "400", description = "Invalid id supplied",
content = @Content),
@ApiResponse(responseCode = "404", description = "Game not found",
content = @Content),
@ApiResponse(responseCode = "401", description = "Unauthorized",
content = @Content) })
// Edit a game
@PutMapping("/{id}")
public ResponseEntity<Game> editGame(Game game, MultipartFile imageField, List<MultipartFile> imageFields,
@PathVariable long id) throws IOException, SQLException {
return gameService.editGame(id, game, imageField, imageFields);
}

@Operation(summary = "Get the cover image of a game")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "Found the cover image",
content = { @Content(mediaType = "application/json",
schema = @Schema(implementation = Game.class)) }),
@ApiResponse(responseCode = "400", description = "Invalid id supplied",
content = @Content),
@ApiResponse(responseCode = "404", description = "Cover not found",
content = @Content) })
@GetMapping("/{id}/coverImage")
public ResponseEntity<Resource> downloadImageProfile(@PathVariable long id) throws SQLException {
return gameService.downloadImageProfile(id);
}

@Operation(summary = "Get the gameplay images of a game")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "Found the gameplay images",
content = { @Content(mediaType = "application/json",
schema = @Schema(implementation = Game.class)) }),
@ApiResponse(responseCode = "400", description = "Invalid id supplied",
content = @Content),
@ApiResponse(responseCode = "404", description = "Gameplay images not found",
content = @Content) })
@GetMapping("/{id}/gameplayImage/{index}")
public ResponseEntity<Resource> downloadGameplayImages(@PathVariable long id, @PathVariable int index)
throws SQLException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import static org.springframework.web.servlet.support.ServletUriComponentsBuilder.fromCurrentRequest;
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 app.model.Game;
import app.model.User;
Expand All @@ -37,7 +42,11 @@ public class ReviewRestController {

@Autowired
private UserService userService;

@Operation(summary = "Get more reviews of a game")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "More reviews", content = {
@Content(mediaType = "application/json", schema = @Schema(implementation = Review.class)) }),
@ApiResponse(responseCode = "404", description = "Game not found", content = @Content) })
@GetMapping("/more/{id}/{page}")
public Page<Review> getMoreReviews(@PathVariable int page, @PathVariable long id) {
// Before returning a page it confirms that there are more left
Expand All @@ -47,7 +56,13 @@ public Page<Review> getMoreReviews(@PathVariable int page, @PathVariable long id
}
return null;
}

@Operation(summary = "Add a review to a game")
@ApiResponses(value = {
@ApiResponse(responseCode = "201", description = "Review added", content = {
@Content(mediaType = "application/json", schema = @Schema(implementation = Review.class)) }),
@ApiResponse(responseCode = "400", description = "Bad request", content = @Content),
@ApiResponse(responseCode = "404", description = "Game not found", content = @Content),
@ApiResponse(responseCode = "409", description = "User already reviewed this game", content = @Content) })
@PostMapping("/{gameId}/{userId}")
public ResponseEntity<Review> addReview(@PathVariable long gameId, @PathVariable long userId,
HttpServletRequest request, String comment, int reviewRate) {
Expand All @@ -69,7 +84,14 @@ public ResponseEntity<Review> addReview(@PathVariable long gameId, @PathVariable
return new ResponseEntity<>(HttpStatus.FORBIDDEN);
}
}

@Operation(summary = "Delete a review")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "Review deleted", content = {
@Content(mediaType = "application/json", schema = @Schema(implementation = Review.class)) }),
@ApiResponse(responseCode = "400", description = "Bad request", content = @Content),
@ApiResponse(responseCode = "404", description = "Review not found", content = @Content),
@ApiResponse(responseCode = "401", description = "Unauthorized",
content = @Content) })
@DeleteMapping("/{reviewId}")
public ResponseEntity<Review> deleteReview(@PathVariable long reviewId,
HttpServletRequest request) {
Expand All @@ -80,7 +102,12 @@ public ResponseEntity<Review> deleteReview(@PathVariable long reviewId,
return null;
}
}

@Operation(summary = "Get a review")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "Review", content = {
@Content(mediaType = "application/json", schema = @Schema(implementation = Review.class)) }),
@ApiResponse(responseCode = "404", description = "Review not found", content = @Content) })

@GetMapping("/{id}")
public ResponseEntity<Review> getReview(@PathVariable long id) {
// Before returning a page it confirms that there are more left
Expand Down
Loading

0 comments on commit 0401151

Please sign in to comment.