docs(api): normalize OpenAPI tagging and operation metadata for app + auth/task endpoints (#437)

* docs(api): add OpenAPI tags and operation metadata to controllers

* docs(api): normalize @Operation annotation formatting in OpenAPI controllers

* docs(api): align operationId values with existing controller method names

* chore(api-docs): update api docs to be enabled by default for dev builds
This commit is contained in:
Zach
2026-04-22 17:27:09 -04:00
committed by Zach Yale
parent a0a7be43dd
commit 402c6f07c8
16 changed files with 294 additions and 0 deletions
@@ -1,5 +1,7 @@
package org.booklore.app.controller;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.booklore.app.dto.AppAuthorDetail;
import org.booklore.app.dto.AppAuthorSummary;
import org.booklore.app.dto.AppPageResponse;
@@ -11,10 +13,16 @@ import org.springframework.web.bind.annotation.*;
@AllArgsConstructor
@RestController
@RequestMapping("/api/v1/app/authors")
@Tag(name = "App Authors", description = "Endpoints for browsing authors in the app experience")
public class AppAuthorController {
private final AppAuthorService mobileAuthorService;
@Operation(
summary = "List app authors",
description = "Retrieve paginated authors for the app with optional filtering and sorting.",
operationId = "appGetAuthors"
)
@GetMapping
public ResponseEntity<AppPageResponse<AppAuthorSummary>> getAuthors(
@RequestParam(required = false, defaultValue = "0") Integer page,
@@ -28,6 +36,11 @@ public class AppAuthorController {
return ResponseEntity.ok(mobileAuthorService.getAuthors(page, size, sort, dir, libraryId, search, hasPhoto));
}
@Operation(
summary = "Get app author details",
description = "Retrieve detailed app-facing information for a single author.",
operationId = "appGetAuthorDetail"
)
@GetMapping("/{authorId}")
public ResponseEntity<AppAuthorDetail> getAuthorDetail(
@PathVariable Long authorId) {
@@ -1,5 +1,7 @@
package org.booklore.app.controller;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.booklore.app.dto.*;
import org.booklore.app.service.AppBookService;
import org.booklore.model.enums.BookFileType;
@@ -14,10 +16,16 @@ import java.util.List;
@AllArgsConstructor
@RestController
@RequestMapping("/api/v1/app/books")
@Tag(name = "App Books", description = "Endpoints for browsing and updating books in the app experience")
public class AppBookController {
private final AppBookService mobileBookService;
@Operation(
summary = "List app books",
description = "Retrieve paginated books for the app with optional filtering and sorting.",
operationId = "appGetBooks"
)
@GetMapping
public ResponseEntity<AppPageResponse<AppBookSummary>> getBooks(
@RequestParam(required = false, defaultValue = "0") Integer page,
@@ -39,6 +47,11 @@ public class AppBookController {
fileType, minRating, maxRating, authors, language));
}
@Operation(
summary = "Get app book details",
description = "Retrieve detailed app-facing information for a single book.",
operationId = "appGetBookDetail"
)
@GetMapping("/{bookId}")
public ResponseEntity<AppBookDetail> getBookDetail(
@PathVariable Long bookId) {
@@ -46,6 +59,11 @@ public class AppBookController {
return ResponseEntity.ok(mobileBookService.getBookDetail(bookId));
}
@Operation(
summary = "Search app books",
description = "Search books in the app catalog using a free-text query.",
operationId = "appSearchBooks"
)
@GetMapping("/search")
public ResponseEntity<AppPageResponse<AppBookSummary>> searchBooks(
@RequestParam String q,
@@ -55,6 +73,11 @@ public class AppBookController {
return ResponseEntity.ok(mobileBookService.searchBooks(q, page, size));
}
@Operation(
summary = "Get continue reading books",
description = "Retrieve books currently in progress for reading in the app.",
operationId = "appGetContinueReading"
)
@GetMapping("/continue-reading")
public ResponseEntity<List<AppBookSummary>> getContinueReading(
@RequestParam(required = false, defaultValue = "10") Integer limit) {
@@ -62,6 +85,11 @@ public class AppBookController {
return ResponseEntity.ok(mobileBookService.getContinueReading(limit));
}
@Operation(
summary = "Get continue listening books",
description = "Retrieve audiobooks currently in progress for listening in the app.",
operationId = "appGetContinueListening"
)
@GetMapping("/continue-listening")
public ResponseEntity<List<AppBookSummary>> getContinueListening(
@RequestParam(required = false, defaultValue = "10") Integer limit) {
@@ -69,6 +97,11 @@ public class AppBookController {
return ResponseEntity.ok(mobileBookService.getContinueListening(limit));
}
@Operation(
summary = "Get recently added books",
description = "Retrieve recently added books for the app home experience.",
operationId = "appGetRecentlyAdded"
)
@GetMapping("/recently-added")
public ResponseEntity<List<AppBookSummary>> getRecentlyAdded(
@RequestParam(required = false, defaultValue = "10") Integer limit) {
@@ -76,6 +109,11 @@ public class AppBookController {
return ResponseEntity.ok(mobileBookService.getRecentlyAdded(limit));
}
@Operation(
summary = "Get recently scanned books",
description = "Retrieve recently scanned books for the app home experience.",
operationId = "appGetRecentlyScanned"
)
@GetMapping("/recently-scanned")
public ResponseEntity<List<AppBookSummary>> getRecentlyScanned(
@RequestParam(required = false, defaultValue = "10") Integer limit) {
@@ -83,6 +121,11 @@ public class AppBookController {
return ResponseEntity.ok(mobileBookService.getRecentlyScanned(limit));
}
@Operation(
summary = "Update app book read status",
description = "Update the read status of a book from the app interface.",
operationId = "appUpdateStatus"
)
@PutMapping("/{bookId}/status")
public ResponseEntity<Void> updateStatus(
@PathVariable Long bookId,
@@ -92,6 +135,11 @@ public class AppBookController {
return ResponseEntity.ok().build();
}
@Operation(
summary = "Update app book rating",
description = "Update the personal rating of a book from the app interface.",
operationId = "appUpdateRating"
)
@PutMapping("/{bookId}/rating")
public ResponseEntity<Void> updateRating(
@PathVariable Long bookId,
@@ -101,6 +149,11 @@ public class AppBookController {
return ResponseEntity.ok().build();
}
@Operation(
summary = "Get random app books",
description = "Retrieve a paginated random selection of books for discovery in the app.",
operationId = "appGetRandomBooks"
)
@GetMapping("/random")
public ResponseEntity<AppPageResponse<AppBookSummary>> getRandomBooks(
@RequestParam(required = false, defaultValue = "0") Integer page,
@@ -1,5 +1,7 @@
package org.booklore.app.controller;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.booklore.app.dto.AppFilterOptions;
import org.booklore.app.service.AppBookService;
import lombok.AllArgsConstructor;
@@ -12,10 +14,16 @@ import org.springframework.web.bind.annotation.RestController;
@AllArgsConstructor
@RestController
@RequestMapping("/api/v1/app")
@Tag(name = "App Filters", description = "Endpoints for retrieving app filter options")
public class AppFilterController {
private final AppBookService mobileBookService;
@Operation(
summary = "Get app filter options",
description = "Retrieve available filter values for app book browsing.",
operationId = "appGetFilterOptions"
)
@GetMapping("/filter-options")
public ResponseEntity<AppFilterOptions> getFilterOptions(
@RequestParam(required = false) Long libraryId,
@@ -1,5 +1,7 @@
package org.booklore.app.controller;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.booklore.config.security.service.AuthenticationService;
import org.booklore.app.dto.AppLibrarySummary;
import org.booklore.app.mapper.AppBookMapper;
@@ -20,6 +22,7 @@ import java.util.stream.Collectors;
@AllArgsConstructor
@RestController
@RequestMapping("/api/v1/app/libraries")
@Tag(name = "App Libraries", description = "Endpoints for retrieving libraries in the app experience")
public class AppLibraryController {
private final AuthenticationService authenticationService;
@@ -27,6 +30,11 @@ public class AppLibraryController {
private final BookRepository bookRepository;
private final AppBookMapper mobileBookMapper;
@Operation(
summary = "List app libraries",
description = "Retrieve libraries visible to the current app user, including per-library book counts.",
operationId = "appGetLibraries"
)
@GetMapping
public ResponseEntity<List<AppLibrarySummary>> getLibraries() {
BookLoreUser user = authenticationService.getAuthenticatedUser();
@@ -1,5 +1,7 @@
package org.booklore.app.controller;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.booklore.app.dto.AppNotebookBookSummary;
import org.booklore.app.dto.AppNotebookEntry;
import org.booklore.app.dto.AppNotebookUpdateRequest;
@@ -15,10 +17,16 @@ import java.util.Set;
@AllArgsConstructor
@RestController
@RequestMapping("/api/v1/app/notebook")
@Tag(name = "App Notebook", description = "Endpoints for notebook browsing and editing in the app experience")
public class AppNotebookController {
private final AppNotebookService mobileNotebookService;
@Operation(
summary = "List notebook books",
description = "Retrieve paginated books that contain notebook entries in the app.",
operationId = "appGetBooksWithAnnotations"
)
@GetMapping("/books")
public ResponseEntity<AppPageResponse<AppNotebookBookSummary>> getBooksWithAnnotations(
@RequestParam(required = false, defaultValue = "0") Integer page,
@@ -28,6 +36,11 @@ public class AppNotebookController {
return ResponseEntity.ok(mobileNotebookService.getBooksWithAnnotations(page, size, search));
}
@Operation(
summary = "List notebook entries for book",
description = "Retrieve paginated notebook entries for a specific book in the app.",
operationId = "appGetEntriesForBook"
)
@GetMapping("/books/{bookId}/entries")
public ResponseEntity<AppPageResponse<AppNotebookEntry>> getEntriesForBook(
@PathVariable Long bookId,
@@ -40,6 +53,11 @@ public class AppNotebookController {
return ResponseEntity.ok(mobileNotebookService.getEntriesForBook(bookId, page, size, types, search, sort));
}
@Operation(
summary = "Update notebook entry",
description = "Update an existing notebook entry in the app.",
operationId = "appUpdateEntry"
)
@PutMapping("/entries/{entryId}")
public ResponseEntity<AppNotebookEntry> updateEntry(
@PathVariable Long entryId,
@@ -49,6 +67,11 @@ public class AppNotebookController {
return ResponseEntity.ok(mobileNotebookService.updateEntry(entryId, type, request));
}
@Operation(
summary = "Delete notebook entry",
description = "Delete an existing notebook entry in the app.",
operationId = "appDeleteEntry"
)
@DeleteMapping("/entries/{entryId}")
public ResponseEntity<Void> deleteEntry(
@PathVariable Long entryId,
@@ -1,5 +1,7 @@
package org.booklore.app.controller;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import org.booklore.app.dto.AppBookSummary;
import org.booklore.app.dto.AppPageResponse;
@@ -11,10 +13,16 @@ import org.springframework.web.bind.annotation.*;
@AllArgsConstructor
@RestController
@RequestMapping("/api/v1/app/series")
@Tag(name = "App Series", description = "Endpoints for browsing series in the app experience")
public class AppSeriesController {
private final AppSeriesService mobileSeriesService;
@Operation(
summary = "List app series",
description = "Retrieve paginated series for the app with optional filtering and sorting.",
operationId = "appGetSeries"
)
@GetMapping
public ResponseEntity<AppPageResponse<AppSeriesSummary>> getSeries(
@RequestParam(required = false, defaultValue = "0") Integer page,
@@ -33,6 +41,11 @@ public class AppSeriesController {
return ResponseEntity.ok(response);
}
@Operation(
summary = "List books in app series",
description = "Retrieve paginated books belonging to a specific series for the app.",
operationId = "appGetSeriesBooks"
)
@GetMapping("/{seriesName}/books")
public ResponseEntity<AppPageResponse<AppBookSummary>> getSeriesBooks(
@PathVariable String seriesName,
@@ -1,5 +1,7 @@
package org.booklore.app.controller;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.booklore.config.security.service.AuthenticationService;
import org.booklore.app.dto.AppBookSummary;
import org.booklore.app.dto.AppMagicShelfSummary;
@@ -25,6 +27,7 @@ import java.util.stream.Collectors;
@AllArgsConstructor
@RestController
@RequestMapping("/api/v1/app/shelves")
@Tag(name = "App Shelves", description = "Endpoints for browsing shelves and magic shelves in the app experience")
public class AppShelfController {
private final AuthenticationService authenticationService;
@@ -33,6 +36,11 @@ public class AppShelfController {
private final AppBookMapper mobileBookMapper;
private final AppBookService mobileBookService;
@Operation(
summary = "List app shelves",
description = "Retrieve all regular shelves visible to the current app user.",
operationId = "appGetShelves"
)
@GetMapping
public ResponseEntity<List<AppShelfSummary>> getShelves() {
BookLoreUser user = authenticationService.getAuthenticatedUser();
@@ -47,6 +55,11 @@ public class AppShelfController {
return ResponseEntity.ok(summaries);
}
@Operation(
summary = "List app magic shelves",
description = "Retrieve all magic shelves visible to the current app user.",
operationId = "appGetMagicShelves"
)
@GetMapping("/magic")
public ResponseEntity<List<AppMagicShelfSummary>> getMagicShelves() {
BookLoreUser user = authenticationService.getAuthenticatedUser();
@@ -80,6 +93,11 @@ public class AppShelfController {
return ResponseEntity.ok(summaries);
}
@Operation(
summary = "List books in app magic shelf",
description = "Retrieve paginated books contained in a specific magic shelf for the app.",
operationId = "appGetBooksByMagicShelf"
)
@GetMapping("/magic/{magicShelfId}/books")
public ResponseEntity<AppPageResponse<AppBookSummary>> getBooksByMagicShelf(
@PathVariable Long magicShelfId,
@@ -1,5 +1,7 @@
package org.booklore.app.controller;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.booklore.config.security.service.AuthenticationService;
import org.booklore.app.dto.AppUserInfo;
import org.booklore.model.dto.BookLoreUser;
@@ -13,11 +15,17 @@ import org.springframework.web.bind.annotation.RestController;
@AllArgsConstructor
@RestController
@RequestMapping("/api/v1/app/users")
@Tag(name = "App Users", description = "Endpoints for retrieving app user capabilities and profile information")
public class AppUserController {
private final AuthenticationService authenticationService;
private final AppSettingService appSettingService;
@Operation(
summary = "Get current app user",
description = "Retrieve current user flags and capability information used by the app experience.",
operationId = "appGetCurrentUser"
)
@GetMapping("/me")
public ResponseEntity<AppUserInfo> getCurrentUser() {
BookLoreUser user = authenticationService.getAuthenticatedUser();
@@ -1,5 +1,7 @@
package org.booklore.controller;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.booklore.config.security.annotation.CheckBookAccess;
import org.booklore.model.dto.BookFile;
import org.booklore.model.dto.request.DetachBookFileRequest;
@@ -21,12 +23,18 @@ import java.util.List;
@RequestMapping("/api/v1/books/{bookId}/files")
@RestController
@AllArgsConstructor
@Tag(name = "Book Files", description = "Endpoints for managing additional files attached to books")
public class AdditionalFileController {
private final AdditionalFileService additionalFileService;
private final FileUploadService fileUploadService;
private final BookFileDetachmentService bookFileDetachmentService;
@Operation(
summary = "List additional book files",
description = "Retrieve additional files for a specific book.",
operationId = "additionalFileGetAdditionalFiles"
)
@GetMapping
@CheckBookAccess(bookIdParam = "bookId")
public ResponseEntity<List<BookFile>> getAdditionalFiles(@PathVariable Long bookId) {
@@ -34,6 +42,11 @@ public class AdditionalFileController {
return ResponseEntity.ok(files);
}
@Operation(
summary = "List additional files by type",
description = "Retrieve additional files for a specific book filtered by whether they are primary book files.",
operationId = "additionalFileGetFilesByIsBook"
)
@GetMapping(params = "isBook")
@CheckBookAccess(bookIdParam = "bookId")
public ResponseEntity<List<BookFile>> getFilesByIsBook(
@@ -43,6 +56,11 @@ public class AdditionalFileController {
return ResponseEntity.ok(files);
}
@Operation(
summary = "Upload additional book file",
description = "Upload and attach a new additional file to a specific book.",
operationId = "additionalFileUploadAdditionalFile"
)
@PostMapping(consumes = "multipart/form-data")
@CheckBookAccess(bookIdParam = "bookId")
@PreAuthorize("@securityUtil.canUpload() or @securityUtil.isAdmin()")
@@ -56,6 +74,11 @@ public class AdditionalFileController {
return ResponseEntity.ok(additionalFile);
}
@Operation(
summary = "Download additional book file",
description = "Download a specific additional file attached to a book.",
operationId = "additionalFileDownloadAdditionalFile"
)
@GetMapping("/{fileId}/download")
@CheckBookAccess(bookIdParam = "bookId")
public ResponseEntity<Resource> downloadAdditionalFile(
@@ -64,6 +87,11 @@ public class AdditionalFileController {
return additionalFileService.downloadAdditionalFile(fileId);
}
@Operation(
summary = "Delete additional book file",
description = "Delete a specific additional file attached to a book.",
operationId = "additionalFileDeleteAdditionalFile"
)
@DeleteMapping("/{fileId}")
@CheckBookAccess(bookIdParam = "bookId")
@PreAuthorize("@securityUtil.canDeleteBook() or @securityUtil.isAdmin()")
@@ -74,6 +102,11 @@ public class AdditionalFileController {
return ResponseEntity.noContent().build();
}
@Operation(
summary = "Detach additional book file",
description = "Detach a specific additional file from a book and optionally copy metadata.",
operationId = "additionalFileDetachFile"
)
@PostMapping("/{fileId}/detach")
@CheckBookAccess(bookIdParam = "bookId")
@PreAuthorize("@securityUtil.canManageLibrary() or @securityUtil.isAdmin()")
@@ -1,5 +1,7 @@
package org.booklore.controller;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import org.booklore.config.security.service.LogoutService;
import org.booklore.model.dto.request.LogoutRequest;
@@ -15,10 +17,16 @@ import org.springframework.web.bind.annotation.RestController;
@AllArgsConstructor
@RestController
@RequestMapping("/api/v1/auth")
@Tag(name = "Authentication", description = "Endpoints for user authentication, registration, and token management")
public class LogoutController {
private final LogoutService logoutService;
@Operation(
summary = "Logout user",
description = "Logout the current user and invalidate refresh token state when provided.",
operationId = "logout"
)
@PostMapping("/logout")
public ResponseEntity<LogoutResponse> logout(Authentication auth,
@RequestBody(required = false) LogoutRequest request,
@@ -1,5 +1,7 @@
package org.booklore.controller;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.validation.Valid;
import lombok.AllArgsConstructor;
@@ -26,6 +28,7 @@ import java.util.Map;
@AllArgsConstructor
@RestController
@RequestMapping("/api/v1/auth/oidc")
@Tag(name = "OIDC Authentication", description = "Endpoints for OIDC state generation, callbacks, and logout flows")
public class OidcAuthController {
private final OidcAuthService oidcAuthService;
@@ -33,11 +36,21 @@ public class OidcAuthController {
private final OidcStateService oidcStateService;
private final AuditService auditService;
@Operation(
summary = "Generate OIDC state",
description = "Generate a one-time state value for initiating an OIDC authentication flow.",
operationId = "oidcGenerateState"
)
@GetMapping("/state")
public ResponseEntity<Map<String, String>> generateState() {
return ResponseEntity.ok(Map.of("state", oidcStateService.generateState()));
}
@Operation(
summary = "Handle OIDC callback",
description = "Process the OIDC callback payload and exchange authorization code for tokens.",
operationId = "oidcHandleCallback"
)
@PostMapping("/callback")
public ResponseEntity<Map<String, String>> handleCallback(
@RequestBody @Valid OidcCallbackRequest request,
@@ -58,6 +71,11 @@ public class OidcAuthController {
}
}
@Operation(
summary = "Handle OIDC redirect callback",
description = "Handle redirect-based OIDC callback and redirect back to the app with token information.",
operationId = "oidcHandleRedirect"
)
@GetMapping("/redirect")
public ResponseEntity<Void> handleRedirect(
@RequestParam("code") String code,
@@ -104,6 +122,11 @@ public class OidcAuthController {
}
}
@Operation(
summary = "Handle OIDC mobile callback",
description = "Process mobile OIDC callback parameters and exchange authorization code for tokens.",
operationId = "oidcHandleMobileCallback"
)
@PostMapping("/mobile/callback")
public ResponseEntity<Map<String, String>> handleMobileCallback(
@RequestParam("code") String code,
@@ -122,6 +145,11 @@ public class OidcAuthController {
}
}
@Operation(
summary = "Handle OIDC backchannel logout",
description = "Process OIDC backchannel logout token and invalidate matching session state.",
operationId = "oidcBackchannelLogout"
)
@PostMapping(value = "/backchannel-logout", consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
public ResponseEntity<Void> backchannelLogout(@RequestParam("logout_token") String logoutToken) {
try {
@@ -1,5 +1,7 @@
package org.booklore.controller;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import org.booklore.model.dto.OidcGroupMapping;
import org.booklore.service.oidc.OidcGroupMappingService;
@@ -13,25 +15,46 @@ import java.util.List;
@RequestMapping("/api/v1/admin/oidc-group-mappings")
@PreAuthorize("@securityUtil.isAdmin()")
@AllArgsConstructor
@Tag(name = "OIDC Group Mappings", description = "Endpoints for managing OIDC group-to-role mappings")
public class OidcGroupMappingController {
private final OidcGroupMappingService oidcGroupMappingService;
@Operation(
summary = "List OIDC group mappings",
description = "Retrieve all configured OIDC group mappings.",
operationId = "oidcGroupMappingGetAll"
)
@GetMapping
public List<OidcGroupMapping> getAll() {
return oidcGroupMappingService.getAll();
}
@Operation(
summary = "Create OIDC group mapping",
description = "Create a new OIDC group mapping.",
operationId = "oidcGroupMappingCreate"
)
@PostMapping
public OidcGroupMapping create(@Valid @RequestBody OidcGroupMapping mapping) {
return oidcGroupMappingService.create(mapping);
}
@Operation(
summary = "Update OIDC group mapping",
description = "Update an existing OIDC group mapping by ID.",
operationId = "oidcGroupMappingUpdate"
)
@PutMapping("/{id}")
public OidcGroupMapping update(@PathVariable Long id, @Valid @RequestBody OidcGroupMapping mapping) {
return oidcGroupMappingService.update(id, mapping);
}
@Operation(
summary = "Delete OIDC group mapping",
description = "Delete an OIDC group mapping by ID.",
operationId = "oidcGroupMappingDelete"
)
@DeleteMapping("/{id}")
public void delete(@PathVariable Long id) {
oidcGroupMappingService.delete(id);
@@ -6,6 +6,7 @@ import org.booklore.service.ReadingSessionService;
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.tags.Tag;
import jakarta.validation.Valid;
import jakarta.validation.constraints.Max;
import jakarta.validation.constraints.Min;
@@ -19,6 +20,7 @@ import org.springframework.web.bind.annotation.*;
@RestController
@AllArgsConstructor
@RequestMapping("/api/v1/reading-sessions")
@Tag(name = "Reading Sessions", description = "Endpoints for recording and retrieving user reading sessions")
public class ReadingSessionController {
private final ReadingSessionService readingSessionService;
@@ -1,5 +1,7 @@
package org.booklore.controller;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.booklore.model.dto.TaskInfo;
import org.booklore.model.dto.request.TaskCreateRequest;
import org.booklore.model.dto.request.TaskCronConfigRequest;
@@ -23,12 +25,18 @@ import java.util.List;
@AllArgsConstructor
@RestController
@RequestMapping("/api/v1/tasks")
@Tag(name = "Tasks", description = "Endpoints for listing, starting, canceling, and scheduling background tasks")
public class TaskController {
private final TaskService service;
private final TaskHistoryService taskHistoryService;
private final TaskCronService taskCronService;
@Operation(
summary = "List available tasks",
description = "Retrieve all task types available to the current user.",
operationId = "taskGetAvailableTasks"
)
@GetMapping
@PreAuthorize("@securityUtil.canAccessTaskManager() or @securityUtil.isAdmin()")
public ResponseEntity<List<TaskInfo>> getAvailableTasks() {
@@ -36,6 +44,11 @@ public class TaskController {
return ResponseEntity.ok(taskInfos);
}
@Operation(
summary = "Start task",
description = "Start a task immediately with the provided task request payload.",
operationId = "taskStartTask"
)
@PostMapping("/start")
@PreAuthorize("@securityUtil.canAccessTaskManager() or @securityUtil.isAdmin()")
public ResponseEntity<TaskCreateResponse> startTask(@RequestBody TaskCreateRequest request) {
@@ -46,6 +59,11 @@ public class TaskController {
return ResponseEntity.ok(response);
}
@Operation(
summary = "Cancel task",
description = "Cancel an in-progress task by task ID.",
operationId = "taskCancelTask"
)
@DeleteMapping("/{taskId}/cancel")
@PreAuthorize("@securityUtil.canAccessTaskManager() or @securityUtil.isAdmin()")
public ResponseEntity<TaskCancelResponse> cancelTask(@PathVariable String taskId) {
@@ -53,6 +71,11 @@ public class TaskController {
return ResponseEntity.ok(response);
}
@Operation(
summary = "Get latest tasks by type",
description = "Retrieve the latest task execution entry for each task type.",
operationId = "taskGetLatestTasksForEachType"
)
@GetMapping("/last")
@PreAuthorize("@securityUtil.canAccessTaskManager() or @securityUtil.isAdmin()")
public ResponseEntity<TasksHistoryResponse> getLatestTasksForEachType() {
@@ -60,6 +83,11 @@ public class TaskController {
return ResponseEntity.ok(response);
}
@Operation(
summary = "Update task cron configuration",
description = "Patch cron schedule configuration for a task type and reschedule execution.",
operationId = "taskPatchCronConfig"
)
@PatchMapping("/{taskType}/cron")
@PreAuthorize("@securityUtil.canAccessTaskManager() or @securityUtil.isAdmin()")
public ResponseEntity<CronConfig> patchCronConfig(@PathVariable TaskType taskType, @RequestBody TaskCronConfigRequest request) {
@@ -5,6 +5,7 @@ import org.booklore.service.ReadingSessionService;
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.tags.Tag;
import lombok.AllArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
@@ -15,6 +16,7 @@ import java.util.List;
@RestController
@AllArgsConstructor
@RequestMapping("/api/v1/user-stats")
@Tag(name = "User Stats", description = "Endpoints for reading and listening analytics derived from user sessions")
public class UserStatsController {
private final ReadingSessionService readingSessionService;
@@ -281,6 +283,11 @@ public class UserStatsController {
return ResponseEntity.ok(readingSessionService.getListeningFinishFunnel());
}
@Operation(
summary = "Get listening peak hours",
description = "Returns listening activity distribution by hour of day. Can be filtered by year and/or month.",
operationId = "getListeningPeakHours"
)
@GetMapping("/listening/peak-hours")
@PreAuthorize("@securityUtil.canAccessUserStats() or @securityUtil.isAdmin()")
public ResponseEntity<List<PeakHoursResponse>> getListeningPeakHours(
@@ -289,24 +296,44 @@ public class UserStatsController {
return ResponseEntity.ok(readingSessionService.getListeningPeakHours(year, month));
}
@Operation(
summary = "Get listening genre statistics",
description = "Returns listening statistics grouped by audiobook genres/categories.",
operationId = "getListeningGenreStatistics"
)
@GetMapping("/listening/genres")
@PreAuthorize("@securityUtil.canAccessUserStats() or @securityUtil.isAdmin()")
public ResponseEntity<List<GenreStatisticsResponse>> getListeningGenreStatistics() {
return ResponseEntity.ok(readingSessionService.getListeningGenreStatistics());
}
@Operation(
summary = "Get listening author statistics",
description = "Returns listening statistics grouped by audiobook authors.",
operationId = "getListeningAuthorStats"
)
@GetMapping("/listening/authors")
@PreAuthorize("@securityUtil.canAccessUserStats() or @securityUtil.isAdmin()")
public ResponseEntity<List<ListeningAuthorResponse>> getListeningAuthorStats() {
return ResponseEntity.ok(readingSessionService.getListeningAuthorStats());
}
@Operation(
summary = "Get listening session scatter data",
description = "Returns individual listening session points for scatter plot visualizations.",
operationId = "getListeningSessionScatter"
)
@GetMapping("/listening/session-scatter")
@PreAuthorize("@securityUtil.canAccessUserStats() or @securityUtil.isAdmin()")
public ResponseEntity<List<SessionScatterResponse>> getListeningSessionScatter() {
return ResponseEntity.ok(readingSessionService.getListeningSessionScatter());
}
@Operation(
summary = "Get longest listened audiobooks",
description = "Returns longest audiobooks ranked by listening duration.",
operationId = "getListeningLongestBooks"
)
@GetMapping("/listening/longest-books")
@PreAuthorize("@securityUtil.canAccessUserStats() or @securityUtil.isAdmin()")
public ResponseEntity<List<LongestAudiobookResponse>> getListeningLongestBooks() {
+1
View File
@@ -16,6 +16,7 @@ services:
- DATABASE_PASSWORD=grimmory
- REMOTE_DEBUG_ENABLED=true
- ALLOWED_ORIGINS=http://localhost:4200
- API_DOCS_ENABLED=true
- JAVA_TOOL_OPTIONS=-XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=compact -XX:+UseCompactObjectHeaders -XX:MaxRAMPercentage=60.0 -XX:InitialRAMPercentage=8.0 -XX:+ExitOnOutOfMemoryError -XX:MaxMetaspaceSize=192m -XX:ReservedCodeCacheSize=64m -Xss512k -XX:CICompilerCount=2 -XX:+UnlockExperimentalVMOptions -XX:ShenandoahUncommitDelay=5000 -XX:ShenandoahGuaranteedGCInterval=30000
stdin_open: true
tty: true