Beispiel #1
0
        /// <summary>
        ///  Concatene la liste des champs donnés dans la Query String pour un nom de modele json api
        ///  Et la liste les champs clés des propriétés de relations
        /// </summary>
        private List <string> GetListeFieldsFromRelations(Type type, IEnumerable <PropertyInfo> relationshipProperties)
        {
            // Récuperation des champs simple pour le type de modele
            List <string> fields = base.GetListeFields(type);

            List <string> fieldsKey = new List <string>();

            foreach (PropertyInfo relation in relationshipProperties)
            {
                PropertyInfo foreignKeyProperty = AttributeRelationsHandling.FindForeignKeyPropertyAndAttribute(type, relation.Name).Item1;

                if (foreignKeyProperty == null)
                {
                    throw new JsonApiArchitectureException($"ForeignKeyJsonApi manquant pour {relation.Name} dans {type.Name}, ajouter[ForeignKeyJsonApi (RelationName = nameof({relation.Name}))]");
                }

                fieldsKey.Add(foreignKeyProperty.Name);
            }

            if (fields != null && fieldsKey.Any())
            {
                fields.AddRange(fieldsKey);
                return(fields);
            }

            if (fields == null && fieldsKey.Any())
            {
                return(fieldsKey);
            }

            return(fields);
        }
Beispiel #2
0
        public JsonApiRelationReadOnlyController(TIDataSource dataSource, IQueryService queryService)
        {
            this._datasource   = dataSource;
            this._queryService = queryService;

            this.PrimaryForeigneKeyProperty = AttributeRelationsHandling.FindForeignKeyPropertyFromType(typeof(TRessource), typeof(TRessourceRelation));
        }
Beispiel #3
0
        /// <summary>
        /// Genere les controllers des relations ressources
        /// </summary>
        private void PopulateControllerRelationShip(ControllerFeature feature, Type typeRessource)
        {
            foreach (Tuple <PropertyInfo, RelationshipJsonApiAttribute> relation in AttributeRelationsHandling.GetRelationshipProperties(typeRessource))
            {
                if (relation.Item2 is HasOneJsonApiAttribute)
                {
                    continue;
                }

                if (relation.Item1.GetPropertyTypeSample() == typeRessource)
                {
                    continue;
                }

                ControllerRelationJsonApiAttribute controllerRelationAttribute =
                    relation.Item1.GetCustomAttribute <ControllerRelationJsonApiAttribute>();

                if (controllerRelationAttribute != null && controllerRelationAttribute.None)
                {
                    continue;
                }

                feature.Controllers.Add(new ControllerMaker(typeRessource, relation.Item1.GetPropertyTypeSample(), controllerRelationAttribute?.ReadOnly ?? false).MakeRelationController());
            }
        }
Beispiel #4
0
        /// <summary>
        ///  Récupere la liste des champs donnés dans la Query String pour un type de modele
        ///  Si des "include" sont demandés, les champs clés des relations sont ajoutés également dans la liste des champs
        /// </summary>
        public override List <string> GetListeFields(Type type, string relationPath)
        {
            IEnumerable <PropertyInfo> relationshipProperties =
                AttributeRelationsHandling.GetRelationshipProperties(type)
                .Where(p => Utils.IsRelationInInclude(relationPath + "." + AttributeHandling.GetLabelProperty(p.Item1), this._includes))
                .Select(p => p.Item1);

            return(this.GetListeFieldsFromRelations(type, relationshipProperties));
        }