mirror of
https://github.com/Sonny93/my-links.git
synced 2025-12-09 23:15:36 +00:00
feat: add shared collection page
This commit is contained in:
24
app/controllers/shared_collections_controller.ts
Normal file
24
app/controllers/shared_collections_controller.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
import { Visibility } from '#enums/visibility';
|
||||
import Collection from '#models/collection';
|
||||
import { getSharedCollectionValidator } from '#validators/shared_collection';
|
||||
import type { HttpContext } from '@adonisjs/core/http';
|
||||
|
||||
export default class SharedCollectionsController {
|
||||
async index({ request, inertia }: HttpContext) {
|
||||
const { params } = await request.validateUsing(
|
||||
getSharedCollectionValidator
|
||||
);
|
||||
|
||||
const collection = await this.getSharedCollectionById(params.id);
|
||||
return inertia.render('shared', { collection });
|
||||
}
|
||||
|
||||
private async getSharedCollectionById(id: Collection['id']) {
|
||||
return await Collection.query()
|
||||
.where('id', id)
|
||||
.andWhere('visibility', Visibility.PUBLIC)
|
||||
.preload('links')
|
||||
.preload('author')
|
||||
.firstOrFail();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user