JSONAPI-Resources / JSONAPI-Resources/jsonapi-resources

Strategy for grouped resources

Abierto
#840 3 comentarios 1 reacción 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Lenguaje dominante
Ruby
Estrellas
2.3k
Forks
546
Métricas de merge de PR
Sin PR fusionados en 30 d

Descripción

I realize this isn't exclusively a JR question, but I feel it's too common to not bring it up and how one might accomplish it using JR.

My current use case has a type of model that's the basis for summed queries grouped by one or more attributes. In this case, it's a timesheet entry, and I initially need to group them by user_id and project_id, but they could easily be grouped by time periods as well. The aggregated value is SUM(hours). I've created an TimesheetEntryCollection model as an ActiveModel::Model object to handle the aggregated data, but I'm unsure how to serialize them, as JR expects and ActiveRecord::Relation to be returned from the Resource's self.records method and I'm not sure how to force a relation out of a tableless model. Do I just need to override the controller methods, or is there some way to do this through the resource?

Am I thinking about this the wrong way? Should JR maybe allow arrays to be returned from self.records with the understanding that you have to handle pagination/filtering yourself?

Any help would be greatly appreciated!

Guía de contribución

No hay ninguna guía de contribución indexada para este repositorio

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Línea de trabajo

Comienza con el contrato self.records de Resource y los métodos del controlador mencionados en el informe; después, sigue cómo JR serializa una ActiveRecord::Relation. Compara ese recorrido con el ActiveModel::Model sin tabla TimesheetEntryCollection y el caso de uso de SUM(hours) agrupado. Se considerará terminado cuando exista un enfoque acordado para los recursos agrupados, incluida la cuestión de si se admiten arrays y la paginación o el filtrado gestionados por quien realiza la llamada.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
rails, ruby
Área
api, backend
Tipo de issue
Nueva funcionalidad
Dificultad
5/5
Tiempo estimado
Más de una semana
Estado de actividad
Estancado
Claridad
Necesita aclaración
Aptitud para principiantes
25/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.