feat(admin-api): label search with an optional code list
POST /api/admin/messages/search takes the list filters plus up to 5,000 codes. The no-create guard test now allows this read-only POST by name. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EFUzfiCVCgCVJZq4NDEqZs
This commit is contained in:
1 parent
89662d0eb2
commit
d2cbc3c227
5 files changed
+74
-2
No files matched your search
+26
@@ -1,11 +1,13 @@
|
||||
package com.solvway.mobile.api.controller.admin;
|
||||
|
||||
import com.solvway.core.annotation.AppAuth;
|
||||
import com.solvway.mobile.api.errorhandler.CodedResponseStatusException;
|
||||
import com.solvway.mobile.api.service.AdminTranslationService;
|
||||
import com.solvway.mobile.api.service.SystemService;
|
||||
import com.solvway.mobile.api.useraccess.AdminModule;
|
||||
import com.solvway.mobile.api.useraccess.Audited;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
@@ -27,6 +29,7 @@ import java.util.Map;
|
||||
@RequestMapping("/api/admin")
|
||||
@RequiredArgsConstructor
|
||||
public class AdminMessageController {
|
||||
private static final int MAX_CODES = 5000;
|
||||
private final AdminTranslationService translations;
|
||||
private final SystemService systemService;
|
||||
|
||||
@@ -52,6 +55,29 @@ public class AdminMessageController {
|
||||
return ResponseEntity.ok(translations.search(searchKey, missingLocale, page, size));
|
||||
}
|
||||
|
||||
/** Same as the list, plus an optional code list; a POST because the portal sends its ~700 label codes. */
|
||||
@AppAuth
|
||||
@AdminModule("BO_MESSAGES")
|
||||
@PostMapping("/messages/search")
|
||||
public ResponseEntity<Map<String, Object>> search(@RequestBody Map<String, Object> body) {
|
||||
Object codes = body.get("codes");
|
||||
if (codes != null && !(codes instanceof List<?> list && list.size() <= MAX_CODES && list.stream().allMatch(String.class::isInstance))) {
|
||||
throw new CodedResponseStatusException(HttpStatus.BAD_REQUEST, "codes must be a list of at most " + MAX_CODES + " strings", "MsgsInvalidCodes");
|
||||
}
|
||||
@SuppressWarnings("unchecked")
|
||||
List<String> codeList = (List<String>) codes;
|
||||
return ResponseEntity.ok(translations.search(text(body.get("searchKey")), text(body.get("missingLocale")),
|
||||
number(body.get("page"), 0), number(body.get("size"), 20), codeList));
|
||||
}
|
||||
|
||||
private static String text(Object v) {
|
||||
return v instanceof String s ? s : null;
|
||||
}
|
||||
|
||||
private static int number(Object v, int fallback) {
|
||||
return v instanceof Number n ? n.intValue() : fallback;
|
||||
}
|
||||
|
||||
@AppAuth
|
||||
@AdminModule("BO_MESSAGES")
|
||||
@Audited(action = "MESSAGES_EXPORT")
|
||||
|
||||
+6
@@ -65,7 +65,13 @@ public class AdminTranslationService {
|
||||
}
|
||||
|
||||
public Map<String, Object> search(String searchKey, String missingLocale, int page, int size) {
|
||||
return search(searchKey, missingLocale, page, size, null);
|
||||
}
|
||||
|
||||
/** codes, when set, limits the list to those codes (ignoring case); null lists every area-A label. */
|
||||
public Map<String, Object> search(String searchKey, String missingLocale, int page, int size, List<String> codes) {
|
||||
Map<String, Object> req = new HashMap<>();
|
||||
req.put("codes", codes);
|
||||
req.put("searchKey", searchKey);
|
||||
req.put("missingLocale", missingLocale);
|
||||
req.put("area", AREA);
|
||||
|
||||
Reference in new issue
Block a user