<?php
//Get list of cass-group
function cass_shortcode_member_course_list_endpoint()
{
    register_rest_route('wp-cass/v1', '/cass-shortcode-member-course-list/(?P<user_id>\d+)', array(
        'methods' => 'GET',
        'callback' => 'get_api_cass_shortcode_member_course_list',
    )
    );
}

add_action('rest_api_init', 'cass_shortcode_member_course_list_endpoint');

function get_api_cass_shortcode_member_course_list($request)
{
    $IDWPUser = intval($request->get_param('user_id'));

    return Race_User::selectAllCourseFromUserStructured($IDWPUser);
}

//Get a specific course
function cass_race_list_element_endpoint() {
    register_rest_route('wp-cass/v1', '/cass-race-list-element/(?P<IDRace>\d+)/', array(
        'methods' => 'GET',
        'callback' => 'get_cass_race_list_element',
    ));
}

add_action('rest_api_init', 'cass_race_list_element_endpoint');

function get_cass_race_list_element($request) {
    $IDRace =  intval($request['IDRace']);

    return Race::selectOneStructured($IDRace);
}



