feat(system): limit the label search to given codes

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EFUzfiCVCgCVJZq4NDEqZs
This commit is contained in:
ngqileandClaude Opus 5.5 committed 2026-12-02 14:47:36 +08:00
1 parent a24291edd2
commit 89662d0eb2
4 files changed
+28 -2

No files matched your search

@@ -4,7 +4,7 @@ Design: `docs/superpowers/specs/2026-12-02-messages-colite-filter-design.md`. Ev
## 1. services-system
- [ ] 1.1 `MessageSearchRequest.codes`; when present, `MessageService.search` keeps only rows whose code matches one of the codes, ignoring case. Existing filters and paging still apply.
- [x] 1.1 `MessageSearchRequest.codes`; when present, `MessageService.search` keeps only rows whose code matches one of the codes, ignoring case. Existing filters and paging still apply.
- Verify: `mvn -T 1C -B -q -pl solvway-services-system -am verify`
## 2. mobile-api
@@ -4,13 +4,16 @@ import com.solvway.services.system.constant.SystemConstants.Area;
import lombok.Getter;
import lombok.Setter;
/** Translations search: searchKey over the code, English and Chinese text; missingLocale lists labels lacking that language. */
import java.util.List;
/** Translations search: searchKey over the code, English and Chinese text; missingLocale lists labels lacking that language; codes, when set, limits to those codes ignoring case. */
@Getter
@Setter
public class MessageSearchRequest {
private String searchKey;
private Area area;
private String missingLocale;
private List<String> codes;
private int page;
private int size;
}
@@ -24,6 +24,8 @@ import java.util.Objects;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
@Service
public class MessageService {
@@ -86,8 +88,12 @@ public class MessageService {
List<Message> rows = req.getArea() == null ? messageRepository.findAll() : messageRepository.findAllByArea(req.getArea());
String key = StringUtils.isEmpty(req.getSearchKey()) || req.getSearchKey().isBlank() ? null : lower(req.getSearchKey().trim());
String missing = StringUtils.isEmpty(req.getMissingLocale()) ? null : req.getMissingLocale();
Set<String> codes = req.getCodes() == null ? null : req.getCodes().stream().map(MessageService::lower).collect(Collectors.toSet());
List<Message> hits = new ArrayList<>();
for (Message m : rows) {
if (codes != null && !codes.contains(lower(m.getCode()))) {
continue;
}
Map<String, String> text = parseContent(m.getContent());
if (key != null && !(lower(m.getCode()).contains(key) || lower(text.get("en_US")).contains(key) || lower(text.get("zh_CN")).contains(key))) {
continue;
@@ -85,6 +85,23 @@ class MessageServiceTranslationsTest {
assertThat(codes(page)).containsExactly("A3");
}
@Test
void codesLimitTheListIgnoringCaseAndCombineWithTheOtherFilters() {
when(repository.findAllByArea(Area.A)).thenReturn(List.of(
msg(1, "Leads", "Leads", "线索"), msg(2, "OrderPayment", "Order payment", null), msg(3, "Users", "Users", null)));
MessageSearchRequest own = req(null, null, 0, 10);
own.setCodes(List.of("leads", "USERS"));
assertThat(codes(service.search(own))).containsExactly("Leads", "Users");
own.setMissingLocale("zh_CN");
Page<Message> missing = service.search(own);
assertThat(codes(missing)).containsExactly("Users");
assertThat(missing.getTotalElements()).isEqualTo(1);
assertThat(codes(service.search(req(null, "zh_CN", 0, 10)))).containsExactly("OrderPayment", "Users");
}
@Test
void savingAnExistingLabelBumpsTheVersion() {
Message stored = msg(7, "Leads", "Leads", "线索");