im not that much in flutter so i have a project and i need to add an images slider on the home page that when customer press on image will navigate to the pressed one.
The data that flutter is getting is from mysql database (API):
<!-- language: lang-html -->
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
require APPPATH . '/libraries/TokenHandler.php';
require APPPATH . 'libraries/REST_Controller.php';
class Api_frontend extends REST_Controller {
protected $token;
public function __construct() {
parent::__construct();
$this->load->database();
// creating object of TokenHandler class at first
$this->tokenHandler = new TokenHandler();
header('Content-Type: application/json');
}
public function token_data_get($auth_token) {
if (isset($auth_token)) {
try
{
$jwtData = $this->tokenHandler->DecodeToken($auth_token);
return json_encode($jwtData);
}
catch (Exception $e)
{
echo 'catch';
http_response_code('401');
echo json_encode(array( "status" => false, "message" => $e->getMessage()));
exit;
}
}else{
echo json_encode(array( "status" => false, "message" => "Invalid Token"));
}
}
public function signup_post(){
$response = array();
$response = $this->customer_frontend->signup_post();
return $this->set_response($response, REST_Controller::HTTP_OK);
}
public function forgot_password_post(){
$response = array();
if(isset($_POST['email']) && !empty($_POST['email'])){
$new_password = get_random_code(6);
$this->email_model->send_forgot_password_mail($new_password, $_POST['email']);
$this->customer_frontend->save_forgot_password($new_password);
$response['message'] = get_phrase('new_password_has_been_sent_to_your_email');
$response['status'] = 200;
$response['validity'] = true;
}else{
$response['message'] = get_phrase('access_denied');
$response['status'] = 403;
$response['validity'] = false;
}
return $this->set_response($response, REST_Controller::HTTP_OK);
}
public function change_password_post(){
$response = array();
if(isset($_POST['auth_token']) && !empty($_POST['auth_token'])){
$user_info = json_decode($this->token_data_get($_POST['auth_token']), true);
$response = $this->customer_frontend->change_password_post($user_info['user_id']);
}else{
$response['message'] = get_phrase('access_denied');
$response['status'] = 403;
$response['validity'] = false;
}
return $this->set_response($response, REST_Controller::HTTP_OK);
}
public function change_profile_photo_post(){
$response = array();
if(isset($_POST['auth_token']) && !empty($_POST['auth_token'])){
$user_info = json_decode($this->token_data_get($_POST['auth_token']), true);
$response = $this->customer_frontend->change_profile_photo_post($user_info['user_id']);
}else{
$response['message'] = get_phrase('access_denied');
$response['status'] = 403;
$response['validity'] = false;
}
return $this->set_response($response, REST_Controller::HTTP_OK);
}
public function verify_email_address_post(){
$response = array();
$response = $this->customer_frontend->verify_email_address_post();
return $this->set_response($response, REST_Controller::HTTP_OK);
}
public function login_post(){
$userdata = array();
$userdata = $this->customer_frontend->login_post();
if ($userdata['validity'] == true) {
$userdata['token'] = $this->tokenHandler->GenerateToken($userdata);
}
return $this->set_response($userdata, REST_Controller::HTTP_OK);
}
public function userdata_get(){
$userdata = array();
if (isset($_GET['auth_token']) && !empty($_GET['auth_token'])) {
$auth_token = $_GET['auth_token'];
$user_info = json_decode($this->token_data_get($auth_token), true);
$response = $this->customer_frontend->userdata_get($user_info['user_id']);
}else{
$response['message'] = get_phrase('access_denied');
$response['status'] = 403;
$response['validity'] = false;
}
return $this->set_response($response, REST_Controller::HTTP_OK);
}
public function update_userdata_post(){
$response = array();
if (isset($_POST['auth_token']) && !empty($_POST['auth_token'])) {
$user_info = json_decode($this->token_data_get($_POST['auth_token']), true);
$response = $this->customer_frontend->update_userdata_post($user_info['user_id']);
}else{
$response['message'] = get_phrase('access_denied');
$response['status'] = 403;
$response['validity'] = false;
}
return $this->set_response($response, REST_Controller::HTTP_OK);
}
public function parent_categories_get(){
$parent_categories = array();
$parent_categories = $this->customer_frontend->parent_categories_get();
return $this->set_response($parent_categories, REST_Controller::HTTP_OK);
}
public function top_products_get(){
$top_products = array();
$user_id = 0;
if (isset($_GET['auth_token']) && !empty($_GET['auth_token'])) {
$user_info = json_decode($this->token_data_get($_GET['auth_token']), true);
$user_id = $user_info['user_id'];
}
$top_products = $this->customer_frontend->top_products_get($user_id);
return $this->set_response($top_products, REST_Controller::HTTP_OK);
}
public function products_get(){
$products = array();
$page_number = 1;
$user_id = 0;
if (isset($_GET['page_number']) && !empty($_GET['page_number'])) {
$page_number = $_GET['page_number'];
}
if (isset($_GET['auth_token']) && !empty($_GET['auth_token'])) {
$user_info = json_decode($this->token_data_get($_GET['auth_token']), true);
$user_id = $user_info['user_id'];
}
$products = $this->customer_frontend->products_get($user_id, $page_number);
return $this->set_response($products, REST_Controller::HTTP_OK);
}
public function product_search_get(){
$products = array();
$page_number = 1;
if (isset($_GET['page_number']) && !empty($_GET['page_number'])) {
$page_number = $_GET['page_number'];
}
$products = $this->customer_frontend->product_search_get($page_number);
return $this->set_response($products, REST_Controller::HTTP_OK);
}
public function highest_and_lowest_price_get(){
$response = array();
$response = $this->customer_frontend->highest_and_lowest_price_get();
return $this->set_response($response, REST_Controller::HTTP_OK);
}
public function product_filter_get(){
$products = array();
$page_number = 1;
if (isset($_GET['page_number']) && !empty($_GET['page_number'])) {
$page_number = $_GET['page_number'];
}
$products = $this->customer_frontend->product_filter_get($page_number);
return $this->set_response($products, REST_Controller::HTTP_OK);
}
public function product_details_get(){
$product_details = array();
$user_id = 0;
if (isset($_GET['product_id']) && !empty($_GET['product_id']) && isset($_GET['auth_token']) && !empty($_GET['auth_token'])) {
$user_info = json_decode($this->token_data_get($_GET['auth_token']), true);
$user_id = $user_info['user_id'];
}
$product_details = $this->customer_frontend->product_details_get($user_id, $_GET['product_id']);
return $this->set_response($product_details, REST_Controller::HTTP_OK);
}
public function categories_and_products_by_category_get(){
$categories_and_products = array();
$user_id = 0;
if (isset($_GET['auth_token']) && !empty($_GET['auth_token'])) {
$user_info = json_decode($this->token_data_get($_GET['auth_token']), true);
$user_id = $user_info['user_id'];
}
$categories_and_products = $this->customer_frontend->categories_and_products_by_category_get($user_id, $_GET['category_id']);
return $this->set_response($categories_and_products, REST_Controller::HTTP_OK);
}
public function products_by_category_get(){
$products_by_category = array();
$user_id = 0;
if (isset($_GET['auth_token']) && !empty($_GET['auth_token'])) {
$user_info = json_decode($this->token_data_get($_GET['auth_token']), true);
$user_id = $user_info['user_id'];
}
$products_by_category = $this->customer_frontend->products_by_category_get($user_id, $_GET['category_id']);
return $this->set_response($products_by_category, REST_Controller::HTTP_OK);
}
//*************** Cart ******************//
public function add_cart_item_get(){
$response = array();
if (isset($_GET['auth_token']) && !empty($_GET['auth_token']) && isset($_GET['product_id']) && !empty($_GET['product_id'])) {
$user_info = json_decode($this->token_data_get($_GET['auth_token']), true);
$response = $this->customer_frontend->add_cart_item_get($user_info['user_id'], $_GET['product_id']);
}else{
$response['message'] = get_phrase('access_denied');
$response['status'] = 403;
$response['validity'] = false;
}
return $this->set_response($response, REST_Controller::HTTP_OK);
}
public function cart_items_get(){
$response = array();
if (isset($_GET['auth_token']) && !empty($_GET['auth_token'])) {
$user_info = json_decode($this->token_data_get($_GET['auth_token']), true);
$response = $this->customer_frontend->cart_items_get($user_info['user_id']);
}else{
$response['message'] = get_phrase('access_denied');
$response['status'] = 403;
$response['validity'] = false;
}
return $this->set_response($response, REST_Controller::HTTP_OK);
}
public function cart_items_remove_get(){
$response = array();
if (isset($_GET['auth_token']) && !empty($_GET['auth_token'])) {
$user_info = json_decode($this->token_data_get($_GET['auth_token']), true);
$response = $this->customer_frontend->cart_items_remove_get($user_info['user_id']);
}else{
$response['message'] = get_phrase('access_denied');
$response['status'] = 403;
$response['validity'] = false;
}
return $this->set_response($response, REST_Controller::HTTP_OK);
}
public function modify_cart_items_get(){
$response = array();
if (isset($_GET['auth_token']) && !empty($_GET['auth_token'])) {
$user_info = json_decode($this->token_data_get($_GET['auth_token']), true);
$response = $this->customer_frontend->modify_cart_items_get($user_info['user_id']);
}else{
$response['message'] = get_phrase('access_denied');
$response['status'] = 403;
$response['validity'] = false;
}
return $this->set_response($response, REST_Controller::HTTP_OK);
}
//*************** Cart end ******************//
//*************** Checkout page ******************//
public function checkout_get(){
$response = array();
if (isset($_GET['auth_token']) && !empty($_GET['auth_token'])) {
$user_info = json_decode($this->token_data_get($_GET['auth_token']), true);
$response = $this->customer_frontend->checkout_get($user_info['user_id']);
}else{
$response['message'] = get_phrase('access_denied');
$response['status'] = 403;
$response['validity'] = false;
}
return $this->set_response($response, REST_Controller::HTTP_OK);
}
//*************** End checkout page ******************//
//*************** Order ******************//
//confirm order for flutter
public function confirm_order_get(){
$response = array();
if (isset($_GET['auth_token']) && !empty($_GET['auth_token'])) {
$user_info = json_decode($this->token_data_get($_GET['auth_token']), true);
$response = $this->customer_frontend->confirm_order_get($user_info['user_id']);
return $this->set_response($response, REST_Controller::HTTP_OK);
}else{
$response['message'] = get_phrase('access_denied');
$response['status'] = 403;
$response['validity'] = false;
return $this->set_response($response, REST_Controller::HTTP_OK);
}
}
public function order_histories_get(){
$response = array();
if (isset($_GET['auth_token']) && !empty($_GET['auth_token'])) {
$user_info = json_decode($this->token_data_get($_GET['auth_token']), true);
$response = $this->customer_frontend->order_histories_get($user_info['user_id']);
return $this->set_response($response, REST_Controller::HTTP_OK);
}else{
$response['message'] = get_phrase('access_denied');
$response['status'] = 403;
$response['validity'] = false;
return $this->set_response($response, REST_Controller::HTTP_OK);
}
}
public function order_history_details_get(){
$response = array();
if (isset($_GET['auth_token']) && !empty($_GET['auth_token'])) {
$user_info = json_decode($this->token_data_get($_GET['auth_token']), true);
$response = $this->customer_frontend->order_history_details_get($user_info['user_id']);
return $this->set_response($response, REST_Controller::HTTP_OK);
}else{
$response['message'] = get_phrase('access_denied');
$response['status'] = 403;
$response['validity'] = false;
return $this->set_response($response, REST_Controller::HTTP_OK);
}
}
//*************** End order ******************//
//*************** Start wishlist item ******************//
public function wishlist_item_get(){
$response = array();
if (isset($_GET['auth_token']) && !empty($_GET['auth_token'])) {
$user_info = json_decode($this->token_data_get($_GET['auth_token']), true);
$response = $this->customer_frontend->wishlist_item_get($user_info['user_id']);
return $this->set_response($response, REST_Controller::HTTP_OK);
}else{
$response['message'] = get_phrase('access_denied');
$response['status'] = 403;
$response['validity'] = false;
return $this->set_response($response, REST_Controller::HTTP_OK);
}
}
public function add_wishlist_item_get(){
$response = array();
if (isset($_GET['auth_token']) && !empty($_GET['auth_token'])) {
$user_info = json_decode($this->token_data_get($_GET['auth_token']), true);
$response = $this->customer_frontend->add_wishlist_item_get($user_info['user_id']);
return $this->set_response($response, REST_Controller::HTTP_OK);
}else{
$response['message'] = get_phrase('access_denied');
$response['status'] = 403;
$response['validity'] = false;
return $this->set_response($response, REST_Controller::HTTP_OK);
}
}
//*************** End wishlist item ******************//
//*************** Start help and support ******************//
public function help_and_support_get(){
$response = array();
$response = $this->customer_frontend->help_and_support_get();
return $this->set_response($response, REST_Controller::HTTP_OK);
}
//*************** End help and support ******************//
}
The navigation will be only for product or category so i made 2 tables in mysql
CategoryBanners (ID ImageBinary ImagePath CategoryID)
ProductBanners (ID ImageBinary ImagePath ProductID)
any help please? thanks inadvance!