Add the /api prefix to the Swagger endpoints so it works correctly behind the internal Nginx. (#1418)
This commit is contained in:
@@ -2,9 +2,12 @@ package com.adityachandel.booklore.config;
|
||||
|
||||
import io.swagger.v3.oas.models.Components;
|
||||
import io.swagger.v3.oas.models.OpenAPI;
|
||||
import io.swagger.v3.oas.models.info.Contact;
|
||||
import io.swagger.v3.oas.models.info.Info;
|
||||
import io.swagger.v3.oas.models.info.License;
|
||||
import io.swagger.v3.oas.models.security.SecurityRequirement;
|
||||
import io.swagger.v3.oas.models.security.SecurityScheme;
|
||||
import io.swagger.v3.oas.models.servers.Server;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@@ -16,7 +19,18 @@ public class OpenApiConfig {
|
||||
final String securitySchemeName = "bearerAuth";
|
||||
|
||||
return new OpenAPI()
|
||||
.info(new Info().title("Booklore API").version("1.0"))
|
||||
.info(new Info()
|
||||
.title("Booklore API")
|
||||
.version("1.0")
|
||||
.description("Booklore is a personal library management system. This API allows you to manage books, libraries, users, shelves, and more.")
|
||||
.contact(new Contact()
|
||||
.name("Booklore")
|
||||
.url("https://github.com/booklore-app/booklore"))
|
||||
.license(new License()
|
||||
.name("GNU General Public License v3.0")
|
||||
.url("https://www.gnu.org/licenses/gpl-3.0.html"))
|
||||
)
|
||||
.addServersItem(new Server().url("/").description("Current server"))
|
||||
.addSecurityItem(new SecurityRequirement().addList(securitySchemeName))
|
||||
.components(new Components().addSecuritySchemes(securitySchemeName,
|
||||
new SecurityScheme()
|
||||
|
||||
+3
-3
@@ -42,9 +42,9 @@ public class SecurityConfig {
|
||||
private final AppProperties appProperties;
|
||||
|
||||
private static final String[] SWAGGER_ENDPOINTS = {
|
||||
"/swagger-ui.html",
|
||||
"/swagger-ui/**",
|
||||
"/v3/api-docs/**"
|
||||
"/api/v1/swagger-ui.html",
|
||||
"/api/v1/swagger-ui/**",
|
||||
"/api/v1/api-docs/**"
|
||||
};
|
||||
|
||||
private static final String[] COMMON_PUBLIC_ENDPOINTS = {
|
||||
|
||||
+15
-1
@@ -5,11 +5,17 @@ import com.adityachandel.booklore.model.dto.settings.AppSettings;
|
||||
import com.adityachandel.booklore.model.dto.settings.SettingRequest;
|
||||
import com.adityachandel.booklore.service.appsettings.AppSettingService;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import io.swagger.v3.oas.annotations.responses.ApiResponse;
|
||||
import io.swagger.v3.oas.annotations.responses.ApiResponses;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Tag(name = "App Settings", description = "Endpoints for retrieving and updating application settings")
|
||||
@AllArgsConstructor
|
||||
@RestController
|
||||
@RequestMapping("/api/v1/settings")
|
||||
@@ -17,13 +23,21 @@ public class AppSettingController {
|
||||
|
||||
private final AppSettingService appSettingService;
|
||||
|
||||
@Operation(summary = "Get application settings", description = "Retrieve all application settings.")
|
||||
@ApiResponse(responseCode = "200", description = "Application settings returned successfully")
|
||||
@GetMapping
|
||||
public AppSettings getAppSettings() {
|
||||
return appSettingService.getAppSettings();
|
||||
}
|
||||
|
||||
@Operation(summary = "Update application settings", description = "Update one or more application settings.")
|
||||
@ApiResponses({
|
||||
@ApiResponse(responseCode = "200", description = "Settings updated successfully"),
|
||||
@ApiResponse(responseCode = "400", description = "Invalid request")
|
||||
})
|
||||
@PutMapping
|
||||
public void updateSettings(@RequestBody List<SettingRequest> settingRequests) throws JsonProcessingException {
|
||||
public void updateSettings(
|
||||
@Parameter(description = "List of settings to update") @RequestBody List<SettingRequest> settingRequests) throws JsonProcessingException {
|
||||
for (SettingRequest settingRequest : settingRequests) {
|
||||
AppSettingKey key = AppSettingKey.valueOf(settingRequest.getName());
|
||||
appSettingService.updateSetting(key, settingRequest.getValue());
|
||||
|
||||
+28
-4
@@ -7,6 +7,11 @@ import com.adityachandel.booklore.model.dto.UserCreateRequest;
|
||||
import com.adityachandel.booklore.model.dto.request.RefreshTokenRequest;
|
||||
import com.adityachandel.booklore.model.dto.request.UserLoginRequest;
|
||||
import com.adityachandel.booklore.service.user.UserProvisioningService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import io.swagger.v3.oas.annotations.responses.ApiResponse;
|
||||
import io.swagger.v3.oas.annotations.responses.ApiResponses;
|
||||
import jakarta.validation.Valid;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@@ -17,6 +22,7 @@ import org.springframework.web.bind.annotation.*;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
@Tag(name = "Authentication", description = "Endpoints for user authentication, registration, and token management")
|
||||
@Slf4j
|
||||
@AllArgsConstructor
|
||||
@RestController
|
||||
@@ -27,25 +33,43 @@ public class AuthenticationController {
|
||||
private final UserProvisioningService userProvisioningService;
|
||||
private final AuthenticationService authenticationService;
|
||||
|
||||
@Operation(summary = "Register a new user", description = "Register a new user. Only admins can register users.")
|
||||
@ApiResponses({
|
||||
@ApiResponse(responseCode = "204", description = "User registered successfully"),
|
||||
@ApiResponse(responseCode = "403", description = "Forbidden")
|
||||
})
|
||||
@PostMapping("/register")
|
||||
@PreAuthorize("@securityUtil.isAdmin()")
|
||||
public ResponseEntity<?> registerUser(@RequestBody @Valid UserCreateRequest userCreateRequest) {
|
||||
public ResponseEntity<?> registerUser(
|
||||
@Parameter(description = "User registration request") @RequestBody @Valid UserCreateRequest userCreateRequest) {
|
||||
userProvisioningService.provisionInternalUser(userCreateRequest);
|
||||
return ResponseEntity.noContent().build();
|
||||
}
|
||||
|
||||
@Operation(summary = "Login user", description = "Authenticate a user and return JWT tokens.")
|
||||
@ApiResponse(responseCode = "200", description = "User authenticated successfully")
|
||||
@PostMapping("/login")
|
||||
public ResponseEntity<Map<String, String>> loginUser(@RequestBody @Valid UserLoginRequest loginRequest) {
|
||||
public ResponseEntity<Map<String, String>> loginUser(
|
||||
@Parameter(description = "User login request") @RequestBody @Valid UserLoginRequest loginRequest) {
|
||||
return authenticationService.loginUser(loginRequest);
|
||||
}
|
||||
|
||||
@Operation(summary = "Refresh JWT token", description = "Refresh the JWT token using a valid refresh token.")
|
||||
@ApiResponse(responseCode = "200", description = "Token refreshed successfully")
|
||||
@PostMapping("/refresh")
|
||||
public ResponseEntity<Map<String, String>> refreshToken(@Valid @RequestBody RefreshTokenRequest request) {
|
||||
public ResponseEntity<Map<String, String>> refreshToken(
|
||||
@Parameter(description = "Refresh token request") @Valid @RequestBody RefreshTokenRequest request) {
|
||||
return authenticationService.refreshToken(request.getRefreshToken());
|
||||
}
|
||||
|
||||
@Operation(summary = "Remote login", description = "Authenticate a user using remote authentication headers.")
|
||||
@ApiResponses({
|
||||
@ApiResponse(responseCode = "200", description = "User authenticated successfully"),
|
||||
@ApiResponse(responseCode = "403", description = "Remote authentication is disabled")
|
||||
})
|
||||
@GetMapping("/remote")
|
||||
public ResponseEntity<Map<String, String>> loginRemote(@RequestHeader Map<String, String> headers) {
|
||||
public ResponseEntity<Map<String, String>> loginRemote(
|
||||
@Parameter(description = "Authentication headers") @RequestHeader Map<String, String> headers) {
|
||||
if (!appProperties.getRemoteAuth().isEnabled()) {
|
||||
throw ApiError.REMOTE_AUTH_DISABLED.createException();
|
||||
}
|
||||
|
||||
+9
-1
@@ -1,12 +1,17 @@
|
||||
package com.adityachandel.booklore.controller;
|
||||
|
||||
import com.adityachandel.booklore.service.AuthorService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import io.swagger.v3.oas.annotations.responses.ApiResponse;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Tag(name = "Authors", description = "Endpoints for retrieving authors related to books")
|
||||
@RequestMapping("/api/v1/authors")
|
||||
@RestController
|
||||
@AllArgsConstructor
|
||||
@@ -14,8 +19,11 @@ public class AuthorController {
|
||||
|
||||
private final AuthorService authorService;
|
||||
|
||||
@Operation(summary = "Get authors by book ID", description = "Retrieve a list of authors for a specific book.")
|
||||
@ApiResponse(responseCode = "200", description = "Authors returned successfully")
|
||||
@GetMapping("/book/{bookId}")
|
||||
public ResponseEntity<List<String>> getAuthorsByBookId(@PathVariable long bookId) {
|
||||
public ResponseEntity<List<String>> getAuthorsByBookId(
|
||||
@Parameter(description = "ID of the book") @PathVariable long bookId) {
|
||||
return ResponseEntity.ok(authorService.getAuthorsByBookId(bookId));
|
||||
}
|
||||
}
|
||||
|
||||
+15
-2
@@ -5,6 +5,10 @@ import com.adityachandel.booklore.model.dto.BookLoreUser;
|
||||
import com.adityachandel.booklore.model.dto.UploadResponse;
|
||||
import com.adityachandel.booklore.model.dto.UrlRequest;
|
||||
import com.adityachandel.booklore.service.BackgroundUploadService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.responses.ApiResponse;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
@@ -12,6 +16,7 @@ import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@Tag(name = "Background Upload", description = "Endpoints for uploading and managing background images")
|
||||
@RestController
|
||||
@RequestMapping("/api/v1/background")
|
||||
@RequiredArgsConstructor
|
||||
@@ -20,8 +25,11 @@ public class BackgroundUploadController {
|
||||
private final BackgroundUploadService backgroundUploadService;
|
||||
private final AuthenticationService authenticationService;
|
||||
|
||||
@Operation(summary = "Upload background image file", description = "Upload a new background image file for the authenticated user.")
|
||||
@ApiResponse(responseCode = "200", description = "Background image uploaded successfully")
|
||||
@PostMapping("/upload")
|
||||
public ResponseEntity<UploadResponse> uploadFile(@RequestParam("file") MultipartFile file) {
|
||||
public ResponseEntity<UploadResponse> uploadFile(
|
||||
@Parameter(description = "Background image file") @RequestParam("file") MultipartFile file) {
|
||||
try {
|
||||
BookLoreUser authenticatedUser = authenticationService.getAuthenticatedUser();
|
||||
UploadResponse response = backgroundUploadService.uploadBackgroundFile(file, authenticatedUser.getId());
|
||||
@@ -31,8 +39,11 @@ public class BackgroundUploadController {
|
||||
}
|
||||
}
|
||||
|
||||
@Operation(summary = "Upload background image from URL", description = "Upload a new background image from a URL for the authenticated user.")
|
||||
@ApiResponse(responseCode = "200", description = "Background image uploaded successfully")
|
||||
@PostMapping("/url")
|
||||
public ResponseEntity<UploadResponse> uploadUrl(@RequestBody UrlRequest request) {
|
||||
public ResponseEntity<UploadResponse> uploadUrl(
|
||||
@Parameter(description = "URL request containing the image URL") @RequestBody UrlRequest request) {
|
||||
try {
|
||||
BookLoreUser authenticatedUser = authenticationService.getAuthenticatedUser();
|
||||
UploadResponse response = backgroundUploadService.uploadBackgroundFromUrl(request.getUrl(), authenticatedUser.getId());
|
||||
@@ -42,6 +53,8 @@ public class BackgroundUploadController {
|
||||
}
|
||||
}
|
||||
|
||||
@Operation(summary = "Reset background to default", description = "Reset the background image to the default for the authenticated user.")
|
||||
@ApiResponse(responseCode = "200", description = "Background reset to default successfully")
|
||||
@DeleteMapping
|
||||
public ResponseEntity<Void> resetToDefault() {
|
||||
try {
|
||||
|
||||
+81
-16
@@ -13,6 +13,11 @@ import com.adityachandel.booklore.model.enums.ResetProgressType;
|
||||
import com.adityachandel.booklore.service.BookService;
|
||||
import com.adityachandel.booklore.service.metadata.BookMetadataService;
|
||||
import com.adityachandel.booklore.service.recommender.BookRecommendationService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import io.swagger.v3.oas.annotations.responses.ApiResponse;
|
||||
import io.swagger.v3.oas.annotations.responses.ApiResponses;
|
||||
import jakarta.validation.Valid;
|
||||
import jakarta.validation.constraints.Max;
|
||||
import jakarta.validation.constraints.Min;
|
||||
@@ -27,6 +32,7 @@ import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
@Tag(name = "Books", description = "Endpoints for managing books, their metadata, progress, and recommendations")
|
||||
@RequestMapping("/api/v1/books")
|
||||
@RestController
|
||||
@AllArgsConstructor
|
||||
@@ -36,89 +42,148 @@ public class BookController {
|
||||
private final BookRecommendationService bookRecommendationService;
|
||||
private final BookMetadataService bookMetadataService;
|
||||
|
||||
@Operation(summary = "Get all books", description = "Retrieve a list of all books. Optionally include descriptions.")
|
||||
@ApiResponse(responseCode = "200", description = "List of books returned successfully")
|
||||
@GetMapping
|
||||
public ResponseEntity<List<Book>> getBooks(@RequestParam(required = false, defaultValue = "false") boolean withDescription) {
|
||||
public ResponseEntity<List<Book>> getBooks(
|
||||
@Parameter(description = "Include book descriptions in the response")
|
||||
@RequestParam(required = false, defaultValue = "false") boolean withDescription) {
|
||||
return ResponseEntity.ok(bookService.getBookDTOs(withDescription));
|
||||
}
|
||||
|
||||
@Operation(summary = "Get a book by ID", description = "Retrieve details of a specific book by its ID.")
|
||||
@ApiResponses({
|
||||
@ApiResponse(responseCode = "200", description = "Book details returned successfully"),
|
||||
@ApiResponse(responseCode = "404", description = "Book not found")
|
||||
})
|
||||
@GetMapping("/{bookId}")
|
||||
@CheckBookAccess(bookIdParam = "bookId")
|
||||
public ResponseEntity<Book> getBook(@PathVariable long bookId, @RequestParam(required = false, defaultValue = "false") boolean withDescription) {
|
||||
public ResponseEntity<Book> getBook(
|
||||
@Parameter(description = "ID of the book to retrieve") @PathVariable long bookId,
|
||||
@Parameter(description = "Include book description in the response") @RequestParam(required = false, defaultValue = "false") boolean withDescription) {
|
||||
return ResponseEntity.ok(bookService.getBook(bookId, withDescription));
|
||||
}
|
||||
|
||||
@Operation(summary = "Delete books", description = "Delete one or more books by their IDs. Requires admin or delete permission.")
|
||||
@ApiResponses({
|
||||
@ApiResponse(responseCode = "200", description = "Books deleted successfully"),
|
||||
@ApiResponse(responseCode = "403", description = "Forbidden")
|
||||
})
|
||||
@PreAuthorize("@securityUtil.canDeleteBook() or @securityUtil.isAdmin()")
|
||||
@DeleteMapping
|
||||
public ResponseEntity<BookDeletionResponse> deleteBooks(@RequestParam Set<Long> ids) {
|
||||
public ResponseEntity<BookDeletionResponse> deleteBooks(
|
||||
@Parameter(description = "Set of book IDs to delete") @RequestParam Set<Long> ids) {
|
||||
return bookService.deleteBooks(ids);
|
||||
}
|
||||
|
||||
@Operation(summary = "Get books by IDs", description = "Retrieve multiple books by their IDs. Optionally include descriptions.")
|
||||
@ApiResponse(responseCode = "200", description = "Books returned successfully")
|
||||
@GetMapping("/batch")
|
||||
public ResponseEntity<List<Book>> getBooksByIds(@RequestParam Set<Long> ids, @RequestParam(required = false, defaultValue = "false") boolean withDescription) {
|
||||
public ResponseEntity<List<Book>> getBooksByIds(
|
||||
@Parameter(description = "Set of book IDs to retrieve") @RequestParam Set<Long> ids,
|
||||
@Parameter(description = "Include book descriptions in the response") @RequestParam(required = false, defaultValue = "false") boolean withDescription) {
|
||||
return ResponseEntity.ok(bookService.getBooksByIds(ids, withDescription));
|
||||
}
|
||||
|
||||
@Operation(summary = "Get ComicInfo metadata", description = "Retrieve ComicInfo metadata for a specific book.")
|
||||
@ApiResponse(responseCode = "200", description = "ComicInfo metadata returned successfully")
|
||||
@GetMapping("/{bookId}/cbx/metadata/comicinfo")
|
||||
public ResponseEntity<?> getComicInfoMetadata(@PathVariable long bookId) {
|
||||
public ResponseEntity<?> getComicInfoMetadata(
|
||||
@Parameter(description = "ID of the book") @PathVariable long bookId) {
|
||||
return ResponseEntity.ok(bookMetadataService.getComicInfoMetadata(bookId));
|
||||
}
|
||||
|
||||
|
||||
@Operation(summary = "Get book content", description = "Retrieve the binary content of a book for reading.")
|
||||
@ApiResponse(responseCode = "200", description = "Book content returned successfully")
|
||||
@GetMapping("/{bookId}/content")
|
||||
@CheckBookAccess(bookIdParam = "bookId")
|
||||
public ResponseEntity<ByteArrayResource> getBookContent(@PathVariable long bookId) throws IOException {
|
||||
public ResponseEntity<ByteArrayResource> getBookContent(
|
||||
@Parameter(description = "ID of the book") @PathVariable long bookId) throws IOException {
|
||||
return bookService.getBookContent(bookId);
|
||||
}
|
||||
|
||||
@Operation(summary = "Download book", description = "Download the book file. Requires download permission or admin.")
|
||||
@ApiResponses({
|
||||
@ApiResponse(responseCode = "200", description = "Book downloaded successfully"),
|
||||
@ApiResponse(responseCode = "403", description = "Forbidden")
|
||||
})
|
||||
@GetMapping("/{bookId}/download")
|
||||
@PreAuthorize("@securityUtil.canDownload() or @securityUtil.isAdmin()")
|
||||
@CheckBookAccess(bookIdParam = "bookId")
|
||||
public ResponseEntity<Resource> downloadBook(@PathVariable("bookId") Long bookId) {
|
||||
public ResponseEntity<Resource> downloadBook(
|
||||
@Parameter(description = "ID of the book to download") @PathVariable("bookId") Long bookId) {
|
||||
return bookService.downloadBook(bookId);
|
||||
}
|
||||
|
||||
@Operation(summary = "Get viewer settings", description = "Retrieve viewer settings for a specific book.")
|
||||
@ApiResponse(responseCode = "200", description = "Viewer settings returned successfully")
|
||||
@GetMapping("/{bookId}/viewer-setting")
|
||||
@CheckBookAccess(bookIdParam = "bookId")
|
||||
public ResponseEntity<BookViewerSettings> getBookViewerSettings(@PathVariable long bookId) {
|
||||
public ResponseEntity<BookViewerSettings> getBookViewerSettings(
|
||||
@Parameter(description = "ID of the book") @PathVariable long bookId) {
|
||||
return ResponseEntity.ok(bookService.getBookViewerSetting(bookId));
|
||||
}
|
||||
|
||||
@Operation(summary = "Update viewer settings", description = "Update viewer settings for a specific book.")
|
||||
@ApiResponse(responseCode = "204", description = "Viewer settings updated successfully")
|
||||
@PutMapping("/{bookId}/viewer-setting")
|
||||
@CheckBookAccess(bookIdParam = "bookId")
|
||||
public ResponseEntity<Void> updateBookViewerSettings(@RequestBody BookViewerSettings bookViewerSettings, @PathVariable long bookId) {
|
||||
public ResponseEntity<Void> updateBookViewerSettings(
|
||||
@Parameter(description = "Viewer settings to update") @RequestBody BookViewerSettings bookViewerSettings,
|
||||
@Parameter(description = "ID of the book") @PathVariable long bookId) {
|
||||
bookService.updateBookViewerSetting(bookId, bookViewerSettings);
|
||||
return ResponseEntity.noContent().build();
|
||||
}
|
||||
|
||||
@Operation(summary = "Assign books to shelves", description = "Assign or unassign books to/from shelves.")
|
||||
@ApiResponse(responseCode = "200", description = "Books assigned/unassigned to shelves successfully")
|
||||
@PostMapping("/shelves")
|
||||
public ResponseEntity<List<Book>> addBookToShelf(@RequestBody @Valid ShelvesAssignmentRequest request) {
|
||||
public ResponseEntity<List<Book>> addBookToShelf(
|
||||
@Parameter(description = "Shelves assignment request") @RequestBody @Valid ShelvesAssignmentRequest request) {
|
||||
return ResponseEntity.ok(bookService.assignShelvesToBooks(request.getBookIds(), request.getShelvesToAssign(), request.getShelvesToUnassign()));
|
||||
}
|
||||
|
||||
@Operation(summary = "Update read progress", description = "Update the read progress for a book.")
|
||||
@ApiResponse(responseCode = "204", description = "Read progress updated successfully")
|
||||
@PostMapping("/progress")
|
||||
public ResponseEntity<Void> addBookToProgress(@RequestBody @Valid ReadProgressRequest request) {
|
||||
public ResponseEntity<Void> addBookToProgress(
|
||||
@Parameter(description = "Read progress request") @RequestBody @Valid ReadProgressRequest request) {
|
||||
bookService.updateReadProgress(request);
|
||||
return ResponseEntity.noContent().build();
|
||||
}
|
||||
|
||||
@Operation(summary = "Get book recommendations", description = "Get recommended books based on a specific book.")
|
||||
@ApiResponse(responseCode = "200", description = "Recommendations returned successfully")
|
||||
@GetMapping("/{id}/recommendations")
|
||||
@CheckBookAccess(bookIdParam = "id")
|
||||
public ResponseEntity<List<BookRecommendation>> getRecommendations(@PathVariable Long id, @RequestParam(defaultValue = "25") @Max(25) @Min(1) int limit) {
|
||||
public ResponseEntity<List<BookRecommendation>> getRecommendations(
|
||||
@Parameter(description = "ID of the book for recommendations") @PathVariable Long id,
|
||||
@Parameter(description = "Maximum number of recommendations to return (max 25)") @RequestParam(defaultValue = "25") @Max(25) @Min(1) int limit) {
|
||||
return ResponseEntity.ok(bookRecommendationService.getRecommendations(id, limit));
|
||||
}
|
||||
|
||||
@Operation(summary = "Update read status", description = "Update the read status for one or more books.")
|
||||
@ApiResponse(responseCode = "200", description = "Read status updated successfully")
|
||||
@PutMapping("/read-status")
|
||||
public ResponseEntity<List<Book>> updateReadStatus(@RequestBody @Valid ReadStatusUpdateRequest request) {
|
||||
public ResponseEntity<List<Book>> updateReadStatus(
|
||||
@Parameter(description = "Read status update request") @RequestBody @Valid ReadStatusUpdateRequest request) {
|
||||
List<Book> updatedBooks = bookService.updateReadStatus(request.ids(), request.status());
|
||||
return ResponseEntity.ok(updatedBooks);
|
||||
}
|
||||
|
||||
@Operation(summary = "Reset reading progress", description = "Reset the reading progress for one or more books.")
|
||||
@ApiResponses({
|
||||
@ApiResponse(responseCode = "200", description = "Progress reset successfully"),
|
||||
@ApiResponse(responseCode = "400", description = "No book IDs provided")
|
||||
})
|
||||
@PostMapping("/reset-progress")
|
||||
public ResponseEntity<List<Book>> resetProgress(@RequestBody List<Long> bookIds, @RequestParam ResetProgressType type) {
|
||||
public ResponseEntity<List<Book>> resetProgress(
|
||||
@Parameter(description = "List of book IDs to reset progress for") @RequestBody List<Long> bookIds,
|
||||
@Parameter(description = "Type of progress reset") @RequestParam ResetProgressType type) {
|
||||
if (bookIds == null || bookIds.isEmpty()) {
|
||||
throw ApiError.GENERIC_BAD_REQUEST.createException("No book IDs provided");
|
||||
}
|
||||
List<Book> updatedBooks = bookService.resetProgress(bookIds, type);
|
||||
return ResponseEntity.ok(updatedBooks);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+31
-5
@@ -4,6 +4,10 @@ import com.adityachandel.booklore.service.BookService;
|
||||
import com.adityachandel.booklore.service.bookdrop.BookDropService;
|
||||
import com.adityachandel.booklore.service.reader.CbxReaderService;
|
||||
import com.adityachandel.booklore.service.reader.PdfReaderService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.responses.ApiResponse;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.core.io.Resource;
|
||||
@@ -19,6 +23,7 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
@Tag(name = "Book Media", description = "Endpoints for retrieving book media such as covers, thumbnails, and pages")
|
||||
@AllArgsConstructor
|
||||
@RestController
|
||||
@RequestMapping("/api/v1/media")
|
||||
@@ -29,30 +34,49 @@ public class BookMediaController {
|
||||
private final CbxReaderService cbxReaderService;
|
||||
private final BookDropService bookDropService;
|
||||
|
||||
@Operation(summary = "Get book thumbnail", description = "Retrieve the thumbnail image for a specific book.")
|
||||
@ApiResponse(responseCode = "200", description = "Book thumbnail returned successfully")
|
||||
@GetMapping("/book/{bookId}/thumbnail")
|
||||
public ResponseEntity<Resource> getBookThumbnail(@PathVariable long bookId) {
|
||||
public ResponseEntity<Resource> getBookThumbnail(
|
||||
@Parameter(description = "ID of the book") @PathVariable long bookId) {
|
||||
return ResponseEntity.ok(bookService.getBookThumbnail(bookId));
|
||||
}
|
||||
|
||||
@Operation(summary = "Get book cover", description = "Retrieve the cover image for a specific book.")
|
||||
@ApiResponse(responseCode = "200", description = "Book cover returned successfully")
|
||||
@GetMapping("/book/{bookId}/cover")
|
||||
public ResponseEntity<Resource> getBookCover(@PathVariable long bookId) {
|
||||
public ResponseEntity<Resource> getBookCover(
|
||||
@Parameter(description = "ID of the book") @PathVariable long bookId) {
|
||||
return ResponseEntity.ok(bookService.getBookCover(bookId));
|
||||
}
|
||||
|
||||
@Operation(summary = "Get PDF page as image", description = "Retrieve a specific page from a PDF book as an image.")
|
||||
@ApiResponse(responseCode = "200", description = "PDF page image returned successfully")
|
||||
@GetMapping("/book/{bookId}/pdf/pages/{pageNumber}")
|
||||
public void getPdfPage(@PathVariable Long bookId, @PathVariable int pageNumber, HttpServletResponse response) throws IOException {
|
||||
public void getPdfPage(
|
||||
@Parameter(description = "ID of the book") @PathVariable Long bookId,
|
||||
@Parameter(description = "Page number to retrieve") @PathVariable int pageNumber,
|
||||
HttpServletResponse response) throws IOException {
|
||||
response.setContentType(MediaType.IMAGE_JPEG_VALUE);
|
||||
pdfReaderService.streamPageImage(bookId, pageNumber, response.getOutputStream());
|
||||
}
|
||||
|
||||
@Operation(summary = "Get CBX page as image", description = "Retrieve a specific page from a CBX book as an image.")
|
||||
@ApiResponse(responseCode = "200", description = "CBX page image returned successfully")
|
||||
@GetMapping("/book/{bookId}/cbx/pages/{pageNumber}")
|
||||
public void getCbxPage(@PathVariable Long bookId, @PathVariable int pageNumber, HttpServletResponse response) throws IOException {
|
||||
public void getCbxPage(
|
||||
@Parameter(description = "ID of the book") @PathVariable Long bookId,
|
||||
@Parameter(description = "Page number to retrieve") @PathVariable int pageNumber,
|
||||
HttpServletResponse response) throws IOException {
|
||||
response.setContentType(MediaType.IMAGE_JPEG_VALUE);
|
||||
cbxReaderService.streamPageImage(bookId, pageNumber, response.getOutputStream());
|
||||
}
|
||||
|
||||
@Operation(summary = "Get bookdrop cover", description = "Retrieve the cover image for a specific bookdrop file.")
|
||||
@ApiResponse(responseCode = "200", description = "Bookdrop cover returned successfully")
|
||||
@GetMapping("/bookdrop/{bookdropId}/cover")
|
||||
public ResponseEntity<Resource> getBookdropCover(@PathVariable long bookdropId) {
|
||||
public ResponseEntity<Resource> getBookdropCover(
|
||||
@Parameter(description = "ID of the bookdrop file") @PathVariable long bookdropId) {
|
||||
Resource file = bookDropService.getBookdropCover(bookdropId);
|
||||
String contentDisposition = ContentDisposition.builder("inline")
|
||||
.filename("cover.jpg", StandardCharsets.UTF_8)
|
||||
@@ -66,6 +90,8 @@ public class BookMediaController {
|
||||
: ResponseEntity.noContent().build();
|
||||
}
|
||||
|
||||
@Operation(summary = "Get background image", description = "Retrieve the current background image for the authenticated user.")
|
||||
@ApiResponse(responseCode = "200", description = "Background image returned successfully")
|
||||
@GetMapping("/background")
|
||||
public ResponseEntity<Resource> getBackgroundImage() {
|
||||
try {
|
||||
|
||||
+18
-4
@@ -3,6 +3,11 @@ package com.adityachandel.booklore.controller;
|
||||
import com.adityachandel.booklore.model.dto.BookNote;
|
||||
import com.adityachandel.booklore.model.dto.CreateBookNoteRequest;
|
||||
import com.adityachandel.booklore.service.BookNoteService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.responses.ApiResponse;
|
||||
import io.swagger.v3.oas.annotations.responses.ApiResponses;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.validation.Valid;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
@@ -13,23 +18,32 @@ import java.util.List;
|
||||
@RestController
|
||||
@RequestMapping("/api/v1/book-notes")
|
||||
@AllArgsConstructor
|
||||
@Tag(name = "Book Notes", description = "Endpoints for managing notes attached to books")
|
||||
public class BookNoteController {
|
||||
|
||||
private final BookNoteService bookNoteService;
|
||||
|
||||
|
||||
@Operation(summary = "Get notes for a book", description = "Retrieve all notes for a specific book.")
|
||||
@ApiResponse(responseCode = "200", description = "Notes returned successfully")
|
||||
@GetMapping("/book/{bookId}")
|
||||
public List<BookNote> getNotesForBook(@PathVariable Long bookId) {
|
||||
public List<BookNote> getNotesForBook(
|
||||
@Parameter(description = "ID of the book") @PathVariable Long bookId) {
|
||||
return bookNoteService.getNotesForBook(bookId);
|
||||
}
|
||||
|
||||
@Operation(summary = "Create or update a note", description = "Create a new note or update an existing note for a book.")
|
||||
@ApiResponse(responseCode = "200", description = "Note created/updated successfully")
|
||||
@PostMapping
|
||||
public BookNote createNote(@Valid @RequestBody CreateBookNoteRequest request) {
|
||||
public BookNote createNote(
|
||||
@Parameter(description = "Note creation request") @Valid @RequestBody CreateBookNoteRequest request) {
|
||||
return bookNoteService.createOrUpdateNote(request);
|
||||
}
|
||||
|
||||
@Operation(summary = "Delete a note", description = "Delete a specific note by its ID.")
|
||||
@ApiResponse(responseCode = "204", description = "Note deleted successfully")
|
||||
@DeleteMapping("/{noteId}")
|
||||
public ResponseEntity<Void> deleteNote(@PathVariable Long noteId) {
|
||||
public ResponseEntity<Void> deleteNote(
|
||||
@Parameter(description = "ID of the note to delete") @PathVariable Long noteId) {
|
||||
bookNoteService.deleteNote(noteId);
|
||||
return ResponseEntity.noContent().build();
|
||||
}
|
||||
|
||||
+25
-5
@@ -2,24 +2,35 @@ package com.adityachandel.booklore.controller;
|
||||
|
||||
import com.adityachandel.booklore.model.dto.BookReview;
|
||||
import com.adityachandel.booklore.service.BookReviewService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.responses.ApiResponse;
|
||||
import io.swagger.v3.oas.annotations.responses.ApiResponses;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.validation.constraints.Positive;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api/v1/reviews")
|
||||
@AllArgsConstructor
|
||||
@Tag(name = "Book Reviews", description = "Endpoints for managing book reviews")
|
||||
public class BookReviewController {
|
||||
|
||||
private final BookReviewService bookReviewService;
|
||||
|
||||
@Operation(summary = "List reviews for a book", description = "Retrieve all reviews for a specific book.")
|
||||
@ApiResponses({
|
||||
@ApiResponse(responseCode = "200", description = "Reviews returned successfully"),
|
||||
@ApiResponse(responseCode = "204", description = "No reviews found")
|
||||
})
|
||||
@GetMapping("/book/{bookId}")
|
||||
public ResponseEntity<List<BookReview>> listByBook(@PathVariable @Positive(message = "Book ID must be positive") Long bookId) {
|
||||
public ResponseEntity<List<BookReview>> listByBook(
|
||||
@Parameter(description = "ID of the book") @PathVariable @Positive(message = "Book ID must be positive") Long bookId) {
|
||||
List<BookReview> reviews = bookReviewService.getByBookId(bookId);
|
||||
if (reviews.isEmpty()) {
|
||||
return ResponseEntity.noContent().build();
|
||||
@@ -27,22 +38,31 @@ public class BookReviewController {
|
||||
return ResponseEntity.ok(reviews);
|
||||
}
|
||||
|
||||
@Operation(summary = "Refresh reviews for a book", description = "Refresh and retrieve reviews for a specific book. Requires metadata edit permission or admin.")
|
||||
@ApiResponse(responseCode = "200", description = "Reviews refreshed successfully")
|
||||
@PostMapping("/book/{bookId}/refresh")
|
||||
@PreAuthorize("@securityUtil.canEditMetadata() or @securityUtil.isAdmin()")
|
||||
public List<BookReview> refreshReviews(@PathVariable Long bookId) {
|
||||
public List<BookReview> refreshReviews(
|
||||
@Parameter(description = "ID of the book") @PathVariable Long bookId) {
|
||||
return bookReviewService.refreshReviews(bookId);
|
||||
}
|
||||
|
||||
@Operation(summary = "Delete a review", description = "Delete a specific review by its ID. Requires metadata edit permission or admin.")
|
||||
@ApiResponse(responseCode = "204", description = "Review deleted successfully")
|
||||
@DeleteMapping("/{id}")
|
||||
@PreAuthorize("@securityUtil.canEditMetadata() or @securityUtil.isAdmin()")
|
||||
public ResponseEntity<Void> delete(@PathVariable Long id) {
|
||||
public ResponseEntity<Void> delete(
|
||||
@Parameter(description = "ID of the review to delete") @PathVariable Long id) {
|
||||
bookReviewService.delete(id);
|
||||
return ResponseEntity.noContent().build();
|
||||
}
|
||||
|
||||
@Operation(summary = "Delete all reviews for a book", description = "Delete all reviews for a specific book. Requires metadata edit permission or admin.")
|
||||
@ApiResponse(responseCode = "204", description = "All reviews deleted successfully")
|
||||
@DeleteMapping("/book/{bookId}")
|
||||
@PreAuthorize("@securityUtil.canEditMetadata() or @securityUtil.isAdmin()")
|
||||
public ResponseEntity<Void> deleteAllByBookId(@PathVariable Long bookId) {
|
||||
public ResponseEntity<Void> deleteAllByBookId(
|
||||
@Parameter(description = "ID of the book") @PathVariable Long bookId) {
|
||||
bookReviewService.deleteAllByBookId(bookId);
|
||||
return ResponseEntity.noContent().build();
|
||||
}
|
||||
|
||||
+22
-3
@@ -8,12 +8,17 @@ import com.adityachandel.booklore.model.dto.response.BookdropFinalizeResult;
|
||||
import com.adityachandel.booklore.service.bookdrop.BookDropService;
|
||||
import com.adityachandel.booklore.service.bookdrop.BookdropMonitoringService;
|
||||
import com.adityachandel.booklore.service.monitoring.MonitoringService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import io.swagger.v3.oas.annotations.responses.ApiResponse;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
@Tag(name = "Bookdrop", description = "Endpoints for managing bookdrop files and imports")
|
||||
@AllArgsConstructor
|
||||
@RestController
|
||||
@RequestMapping("/api/v1/bookdrop")
|
||||
@@ -22,28 +27,42 @@ public class BookdropFileController {
|
||||
private final BookDropService bookDropService;
|
||||
private final BookdropMonitoringService monitoringService;
|
||||
|
||||
@Operation(summary = "Get bookdrop notification summary", description = "Retrieve a summary of bookdrop file notifications.")
|
||||
@ApiResponse(responseCode = "200", description = "Notification summary returned successfully")
|
||||
@GetMapping("/notification")
|
||||
public BookdropFileNotification getSummary() {
|
||||
return bookDropService.getFileNotificationSummary();
|
||||
}
|
||||
|
||||
@Operation(summary = "Get bookdrop files by status", description = "Retrieve a paginated list of bookdrop files filtered by status.")
|
||||
@ApiResponse(responseCode = "200", description = "Bookdrop files returned successfully")
|
||||
@GetMapping("/files")
|
||||
public Page<BookdropFile> getFilesByStatus(@RequestParam(required = false) String status, Pageable pageable) {
|
||||
public Page<BookdropFile> getFilesByStatus(
|
||||
@Parameter(description = "Status to filter files by") @RequestParam(required = false) String status,
|
||||
Pageable pageable) {
|
||||
return bookDropService.getFilesByStatus(status, pageable);
|
||||
}
|
||||
|
||||
@Operation(summary = "Discard selected bookdrop files", description = "Discard selected bookdrop files based on selection criteria.")
|
||||
@ApiResponse(responseCode = "200", description = "Files discarded successfully")
|
||||
@PostMapping("/files/discard")
|
||||
public ResponseEntity<Void> discardSelectedFiles(@RequestBody BookdropSelectionRequest request) {
|
||||
public ResponseEntity<Void> discardSelectedFiles(
|
||||
@Parameter(description = "Selection request for files to discard") @RequestBody BookdropSelectionRequest request) {
|
||||
bookDropService.discardSelectedFiles(request.isSelectAll(), request.getExcludedIds(), request.getSelectedIds());
|
||||
return ResponseEntity.ok().build();
|
||||
}
|
||||
|
||||
@Operation(summary = "Finalize bookdrop import", description = "Finalize the import of selected bookdrop files.")
|
||||
@ApiResponse(responseCode = "200", description = "Import finalized successfully")
|
||||
@PostMapping("/imports/finalize")
|
||||
public ResponseEntity<BookdropFinalizeResult> finalizeImport(@RequestBody BookdropFinalizeRequest request) {
|
||||
public ResponseEntity<BookdropFinalizeResult> finalizeImport(
|
||||
@Parameter(description = "Finalize import request") @RequestBody BookdropFinalizeRequest request) {
|
||||
BookdropFinalizeResult result = bookDropService.finalizeImport(request);
|
||||
return ResponseEntity.ok(result);
|
||||
}
|
||||
|
||||
@Operation(summary = "Rescan bookdrop folder", description = "Trigger a rescan of the bookdrop folder for new files.")
|
||||
@ApiResponse(responseCode = "200", description = "Bookdrop folder rescanned successfully")
|
||||
@PostMapping("/rescan")
|
||||
public ResponseEntity<Void> rescanBookdrop() {
|
||||
monitoringService.rescanBookdropFolder();
|
||||
|
||||
+9
-1
@@ -1,6 +1,10 @@
|
||||
package com.adityachandel.booklore.controller;
|
||||
|
||||
import com.adityachandel.booklore.service.reader.CbxReaderService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.responses.ApiResponse;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
@@ -12,12 +16,16 @@ import java.util.List;
|
||||
@RestController
|
||||
@RequestMapping("/api/v1/cbx")
|
||||
@RequiredArgsConstructor
|
||||
@Tag(name = "CBX Reader", description = "Endpoints for reading CBX format books")
|
||||
public class CbxReaderController {
|
||||
|
||||
private final CbxReaderService cbxReaderService;
|
||||
|
||||
@Operation(summary = "List pages in a CBX book", description = "Retrieve a list of available page numbers for a CBX book.")
|
||||
@ApiResponse(responseCode = "200", description = "Page numbers returned successfully")
|
||||
@GetMapping("/{bookId}/pages")
|
||||
public List<Integer> listPages(@PathVariable Long bookId) {
|
||||
public List<Integer> listPages(
|
||||
@Parameter(description = "ID of the book") @PathVariable Long bookId) {
|
||||
return cbxReaderService.getAvailablePages(bookId);
|
||||
}
|
||||
}
|
||||
+28
-5
@@ -3,6 +3,10 @@ package com.adityachandel.booklore.controller;
|
||||
import com.adityachandel.booklore.model.dto.EmailProviderV2;
|
||||
import com.adityachandel.booklore.model.dto.request.CreateEmailProviderRequest;
|
||||
import com.adityachandel.booklore.service.email.EmailProviderV2Service;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.responses.ApiResponse;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
@@ -13,44 +17,63 @@ import java.util.List;
|
||||
@AllArgsConstructor
|
||||
@RestController
|
||||
@RequestMapping("/api/v2/email/providers")
|
||||
@Tag(name = "Email Providers", description = "Endpoints for managing email providers for book delivery")
|
||||
public class EmailProviderV2Controller {
|
||||
|
||||
private final EmailProviderV2Service service;
|
||||
|
||||
@Operation(summary = "Get all email providers", description = "Retrieve a list of all configured email providers.")
|
||||
@ApiResponse(responseCode = "200", description = "Email providers returned successfully")
|
||||
@PreAuthorize("@securityUtil.isAdmin() or @securityUtil.canEmailBook()")
|
||||
@GetMapping
|
||||
public ResponseEntity<List<EmailProviderV2>> getEmailProviders() {
|
||||
return ResponseEntity.ok(service.getEmailProviders());
|
||||
}
|
||||
|
||||
@Operation(summary = "Get an email provider by ID", description = "Retrieve details of a specific email provider.")
|
||||
@ApiResponse(responseCode = "200", description = "Email provider returned successfully")
|
||||
@PreAuthorize("@securityUtil.isAdmin() or @securityUtil.canEmailBook()")
|
||||
@GetMapping("/{id}")
|
||||
public ResponseEntity<EmailProviderV2> getEmailProvider(@PathVariable Long id) {
|
||||
public ResponseEntity<EmailProviderV2> getEmailProvider(
|
||||
@Parameter(description = "ID of the email provider") @PathVariable Long id) {
|
||||
return ResponseEntity.ok(service.getEmailProvider(id));
|
||||
}
|
||||
|
||||
@Operation(summary = "Create an email provider", description = "Create a new email provider configuration.")
|
||||
@ApiResponse(responseCode = "200", description = "Email provider created successfully")
|
||||
@PreAuthorize("@securityUtil.isAdmin() or @securityUtil.canEmailBook()")
|
||||
@PostMapping
|
||||
public ResponseEntity<EmailProviderV2> createEmailProvider(@RequestBody CreateEmailProviderRequest createEmailProviderRequest) {
|
||||
public ResponseEntity<EmailProviderV2> createEmailProvider(
|
||||
@Parameter(description = "Email provider creation request") @RequestBody CreateEmailProviderRequest createEmailProviderRequest) {
|
||||
return ResponseEntity.ok(service.createEmailProvider(createEmailProviderRequest));
|
||||
}
|
||||
|
||||
@Operation(summary = "Update an email provider", description = "Update an existing email provider configuration.")
|
||||
@ApiResponse(responseCode = "200", description = "Email provider updated successfully")
|
||||
@PreAuthorize("@securityUtil.isAdmin() or @securityUtil.canEmailBook()")
|
||||
@PutMapping("/{id}")
|
||||
public ResponseEntity<EmailProviderV2> updateEmailProvider(@PathVariable Long id, @RequestBody CreateEmailProviderRequest updateRequest) {
|
||||
public ResponseEntity<EmailProviderV2> updateEmailProvider(
|
||||
@Parameter(description = "ID of the email provider") @PathVariable Long id,
|
||||
@Parameter(description = "Email provider update request") @RequestBody CreateEmailProviderRequest updateRequest) {
|
||||
return ResponseEntity.ok(service.updateEmailProvider(id, updateRequest));
|
||||
}
|
||||
|
||||
@Operation(summary = "Set default email provider", description = "Set a specific email provider as the default.")
|
||||
@ApiResponse(responseCode = "204", description = "Default email provider set successfully")
|
||||
@PreAuthorize("@securityUtil.isAdmin() or @securityUtil.canEmailBook()")
|
||||
@PatchMapping("/{id}/set-default")
|
||||
public ResponseEntity<Void> setDefaultEmailProvider(@PathVariable Long id) {
|
||||
public ResponseEntity<Void> setDefaultEmailProvider(
|
||||
@Parameter(description = "ID of the email provider") @PathVariable Long id) {
|
||||
service.setDefaultEmailProvider(id);
|
||||
return ResponseEntity.noContent().build();
|
||||
}
|
||||
|
||||
@Operation(summary = "Delete an email provider", description = "Delete a specific email provider configuration.")
|
||||
@ApiResponse(responseCode = "204", description = "Email provider deleted successfully")
|
||||
@PreAuthorize("@securityUtil.isAdmin() or @securityUtil.canEmailBook()")
|
||||
@DeleteMapping("/{id}")
|
||||
public ResponseEntity<?> deleteEmailProvider(@PathVariable Long id) {
|
||||
public ResponseEntity<?> deleteEmailProvider(
|
||||
@Parameter(description = "ID of the email provider") @PathVariable Long id) {
|
||||
service.deleteEmailProvider(id);
|
||||
return ResponseEntity.noContent().build();
|
||||
}
|
||||
|
||||
+28
-5
@@ -3,6 +3,10 @@ package com.adityachandel.booklore.controller;
|
||||
import com.adityachandel.booklore.model.dto.EmailRecipientV2;
|
||||
import com.adityachandel.booklore.model.dto.request.CreateEmailRecipientRequest;
|
||||
import com.adityachandel.booklore.service.email.EmailRecipientV2Service;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.responses.ApiResponse;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
@@ -13,44 +17,63 @@ import java.util.List;
|
||||
@AllArgsConstructor
|
||||
@RestController
|
||||
@RequestMapping("/api/v2/email/recipients")
|
||||
@Tag(name = "Email Recipients", description = "Endpoints for managing email recipients for book delivery")
|
||||
public class EmailRecipientV2Controller {
|
||||
|
||||
private final EmailRecipientV2Service service;
|
||||
|
||||
@Operation(summary = "Get all email recipients", description = "Retrieve a list of all configured email recipients.")
|
||||
@ApiResponse(responseCode = "200", description = "Email recipients returned successfully")
|
||||
@PreAuthorize("@securityUtil.isAdmin() or @securityUtil.canEmailBook()")
|
||||
@GetMapping
|
||||
public ResponseEntity<List<EmailRecipientV2>> getEmailRecipients() {
|
||||
return ResponseEntity.ok(service.getEmailRecipients());
|
||||
}
|
||||
|
||||
@Operation(summary = "Get an email recipient by ID", description = "Retrieve details of a specific email recipient.")
|
||||
@ApiResponse(responseCode = "200", description = "Email recipient returned successfully")
|
||||
@PreAuthorize("@securityUtil.isAdmin() or @securityUtil.canEmailBook()")
|
||||
@GetMapping("/{id}")
|
||||
public ResponseEntity<EmailRecipientV2> getEmailRecipient(@PathVariable Long id) {
|
||||
public ResponseEntity<EmailRecipientV2> getEmailRecipient(
|
||||
@Parameter(description = "ID of the email recipient") @PathVariable Long id) {
|
||||
return ResponseEntity.ok(service.getEmailRecipient(id));
|
||||
}
|
||||
|
||||
@Operation(summary = "Create an email recipient", description = "Create a new email recipient configuration.")
|
||||
@ApiResponse(responseCode = "200", description = "Email recipient created successfully")
|
||||
@PreAuthorize("@securityUtil.isAdmin() or @securityUtil.canEmailBook()")
|
||||
@PostMapping
|
||||
public ResponseEntity<EmailRecipientV2> createEmailRecipient(@RequestBody CreateEmailRecipientRequest createEmailRecipientRequest) {
|
||||
public ResponseEntity<EmailRecipientV2> createEmailRecipient(
|
||||
@Parameter(description = "Email recipient creation request") @RequestBody CreateEmailRecipientRequest createEmailRecipientRequest) {
|
||||
return ResponseEntity.ok(service.createEmailRecipient(createEmailRecipientRequest));
|
||||
}
|
||||
|
||||
@Operation(summary = "Update an email recipient", description = "Update an existing email recipient configuration.")
|
||||
@ApiResponse(responseCode = "200", description = "Email recipient updated successfully")
|
||||
@PreAuthorize("@securityUtil.isAdmin() or @securityUtil.canEmailBook()")
|
||||
@PutMapping("/{id}")
|
||||
public ResponseEntity<EmailRecipientV2> updateEmailRecipient(@PathVariable Long id, @RequestBody CreateEmailRecipientRequest updateRequest) {
|
||||
public ResponseEntity<EmailRecipientV2> updateEmailRecipient(
|
||||
@Parameter(description = "ID of the email recipient") @PathVariable Long id,
|
||||
@Parameter(description = "Email recipient update request") @RequestBody CreateEmailRecipientRequest updateRequest) {
|
||||
return ResponseEntity.ok(service.updateEmailRecipient(id, updateRequest));
|
||||
}
|
||||
|
||||
@Operation(summary = "Set default email recipient", description = "Set a specific email recipient as the default.")
|
||||
@ApiResponse(responseCode = "204", description = "Default email recipient set successfully")
|
||||
@PreAuthorize("@securityUtil.isAdmin() or @securityUtil.canEmailBook()")
|
||||
@PatchMapping("/{id}/set-default")
|
||||
public ResponseEntity<Void> setDefaultEmailRecipient(@PathVariable Long id) {
|
||||
public ResponseEntity<Void> setDefaultEmailRecipient(
|
||||
@Parameter(description = "ID of the email recipient") @PathVariable Long id) {
|
||||
service.setDefaultRecipient(id);
|
||||
return ResponseEntity.noContent().build();
|
||||
}
|
||||
|
||||
@Operation(summary = "Delete an email recipient", description = "Delete a specific email recipient configuration.")
|
||||
@ApiResponse(responseCode = "204", description = "Email recipient deleted successfully")
|
||||
@PreAuthorize("@securityUtil.isAdmin() or @securityUtil.canEmailBook()")
|
||||
@DeleteMapping("/{id}")
|
||||
public ResponseEntity<Void> deleteEmailRecipient(@PathVariable Long id) {
|
||||
public ResponseEntity<Void> deleteEmailRecipient(
|
||||
@Parameter(description = "ID of the email recipient") @PathVariable Long id) {
|
||||
service.deleteEmailRecipient(id);
|
||||
return ResponseEntity.noContent().build();
|
||||
}
|
||||
|
||||
+9
-1
@@ -2,6 +2,10 @@ package com.adityachandel.booklore.controller;
|
||||
|
||||
import com.adityachandel.booklore.model.dto.request.FileMoveRequest;
|
||||
import com.adityachandel.booklore.service.file.FileMoveService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.responses.ApiResponse;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
@@ -12,12 +16,16 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
@AllArgsConstructor
|
||||
@RestController
|
||||
@RequestMapping("/api/v1/files")
|
||||
@Tag(name = "File Move", description = "Endpoints for moving files within the library")
|
||||
public class FileMoveController {
|
||||
|
||||
private final FileMoveService fileMoveService;
|
||||
|
||||
@Operation(summary = "Move files", description = "Bulk move files to a different location within the library.")
|
||||
@ApiResponse(responseCode = "200", description = "Files moved successfully")
|
||||
@PostMapping("/move")
|
||||
public ResponseEntity<?> moveFiles(@RequestBody FileMoveRequest request) {
|
||||
public ResponseEntity<?> moveFiles(
|
||||
@Parameter(description = "File move request") @RequestBody FileMoveRequest request) {
|
||||
fileMoveService.bulkMoveFiles(request);
|
||||
return ResponseEntity.ok().build();
|
||||
}
|
||||
|
||||
+16
-2
@@ -11,18 +11,29 @@ import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.responses.ApiResponse;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
@AllArgsConstructor
|
||||
@RestController
|
||||
@RequestMapping("/api/v1/files")
|
||||
@Tag(name = "File Upload", description = "Endpoints for uploading files and books")
|
||||
public class FileUploadController {
|
||||
|
||||
private final FileUploadService fileUploadService;
|
||||
|
||||
@Operation(summary = "Upload a file", description = "Upload a file to a specific library and path. Requires upload permission or admin.")
|
||||
@ApiResponse(responseCode = "204", description = "File uploaded successfully")
|
||||
@PreAuthorize("@securityUtil.isAdmin() or @securityUtil.canUpload()")
|
||||
@PostMapping(value = "/upload", consumes = "multipart/form-data")
|
||||
public ResponseEntity<?> uploadFile(@RequestParam("file") MultipartFile file, @RequestParam("libraryId") long libraryId, @RequestParam("pathId") long pathId) throws IOException {
|
||||
public ResponseEntity<?> uploadFile(
|
||||
@Parameter(description = "File to upload") @RequestParam("file") MultipartFile file,
|
||||
@Parameter(description = "Library ID") @RequestParam("libraryId") long libraryId,
|
||||
@Parameter(description = "Path ID") @RequestParam("pathId") long pathId) throws IOException {
|
||||
if (file.isEmpty()) {
|
||||
throw new IllegalArgumentException("Uploaded file is missing.");
|
||||
}
|
||||
@@ -30,9 +41,12 @@ public class FileUploadController {
|
||||
return ResponseEntity.noContent().build();
|
||||
}
|
||||
|
||||
@Operation(summary = "Upload a book via BookDrop", description = "Upload a book using BookDrop. Requires upload permission or admin.")
|
||||
@ApiResponse(responseCode = "200", description = "Book uploaded successfully")
|
||||
@PreAuthorize("@securityUtil.isAdmin() or @securityUtil.canUpload()")
|
||||
@PostMapping(value = "/upload/bookdrop", consumes = "multipart/form-data")
|
||||
public ResponseEntity<Book> uploadFile(@RequestParam("file") MultipartFile file) throws IOException {
|
||||
public ResponseEntity<Book> uploadFile(
|
||||
@Parameter(description = "Book file to upload") @RequestParam("file") MultipartFile file) throws IOException {
|
||||
if (file.isEmpty()) {
|
||||
throw new IllegalArgumentException("Uploaded file is missing.");
|
||||
}
|
||||
|
||||
+52
-15
@@ -10,6 +10,10 @@ import com.adityachandel.booklore.service.*;
|
||||
import com.adityachandel.booklore.service.kobo.*;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.responses.ApiResponse;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
@@ -31,6 +35,7 @@ import java.util.Set;
|
||||
@RequiredArgsConstructor
|
||||
@RestController
|
||||
@RequestMapping(value = "/api/kobo/{token}")
|
||||
@Tag(name = "Kobo Integration", description = "Endpoints for Kobo device and library integration")
|
||||
public class KoboController {
|
||||
|
||||
private String token;
|
||||
@@ -50,21 +55,27 @@ public class KoboController {
|
||||
this.token = token;
|
||||
}
|
||||
|
||||
@Operation(summary = "Initialize Kobo resources", description = "Initialize Kobo resources for the device.")
|
||||
@ApiResponse(responseCode = "200", description = "Initialization successful")
|
||||
@GetMapping("/v1/initialization")
|
||||
public ResponseEntity<KoboResources> initialization() throws JsonProcessingException {
|
||||
return koboInitializationService.initialize(token);
|
||||
}
|
||||
|
||||
@Operation(summary = "Sync Kobo library", description = "Sync the user's Kobo library.")
|
||||
@ApiResponse(responseCode = "200", description = "Library synced successfully")
|
||||
@GetMapping("/v1/library/sync")
|
||||
public ResponseEntity<?> syncLibrary(@AuthenticationPrincipal BookLoreUser user) {
|
||||
return koboLibrarySyncService.syncLibrary(user, token);
|
||||
}
|
||||
|
||||
@Operation(summary = "Get book thumbnail", description = "Retrieve the thumbnail image for a book.")
|
||||
@ApiResponse(responseCode = "200", description = "Thumbnail returned successfully")
|
||||
@GetMapping("/v1/books/{imageId}/thumbnail/{width}/{height}/false/image.jpg")
|
||||
public ResponseEntity<Resource> getThumbnail(
|
||||
@PathVariable String imageId,
|
||||
@PathVariable int width,
|
||||
@PathVariable int height) {
|
||||
@Parameter(description = "Image ID") @PathVariable String imageId,
|
||||
@Parameter(description = "Width of the thumbnail") @PathVariable int width,
|
||||
@Parameter(description = "Height of the thumbnail") @PathVariable int height) {
|
||||
|
||||
if (StringUtils.isNumeric(imageId)) {
|
||||
return koboThumbnailService.getThumbnail(Long.valueOf(imageId));
|
||||
@@ -74,13 +85,15 @@ public class KoboController {
|
||||
}
|
||||
}
|
||||
|
||||
@Operation(summary = "Get greyscale book thumbnail", description = "Retrieve a greyscale thumbnail image for a book.")
|
||||
@ApiResponse(responseCode = "200", description = "Greyscale thumbnail returned successfully")
|
||||
@GetMapping("/v1/books/{bookId}/thumbnail/{width}/{height}/{quality}/{isGreyscale}/image.jpg")
|
||||
public ResponseEntity<Resource> getGreyThumbnail(
|
||||
@PathVariable String bookId,
|
||||
@PathVariable int width,
|
||||
@PathVariable int height,
|
||||
@PathVariable int quality,
|
||||
@PathVariable boolean isGreyscale) {
|
||||
@Parameter(description = "Book ID") @PathVariable String bookId,
|
||||
@Parameter(description = "Width of the thumbnail") @PathVariable int width,
|
||||
@Parameter(description = "Height of the thumbnail") @PathVariable int height,
|
||||
@Parameter(description = "Quality of the thumbnail") @PathVariable int quality,
|
||||
@Parameter(description = "Is greyscale") @PathVariable boolean isGreyscale) {
|
||||
|
||||
if (StringUtils.isNumeric(bookId)) {
|
||||
return koboThumbnailService.getThumbnail(Long.valueOf(bookId));
|
||||
@@ -90,13 +103,19 @@ public class KoboController {
|
||||
}
|
||||
}
|
||||
|
||||
@Operation(summary = "Authenticate Kobo device", description = "Authenticate a Kobo device.")
|
||||
@ApiResponse(responseCode = "200", description = "Device authenticated successfully")
|
||||
@PostMapping("/v1/auth/device")
|
||||
public ResponseEntity<KoboAuthentication> authenticateDevice(@RequestBody JsonNode body) {
|
||||
public ResponseEntity<KoboAuthentication> authenticateDevice(
|
||||
@Parameter(description = "Authentication request body") @RequestBody JsonNode body) {
|
||||
return koboDeviceAuthService.authenticateDevice(body);
|
||||
}
|
||||
|
||||
@Operation(summary = "Get book metadata", description = "Retrieve metadata for a book in the Kobo library.")
|
||||
@ApiResponse(responseCode = "200", description = "Metadata returned successfully")
|
||||
@GetMapping("/v1/library/{bookId}/metadata")
|
||||
public ResponseEntity<?> getBookMetadata(@PathVariable String bookId) {
|
||||
public ResponseEntity<?> getBookMetadata(
|
||||
@Parameter(description = "Book ID") @PathVariable String bookId) {
|
||||
if (StringUtils.isNumeric(bookId)) {
|
||||
return ResponseEntity.ok(List.of(koboEntitlementService.getMetadataForBook(Long.parseLong(bookId), token)));
|
||||
} else {
|
||||
@@ -104,8 +123,11 @@ public class KoboController {
|
||||
}
|
||||
}
|
||||
|
||||
@Operation(summary = "Get reading state", description = "Retrieve the reading state for a book.")
|
||||
@ApiResponse(responseCode = "200", description = "Reading state returned successfully")
|
||||
@GetMapping("/v1/library/{bookId}/state")
|
||||
public ResponseEntity<?> getState(@PathVariable String bookId) {
|
||||
public ResponseEntity<?> getState(
|
||||
@Parameter(description = "Book ID") @PathVariable String bookId) {
|
||||
if (StringUtils.isNumeric(bookId)) {
|
||||
return ResponseEntity.ok(koboReadingStateService.getReadingState(bookId));
|
||||
} else {
|
||||
@@ -113,8 +135,12 @@ public class KoboController {
|
||||
}
|
||||
}
|
||||
|
||||
@Operation(summary = "Update reading state", description = "Update the reading state for a book.")
|
||||
@ApiResponse(responseCode = "200", description = "Reading state updated successfully")
|
||||
@PutMapping("/v1/library/{bookId}/state")
|
||||
public ResponseEntity<?> updateState(@PathVariable String bookId, @RequestBody KoboReadingStateWrapper body) {
|
||||
public ResponseEntity<?> updateState(
|
||||
@Parameter(description = "Book ID") @PathVariable String bookId,
|
||||
@Parameter(description = "Reading state update body") @RequestBody KoboReadingStateWrapper body) {
|
||||
if (StringUtils.isNumeric(bookId)) {
|
||||
return ResponseEntity.ok(koboReadingStateService.saveReadingState(body.getReadingStates()));
|
||||
} else {
|
||||
@@ -122,16 +148,22 @@ public class KoboController {
|
||||
}
|
||||
}
|
||||
|
||||
@Operation(summary = "Get Kobo test analytics", description = "Get test analytics for Kobo.")
|
||||
@ApiResponse(responseCode = "200", description = "Test analytics returned successfully")
|
||||
@PostMapping("/v1/analytics/gettests")
|
||||
public ResponseEntity<?> getTests(@RequestBody Object body) {
|
||||
public ResponseEntity<?> getTests(
|
||||
@Parameter(description = "Test analytics request body") @RequestBody Object body) {
|
||||
return ResponseEntity.ok(KoboTestResponse.builder()
|
||||
.result("Success")
|
||||
.testKey(RandomStringUtils.secure().nextAlphanumeric(24))
|
||||
.build());
|
||||
}
|
||||
|
||||
@Operation(summary = "Download Kobo book", description = "Download a book from the Kobo library.")
|
||||
@ApiResponse(responseCode = "200", description = "Book downloaded successfully")
|
||||
@GetMapping("/v1/books/{bookId}/download")
|
||||
public void downloadBook(@PathVariable String bookId, HttpServletResponse response) throws IOException {
|
||||
public void downloadBook(
|
||||
@Parameter(description = "Book ID") @PathVariable String bookId, HttpServletResponse response) throws IOException {
|
||||
if (StringUtils.isNumeric(bookId)) {
|
||||
bookDownloadService.downloadKoboBook(Long.parseLong(bookId), response);
|
||||
} else {
|
||||
@@ -139,8 +171,11 @@ public class KoboController {
|
||||
}
|
||||
}
|
||||
|
||||
@Operation(summary = "Delete book from Kobo library", description = "Delete a book from the user's Kobo library.")
|
||||
@ApiResponse(responseCode = "200", description = "Book deleted successfully")
|
||||
@DeleteMapping("/v1/library/{bookId}")
|
||||
public ResponseEntity<?> deleteBookFromLibrary(@PathVariable String bookId) {
|
||||
public ResponseEntity<?> deleteBookFromLibrary(
|
||||
@Parameter(description = "Book ID") @PathVariable String bookId) {
|
||||
if (StringUtils.isNumeric(bookId)) {
|
||||
Shelf userKoboShelf = shelfService.getUserKoboShelf();
|
||||
if (userKoboShelf != null) {
|
||||
@@ -152,6 +187,8 @@ public class KoboController {
|
||||
}
|
||||
}
|
||||
|
||||
@Operation(summary = "Catch-all for Kobo API", description = "Catch-all endpoint for unhandled Kobo API requests.")
|
||||
@ApiResponse(responseCode = "200", description = "Request proxied successfully")
|
||||
@RequestMapping(value = "/**", method = {RequestMethod.GET, RequestMethod.POST, RequestMethod.PUT, RequestMethod.DELETE, RequestMethod.PATCH})
|
||||
public ResponseEntity<JsonNode> catchAll(HttpServletRequest request, @RequestBody(required = false) Object body) {
|
||||
String path = request.getRequestURI();
|
||||
|
||||
+13
-1
@@ -2,6 +2,10 @@ package com.adityachandel.booklore.controller;
|
||||
|
||||
import com.adityachandel.booklore.model.dto.KoboSyncSettings;
|
||||
import com.adityachandel.booklore.service.KoboSettingsService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.responses.ApiResponse;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
@@ -12,16 +16,21 @@ import org.springframework.web.bind.annotation.*;
|
||||
@RestController
|
||||
@RequestMapping("/api/v1/kobo-settings")
|
||||
@RequiredArgsConstructor
|
||||
@Tag(name = "Kobo Settings", description = "Endpoints for managing Kobo sync settings")
|
||||
public class KoboSettingsController {
|
||||
|
||||
private final KoboSettingsService koboService;
|
||||
|
||||
@Operation(summary = "Get Kobo sync settings", description = "Retrieve the current user's Kobo sync settings.")
|
||||
@ApiResponse(responseCode = "200", description = "Settings returned successfully")
|
||||
@GetMapping
|
||||
public ResponseEntity<KoboSyncSettings> getSettings() {
|
||||
KoboSyncSettings settings = koboService.getCurrentUserSettings();
|
||||
return ResponseEntity.ok(settings);
|
||||
}
|
||||
|
||||
@Operation(summary = "Create or update Kobo token", description = "Create or update the Kobo sync token for the current user. Requires sync permission or admin.")
|
||||
@ApiResponse(responseCode = "200", description = "Token created/updated successfully")
|
||||
@PutMapping
|
||||
@PreAuthorize("@securityUtil.canSyncKobo() or @securityUtil.isAdmin()")
|
||||
public ResponseEntity<KoboSyncSettings> createOrUpdateToken() {
|
||||
@@ -29,9 +38,12 @@ public class KoboSettingsController {
|
||||
return ResponseEntity.ok(updated);
|
||||
}
|
||||
|
||||
@Operation(summary = "Toggle Kobo sync", description = "Enable or disable Kobo sync for the current user. Requires sync permission or admin.")
|
||||
@ApiResponse(responseCode = "204", description = "Sync toggled successfully")
|
||||
@PutMapping("/sync")
|
||||
@PreAuthorize("@securityUtil.canSyncKobo() or @securityUtil.isAdmin()")
|
||||
public ResponseEntity<Void> toggleSync(@RequestParam boolean enabled) {
|
||||
public ResponseEntity<Void> toggleSync(
|
||||
@Parameter(description = "Enable or disable sync") @RequestParam boolean enabled) {
|
||||
koboService.setSyncEnabled(enabled);
|
||||
return ResponseEntity.noContent().build();
|
||||
}
|
||||
|
||||
+19
-3
@@ -2,6 +2,10 @@ package com.adityachandel.booklore.controller;
|
||||
|
||||
import com.adityachandel.booklore.model.dto.progress.KoreaderProgress;
|
||||
import com.adityachandel.booklore.service.KoreaderService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.responses.ApiResponse;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.validation.Valid;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@@ -16,32 +20,44 @@ import java.util.Map;
|
||||
@RestController
|
||||
@AllArgsConstructor
|
||||
@RequestMapping("/api/koreader")
|
||||
@Tag(name = "KoReader", description = "Endpoints for KoReader device integration and progress sync")
|
||||
public class KoreaderController {
|
||||
|
||||
private final KoreaderService koreaderService;
|
||||
|
||||
@Operation(summary = "Authorize KoReader user", description = "Authorize a user for KoReader sync.")
|
||||
@ApiResponse(responseCode = "200", description = "User authorized successfully")
|
||||
@GetMapping("/users/auth")
|
||||
public ResponseEntity<Map<String, String>> authorizeUser() {
|
||||
return koreaderService
|
||||
.authorizeUser();
|
||||
}
|
||||
|
||||
@Operation(summary = "Create KoReader user (disabled)", description = "Attempt to register a user via KoReader (always forbidden).")
|
||||
@ApiResponse(responseCode = "403", description = "User registration forbidden")
|
||||
@PostMapping("/users/create")
|
||||
public ResponseEntity<?> createUser(@RequestBody Map<String, Object> userData) {
|
||||
public ResponseEntity<?> createUser(
|
||||
@Parameter(description = "User data") @RequestBody Map<String, Object> userData) {
|
||||
log.warn("Attempt to register user via Koreader blocked: {}", userData);
|
||||
return ResponseEntity.status(HttpStatus.FORBIDDEN).body(Map.of("error", "User registration via Koreader is disabled"));
|
||||
}
|
||||
|
||||
@Operation(summary = "Get KoReader progress", description = "Retrieve reading progress for a book by its hash.")
|
||||
@ApiResponse(responseCode = "200", description = "Progress returned successfully")
|
||||
@GetMapping("/syncs/progress/{bookHash}")
|
||||
public ResponseEntity<KoreaderProgress> getProgress(@PathVariable String bookHash) {
|
||||
public ResponseEntity<KoreaderProgress> getProgress(
|
||||
@Parameter(description = "Book hash") @PathVariable String bookHash) {
|
||||
KoreaderProgress progress = koreaderService.getProgress(bookHash);
|
||||
return ResponseEntity.ok()
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.body(progress);
|
||||
}
|
||||
|
||||
@Operation(summary = "Update KoReader progress", description = "Update reading progress for a book.")
|
||||
@ApiResponse(responseCode = "200", description = "Progress updated successfully")
|
||||
@PutMapping("/syncs/progress")
|
||||
public ResponseEntity<?> updateProgress(@Valid @RequestBody KoreaderProgress koreaderProgress) {
|
||||
public ResponseEntity<?> updateProgress(
|
||||
@Parameter(description = "KoReader progress object") @Valid @RequestBody KoreaderProgress koreaderProgress) {
|
||||
koreaderService.saveProgress(koreaderProgress.getDocument(), koreaderProgress);
|
||||
return ResponseEntity.ok(Map.of("status", "progress updated"));
|
||||
}
|
||||
|
||||
+15
-2
@@ -2,6 +2,10 @@ package com.adityachandel.booklore.controller;
|
||||
|
||||
import com.adityachandel.booklore.model.dto.KoreaderUser;
|
||||
import com.adityachandel.booklore.service.KoreaderUserService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.responses.ApiResponse;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
@@ -14,26 +18,35 @@ import java.util.Map;
|
||||
@RestController
|
||||
@RequestMapping("/api/v1/koreader-users")
|
||||
@RequiredArgsConstructor
|
||||
@Tag(name = "KoReader Users", description = "Endpoints for managing KoReader user accounts and sync settings")
|
||||
public class KoreaderUserController {
|
||||
|
||||
private final KoreaderUserService koreaderUserService;
|
||||
|
||||
@Operation(summary = "Get current KoReader user", description = "Retrieve the current KoReader user profile.")
|
||||
@ApiResponse(responseCode = "200", description = "User profile returned successfully")
|
||||
@GetMapping("/me")
|
||||
@PreAuthorize("@securityUtil.canSyncKoReader() or @securityUtil.isAdmin()")
|
||||
public ResponseEntity<KoreaderUser> getCurrentUser() {
|
||||
return ResponseEntity.ok(koreaderUserService.getUser());
|
||||
}
|
||||
|
||||
@Operation(summary = "Upsert current KoReader user", description = "Create or update the current KoReader user profile.")
|
||||
@ApiResponse(responseCode = "200", description = "User profile upserted successfully")
|
||||
@PutMapping("/me")
|
||||
@PreAuthorize("@securityUtil.canSyncKoReader() or @securityUtil.isAdmin()")
|
||||
public ResponseEntity<KoreaderUser> upsertCurrentUser(@RequestBody Map<String, String> userData) {
|
||||
public ResponseEntity<KoreaderUser> upsertCurrentUser(
|
||||
@Parameter(description = "User data map") @RequestBody Map<String, String> userData) {
|
||||
KoreaderUser user = koreaderUserService.upsertUser(userData.get("username"), userData.get("password"));
|
||||
return ResponseEntity.ok(user);
|
||||
}
|
||||
|
||||
@Operation(summary = "Toggle KoReader sync", description = "Enable or disable KoReader sync for the current user.")
|
||||
@ApiResponse(responseCode = "204", description = "Sync toggled successfully")
|
||||
@PatchMapping("/me/sync")
|
||||
@PreAuthorize("@securityUtil.canSyncKoReader() or @securityUtil.isAdmin()")
|
||||
public ResponseEntity<Void> updateSyncEnabled(@RequestParam boolean enabled) {
|
||||
public ResponseEntity<Void> updateSyncEnabled(
|
||||
@Parameter(description = "Enable or disable sync") @RequestParam boolean enabled) {
|
||||
koreaderUserService.toggleSync(enabled);
|
||||
return ResponseEntity.noContent().build();
|
||||
}
|
||||
|
||||
+46
-9
@@ -5,6 +5,11 @@ import com.adityachandel.booklore.model.dto.Book;
|
||||
import com.adityachandel.booklore.model.dto.Library;
|
||||
import com.adityachandel.booklore.model.dto.request.CreateLibraryRequest;
|
||||
import com.adityachandel.booklore.service.library.LibraryService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.responses.ApiResponse;
|
||||
import io.swagger.v3.oas.annotations.responses.ApiResponses;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
@@ -16,68 +21,100 @@ import java.util.Map;
|
||||
@RestController
|
||||
@RequestMapping("/api/v1/libraries")
|
||||
@AllArgsConstructor
|
||||
@Tag(name = "Libraries", description = "Endpoints for managing libraries and their books")
|
||||
public class LibraryController {
|
||||
|
||||
private final LibraryService libraryService;
|
||||
|
||||
@Operation(summary = "Get all libraries", description = "Retrieve a list of all libraries.")
|
||||
@ApiResponse(responseCode = "200", description = "Libraries returned successfully")
|
||||
@GetMapping
|
||||
public ResponseEntity<List<Library>> getLibraries() {
|
||||
return ResponseEntity.ok(libraryService.getLibraries());
|
||||
}
|
||||
|
||||
@Operation(summary = "Get a library by ID", description = "Retrieve details of a specific library by its ID.")
|
||||
@ApiResponses({
|
||||
@ApiResponse(responseCode = "200", description = "Library details returned successfully"),
|
||||
@ApiResponse(responseCode = "404", description = "Library not found")
|
||||
})
|
||||
@GetMapping("/{libraryId}")
|
||||
@CheckLibraryAccess(libraryIdParam = "libraryId")
|
||||
public ResponseEntity<Library> getLibrary(@PathVariable long libraryId) {
|
||||
public ResponseEntity<Library> getLibrary(
|
||||
@Parameter(description = "ID of the library") @PathVariable long libraryId) {
|
||||
return ResponseEntity.ok(libraryService.getLibrary(libraryId));
|
||||
}
|
||||
|
||||
@Operation(summary = "Create a library", description = "Create a new library. Requires admin or manipulation permission.")
|
||||
@ApiResponse(responseCode = "200", description = "Library created successfully")
|
||||
@PostMapping
|
||||
@PreAuthorize("@securityUtil.canManipulateLibrary() or @securityUtil.isAdmin()")
|
||||
public ResponseEntity<Library> createLibrary(@RequestBody CreateLibraryRequest request) {
|
||||
public ResponseEntity<Library> createLibrary(
|
||||
@Parameter(description = "Library creation request") @RequestBody CreateLibraryRequest request) {
|
||||
return ResponseEntity.ok(libraryService.createLibrary(request));
|
||||
}
|
||||
|
||||
@Operation(summary = "Update a library", description = "Update an existing library. Requires admin or manipulation permission.")
|
||||
@ApiResponse(responseCode = "200", description = "Library updated successfully")
|
||||
@PutMapping("/{libraryId}")
|
||||
@CheckLibraryAccess(libraryIdParam = "libraryId")
|
||||
@PreAuthorize("@securityUtil.canManipulateLibrary() or @securityUtil.isAdmin()")
|
||||
public ResponseEntity<Library> updateLibrary(@RequestBody CreateLibraryRequest request, @PathVariable Long libraryId) {
|
||||
public ResponseEntity<Library> updateLibrary(
|
||||
@Parameter(description = "Library update request") @RequestBody CreateLibraryRequest request,
|
||||
@Parameter(description = "ID of the library") @PathVariable Long libraryId) {
|
||||
return ResponseEntity.ok(libraryService.updateLibrary(request, libraryId));
|
||||
}
|
||||
|
||||
@Operation(summary = "Delete a library", description = "Delete a library by its ID. Requires admin or manipulation permission.")
|
||||
@ApiResponse(responseCode = "204", description = "Library deleted successfully")
|
||||
@DeleteMapping("/{libraryId}")
|
||||
@CheckLibraryAccess(libraryIdParam = "libraryId")
|
||||
@PreAuthorize("@securityUtil.canManipulateLibrary() or @securityUtil.isAdmin()")
|
||||
public ResponseEntity<?> deleteLibrary(@PathVariable long libraryId) {
|
||||
public ResponseEntity<?> deleteLibrary(
|
||||
@Parameter(description = "ID of the library") @PathVariable long libraryId) {
|
||||
libraryService.deleteLibrary(libraryId);
|
||||
return ResponseEntity.noContent().build();
|
||||
}
|
||||
|
||||
@Operation(summary = "Get a book from a library", description = "Retrieve a specific book from a library by its ID.")
|
||||
@ApiResponse(responseCode = "200", description = "Book returned successfully")
|
||||
@GetMapping("/{libraryId}/book/{bookId}")
|
||||
@CheckLibraryAccess(libraryIdParam = "libraryId")
|
||||
public ResponseEntity<Book> getBook(@PathVariable long libraryId, @PathVariable long bookId) {
|
||||
public ResponseEntity<Book> getBook(
|
||||
@Parameter(description = "ID of the library") @PathVariable long libraryId,
|
||||
@Parameter(description = "ID of the book") @PathVariable long bookId) {
|
||||
return ResponseEntity.ok(libraryService.getBook(libraryId, bookId));
|
||||
}
|
||||
|
||||
|
||||
@Operation(summary = "Get all books from a library", description = "Retrieve all books from a specific library.")
|
||||
@ApiResponse(responseCode = "200", description = "Books returned successfully")
|
||||
@GetMapping("/{libraryId}/book")
|
||||
@CheckLibraryAccess(libraryIdParam = "libraryId")
|
||||
public ResponseEntity<List<Book>> getBooks(@PathVariable long libraryId) {
|
||||
public ResponseEntity<List<Book>> getBooks(
|
||||
@Parameter(description = "ID of the library") @PathVariable long libraryId) {
|
||||
List<Book> books = libraryService.getBooks(libraryId);
|
||||
return ResponseEntity.ok(books);
|
||||
}
|
||||
|
||||
@Operation(summary = "Rescan a library", description = "Rescan a library to refresh its contents. Requires admin or manipulation permission.")
|
||||
@ApiResponse(responseCode = "204", description = "Library rescanned successfully")
|
||||
@PutMapping("/{libraryId}/refresh")
|
||||
@CheckLibraryAccess(libraryIdParam = "libraryId")
|
||||
@PreAuthorize("@securityUtil.canManipulateLibrary() or @securityUtil.isAdmin()")
|
||||
public ResponseEntity<?> rescanLibrary(@PathVariable long libraryId) {
|
||||
public ResponseEntity<?> rescanLibrary(
|
||||
@Parameter(description = "ID of the library") @PathVariable long libraryId) {
|
||||
libraryService.rescanLibrary(libraryId);
|
||||
return ResponseEntity.noContent().build();
|
||||
}
|
||||
|
||||
@Operation(summary = "Set file naming pattern", description = "Set the file naming pattern for a library. Requires admin or manipulation permission.")
|
||||
@ApiResponse(responseCode = "200", description = "File naming pattern updated successfully")
|
||||
@PatchMapping("/{libraryId}/file-naming-pattern")
|
||||
@CheckLibraryAccess(libraryIdParam = "libraryId")
|
||||
@PreAuthorize("@securityUtil.canManipulateLibrary() or @securityUtil.isAdmin()")
|
||||
public ResponseEntity<Library> setFileNamingPattern(@PathVariable long libraryId, @RequestBody Map<String, String> body) {
|
||||
public ResponseEntity<Library> setFileNamingPattern(
|
||||
@Parameter(description = "ID of the library") @PathVariable long libraryId,
|
||||
@Parameter(description = "File naming pattern body") @RequestBody Map<String, String> body) {
|
||||
String pattern = body.get("fileNamingPattern");
|
||||
Library updated = libraryService.setFileNamingPattern(libraryId, pattern);
|
||||
return ResponseEntity.ok(updated);
|
||||
|
||||
+19
-3
@@ -2,6 +2,10 @@ package com.adityachandel.booklore.controller;
|
||||
|
||||
import com.adityachandel.booklore.model.dto.MagicShelf;
|
||||
import com.adityachandel.booklore.service.MagicShelfService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.responses.ApiResponse;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.validation.Valid;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
@@ -10,6 +14,7 @@ import java.util.List;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api/magic-shelves")
|
||||
@Tag(name = "Magic Shelves", description = "Endpoints for managing user-defined magic shelves")
|
||||
public class MagicShelfController {
|
||||
|
||||
private final MagicShelfService magicShelfService;
|
||||
@@ -18,23 +23,34 @@ public class MagicShelfController {
|
||||
this.magicShelfService = magicShelfService;
|
||||
}
|
||||
|
||||
@Operation(summary = "Get all magic shelves for user", description = "Retrieve all magic shelves for the current user.")
|
||||
@ApiResponse(responseCode = "200", description = "Magic shelves returned successfully")
|
||||
@GetMapping
|
||||
public ResponseEntity<List<MagicShelf>> getAllForUser() {
|
||||
return ResponseEntity.ok(magicShelfService.getUserShelves());
|
||||
}
|
||||
|
||||
@Operation(summary = "Get a magic shelf by ID", description = "Retrieve a specific magic shelf by its ID.")
|
||||
@ApiResponse(responseCode = "200", description = "Magic shelf returned successfully")
|
||||
@GetMapping("/{id}")
|
||||
public ResponseEntity<MagicShelf> getShelf(@PathVariable Long id) {
|
||||
public ResponseEntity<MagicShelf> getShelf(
|
||||
@Parameter(description = "ID of the magic shelf") @PathVariable Long id) {
|
||||
return ResponseEntity.ok(magicShelfService.getShelf(id));
|
||||
}
|
||||
|
||||
@Operation(summary = "Create or update a magic shelf", description = "Create or update a magic shelf for the user.")
|
||||
@ApiResponse(responseCode = "200", description = "Magic shelf created/updated successfully")
|
||||
@PostMapping
|
||||
public ResponseEntity<MagicShelf> createUpdateShelf(@Valid @RequestBody MagicShelf shelf) {
|
||||
public ResponseEntity<MagicShelf> createUpdateShelf(
|
||||
@Parameter(description = "Magic shelf object") @Valid @RequestBody MagicShelf shelf) {
|
||||
return ResponseEntity.ok(magicShelfService.createOrUpdateShelf(shelf));
|
||||
}
|
||||
|
||||
@Operation(summary = "Delete a magic shelf", description = "Delete a specific magic shelf by its ID.")
|
||||
@ApiResponse(responseCode = "204", description = "Magic shelf deleted successfully")
|
||||
@DeleteMapping("/{id}")
|
||||
public ResponseEntity<Void> deleteShelf(@PathVariable Long id) {
|
||||
public ResponseEntity<Void> deleteShelf(
|
||||
@Parameter(description = "ID of the magic shelf") @PathVariable Long id) {
|
||||
magicShelfService.deleteShelf(id);
|
||||
return ResponseEntity.noContent().build();
|
||||
}
|
||||
|
||||
+60
-11
@@ -20,12 +20,19 @@ import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.responses.ApiResponse;
|
||||
import io.swagger.v3.oas.annotations.responses.ApiResponses;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api/v1/books")
|
||||
@AllArgsConstructor
|
||||
@Tag(name = "Book Metadata", description = "Endpoints for managing book metadata, covers, and metadata operations")
|
||||
public class MetadataController {
|
||||
|
||||
private final BookMetadataService bookMetadataService;
|
||||
@@ -37,17 +44,26 @@ public class MetadataController {
|
||||
private final BookRepository bookRepository;
|
||||
private final MetadataManagementService metadataManagementService;
|
||||
|
||||
@Operation(summary = "Get prospective metadata for a book", description = "Fetch prospective metadata for a book by its ID. Requires metadata edit permission or admin.")
|
||||
@ApiResponse(responseCode = "200", description = "Prospective metadata returned successfully")
|
||||
@PostMapping("/{bookId}/metadata/prospective")
|
||||
@PreAuthorize("@securityUtil.canEditMetadata() or @securityUtil.isAdmin()")
|
||||
@CheckBookAccess(bookIdParam = "bookId")
|
||||
public ResponseEntity<List<BookMetadata>> getMetadataList(@RequestBody(required = false) FetchMetadataRequest fetchMetadataRequest, @PathVariable Long bookId) {
|
||||
public ResponseEntity<List<BookMetadata>> getMetadataList(
|
||||
@Parameter(description = "Fetch metadata request") @RequestBody(required = false) FetchMetadataRequest fetchMetadataRequest,
|
||||
@Parameter(description = "ID of the book") @PathVariable Long bookId) {
|
||||
return ResponseEntity.ok(bookMetadataService.getProspectiveMetadataListForBookId(bookId, fetchMetadataRequest));
|
||||
}
|
||||
|
||||
@Operation(summary = "Update book metadata", description = "Update metadata for a book. Requires metadata edit permission or admin.")
|
||||
@ApiResponse(responseCode = "200", description = "Metadata updated successfully")
|
||||
@PutMapping("/{bookId}/metadata")
|
||||
@PreAuthorize("@securityUtil.canEditMetadata() or @securityUtil.isAdmin()")
|
||||
@CheckBookAccess(bookIdParam = "bookId")
|
||||
public ResponseEntity<BookMetadata> updateMetadata(@RequestBody MetadataUpdateWrapper metadataUpdateWrapper, @PathVariable long bookId, @RequestParam(defaultValue = "true") boolean mergeCategories) {
|
||||
public ResponseEntity<BookMetadata> updateMetadata(
|
||||
@Parameter(description = "Metadata update wrapper") @RequestBody MetadataUpdateWrapper metadataUpdateWrapper,
|
||||
@Parameter(description = "ID of the book") @PathVariable long bookId,
|
||||
@Parameter(description = "Merge categories") @RequestParam(defaultValue = "true") boolean mergeCategories) {
|
||||
BookEntity bookEntity = bookRepository.findById(bookId).orElseThrow(() -> ApiError.BOOK_NOT_FOUND.createException(bookId));
|
||||
|
||||
MetadataUpdateContext context = MetadataUpdateContext.builder()
|
||||
@@ -64,9 +80,12 @@ public class MetadataController {
|
||||
return ResponseEntity.ok(bookMetadata);
|
||||
}
|
||||
|
||||
@Operation(summary = "Bulk edit book metadata", description = "Bulk update metadata for multiple books. Requires metadata edit permission or admin.")
|
||||
@ApiResponse(responseCode = "204", description = "Bulk metadata updated successfully")
|
||||
@PutMapping("/bulk-edit-metadata")
|
||||
@PreAuthorize("@securityUtil.canEditMetadata() or @securityUtil.isAdmin()")
|
||||
public ResponseEntity<Void> bulkEditMetadata(@RequestBody BulkMetadataUpdateRequest bulkMetadataUpdateRequest) {
|
||||
public ResponseEntity<Void> bulkEditMetadata(
|
||||
@Parameter(description = "Bulk metadata update request") @RequestBody BulkMetadataUpdateRequest bulkMetadataUpdateRequest) {
|
||||
boolean mergeCategories = bulkMetadataUpdateRequest.isMergeCategories();
|
||||
boolean mergeMoods = bulkMetadataUpdateRequest.isMergeMoods();
|
||||
boolean mergeTags = bulkMetadataUpdateRequest.isMergeTags();
|
||||
@@ -74,48 +93,69 @@ public class MetadataController {
|
||||
return ResponseEntity.noContent().build();
|
||||
}
|
||||
|
||||
@Operation(summary = "Upload cover image from file", description = "Upload a cover image for a book from a file. Requires metadata edit permission or admin.")
|
||||
@ApiResponse(responseCode = "200", description = "Cover image uploaded successfully")
|
||||
@PostMapping("/{bookId}/metadata/cover/upload")
|
||||
@PreAuthorize("@securityUtil.canEditMetadata() or @securityUtil.isAdmin()")
|
||||
@CheckBookAccess(bookIdParam = "bookId")
|
||||
public ResponseEntity<BookMetadata> uploadCoverFromFile(@PathVariable Long bookId, @RequestParam("file") MultipartFile file) {
|
||||
public ResponseEntity<BookMetadata> uploadCoverFromFile(
|
||||
@Parameter(description = "ID of the book") @PathVariable Long bookId,
|
||||
@Parameter(description = "Cover image file") @RequestParam("file") MultipartFile file) {
|
||||
BookMetadata updated = bookMetadataService.updateCoverImageFromFile(bookId, file);
|
||||
return ResponseEntity.ok(updated);
|
||||
}
|
||||
|
||||
@Operation(summary = "Upload cover image from URL", description = "Upload a cover image for a book from a URL. Requires metadata edit permission or admin.")
|
||||
@ApiResponse(responseCode = "200", description = "Cover image uploaded successfully")
|
||||
@PostMapping("/{bookId}/metadata/cover/from-url")
|
||||
@PreAuthorize("@securityUtil.canEditMetadata() or @securityUtil.isAdmin()")
|
||||
@CheckBookAccess(bookIdParam = "bookId")
|
||||
public ResponseEntity<BookMetadata> uploadCoverFromUrl(@PathVariable Long bookId, @RequestBody Map<String, String> body) {
|
||||
public ResponseEntity<BookMetadata> uploadCoverFromUrl(
|
||||
@Parameter(description = "ID of the book") @PathVariable Long bookId,
|
||||
@Parameter(description = "URL body") @RequestBody Map<String, String> body) {
|
||||
BookMetadata updated = bookMetadataService.updateCoverImageFromUrl(bookId, body.get("url"));
|
||||
return ResponseEntity.ok(updated);
|
||||
}
|
||||
|
||||
@Operation(summary = "Toggle all metadata locks", description = "Toggle all metadata locks for books. Requires metadata edit permission or admin.")
|
||||
@ApiResponse(responseCode = "200", description = "Metadata locks toggled successfully")
|
||||
@PutMapping("/metadata/toggle-all-lock")
|
||||
@PreAuthorize("@securityUtil.canEditMetadata() or @securityUtil.isAdmin()")
|
||||
public ResponseEntity<List<BookMetadata>> toggleAllMetadata(@RequestBody ToggleAllLockRequest request) {
|
||||
public ResponseEntity<List<BookMetadata>> toggleAllMetadata(
|
||||
@Parameter(description = "Toggle all lock request") @RequestBody ToggleAllLockRequest request) {
|
||||
return ResponseEntity.ok(bookMetadataService.toggleAllLock(request));
|
||||
}
|
||||
|
||||
@Operation(summary = "Toggle field locks for metadata", description = "Toggle field locks for book metadata. Requires metadata edit permission or admin.")
|
||||
@ApiResponse(responseCode = "200", description = "Field locks toggled successfully")
|
||||
@PutMapping("/metadata/toggle-field-locks")
|
||||
@PreAuthorize("@securityUtil.canEditMetadata() or @securityUtil.isAdmin()")
|
||||
public ResponseEntity<List<BookMetadata>> toggleFieldLocks(@RequestBody ToggleFieldLocksRequest request) {
|
||||
public ResponseEntity<List<BookMetadata>> toggleFieldLocks(
|
||||
@Parameter(description = "Toggle field locks request") @RequestBody ToggleFieldLocksRequest request) {
|
||||
bookMetadataService.toggleFieldLocks(request.getBookIds(), request.getFieldActions());
|
||||
return ResponseEntity.ok().build();
|
||||
}
|
||||
|
||||
@Operation(summary = "Regenerate all covers", description = "Regenerate covers for all books. Requires metadata edit permission or admin.")
|
||||
@ApiResponse(responseCode = "204", description = "Covers regenerated successfully")
|
||||
@PostMapping("/regenerate-covers")
|
||||
@PreAuthorize("@securityUtil.canEditMetadata() or @securityUtil.isAdmin()")
|
||||
public void regenerateCovers() {
|
||||
bookMetadataService.regenerateCovers();
|
||||
}
|
||||
|
||||
@Operation(summary = "Regenerate cover for a book", description = "Regenerate cover for a specific book. Requires metadata edit permission or admin.")
|
||||
@ApiResponse(responseCode = "204", description = "Cover regenerated successfully")
|
||||
@PostMapping("/{bookId}/regenerate-cover")
|
||||
@PreAuthorize("@securityUtil.canEditMetadata() or @securityUtil.isAdmin()")
|
||||
@CheckBookAccess(bookIdParam = "bookId")
|
||||
public void regenerateCovers(@PathVariable Long bookId) {
|
||||
public void regenerateCovers(
|
||||
@Parameter(description = "ID of the book") @PathVariable Long bookId) {
|
||||
bookMetadataService.regenerateCover(bookId);
|
||||
}
|
||||
|
||||
@Operation(summary = "Recalculate metadata match scores", description = "Recalculate match scores for all metadata. Requires admin.")
|
||||
@ApiResponse(responseCode = "204", description = "Match scores recalculated successfully")
|
||||
@PostMapping("/metadata/recalculate-match-scores")
|
||||
@PreAuthorize("@securityUtil.isAdmin()")
|
||||
public ResponseEntity<Void> recalculateMatchScores() {
|
||||
@@ -123,21 +163,30 @@ public class MetadataController {
|
||||
return ResponseEntity.noContent().build();
|
||||
}
|
||||
|
||||
@Operation(summary = "Get cover images for a book", description = "Fetch cover images for a book.")
|
||||
@ApiResponse(responseCode = "200", description = "Cover images returned successfully")
|
||||
@PostMapping("/{bookId}/metadata/covers")
|
||||
public ResponseEntity<List<CoverImage>> getImages(@RequestBody CoverFetchRequest request) {
|
||||
public ResponseEntity<List<CoverImage>> getImages(
|
||||
@Parameter(description = "Cover fetch request") @RequestBody CoverFetchRequest request) {
|
||||
return ResponseEntity.ok(duckDuckGoCoverService.getCovers(request));
|
||||
}
|
||||
|
||||
@Operation(summary = "Consolidate metadata", description = "Merge metadata values. Requires metadata edit permission or admin.")
|
||||
@ApiResponse(responseCode = "204", description = "Metadata consolidated successfully")
|
||||
@PostMapping("/metadata/manage/consolidate")
|
||||
@PreAuthorize("@securityUtil.canEditMetadata() or @securityUtil.isAdmin()")
|
||||
public ResponseEntity<Void> mergeMetadata(@Validated @RequestBody MergeMetadataRequest request) {
|
||||
public ResponseEntity<Void> mergeMetadata(
|
||||
@Parameter(description = "Merge metadata request") @Validated @RequestBody MergeMetadataRequest request) {
|
||||
metadataManagementService.consolidateMetadata(request.getMetadataType(), request.getTargetValues(), request.getValuesToMerge());
|
||||
return ResponseEntity.noContent().build();
|
||||
}
|
||||
|
||||
@Operation(summary = "Delete metadata values", description = "Delete metadata values. Requires metadata edit permission or admin.")
|
||||
@ApiResponse(responseCode = "204", description = "Metadata deleted successfully")
|
||||
@PostMapping("/metadata/manage/delete")
|
||||
@PreAuthorize("@securityUtil.canEditMetadata() or @securityUtil.isAdmin()")
|
||||
public ResponseEntity<Void> deleteMetadata(@Validated @RequestBody DeleteMetadataRequest request) {
|
||||
public ResponseEntity<Void> deleteMetadata(
|
||||
@Parameter(description = "Delete metadata request") @Validated @RequestBody DeleteMetadataRequest request) {
|
||||
metadataManagementService.deleteMetadata(request.getMetadataType(), request.getValuesToDelete());
|
||||
return ResponseEntity.noContent().build();
|
||||
}
|
||||
|
||||
+21
-3
@@ -3,6 +3,10 @@ package com.adityachandel.booklore.controller;
|
||||
import com.adityachandel.booklore.model.dto.MetadataBatchProgressNotification;
|
||||
import com.adityachandel.booklore.model.dto.response.MetadataTaskDetailsResponse;
|
||||
import com.adityachandel.booklore.service.MetadataTaskService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.responses.ApiResponse;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
@@ -13,34 +17,48 @@ import java.util.List;
|
||||
@RestController
|
||||
@RequestMapping("/api/metadata/tasks")
|
||||
@RequiredArgsConstructor
|
||||
@Tag(name = "Metadata Tasks", description = "Endpoints for managing metadata batch tasks and proposals")
|
||||
public class MetadataTaskController {
|
||||
|
||||
private final MetadataTaskService metadataTaskService;
|
||||
|
||||
@Operation(summary = "Get metadata task with proposals", description = "Retrieve a metadata task and its proposals by task ID. Requires metadata edit permission or admin.")
|
||||
@ApiResponse(responseCode = "200", description = "Task details returned successfully")
|
||||
@GetMapping("/{taskId}")
|
||||
@PreAuthorize("@securityUtil.canEditMetadata() or @securityUtil.isAdmin()")
|
||||
public ResponseEntity<MetadataTaskDetailsResponse> getTaskWithProposals(@PathVariable String taskId) {
|
||||
public ResponseEntity<MetadataTaskDetailsResponse> getTaskWithProposals(
|
||||
@Parameter(description = "Task ID") @PathVariable String taskId) {
|
||||
return metadataTaskService.getTaskWithProposals(taskId)
|
||||
.map(ResponseEntity::ok)
|
||||
.orElse(ResponseEntity.notFound().build());
|
||||
}
|
||||
|
||||
@Operation(summary = "Get active metadata tasks", description = "Retrieve all active metadata batch tasks. Requires metadata edit permission or admin.")
|
||||
@ApiResponse(responseCode = "200", description = "Active tasks returned successfully")
|
||||
@GetMapping("/active")
|
||||
@PreAuthorize("@securityUtil.canEditMetadata() or @securityUtil.isAdmin()")
|
||||
public ResponseEntity<List<MetadataBatchProgressNotification>> getActiveTasks() {
|
||||
return ResponseEntity.ok(metadataTaskService.getActiveTasks());
|
||||
}
|
||||
|
||||
@Operation(summary = "Delete a metadata task", description = "Delete a metadata task and its proposals by task ID. Requires metadata edit permission or admin.")
|
||||
@ApiResponse(responseCode = "204", description = "Task deleted successfully")
|
||||
@DeleteMapping("/{taskId}")
|
||||
@PreAuthorize("@securityUtil.canEditMetadata() or @securityUtil.isAdmin()")
|
||||
public ResponseEntity<Void> deleteTask(@PathVariable String taskId) {
|
||||
public ResponseEntity<Void> deleteTask(
|
||||
@Parameter(description = "Task ID") @PathVariable String taskId) {
|
||||
boolean deleted = metadataTaskService.deleteTaskAndProposals(taskId);
|
||||
return deleted ? ResponseEntity.noContent().build() : ResponseEntity.notFound().build();
|
||||
}
|
||||
|
||||
@Operation(summary = "Update proposal status", description = "Update the status of a proposal for a metadata task. Requires metadata edit permission or admin.")
|
||||
@ApiResponse(responseCode = "200", description = "Proposal status updated successfully")
|
||||
@PostMapping("/{taskId}/proposals/{proposalId}/status")
|
||||
@PreAuthorize("@securityUtil.canEditMetadata() or @securityUtil.isAdmin()")
|
||||
public ResponseEntity<Void> updateProposalStatus(@PathVariable String taskId, @PathVariable Long proposalId, @RequestParam String status) {
|
||||
public ResponseEntity<Void> updateProposalStatus(
|
||||
@Parameter(description = "Task ID") @PathVariable String taskId,
|
||||
@Parameter(description = "Proposal ID") @PathVariable Long proposalId,
|
||||
@Parameter(description = "New status") @RequestParam String status) {
|
||||
boolean updated = metadataTaskService.updateProposalStatus(taskId, proposalId, status);
|
||||
return updated ? ResponseEntity.ok().build() : ResponseEntity.notFound().build();
|
||||
}
|
||||
|
||||
+47
-9
@@ -1,7 +1,12 @@
|
||||
package com.adityachandel.booklore.controller.opds;
|
||||
package com.adityachandel.booklore.controller;
|
||||
|
||||
import com.adityachandel.booklore.service.BookService;
|
||||
import com.adityachandel.booklore.service.opds.OpdsFeedService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import io.swagger.v3.oas.annotations.responses.ApiResponse;
|
||||
import io.swagger.v3.oas.annotations.responses.ApiResponses;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@@ -14,6 +19,7 @@ import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@Tag(name = "OPDS", description = "Endpoints for OPDS catalog feeds, book downloads, covers, and search description")
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("/api/v1/opds")
|
||||
@@ -26,13 +32,25 @@ public class OpdsController {
|
||||
private final OpdsFeedService opdsFeedService;
|
||||
private final BookService bookService;
|
||||
|
||||
@Operation(summary = "Download book file", description = "Download the book file by its ID.")
|
||||
@ApiResponses({
|
||||
@ApiResponse(responseCode = "200", description = "Book file downloaded successfully"),
|
||||
@ApiResponse(responseCode = "404", description = "Book not found")
|
||||
})
|
||||
@GetMapping("/{bookId}/download")
|
||||
public ResponseEntity<Resource> downloadBook(@PathVariable("bookId") Long bookId) {
|
||||
public ResponseEntity<Resource> downloadBook(
|
||||
@Parameter(description = "ID of the book to download") @PathVariable("bookId") Long bookId) {
|
||||
return bookService.downloadBook(bookId);
|
||||
}
|
||||
|
||||
@Operation(summary = "Get book cover image", description = "Retrieve the cover image for a book by its ID.")
|
||||
@ApiResponses({
|
||||
@ApiResponse(responseCode = "200", description = "Cover image returned successfully"),
|
||||
@ApiResponse(responseCode = "404", description = "Book or cover not found")
|
||||
})
|
||||
@GetMapping("/{bookId}/cover")
|
||||
public ResponseEntity<Resource> getBookCover(@PathVariable long bookId) {
|
||||
public ResponseEntity<Resource> getBookCover(
|
||||
@Parameter(description = "ID of the book") @PathVariable long bookId) {
|
||||
Resource coverImage = bookService.getBookThumbnail(bookId);
|
||||
String contentType = "image/jpeg";
|
||||
return ResponseEntity.ok()
|
||||
@@ -41,54 +59,74 @@ public class OpdsController {
|
||||
.body(coverImage);
|
||||
}
|
||||
|
||||
@Operation(summary = "Get OPDS root catalog", description = "Retrieve the OPDS root navigation feed.")
|
||||
@ApiResponse(responseCode = "200", description = "Root OPDS catalog returned successfully")
|
||||
@GetMapping(produces = OPDS_CATALOG_MEDIA_TYPE)
|
||||
public ResponseEntity<String> getRootCatalog(HttpServletRequest request) {
|
||||
public ResponseEntity<String> getRootCatalog(
|
||||
@Parameter(hidden = true) HttpServletRequest request) {
|
||||
String feed = opdsFeedService.generateRootNavigation(request);
|
||||
return ResponseEntity.ok()
|
||||
.contentType(MediaType.parseMediaType(OPDS_CATALOG_MEDIA_TYPE))
|
||||
.body(feed);
|
||||
}
|
||||
|
||||
@Operation(summary = "Get OPDS libraries navigation", description = "Retrieve the OPDS libraries navigation feed.")
|
||||
@ApiResponse(responseCode = "200", description = "Libraries navigation feed returned successfully")
|
||||
@GetMapping(value = "/libraries", produces = OPDS_CATALOG_MEDIA_TYPE)
|
||||
public ResponseEntity<String> getLibrariesNavigation(HttpServletRequest request) {
|
||||
public ResponseEntity<String> getLibrariesNavigation(
|
||||
@Parameter(hidden = true) HttpServletRequest request) {
|
||||
String feed = opdsFeedService.generateLibrariesNavigation(request);
|
||||
return ResponseEntity.ok()
|
||||
.contentType(MediaType.parseMediaType(OPDS_CATALOG_MEDIA_TYPE))
|
||||
.body(feed);
|
||||
}
|
||||
|
||||
@Operation(summary = "Get OPDS shelves navigation", description = "Retrieve the OPDS shelves navigation feed.")
|
||||
@ApiResponse(responseCode = "200", description = "Shelves navigation feed returned successfully")
|
||||
@GetMapping(value = "/shelves", produces = OPDS_CATALOG_MEDIA_TYPE)
|
||||
public ResponseEntity<String> getShelvesNavigation(HttpServletRequest request) {
|
||||
public ResponseEntity<String> getShelvesNavigation(
|
||||
@Parameter(hidden = true) HttpServletRequest request) {
|
||||
String feed = opdsFeedService.generateShelvesNavigation(request);
|
||||
return ResponseEntity.ok()
|
||||
.contentType(MediaType.parseMediaType(OPDS_CATALOG_MEDIA_TYPE))
|
||||
.body(feed);
|
||||
}
|
||||
|
||||
@Operation(summary = "Get OPDS catalog feed", description = "Retrieve the OPDS acquisition catalog feed.")
|
||||
@ApiResponse(responseCode = "200", description = "Catalog feed returned successfully")
|
||||
@GetMapping(value = "/catalog", produces = OPDS_ACQUISITION_MEDIA_TYPE)
|
||||
public ResponseEntity<String> getCatalog(HttpServletRequest request) {
|
||||
public ResponseEntity<String> getCatalog(
|
||||
@Parameter(hidden = true) HttpServletRequest request) {
|
||||
String feed = opdsFeedService.generateCatalogFeed(request);
|
||||
return ResponseEntity.ok()
|
||||
.contentType(MediaType.parseMediaType(OPDS_ACQUISITION_MEDIA_TYPE))
|
||||
.body(feed);
|
||||
}
|
||||
|
||||
@Operation(summary = "Get recent books feed", description = "Retrieve the OPDS feed for recently added books.")
|
||||
@ApiResponse(responseCode = "200", description = "Recent books feed returned successfully")
|
||||
@GetMapping(value = "/recent", produces = OPDS_ACQUISITION_MEDIA_TYPE)
|
||||
public ResponseEntity<String> getRecentBooks(HttpServletRequest request) {
|
||||
public ResponseEntity<String> getRecentBooks(
|
||||
@Parameter(hidden = true) HttpServletRequest request) {
|
||||
String feed = opdsFeedService.generateRecentFeed(request);
|
||||
return ResponseEntity.ok()
|
||||
.contentType(MediaType.parseMediaType(OPDS_ACQUISITION_MEDIA_TYPE))
|
||||
.body(feed);
|
||||
}
|
||||
|
||||
@Operation(summary = "Get surprise feed", description = "Retrieve the OPDS feed for surprise/random books.")
|
||||
@ApiResponse(responseCode = "200", description = "Surprise feed returned successfully")
|
||||
@GetMapping(value = "/surprise", produces = OPDS_ACQUISITION_MEDIA_TYPE)
|
||||
public ResponseEntity<String> getSurpriseFeed(HttpServletRequest request) {
|
||||
public ResponseEntity<String> getSurpriseFeed(
|
||||
@Parameter(hidden = true) HttpServletRequest request) {
|
||||
String feed = opdsFeedService.generateSurpriseFeed(request);
|
||||
return ResponseEntity.ok()
|
||||
.contentType(MediaType.parseMediaType(OPDS_ACQUISITION_MEDIA_TYPE))
|
||||
.body(feed);
|
||||
}
|
||||
|
||||
@Operation(summary = "Get OPDS search description", description = "Retrieve the OpenSearch description document for OPDS search.")
|
||||
@ApiResponse(responseCode = "200", description = "OpenSearch description returned successfully")
|
||||
@GetMapping(value = "/search.opds", produces = {
|
||||
"application/opensearchdescription+xml",
|
||||
"application/atom+xml",
|
||||
+15
-2
@@ -4,6 +4,10 @@ package com.adityachandel.booklore.controller;
|
||||
import com.adityachandel.booklore.model.dto.OpdsUserV2;
|
||||
import com.adityachandel.booklore.model.dto.request.OpdsUserV2CreateRequest;
|
||||
import com.adityachandel.booklore.service.OpdsUserV2Service;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.responses.ApiResponse;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
@@ -13,25 +17,34 @@ import java.util.List;
|
||||
@RestController
|
||||
@RequestMapping("/api/v2/opds-users")
|
||||
@RequiredArgsConstructor
|
||||
@Tag(name = "OPDS Users", description = "Endpoints for managing OPDS users")
|
||||
public class OpdsUserV2Controller {
|
||||
|
||||
private final OpdsUserV2Service service;
|
||||
|
||||
@Operation(summary = "Get all OPDS users", description = "Retrieve a list of all OPDS users.")
|
||||
@ApiResponse(responseCode = "200", description = "List of OPDS users returned successfully")
|
||||
@GetMapping
|
||||
@PreAuthorize("@securityUtil.isAdmin() or @securityUtil.canAccessOpds()")
|
||||
public List<OpdsUserV2> getUsers() {
|
||||
return service.getOpdsUsers();
|
||||
}
|
||||
|
||||
@Operation(summary = "Create OPDS user", description = "Create a new OPDS user.")
|
||||
@ApiResponse(responseCode = "200", description = "OPDS user created successfully")
|
||||
@PostMapping
|
||||
@PreAuthorize("@securityUtil.isAdmin() or @securityUtil.canAccessOpds()")
|
||||
public OpdsUserV2 createUser(@RequestBody OpdsUserV2CreateRequest createRequest) {
|
||||
public OpdsUserV2 createUser(
|
||||
@Parameter(description = "OPDS user creation request") @RequestBody OpdsUserV2CreateRequest createRequest) {
|
||||
return service.createOpdsUser(createRequest);
|
||||
}
|
||||
|
||||
@Operation(summary = "Delete OPDS user", description = "Delete an OPDS user by ID.")
|
||||
@ApiResponse(responseCode = "204", description = "OPDS user deleted successfully")
|
||||
@DeleteMapping("/{id}")
|
||||
@PreAuthorize("@securityUtil.isAdmin() or @securityUtil.canAccessOpds()")
|
||||
public void deleteUser(@PathVariable Long id) {
|
||||
public void deleteUser(
|
||||
@Parameter(description = "ID of the OPDS user to delete") @PathVariable Long id) {
|
||||
service.deleteOpdsUser(id);
|
||||
}
|
||||
}
|
||||
|
||||
+10
-1
@@ -8,18 +8,27 @@ import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.responses.ApiResponse;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api/v1/path")
|
||||
@AllArgsConstructor
|
||||
@Tag(name = "Library Paths", description = "Endpoints for retrieving folder paths within libraries")
|
||||
public class PathController {
|
||||
|
||||
private final PathService pathService;
|
||||
|
||||
@Operation(summary = "Get folders at a path", description = "Retrieve a list of folders at a given path. Requires admin or library manipulation permission.")
|
||||
@ApiResponse(responseCode = "200", description = "Folders returned successfully")
|
||||
@GetMapping
|
||||
@PreAuthorize("@securityUtil.canManipulateLibrary() or @securityUtil.isAdmin()")
|
||||
public List<String> getFolders(@RequestParam String path) {
|
||||
public List<String> getFolders(
|
||||
@Parameter(description = "Path to list folders at") @RequestParam String path) {
|
||||
return pathService.getFoldersAtPath(path);
|
||||
}
|
||||
}
|
||||
|
||||
+9
-1
@@ -1,6 +1,10 @@
|
||||
package com.adityachandel.booklore.controller;
|
||||
|
||||
import com.adityachandel.booklore.service.reader.PdfReaderService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.responses.ApiResponse;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.http.MediaType;
|
||||
@@ -15,12 +19,16 @@ import java.util.List;
|
||||
@RestController
|
||||
@RequestMapping("/api/v1/pdf")
|
||||
@RequiredArgsConstructor
|
||||
@Tag(name = "PDF Reader", description = "Endpoints for reading PDF format books")
|
||||
public class PdfReaderController {
|
||||
|
||||
private final PdfReaderService pdfReaderService;
|
||||
|
||||
@Operation(summary = "List pages in a PDF book", description = "Retrieve a list of available page numbers for a PDF book.")
|
||||
@ApiResponse(responseCode = "200", description = "Page numbers returned successfully")
|
||||
@GetMapping("/{bookId}/pages")
|
||||
public List<Integer> listPages(@PathVariable Long bookId) throws IOException {
|
||||
public List<Integer> listPages(
|
||||
@Parameter(description = "ID of the book") @PathVariable Long bookId) throws IOException {
|
||||
return pdfReaderService.getAvailablePages(bookId);
|
||||
}
|
||||
}
|
||||
+6
@@ -2,6 +2,9 @@ package com.adityachandel.booklore.controller;
|
||||
|
||||
import com.adityachandel.booklore.model.dto.settings.PublicAppSetting;
|
||||
import com.adityachandel.booklore.service.appsettings.AppSettingService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.responses.ApiResponse;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
@@ -12,10 +15,13 @@ import java.util.List;
|
||||
@RestController
|
||||
@RequestMapping("/api/v1/public-settings")
|
||||
@RequiredArgsConstructor
|
||||
@Tag(name = "Public App Settings", description = "Endpoints for retrieving public application settings")
|
||||
public class PublicAppSettingController {
|
||||
|
||||
private final AppSettingService appSettingService;
|
||||
|
||||
@Operation(summary = "Get public app settings", description = "Retrieve public application settings.")
|
||||
@ApiResponse(responseCode = "200", description = "Settings returned successfully")
|
||||
@GetMapping
|
||||
public PublicAppSetting getPublicSettings() {
|
||||
return appSettingService.getPublicSettings();
|
||||
|
||||
+13
-2
@@ -2,6 +2,10 @@ package com.adityachandel.booklore.controller;
|
||||
|
||||
import com.adityachandel.booklore.model.dto.request.SendBookByEmailRequest;
|
||||
import com.adityachandel.booklore.service.email.SendEmailV2Service;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.responses.ApiResponse;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
@@ -11,20 +15,27 @@ import org.springframework.web.bind.annotation.*;
|
||||
@AllArgsConstructor
|
||||
@RestController
|
||||
@RequestMapping("/api/v2/email")
|
||||
@Tag(name = "Send Email", description = "Endpoints for sending books via email")
|
||||
public class SendEmailV2Controller {
|
||||
|
||||
private final SendEmailV2Service service;
|
||||
|
||||
@Operation(summary = "Send book by email", description = "Send a book to a recipient via email. Requires email permission or admin.")
|
||||
@ApiResponse(responseCode = "204", description = "Book sent successfully")
|
||||
@PreAuthorize("@securityUtil.canEmailBook() or @securityUtil.isAdmin()")
|
||||
@PostMapping("/book")
|
||||
public ResponseEntity<?> sendEmail(@Validated @RequestBody SendBookByEmailRequest request) {
|
||||
public ResponseEntity<?> sendEmail(
|
||||
@Parameter(description = "Send book by email request") @Validated @RequestBody SendBookByEmailRequest request) {
|
||||
service.emailBook(request);
|
||||
return ResponseEntity.noContent().build();
|
||||
}
|
||||
|
||||
@Operation(summary = "Quick send book by email", description = "Quickly send a book by its ID via email. Requires email permission or admin.")
|
||||
@ApiResponse(responseCode = "204", description = "Book sent successfully")
|
||||
@PreAuthorize("@securityUtil.canEmailBook() or @securityUtil.isAdmin()")
|
||||
@PostMapping("/book/{bookId}")
|
||||
public ResponseEntity<?> emailBookQuick(@PathVariable Long bookId) {
|
||||
public ResponseEntity<?> emailBookQuick(
|
||||
@Parameter(description = "ID of the book to send") @PathVariable Long bookId) {
|
||||
service.emailBookQuick(bookId);
|
||||
return ResponseEntity.noContent().build();
|
||||
}
|
||||
|
||||
+11
-1
@@ -4,6 +4,10 @@ import com.adityachandel.booklore.exception.ErrorResponse;
|
||||
import com.adityachandel.booklore.model.dto.request.InitialUserRequest;
|
||||
import com.adityachandel.booklore.model.dto.response.SuccessResponse;
|
||||
import com.adityachandel.booklore.service.user.UserProvisioningService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.responses.ApiResponse;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
@@ -11,10 +15,13 @@ import org.springframework.web.bind.annotation.*;
|
||||
@RestController
|
||||
@RequestMapping("/api/v1/setup")
|
||||
@RequiredArgsConstructor
|
||||
@Tag(name = "Setup", description = "Endpoints for initial application setup and user provisioning")
|
||||
public class SetupController {
|
||||
|
||||
private final UserProvisioningService userProvisioningService;
|
||||
|
||||
@Operation(summary = "Get setup status", description = "Check if initial setup has been completed.")
|
||||
@ApiResponse(responseCode = "200", description = "Setup status returned successfully")
|
||||
@GetMapping("/status")
|
||||
public ResponseEntity<?> getSetupStatus() {
|
||||
boolean isCompleted = userProvisioningService.isInitialUserAlreadyProvisioned();
|
||||
@@ -24,8 +31,11 @@ public class SetupController {
|
||||
return ResponseEntity.ok(new SuccessResponse<>(200, message, isCompleted));
|
||||
}
|
||||
|
||||
@Operation(summary = "Setup first user", description = "Provision the initial admin user during setup.")
|
||||
@ApiResponse(responseCode = "200", description = "Admin user created successfully")
|
||||
@PostMapping
|
||||
public ResponseEntity<?> setupFirstUser(@RequestBody InitialUserRequest request) {
|
||||
public ResponseEntity<?> setupFirstUser(
|
||||
@Parameter(description = "Initial user request") @RequestBody InitialUserRequest request) {
|
||||
if (userProvisioningService.isInitialUserAlreadyProvisioned()) {
|
||||
return ResponseEntity.status(403).body(new ErrorResponse(403, "Setup is disabled after the first user is created."));
|
||||
}
|
||||
|
||||
+32
-5
@@ -4,6 +4,11 @@ import com.adityachandel.booklore.model.dto.Book;
|
||||
import com.adityachandel.booklore.model.dto.Shelf;
|
||||
import com.adityachandel.booklore.model.dto.request.ShelfCreateRequest;
|
||||
import com.adityachandel.booklore.service.ShelfService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.responses.ApiResponse;
|
||||
import io.swagger.v3.oas.annotations.responses.ApiResponses;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.validation.Valid;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.http.HttpStatus;
|
||||
@@ -16,42 +21,64 @@ import java.util.List;
|
||||
@AllArgsConstructor
|
||||
@RestController
|
||||
@RequestMapping(("/api/v1/shelves"))
|
||||
@Tag(name = "Shelves", description = "Endpoints for managing shelves and their books")
|
||||
public class ShelfController {
|
||||
|
||||
private final ShelfService shelfService;
|
||||
|
||||
@Operation(summary = "Get all shelves", description = "Retrieve a list of all shelves.")
|
||||
@ApiResponse(responseCode = "200", description = "Shelves returned successfully")
|
||||
@GetMapping
|
||||
public ResponseEntity<List<Shelf>> getAllShelves() {
|
||||
return ResponseEntity.ok(shelfService.getShelves());
|
||||
}
|
||||
|
||||
@Operation(summary = "Get a shelf by ID", description = "Retrieve details of a specific shelf by its ID.")
|
||||
@ApiResponses({
|
||||
@ApiResponse(responseCode = "200", description = "Shelf details returned successfully"),
|
||||
@ApiResponse(responseCode = "403", description = "Forbidden")
|
||||
})
|
||||
@GetMapping("/{shelfId}")
|
||||
@PreAuthorize("@securityUtil.isShelfOwner(#shelfId)")
|
||||
public ResponseEntity<Shelf> getShelf(@PathVariable Long shelfId) {
|
||||
public ResponseEntity<Shelf> getShelf(
|
||||
@Parameter(description = "ID of the shelf") @PathVariable Long shelfId) {
|
||||
return ResponseEntity.ok(shelfService.getShelf(shelfId));
|
||||
}
|
||||
|
||||
@Operation(summary = "Create a shelf", description = "Create a new shelf.")
|
||||
@ApiResponse(responseCode = "201", description = "Shelf created successfully")
|
||||
@PostMapping
|
||||
public ResponseEntity<Shelf> createShelf(@Valid @RequestBody ShelfCreateRequest request) {
|
||||
public ResponseEntity<Shelf> createShelf(
|
||||
@Parameter(description = "Shelf creation request") @Valid @RequestBody ShelfCreateRequest request) {
|
||||
return ResponseEntity.status(HttpStatus.CREATED).body(shelfService.createShelf(request));
|
||||
}
|
||||
|
||||
@Operation(summary = "Update a shelf", description = "Update an existing shelf by its ID.")
|
||||
@ApiResponse(responseCode = "200", description = "Shelf updated successfully")
|
||||
@PutMapping("/{shelfId}")
|
||||
@PreAuthorize("@securityUtil.isShelfOwner(#shelfId)")
|
||||
public ResponseEntity<Shelf> updateShelf(@Valid @RequestBody ShelfCreateRequest request, @PathVariable Long shelfId) {
|
||||
public ResponseEntity<Shelf> updateShelf(
|
||||
@Parameter(description = "Shelf update request") @Valid @RequestBody ShelfCreateRequest request,
|
||||
@Parameter(description = "ID of the shelf") @PathVariable Long shelfId) {
|
||||
return ResponseEntity.ok(shelfService.updateShelf(shelfId, request));
|
||||
}
|
||||
|
||||
@Operation(summary = "Delete a shelf", description = "Delete a shelf by its ID.")
|
||||
@ApiResponse(responseCode = "204", description = "Shelf deleted successfully")
|
||||
@DeleteMapping("/{shelfId}")
|
||||
@PreAuthorize("@securityUtil.isShelfOwner(#shelfId)")
|
||||
public ResponseEntity<Void> deleteShelf(@PathVariable Long shelfId) {
|
||||
public ResponseEntity<Void> deleteShelf(
|
||||
@Parameter(description = "ID of the shelf") @PathVariable Long shelfId) {
|
||||
shelfService.deleteShelf(shelfId);
|
||||
return ResponseEntity.status(HttpStatus.NO_CONTENT).build();
|
||||
}
|
||||
|
||||
@Operation(summary = "Get books on a shelf", description = "Retrieve all books assigned to a specific shelf.")
|
||||
@ApiResponse(responseCode = "200", description = "Books returned successfully")
|
||||
@GetMapping("/{shelfId}/books")
|
||||
@PreAuthorize("@securityUtil.isShelfOwner(#shelfId)")
|
||||
public ResponseEntity<List<Book>> getShelfBooks(@PathVariable Long shelfId) {
|
||||
public ResponseEntity<List<Book>> getShelfBooks(
|
||||
@Parameter(description = "ID of the shelf") @PathVariable Long shelfId) {
|
||||
return ResponseEntity.ok(shelfService.getShelfBooks(shelfId));
|
||||
}
|
||||
}
|
||||
|
||||
+15
-2
@@ -7,6 +7,10 @@ import com.adityachandel.booklore.model.dto.response.TaskStatusResponse;
|
||||
import com.adityachandel.booklore.service.TaskHistoryService;
|
||||
import com.adityachandel.booklore.service.TaskService;
|
||||
import com.adityachandel.booklore.task.*;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.responses.ApiResponse;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
@@ -16,14 +20,18 @@ import org.springframework.web.bind.annotation.*;
|
||||
@AllArgsConstructor
|
||||
@RestController
|
||||
@RequestMapping("/api/v2/tasks")
|
||||
@Tag(name = "Tasks", description = "Endpoints for managing background tasks")
|
||||
public class TaskV2Controller {
|
||||
|
||||
private final TaskService service;
|
||||
private final TaskHistoryService taskHistoryService;
|
||||
|
||||
@Operation(summary = "Start a new task", description = "Start a new background task. Requires admin.")
|
||||
@ApiResponse(responseCode = "202", description = "Task accepted")
|
||||
@PostMapping
|
||||
@PreAuthorize("@securityUtil.isAdmin()")
|
||||
public ResponseEntity<TaskCreateResponse> startTask(@RequestBody TaskCreateRequest request) {
|
||||
public ResponseEntity<TaskCreateResponse> startTask(
|
||||
@Parameter(description = "Task creation request") @RequestBody TaskCreateRequest request) {
|
||||
TaskCreateResponse response = service.run(request);
|
||||
if (response.getStatus() == TaskStatus.ACCEPTED) {
|
||||
return ResponseEntity.status(HttpStatus.ACCEPTED).body(response);
|
||||
@@ -31,13 +39,18 @@ public class TaskV2Controller {
|
||||
return ResponseEntity.ok(response);
|
||||
}
|
||||
|
||||
@Operation(summary = "Cancel a task", description = "Cancel a running task by its ID. Requires admin.")
|
||||
@ApiResponse(responseCode = "200", description = "Task cancelled successfully")
|
||||
@DeleteMapping("/{taskId}")
|
||||
@PreAuthorize("@securityUtil.isAdmin()")
|
||||
public ResponseEntity<TaskCancelResponse> cancelTask(@PathVariable String taskId) {
|
||||
public ResponseEntity<TaskCancelResponse> cancelTask(
|
||||
@Parameter(description = "ID of the task to cancel") @PathVariable String taskId) {
|
||||
TaskCancelResponse response = service.cancelTask(taskId);
|
||||
return ResponseEntity.ok(response);
|
||||
}
|
||||
|
||||
@Operation(summary = "Get latest tasks for each type", description = "Retrieve the latest tasks for each type. Requires admin.")
|
||||
@ApiResponse(responseCode = "200", description = "Latest tasks returned successfully")
|
||||
@GetMapping("/latest")
|
||||
@PreAuthorize("@securityUtil.isAdmin()")
|
||||
public ResponseEntity<TaskStatusResponse> getLatestTasksForEachType() {
|
||||
|
||||
+39
-6
@@ -6,6 +6,11 @@ import com.adityachandel.booklore.model.dto.request.UpdateUserSettingRequest;
|
||||
import com.adityachandel.booklore.model.dto.BookLoreUser;
|
||||
import com.adityachandel.booklore.model.dto.request.UserUpdateRequest;
|
||||
import com.adityachandel.booklore.service.user.UserService;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.responses.ApiResponse;
|
||||
import io.swagger.v3.oas.annotations.responses.ApiResponses;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import jakarta.validation.Valid;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
@@ -17,56 +22,84 @@ import java.util.List;
|
||||
@AllArgsConstructor
|
||||
@RestController
|
||||
@RequestMapping("/api/v1/users")
|
||||
@Tag(name = "Users", description = "Endpoints for managing users and their settings")
|
||||
public class UserController {
|
||||
|
||||
private final UserService userService;
|
||||
|
||||
@Operation(summary = "Get current user", description = "Retrieve the profile of the currently authenticated user.")
|
||||
@ApiResponse(responseCode = "200", description = "User profile returned successfully")
|
||||
@GetMapping("/me")
|
||||
public ResponseEntity<BookLoreUser> getMyself() {
|
||||
return ResponseEntity.ok(userService.getMyself());
|
||||
}
|
||||
|
||||
@Operation(summary = "Get user by ID", description = "Retrieve a user's profile by their ID.")
|
||||
@ApiResponses({
|
||||
@ApiResponse(responseCode = "200", description = "User profile returned successfully"),
|
||||
@ApiResponse(responseCode = "403", description = "Forbidden")
|
||||
})
|
||||
@GetMapping("/{id}")
|
||||
@PreAuthorize("@securityUtil.canViewUserProfile(#id)")
|
||||
public ResponseEntity<BookLoreUser> getUser(@PathVariable Long id) {
|
||||
public ResponseEntity<BookLoreUser> getUser(
|
||||
@Parameter(description = "ID of the user") @PathVariable Long id) {
|
||||
return ResponseEntity.ok(userService.getBookLoreUser(id));
|
||||
}
|
||||
|
||||
@Operation(summary = "Get all users", description = "Retrieve a list of all users. Requires admin.")
|
||||
@ApiResponse(responseCode = "200", description = "Users returned successfully")
|
||||
@GetMapping
|
||||
@PreAuthorize("@securityUtil.isAdmin()")
|
||||
public ResponseEntity<List<BookLoreUser>> getAllUsers() {
|
||||
return ResponseEntity.ok(userService.getBookLoreUsers());
|
||||
}
|
||||
|
||||
@Operation(summary = "Update user", description = "Update a user's profile by their ID. Requires admin.")
|
||||
@ApiResponse(responseCode = "200", description = "User updated successfully")
|
||||
@PutMapping("/{id}")
|
||||
@PreAuthorize("@securityUtil.isAdmin()")
|
||||
public ResponseEntity<BookLoreUser> updateUser(@PathVariable Long id, @Valid @RequestBody UserUpdateRequest updateRequest) {
|
||||
public ResponseEntity<BookLoreUser> updateUser(
|
||||
@Parameter(description = "ID of the user") @PathVariable Long id,
|
||||
@Parameter(description = "User update request") @Valid @RequestBody UserUpdateRequest updateRequest) {
|
||||
BookLoreUser updatedUser = userService.updateUser(id, updateRequest);
|
||||
return ResponseEntity.ok(updatedUser);
|
||||
}
|
||||
|
||||
@Operation(summary = "Delete user", description = "Delete a user by their ID. Requires admin.")
|
||||
@ApiResponse(responseCode = "204", description = "User deleted successfully")
|
||||
@DeleteMapping("/{id}")
|
||||
@PreAuthorize("@securityUtil.isAdmin()")
|
||||
public void deleteUser(@PathVariable Long id) {
|
||||
public void deleteUser(
|
||||
@Parameter(description = "ID of the user") @PathVariable Long id) {
|
||||
userService.deleteUser(id);
|
||||
}
|
||||
|
||||
@Operation(summary = "Change password", description = "Change the password for the current user.")
|
||||
@ApiResponse(responseCode = "200", description = "Password changed successfully")
|
||||
@PutMapping("/change-password")
|
||||
public ResponseEntity<?> changePassword(@RequestBody ChangePasswordRequest request) {
|
||||
public ResponseEntity<?> changePassword(
|
||||
@Parameter(description = "Change password request") @RequestBody ChangePasswordRequest request) {
|
||||
userService.changePassword(request);
|
||||
return ResponseEntity.ok().build();
|
||||
}
|
||||
|
||||
@Operation(summary = "Change another user's password", description = "Change the password for another user. Requires admin.")
|
||||
@ApiResponse(responseCode = "200", description = "Password changed successfully")
|
||||
@PutMapping("/change-user-password")
|
||||
@PreAuthorize("@securityUtil.isAdmin()")
|
||||
public ResponseEntity<?> changeUserPassword(@RequestBody ChangeUserPasswordRequest request) {
|
||||
public ResponseEntity<?> changeUserPassword(
|
||||
@Parameter(description = "Change user password request") @RequestBody ChangeUserPasswordRequest request) {
|
||||
userService.changeUserPassword(request);
|
||||
return ResponseEntity.ok().build();
|
||||
}
|
||||
|
||||
@Operation(summary = "Update user settings", description = "Update settings for the current user.")
|
||||
@ApiResponse(responseCode = "204", description = "User settings updated successfully")
|
||||
@PutMapping("/{id}/settings")
|
||||
@PreAuthorize("@securityUtil.isSelf(#id)")
|
||||
public void updateUserSetting(@PathVariable Long id, @RequestBody UpdateUserSettingRequest request) {
|
||||
public void updateUserSetting(
|
||||
@Parameter(description = "ID of the user") @PathVariable Long id,
|
||||
@Parameter(description = "Update user setting request") @RequestBody UpdateUserSettingRequest request) {
|
||||
userService.updateUserSetting(id, request);
|
||||
}
|
||||
}
|
||||
|
||||
+8
@@ -3,6 +3,9 @@ package com.adityachandel.booklore.controller;
|
||||
import com.adityachandel.booklore.model.dto.ReleaseNote;
|
||||
import com.adityachandel.booklore.model.dto.VersionInfo;
|
||||
import com.adityachandel.booklore.service.VersionService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.responses.ApiResponse;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
@@ -14,15 +17,20 @@ import java.util.List;
|
||||
@AllArgsConstructor
|
||||
@RestController
|
||||
@RequestMapping("/api/v1/version")
|
||||
@Tag(name = "Version", description = "Endpoints for retrieving application version and changelog")
|
||||
public class VersionController {
|
||||
|
||||
private final VersionService versionService;
|
||||
|
||||
@Operation(summary = "Get application version", description = "Retrieve the current application version.")
|
||||
@ApiResponse(responseCode = "200", description = "Version info returned successfully")
|
||||
@GetMapping
|
||||
public ResponseEntity<VersionInfo> getVersionInfo() {
|
||||
return ResponseEntity.ok(versionService.getVersionInfo());
|
||||
}
|
||||
|
||||
@Operation(summary = "Get changelog since current version", description = "Retrieve the changelog since the current version.")
|
||||
@ApiResponse(responseCode = "200", description = "Changelog returned successfully")
|
||||
@GetMapping("/changelog")
|
||||
public ResponseEntity<List<ReleaseNote>> getChangelogSinceCurrent() {
|
||||
return ResponseEntity.ok(versionService.getChangelogSinceCurrentVersion());
|
||||
|
||||
@@ -54,7 +54,10 @@ spring:
|
||||
|
||||
springdoc:
|
||||
swagger-ui:
|
||||
path: /api/v1/swagger-ui.html
|
||||
persist-authorization: true
|
||||
api-docs:
|
||||
path: /api/v1/api-docs
|
||||
|
||||
logging:
|
||||
level:
|
||||
|
||||
Reference in New Issue
Block a user