refactor: 修复 modules 三层架构违规
- auth: actionDeleteAccount 改用 service+repo,forgot-password 完整三层实现 - card: serviceCheckCardOwnership 替代直接调用 repository - deck: 移除 service 层的 use server 指令 - dictionary: 数据转换逻辑从 repository 移到 service - ocr: 认证移到 action 层,跨模块调用改用 service - translator: genIPA/genLanguage 改用 service 层
This commit is contained in:
@@ -2,9 +2,23 @@ import { executeDictionaryLookup } from "@/lib/bigmodel/dictionary/orchestrator"
|
||||
import { repoCreateLookUp, repoCreateLookUpWithItemAndEntries, repoSelectLastLookUpResult } from "./dictionary-repository";
|
||||
import { ServiceInputLookUp } from "./dictionary-service-dto";
|
||||
import { createLogger } from "@/lib/logger";
|
||||
import { RepoOutputSelectLastLookUpResultItem } from "./dictionary-repository-dto";
|
||||
|
||||
const log = createLogger("dictionary-service");
|
||||
|
||||
function transformRawItemToSharedItem(rawItem: RepoOutputSelectLastLookUpResultItem) {
|
||||
return {
|
||||
id: rawItem.id,
|
||||
standardForm: rawItem.standardForm,
|
||||
entries: rawItem.entries.map(entry => ({
|
||||
ipa: entry.ipa ?? undefined,
|
||||
definition: entry.definition,
|
||||
partOfSpeech: entry.partOfSpeech ?? undefined,
|
||||
example: entry.example
|
||||
}))
|
||||
};
|
||||
}
|
||||
|
||||
export const serviceLookUp = async (dto: ServiceInputLookUp) => {
|
||||
const {
|
||||
text,
|
||||
@@ -27,7 +41,6 @@ export const serviceLookUp = async (dto: ServiceInputLookUp) => {
|
||||
definitionLang
|
||||
);
|
||||
|
||||
// 使用事务确保数据一致性
|
||||
repoCreateLookUpWithItemAndEntries(
|
||||
{
|
||||
standardForm: response.standardForm,
|
||||
@@ -47,18 +60,20 @@ export const serviceLookUp = async (dto: ServiceInputLookUp) => {
|
||||
|
||||
return response;
|
||||
} else {
|
||||
const transformedResult = transformRawItemToSharedItem(lastLookUpResult);
|
||||
|
||||
repoCreateLookUp({
|
||||
userId: userId,
|
||||
text: text,
|
||||
queryLang: queryLang,
|
||||
definitionLang: definitionLang,
|
||||
dictionaryItemId: lastLookUpResult.id
|
||||
dictionaryItemId: transformedResult.id
|
||||
}).catch(error => {
|
||||
log.error("Failed to save dictionary data", { error: error instanceof Error ? error.message : String(error) });
|
||||
});
|
||||
return {
|
||||
standardForm: lastLookUpResult.standardForm,
|
||||
entries: lastLookUpResult.entries
|
||||
standardForm: transformedResult.standardForm,
|
||||
entries: transformedResult.entries
|
||||
};
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user