Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 11

YII 2 AND KSS

MICROSERVICE
YII2 – PHP FRAMEWORK

• - REST API
• - Active Record
• - Authentication and Authorization
YII2 – REST API
• Method GET/PUT/POST/DELETE/OPTION • pluralize = true (default)
• URL rules GET /api/v1/i20-records
• Eg:  GET /api/v1/i20-records/search
•     [ GET /api/v1/i20-records/1

•     'class'         => 'yii\rest\UrlRule', POST /api/v1/i20-records

•     'controller'    => [ 'api/v1/i20-record' ], PUT /api/v1/i20-records/1


DELETE /api/v1/i20-records/1
•     'extraPatterns' => [
• pluralize = false 
•         'GET,POST,HEAD recepients/{id}' =>
'recepients', GET /api/v1/i20-record
GET /api/v1/i20-record/search
•         'OPTIONS recepients/{id}' => 'option',
GET /api/v1/i20-record/1
•     ]
POST /api/v1/i20-record
•   'pluralize'     => true/false
PUT /api/v1/i20-record/1
• ],
DELETE /api/v1/i20-record/1
YII2 – ACTIVE RECORD
• Active Record provides an object-oriented interface for accessing and
manipulating data stored in databases
• Accessing Relational Data
• Working with Relational Data
class Customer extends ActiveRecord
$customer = Customer::findOne(123);
{
// SELECT * FROM `order` WHERE `customer_id` =
    public function getOrders(){
123
        return $this->hasMany(Order::className(), ['customer_id' => 'id']);
// $orders is an array of Order objects
    }
}
$orders = $customer->orders;

class Order extends ActiveRecord OR we might want to sort the orders

{ // SELECT * FROM `order` WHERE `customer_id` =


    public function getCustomer(){ 123 order by order_date DESC

        return $this->hasOne(Customer::className(), ['id' => 'customer_id']); $orders = $customer->getOrders()


    }    ->orderBy('order_date DESC')
}    ->all();
YII2 – ACTIVE RECORD – _WITHS/EXPAND
PARAM
• To get the relational data from URL. This gives FE all control of what data to get
• [_withs] is custom param which is the same [expand] of Yii
class Customer extends ActiveRecord
{
URL access
    public function extraFields(){
        return ['orders']; Using KSS way
  /api/v1/customers/1?_withs[0]=orders
    }
    public function getOrders(){ Using Yii way
        return $this->hasMany(Order::className(), /api/v1/customers/1?expand=orders
['customer_id' => 'id']);
    }
}
YII2 – ACTIVE RECORD – _FILTERS/FILTER
PARAM
• To filter the data from URL. This gives FE all control of what data to get
• [_filters] is custom param which is the same [filter] of Yii
Result
URL access
/api/v1/customers/? Select * from customer where name like
_filters[name]=SomeOne '%SomeOne%'

/api/v1/customers/search? Select * from customer where name like


_filters[name]=SomeOne '%SomeOne%' limit 0, 20
Select * from customer where name =
/api/v1/customers/?_filters[name]
'SomeOne'
[eq]=SomeOne
Select * from customer c join orders o on c.id =
/api/v1/customers/?_filters[name] o.customer_id where c.name = 'SomeOne'
[eq]=SomeOne&_filters[orders.amount] and o.amount >=5000
YII2 – AUTHENTICATE AND AUTHORIZATION

• Login at IDM
• All request must include iPlanetDirectoryPro token in header for authentication
• Validate the token request against IDM
• Call to get the policy file and use YII Access Filter to Authorize the access at
function level
• Authorize the access at rows level
• Authorize the access at fields level
KSS MICROSERVICES
• Profile - IDM (Chris)
• Product Catalog (PROC) (Moises)
• Admission
• Task/Activity
• Enrolment
• Individual Study Plan (ISP)
• Scheduling
• Grade
KSS MICROSERVICES - ENVIRONMENTS
• DEV --> GIT /KSS-application-microservice [dev] branch
- URL http://54.169.121.216
- Need code review by leader
• TEST --> GIT /KSS-application-microservice [uat-test] branch
- URL http://52.221.101.132
- merge by leader
• STABLE --> Different GIT repos for different microservices.
- [stable] branch of the repos
- URL http://kss3-stable.kss-uat.kapintdc.com/
- It's dockerized
- Need code review by Roldan
KSS MICROSERVICES - CODEBASE
• https://github.com/Kaplan-Singapore/KSS- • https://github.com/Kaplan-Singapore/KSS
application-microservice -application-microservice
--> [dev] branch --> [uat-test] branch

KSS KSS
admission admission
common common
enrolment enrolment
master master
studyplan studyplan
task task
timetable timetable
KSS MICROSERVICES - CODEBASE
• STABLE environment is Dockerize as below
Git /KSS-application- Profile - IDM
microservice
/KSS
/admission
/common
RabbitMQ
Git /KSS-activity-microservice Product Catalog
/KSS
/task
/common

Git /KSS-scheduling- Git /KSS-grades- Git /KSS-studyplan- Git /KSS-enrollment-


microservice microservice microservice microservice
/KSS /KSS /KSS​ /KSS
/timetable /grades /studyplan /enrolment
/common /common /common​ /common

You might also like