-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLogFileController.java
More file actions
74 lines (69 loc) · 3.44 KB
/
Copy pathLogFileController.java
File metadata and controls
74 lines (69 loc) · 3.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package com.itasocialacademy.oitassist.logfile.controller;
import com.itasocialacademy.oitassist.logfile.api.LogFileResponse;
import com.itasocialacademy.oitassist.logfile.api.PageResponse;
import com.itasocialacademy.oitassist.logfile.service.LogFileService;
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 org.springdoc.core.annotations.ParameterObject;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.web.PageableDefault;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/api/v1/admin/log-files")
@PreAuthorize("hasRole('ADMIN')")
@Tag(name = "Admin Log Files", description = "Administrative API for application log files")
public class LogFileController {
private final LogFileService logFileService;
public LogFileController(LogFileService logFileService) {
this.logFileService = logFileService;
}
@GetMapping
@Operation(
summary = "Get application log files",
description = """
Returns a paginated list of application log files.
Files are sorted by modification date from newest
to oldest.
""")
@ApiResponses({
@ApiResponse(responseCode = "200", description = "List of log files retrieved successfully"),
@ApiResponse(responseCode = "400", description = "Invalid page or size parameters"),
@ApiResponse(responseCode = "401", description = "Unauthorized - token is missing or invalid"),
@ApiResponse(responseCode = "403", description = "Forbidden - insufficient permissions")})
public PageResponse<LogFileResponse> getAll(
@ParameterObject @PageableDefault(
size = 10,
sort = "lastModified",
direction = Sort.Direction.DESC) Pageable pageable) {
return logFileService.getAll(pageable);
}
@GetMapping("/search")
@Operation(
summary = "Search log files by name",
description = """
Searches application log files by a partial file name match.
The search is case-insensitive and supports pagination and sorting.
Access is restricted to administrators.
""")
@ApiResponses({
@ApiResponse(responseCode = "200",
description = "Log files matching the specified name were successfully retrieved"),
@ApiResponse(responseCode = "400", description = "Invalid search or sorting parameters"),
@ApiResponse(responseCode = "401", description = "Unauthorized - token is missing or invalid"),
@ApiResponse(responseCode = "403", description = "Forbidden - insufficient permissions")})
public PageResponse<LogFileResponse> searchByName(
@Parameter(
description = "Full or partial log file name to search for",
example = "app") @RequestParam String name,
@ParameterObject @PageableDefault(size = 10) Pageable pageable) {
return logFileService.searchByName(name, pageable);
}
}