JackHaK / TMF

0 stars 0 forks source link

Categories EndPoint #11

Closed seanthepottingshed closed 6 years ago

seanthepottingshed commented 6 years ago

@JackHaK

Is it possible to format the Categories endpoint JSON as follows please?

{
    "categories" : [
        {
            "id"    : 1,
            "title" : "Conferences & Seminars",
            "slug"  : "conferences-seminars"
        },
        {
            "id"    : 2,
            "title" : "Director Development",
            "slug"  : "director-development"
        },
        {
            "id"    : 3,
            "title" : "Finance",
            "slug"  : "finance"
            "categories" : [
                {
                    "id"    : 11,
                    "title" : "Insurance",
                    "slug"  : "insurance"
                },
                {
                    "id"    : 12,
                    "title" : "Banking",
                    "slug"  : "banking"
                },
                {
                    "id"    : 13,
                    "title" : "Investment",
                    "slug"  : "investment"
                },
                {
                    "id"    : 14,
                    "title" : "Trust",
                    "slug"  : "trust"
                },
                {
                    "id"    : 15,
                    "title" : "AML / Compliance",
                    "slug"  : "aml-compliance"
                },
                {
                    "id"    : 16,
                    "title" : "Corporate Governance",
                    "slug"  : "corporate-governance"
                },
                {
                    "id"    : 17,
                    "title" : "Accounting",
                    "slug"  : "accounting"
                }
            ]
        },
        {
            "id"    : 4,
            "title" : "IT & eCommerce",
            "slug"  : "it-ecommerce"
        },
        {
            "id"    : 5,
            "title" : "Law",
            "slug"  : "law"
        },
        {
            "id"    : 6,
            "title" : "Leadership & Management",
            "slug"  : "leadership-management"
        },
        {
            "id"    : 7,
            "title" : "Personal Development",
            "slug"  : "personal-development"
        },
        {
            "id"    : 8,
            "title" : "Project Management",
            "slug"  : "project-management"
        },
        {
            "id"    : 9,
            "title" : "Sales & Marketing",
            "slug"  : "sales-marketing"
        },
        {
            "id"    : 10,
            "title" : "University Programmes",
            "slug"  : "university-programmes"
        },
    ]
}

Basically I need to associate images in the CMS side of things with categories, so I need an id to o keep things in sync. Also best if the slug is generated on your side to ensure that the same format is used both in the website and the Integration Tier.

JackHaK commented 6 years ago

@seanthepottingshed

which route are you using?

seanthepottingshed commented 6 years ago

@JackHaK

Sorry:

seanthepottingshed commented 6 years ago

@JackHaK

This could be another API route if it's easy for you.

seanthepottingshed commented 6 years ago

Revised structure with id and without first categories key:

[
    {
        "title": "Conferences & Seminars",
        "slug": "conferences-seminars"
    },
    {
        "title": "Director Development",
        "slug": "director-development"
    },
    {
        "title": "Finance",
        "slug": "finance",
        "categories": [
            {
                "title": "Insurance",
                "slug": "insurance"
            },
            {
                "title": "Banking",
                "slug": "banking"
            },
            {
                "title": "Investment",
                "slug": "investment"
            },
            {
                "title": "Trust",
                "slug": "trust"
            },
            {
                "title": "AML / Compliance",
                "slug": "aml-compliance"
            },
            {
                "title": "Corporate Governance",
                "slug": "corporate-governance"
            },
            {
                "title": "Accounting",
                "slug": "accounting"
            }
        ]
    },
    {
        "title": "IT & eCommerce",
        "slug": "it-ecommerce"
    },
    {
        "title": "Law",
        "slug": "law"
    },
    {
        "title": "Leadership & Management",
        "slug": "leadership-management"
    },
    {
        "title": "Personal Development",
        "slug": "personal-development"
    },
    {
        "title": "Project Management",
        "slug": "project-management"
    },
    {
        "title": "Sales & Marketing",
        "slug": "sales-marketing"
    },
    {
        "title": "University Programmes",
        "slug": "university-programmes"
    }
]
PeteHaK commented 6 years ago

Hi @seanthepottingshed - Jack and I both looked at this this afternoon as Administrate was giving us the run around with some of the data. We have now changed the service to return what you wanted adding in ID and also moving the array to an object. We have also created slugs but I'm not sure why they would be relevant in the middle tier and we create them on the fly so we need to be careful. Not tied down the regex on them yet so we can tweak as required.

PeteHaK commented 6 years ago

Introduced str_slug to produce slugs.

seanthepottingshed commented 6 years ago

@PeteHaK @JackHaK

LEGENDS, really appreciated!

OctoberCMS uses it's own Slug generation class which I can't guarantee will generate the same slug as the native Laravel str_slug function.