Small refactoring

This commit is contained in:
kitelev 2025-01-04 01:09:59 +05:00
parent 8e02bf62bf
commit edefd702a8
7 changed files with 15 additions and 29 deletions

View File

@ -20,8 +20,4 @@ export default class ExoCommands {
new CreateEffortExoCommand(ctx)
];
}
static bySlug(ctx: ExoContext, slug: string): ExoCommand | undefined {
return ExoCommands.all(ctx).find(c => c.slug === slug);
}
}

View File

@ -118,10 +118,6 @@ export default class AppUtils {
return this.app.vault.getMarkdownFiles();
}
getFileCache(file: TFile): CachedMetadata | null {
return this.app.metadataCache.getFileCache(file);
}
findMdWith(filter: (f: TFile) => boolean) {
return this.getAllMdFiles().filter(filter);
}

View File

@ -25,7 +25,7 @@ export default class KObjectUtility {
for (let f of withoutId) {
await this.ctx.app.fileManager.processFrontMatter(f, (frontmatter) => {
frontmatter['uid'] = crypto.randomUUID();
frontmatter['uid'] = this.ctx.utils.generateUid();
});
}
}

View File

@ -3,7 +3,7 @@ import {UUID} from "node:crypto";
import ExoContext from "../../../../common/ExoContext";
export default abstract class AbstractCreator<KO> {
constructor(protected ctx: ExoContext) {
protected constructor(protected ctx: ExoContext) {
}
async create(file: TFile): Promise<KO> {

View File

@ -38,7 +38,7 @@ export default class ExoContext {
public readonly effortPathRulesHelper: EffortPathRulesHelper;
constructor(public app: App) {
this.utils = new Utils(this.app);
this.utils = new Utils();
this.appUtils = new AppUtils(this.app);
this.layoutFactory = new LayoutFactory(this);
@ -53,7 +53,7 @@ export default class ExoContext {
this.countNotesUseCase = new CountNotesService(this.appUtils);
this.getCurrentDNUseCase = new GetCurrentDailyNoteService(this.dailyNoteRepository);
this.effortRepository = new EffortPersistenceAdapter(this);
this.createEffortUseCase = new CreateEffortService(this.effortRepository);
this.createEffortUseCase = new CreateEffortService(this);
this.effortPathRulesHelper = new EffortPathRulesHelper(this);
}
}

View File

@ -1,30 +1,29 @@
import CreateEffortUseCase from "../ports/input/CreateEffortUseCase";
import Area from "../domain/Area";
import {EffortStatus} from "../domain/effort/EffortStatus";
import EffortRepository from "../ports/output/EffortRepository";
import {UUID} from "node:crypto";
import Effort from "../domain/effort/Effort";
import ExoContext from "../../../common/ExoContext";
export default class CreateEffortService implements CreateEffortUseCase {
constructor(private effortRepository: EffortRepository) {
constructor(private ctx: ExoContext) {
}
async taskUnderArea(area: Area): Promise<Effort> {
const title = crypto.randomUUID();
const id = crypto.randomUUID() as UUID;
const title = this.ctx.utils.generateUid();
const id = this.ctx.utils.generateUid();
const effort = new Effort(id, title, EffortStatus.DRAFT, null, null, area, null, "Body");
await this.effortRepository.save(effort);
await this.ctx.effortRepository.save(effort);
return effort;
}
async taskUnderEffort(parentEffort: Effort): Promise<Effort> {
const title = crypto.randomUUID();
const id = crypto.randomUUID() as UUID;
const title = this.ctx.utils.generateUid();
const id = this.ctx.utils.generateUid();
const effort = new Effort(id, title, EffortStatus.DRAFT, null, null, null, parentEffort, "Body");
await this.effortRepository.save(effort);
await this.ctx.effortRepository.save(effort);
return effort;
}

View File

@ -1,12 +1,7 @@
import {App} from "obsidian";
import {UUID} from "node:crypto";
export default class Utils {
constructor(private app: App) {
}
generateUid(): string {
return crypto.randomUUID();
generateUid(): UUID {
return crypto.randomUUID() as UUID;
}
}