refactor: split links controller into multiple controllers

This commit is contained in:
Sonny
2025-08-17 00:39:51 +02:00
parent 56b52adac0
commit 9ff3ca112c
16 changed files with 260 additions and 208 deletions

View File

@@ -0,0 +1,34 @@
import { CollectionService } from '#collections/services/collection_service';
import { LinkService } from '#links/services/link_service';
import { updateLinkValidator } from '#links/validators/update_link_validator';
import { inject } from '@adonisjs/core';
import { HttpContext } from '@adonisjs/core/http';
@inject()
export default class UpdateLinkController {
constructor(
private linkService: LinkService,
private collectionsService: CollectionService
) {}
async render({ auth, inertia, request, response }: HttpContext) {
const linkId = request.qs()?.linkId;
if (!linkId) {
return response.redirectToNamedRoute('dashboard');
}
const collections =
await this.collectionsService.getCollectionsForAuthenticatedUser();
const link = await this.linkService.getLinkById(linkId, auth.user!.id);
return inertia.render('links/edit', { collections, link });
}
async execute({ request }: HttpContext) {
const { params, ...payload } =
await request.validateUsing(updateLinkValidator);
await this.linkService.updateLink(params.id, payload);
return this.collectionsService.redirectToCollectionId(payload.collectionId);
}
}