2024-03-14 19:25:27 +00:00
|
|
|
import type { HttpContext } from '@adonisjs/core/http';
|
2023-03-03 15:54:28 +00:00
|
|
|
// import Person from 'App/Models/Person';
|
2024-03-14 19:25:27 +00:00
|
|
|
import Dataset from '#app/Models/Dataset';
|
2023-09-04 11:24:58 +00:00
|
|
|
import { StatusCodes } from 'http-status-codes';
|
2023-03-03 15:54:28 +00:00
|
|
|
|
|
|
|
// node ace make:controller Author
|
|
|
|
export default class DatasetController {
|
2024-03-14 19:25:27 +00:00
|
|
|
public async index({}: HttpContext) {
|
2023-06-22 15:20:04 +00:00
|
|
|
// select * from gba.persons
|
|
|
|
// where exists (select * from gba.documents inner join gba.link_documents_persons on "documents"."id" = "link_documents_persons"."document_id"
|
|
|
|
// where ("link_documents_persons"."role" = 'author') and ("persons"."id" = "link_documents_persons"."person_id"));
|
|
|
|
const datasets = await Dataset.query().where('server_state', 'published').orWhere('server_state', 'deleted');
|
|
|
|
|
|
|
|
return datasets;
|
|
|
|
}
|
2023-09-04 11:24:58 +00:00
|
|
|
|
2024-03-14 19:25:27 +00:00
|
|
|
public async findAll({ response }: HttpContext) {
|
2023-09-04 11:24:58 +00:00
|
|
|
try {
|
|
|
|
const datasets = await Dataset.query()
|
|
|
|
.where('server_state', 'published')
|
|
|
|
.orWhere('server_state', 'deleted')
|
|
|
|
.preload('descriptions') // Preload any relationships you need
|
|
|
|
.orderBy('server_date_published');
|
|
|
|
return response.status(StatusCodes.OK).json(datasets);
|
|
|
|
} catch (error) {
|
|
|
|
return response.status(500).json({
|
|
|
|
message: error.message || 'Some error occurred while retrieving datasets.',
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-14 19:25:27 +00:00
|
|
|
public async findOne({ params }: HttpContext) {
|
2023-09-04 11:24:58 +00:00
|
|
|
const datasets = await Dataset.query()
|
|
|
|
.where('publish_id', params.publish_id)
|
|
|
|
.preload('titles')
|
|
|
|
.preload('descriptions')
|
|
|
|
.preload('user')
|
|
|
|
.preload('authors', (builder) => {
|
|
|
|
builder.orderBy('pivot_sort_order', 'asc');
|
|
|
|
})
|
|
|
|
.preload('contributors', (builder) => {
|
|
|
|
builder.orderBy('pivot_sort_order', 'asc');
|
|
|
|
})
|
|
|
|
.preload('subjects')
|
|
|
|
.preload('coverage')
|
|
|
|
.preload('licenses')
|
|
|
|
.preload('references')
|
|
|
|
.preload('project')
|
|
|
|
.preload('referenced_by', (builder) => {
|
|
|
|
builder.preload('dataset', (builder) => {
|
|
|
|
builder.preload('identifier');
|
|
|
|
});
|
|
|
|
})
|
|
|
|
.preload('files', (builder) => {
|
|
|
|
builder.preload('hashvalues');
|
|
|
|
})
|
|
|
|
.preload('identifier')
|
|
|
|
.firstOrFail();
|
|
|
|
|
|
|
|
return datasets;
|
|
|
|
}
|
2023-03-03 15:54:28 +00:00
|
|
|
}
|