feat: add shared collection page

This commit is contained in:
Sonny
2024-06-02 18:35:10 +02:00
committed by Sonny
parent dc54a1197d
commit 8a4f895853
15 changed files with 93 additions and 18 deletions

View 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();
}
}

View File

@@ -21,7 +21,7 @@ export default class Collection extends AppBaseModel {
@column()
declare authorId: number;
@belongsTo(() => User, { foreignKey: 'author_id' })
@belongsTo(() => User, { foreignKey: 'authorId' })
declare author: BelongsTo<typeof User>;
@hasMany(() => Link)

View File

@@ -0,0 +1,11 @@
import vine from '@vinejs/vine';
const params = vine.object({
id: vine.number(),
});
export const getSharedCollectionValidator = vine.compile(
vine.object({
params,
})
);