├── frontend
├── src
│ ├── assets
│ │ └── .gitkeep
│ ├── app
│ │ ├── app.component.css
│ │ ├── app.component.html
│ │ ├── policy.ts
│ │ ├── app.component.ts
│ │ ├── api.service.spec.ts
│ │ ├── app-routing.module.ts
│ │ ├── dashboard
│ │ │ ├── dashboard.component.css
│ │ │ ├── dashboard.component.spec.ts
│ │ │ ├── dashboard.component.html
│ │ │ └── dashboard.component.ts
│ │ ├── app.module.ts
│ │ ├── api.service.ts
│ │ └── app.component.spec.ts
│ ├── environments
│ │ ├── environment.prod.ts
│ │ └── environment.ts
│ ├── styles.css
│ ├── favicon.ico
│ ├── tsconfig.app.json
│ ├── tsconfig.spec.json
│ ├── index.html
│ ├── tslint.json
│ ├── main.ts
│ ├── browserslist
│ ├── test.ts
│ ├── karma.conf.js
│ └── polyfills.ts
├── e2e
│ ├── src
│ │ ├── app.po.ts
│ │ └── app.e2e-spec.ts
│ ├── tsconfig.e2e.json
│ └── protractor.conf.js
├── .editorconfig
├── tsconfig.json
├── .gitignore
├── README.md
├── package.json
├── tslint.json
└── angular.json
├── README.md
├── backend
├── api
│ ├── delete.php
│ ├── read.php
│ ├── database.php
│ ├── update.php
│ └── create.php
├── api.php
└── index.php
└── .gitignore
/frontend/src/assets/.gitkeep:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/frontend/src/app/app.component.css:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/frontend/src/app/app.component.html:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/frontend/src/environments/environment.prod.ts:
--------------------------------------------------------------------------------
1 | export const environment = {
2 | production: true
3 | };
4 |
--------------------------------------------------------------------------------
/frontend/src/styles.css:
--------------------------------------------------------------------------------
1 | /* You can add global styles to this file, and also import other style files */
2 |
--------------------------------------------------------------------------------
/frontend/src/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/techiediaries/angular-php-example/HEAD/frontend/src/favicon.ico
--------------------------------------------------------------------------------
/frontend/src/app/policy.ts:
--------------------------------------------------------------------------------
1 | export class Policy {
2 | id: number;
3 | number: number;
4 | amount: number;
5 | }
6 |
--------------------------------------------------------------------------------
/frontend/src/tsconfig.app.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "../tsconfig.json",
3 | "compilerOptions": {
4 | "outDir": "../out-tsc/app",
5 | "types": []
6 | },
7 | "exclude": [
8 | "test.ts",
9 | "**/*.spec.ts"
10 | ]
11 | }
12 |
--------------------------------------------------------------------------------
/frontend/e2e/src/app.po.ts:
--------------------------------------------------------------------------------
1 | import { browser, by, element } from 'protractor';
2 |
3 | export class AppPage {
4 | navigateTo() {
5 | return browser.get('/');
6 | }
7 |
8 | getParagraphText() {
9 | return element(by.css('app-root h1')).getText();
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/frontend/src/app/app.component.ts:
--------------------------------------------------------------------------------
1 | import { Component } from '@angular/core';
2 |
3 | @Component({
4 | selector: 'app-root',
5 | templateUrl: './app.component.html',
6 | styleUrls: ['./app.component.css']
7 | })
8 | export class AppComponent {
9 | title = 'frontend';
10 | }
11 |
--------------------------------------------------------------------------------
/frontend/e2e/tsconfig.e2e.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "../tsconfig.json",
3 | "compilerOptions": {
4 | "outDir": "../out-tsc/app",
5 | "module": "commonjs",
6 | "target": "es5",
7 | "types": [
8 | "jasmine",
9 | "jasminewd2",
10 | "node"
11 | ]
12 | }
13 | }
--------------------------------------------------------------------------------
/frontend/.editorconfig:
--------------------------------------------------------------------------------
1 | # Editor configuration, see http://editorconfig.org
2 | root = true
3 |
4 | [*]
5 | charset = utf-8
6 | indent_style = space
7 | indent_size = 2
8 | insert_final_newline = true
9 | trim_trailing_whitespace = true
10 |
11 | [*.md]
12 | max_line_length = off
13 | trim_trailing_whitespace = false
14 |
--------------------------------------------------------------------------------
/frontend/src/tsconfig.spec.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "../tsconfig.json",
3 | "compilerOptions": {
4 | "outDir": "../out-tsc/spec",
5 | "types": [
6 | "jasmine",
7 | "node"
8 | ]
9 | },
10 | "files": [
11 | "test.ts",
12 | "polyfills.ts"
13 | ],
14 | "include": [
15 | "**/*.spec.ts",
16 | "**/*.d.ts"
17 | ]
18 | }
19 |
--------------------------------------------------------------------------------
/frontend/src/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Frontend
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/frontend/e2e/src/app.e2e-spec.ts:
--------------------------------------------------------------------------------
1 | import { AppPage } from './app.po';
2 |
3 | describe('workspace-project App', () => {
4 | let page: AppPage;
5 |
6 | beforeEach(() => {
7 | page = new AppPage();
8 | });
9 |
10 | it('should display welcome message', () => {
11 | page.navigateTo();
12 | expect(page.getParagraphText()).toEqual('Welcome to frontend!');
13 | });
14 | });
15 |
--------------------------------------------------------------------------------
/frontend/src/app/api.service.spec.ts:
--------------------------------------------------------------------------------
1 | import { TestBed } from '@angular/core/testing';
2 |
3 | import { ApiService } from './api.service';
4 |
5 | describe('ApiService', () => {
6 | beforeEach(() => TestBed.configureTestingModule({}));
7 |
8 | it('should be created', () => {
9 | const service: ApiService = TestBed.get(ApiService);
10 | expect(service).toBeTruthy();
11 | });
12 | });
13 |
--------------------------------------------------------------------------------
/frontend/src/tslint.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "../tslint.json",
3 | "rules": {
4 | "directive-selector": [
5 | true,
6 | "attribute",
7 | "app",
8 | "camelCase"
9 | ],
10 | "component-selector": [
11 | true,
12 | "element",
13 | "app",
14 | "kebab-case"
15 | ]
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/frontend/src/main.ts:
--------------------------------------------------------------------------------
1 | import { enableProdMode } from '@angular/core';
2 | import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
3 |
4 | import { AppModule } from './app/app.module';
5 | import { environment } from './environments/environment';
6 |
7 | if (environment.production) {
8 | enableProdMode();
9 | }
10 |
11 | platformBrowserDynamic().bootstrapModule(AppModule)
12 | .catch(err => console.error(err));
13 |
--------------------------------------------------------------------------------
/frontend/src/browserslist:
--------------------------------------------------------------------------------
1 | # This file is currently used by autoprefixer to adjust CSS to support the below specified browsers
2 | # For additional information regarding the format and rule options, please see:
3 | # https://github.com/browserslist/browserslist#queries
4 | #
5 | # For IE 9-11 support, please remove 'not' from the last line of the file and adjust as needed
6 |
7 | > 0.5%
8 | last 2 versions
9 | Firefox ESR
10 | not dead
11 | not IE 9-11
--------------------------------------------------------------------------------
/frontend/src/app/app-routing.module.ts:
--------------------------------------------------------------------------------
1 | import { NgModule } from '@angular/core';
2 | import { Routes, RouterModule } from '@angular/router';
3 | import { DashboardComponent } from './dashboard/dashboard.component';
4 |
5 |
6 | const routes: Routes = [
7 | { path: 'dashboard', component: DashboardComponent }
8 | ];
9 |
10 | @NgModule({
11 | imports: [RouterModule.forRoot(routes)],
12 | exports: [RouterModule]
13 | })
14 | export class AppRoutingModule { }
15 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Angular 7/8/9 Application with PHP Back-End Example
2 |
3 | Angular 7/8/9 Application with PHP Back-End
4 |
5 | For details on how to implement and run this project see:
6 |
7 | [Angular 9/8 with PHP and MySQL RESTful CRUD Example & Tutorial](https://www.techiediaries.com/angular/angular-9-php-mysql-database/)
8 |
9 |
10 | [Angular 9/8 with PHP: Consuming a RESTful CRUD API with HttpClient and Forms](https://www.techiediaries.com/angular/php-angular-9-crud-api-httpclient/)
11 |
--------------------------------------------------------------------------------
/frontend/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "compileOnSave": false,
3 | "compilerOptions": {
4 | "baseUrl": "./",
5 | "outDir": "./dist/out-tsc",
6 | "sourceMap": true,
7 | "declaration": false,
8 | "module": "es2015",
9 | "moduleResolution": "node",
10 | "emitDecoratorMetadata": true,
11 | "experimentalDecorators": true,
12 | "target": "es5",
13 | "typeRoots": [
14 | "node_modules/@types"
15 | ],
16 | "lib": [
17 | "es2018",
18 | "dom"
19 | ]
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/backend/api/delete.php:
--------------------------------------------------------------------------------
1 | 0)? mysqli_real_escape_string($con, (int)$_GET['id']) : false;
7 |
8 | if(!$id)
9 | {
10 | return http_response_code(400);
11 | }
12 |
13 | // Delete.
14 | $sql = "DELETE FROM `policies` WHERE `id` ='{$id}' LIMIT 1";
15 |
16 | if(mysqli_query($con, $sql))
17 | {
18 | http_response_code(204);
19 | }
20 | else
21 | {
22 | return http_response_code(422);
23 | }
--------------------------------------------------------------------------------
/backend/api/read.php:
--------------------------------------------------------------------------------
1 | {
6 | let component: DashboardComponent;
7 | let fixture: ComponentFixture;
8 |
9 | beforeEach(async(() => {
10 | TestBed.configureTestingModule({
11 | declarations: [ DashboardComponent ]
12 | })
13 | .compileComponents();
14 | }));
15 |
16 | beforeEach(() => {
17 | fixture = TestBed.createComponent(DashboardComponent);
18 | component = fixture.componentInstance;
19 | fixture.detectChanges();
20 | });
21 |
22 | it('should create', () => {
23 | expect(component).toBeTruthy();
24 | });
25 | });
26 |
--------------------------------------------------------------------------------
/frontend/e2e/protractor.conf.js:
--------------------------------------------------------------------------------
1 | // Protractor configuration file, see link for more information
2 | // https://github.com/angular/protractor/blob/master/lib/config.ts
3 |
4 | const { SpecReporter } = require('jasmine-spec-reporter');
5 |
6 | exports.config = {
7 | allScriptsTimeout: 11000,
8 | specs: [
9 | './src/**/*.e2e-spec.ts'
10 | ],
11 | capabilities: {
12 | 'browserName': 'chrome'
13 | },
14 | directConnect: true,
15 | baseUrl: 'http://localhost:4200/',
16 | framework: 'jasmine',
17 | jasmineNodeOpts: {
18 | showColors: true,
19 | defaultTimeoutInterval: 30000,
20 | print: function() {}
21 | },
22 | onPrepare() {
23 | require('ts-node').register({
24 | project: require('path').join(__dirname, './tsconfig.e2e.json')
25 | });
26 | jasmine.getEnv().addReporter(new SpecReporter({ spec: { displayStacktrace: true } }));
27 | }
28 | };
--------------------------------------------------------------------------------
/backend/api/update.php:
--------------------------------------------------------------------------------
1 | id < 1 || trim($request->number) == '' || (float)$request->amount < 0) {
14 | return http_response_code(400);
15 | }
16 |
17 | // Sanitize.
18 | $id = mysqli_real_escape_string($con, (int)$request->id);
19 | $number = mysqli_real_escape_string($con, trim($request->number));
20 | $amount = mysqli_real_escape_string($con, (float)$request->amount);
21 |
22 | // Update.
23 | $sql = "UPDATE `policies` SET `number`='$number',`amount`='$amount' WHERE `id` = '{$id}' LIMIT 1";
24 |
25 | if(mysqli_query($con, $sql))
26 | {
27 | http_response_code(204);
28 | }
29 | else
30 | {
31 | return http_response_code(422);
32 | }
33 | }
--------------------------------------------------------------------------------
/frontend/src/app/api.service.ts:
--------------------------------------------------------------------------------
1 | import { Injectable } from '@angular/core';
2 | import { HttpClient, HttpHeaders } from '@angular/common/http';
3 | import { Policy } from './policy';
4 | import { Observable } from 'rxjs';
5 |
6 | @Injectable({
7 | providedIn: 'root'
8 | })
9 | export class ApiService {
10 |
11 | PHP_API_SERVER = "http://127.0.0.1:8080";
12 |
13 | constructor(private httpClient: HttpClient) {
14 |
15 | }
16 |
17 | readPolicies(): Observable{
18 | return this.httpClient.get(`${this.PHP_API_SERVER}/api/read.php`);
19 | }
20 |
21 | createPolicy(policy: Policy): Observable{
22 | return this.httpClient.post(`${this.PHP_API_SERVER}/api/create.php`, policy);
23 | }
24 | updatePolicy(policy: Policy){
25 | return this.httpClient.put(`${this.PHP_API_SERVER}/api/update.php`, policy);
26 | }
27 | deletePolicy(id: number){
28 | return this.httpClient.delete(`${this.PHP_API_SERVER}/api/delete.php/?id=${id}`);
29 | }
30 |
31 |
32 | }
33 |
--------------------------------------------------------------------------------
/backend/api/create.php:
--------------------------------------------------------------------------------
1 | number) === '' || (float)$request->amount < 0)
15 | {
16 | return http_response_code(400);
17 | }
18 |
19 | // Sanitize.
20 | $number = mysqli_real_escape_string($con, trim($request->number));
21 | $amount = mysqli_real_escape_string($con, (int)$request->amount);
22 |
23 |
24 | // Store.
25 | $sql = "INSERT INTO `policies`(`id`,`number`,`amount`) VALUES (null,'{$number}','{$amount}')";
26 |
27 | if(mysqli_query($con,$sql))
28 | {
29 | http_response_code(201);
30 | $policy = [
31 | 'number' => $number,
32 | 'amount' => $amount,
33 | 'id' => mysqli_insert_id($con)
34 | ];
35 | echo json_encode($policy);
36 | }
37 | else
38 | {
39 | http_response_code(422);
40 | }
41 | }
--------------------------------------------------------------------------------
/frontend/src/app/dashboard/dashboard.component.html:
--------------------------------------------------------------------------------
1 | Insurance Policy Management
2 |
3 |
4 |
5 |
6 | | ID |
7 | Policy Number |
8 | Policy Amount |
9 | Operations |
10 |
11 |
12 |
13 |
14 | | {{ policy.id }} |
15 | {{ policy.number }} |
16 | {{ policy.amount }} |
17 |
18 |
19 |
20 | |
21 |
22 |
23 |
24 |
25 |
26 |
35 |
36 |
--------------------------------------------------------------------------------
/frontend/src/karma.conf.js:
--------------------------------------------------------------------------------
1 | // Karma configuration file, see link for more information
2 | // https://karma-runner.github.io/1.0/config/configuration-file.html
3 |
4 | module.exports = function (config) {
5 | config.set({
6 | basePath: '',
7 | frameworks: ['jasmine', '@angular-devkit/build-angular'],
8 | plugins: [
9 | require('karma-jasmine'),
10 | require('karma-chrome-launcher'),
11 | require('karma-jasmine-html-reporter'),
12 | require('karma-coverage-istanbul-reporter'),
13 | require('@angular-devkit/build-angular/plugins/karma')
14 | ],
15 | client: {
16 | clearContext: false // leave Jasmine Spec Runner output visible in browser
17 | },
18 | coverageIstanbulReporter: {
19 | dir: require('path').join(__dirname, '../coverage'),
20 | reports: ['html', 'lcovonly'],
21 | fixWebpackSourcePaths: true
22 | },
23 | reporters: ['progress', 'kjhtml'],
24 | port: 9876,
25 | colors: true,
26 | logLevel: config.LOG_INFO,
27 | autoWatch: true,
28 | browsers: ['Chrome'],
29 | singleRun: false
30 | });
31 | };
--------------------------------------------------------------------------------
/frontend/README.md:
--------------------------------------------------------------------------------
1 | # Frontend
2 |
3 | This project was generated with [Angular CLI](https://github.com/angular/angular-cli) version 7.0.3.
4 |
5 | ## Development server
6 |
7 | Run `ng serve` for a dev server. Navigate to `http://localhost:4200/`. The app will automatically reload if you change any of the source files.
8 |
9 | ## Code scaffolding
10 |
11 | Run `ng generate component component-name` to generate a new component. You can also use `ng generate directive|pipe|service|class|guard|interface|enum|module`.
12 |
13 | ## Build
14 |
15 | Run `ng build` to build the project. The build artifacts will be stored in the `dist/` directory. Use the `--prod` flag for a production build.
16 |
17 | ## Running unit tests
18 |
19 | Run `ng test` to execute the unit tests via [Karma](https://karma-runner.github.io).
20 |
21 | ## Running end-to-end tests
22 |
23 | Run `ng e2e` to execute the end-to-end tests via [Protractor](http://www.protractortest.org/).
24 |
25 | ## Further help
26 |
27 | To get more help on the Angular CLI use `ng help` or go check out the [Angular CLI README](https://github.com/angular/angular-cli/blob/master/README.md).
28 |
--------------------------------------------------------------------------------
/frontend/src/app/app.component.spec.ts:
--------------------------------------------------------------------------------
1 | import { TestBed, async } from '@angular/core/testing';
2 | import { RouterTestingModule } from '@angular/router/testing';
3 | import { AppComponent } from './app.component';
4 |
5 | describe('AppComponent', () => {
6 | beforeEach(async(() => {
7 | TestBed.configureTestingModule({
8 | imports: [
9 | RouterTestingModule
10 | ],
11 | declarations: [
12 | AppComponent
13 | ],
14 | }).compileComponents();
15 | }));
16 |
17 | it('should create the app', () => {
18 | const fixture = TestBed.createComponent(AppComponent);
19 | const app = fixture.debugElement.componentInstance;
20 | expect(app).toBeTruthy();
21 | });
22 |
23 | it(`should have as title 'frontend'`, () => {
24 | const fixture = TestBed.createComponent(AppComponent);
25 | const app = fixture.debugElement.componentInstance;
26 | expect(app.title).toEqual('frontend');
27 | });
28 |
29 | it('should render title in a h1 tag', () => {
30 | const fixture = TestBed.createComponent(AppComponent);
31 | fixture.detectChanges();
32 | const compiled = fixture.debugElement.nativeElement;
33 | expect(compiled.querySelector('h1').textContent).toContain('Welcome to frontend!');
34 | });
35 | });
36 |
--------------------------------------------------------------------------------
/frontend/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "frontend",
3 | "version": "0.0.0",
4 | "scripts": {
5 | "ng": "ng",
6 | "start": "ng serve",
7 | "build": "ng build",
8 | "test": "ng test",
9 | "lint": "ng lint",
10 | "e2e": "ng e2e"
11 | },
12 | "private": true,
13 | "dependencies": {
14 | "@angular/animations": "~7.0.0",
15 | "@angular/common": "~7.0.0",
16 | "@angular/compiler": "~7.0.0",
17 | "@angular/core": "~7.0.0",
18 | "@angular/forms": "~7.0.0",
19 | "@angular/http": "~7.0.0",
20 | "@angular/platform-browser": "~7.0.0",
21 | "@angular/platform-browser-dynamic": "~7.0.0",
22 | "@angular/router": "~7.0.0",
23 | "core-js": "^2.5.4",
24 | "rxjs": "~6.3.3",
25 | "zone.js": "~0.8.26"
26 | },
27 | "devDependencies": {
28 | "@angular-devkit/build-angular": "~0.10.0",
29 | "@angular/cli": "~7.0.3",
30 | "@angular/compiler-cli": "~7.0.0",
31 | "@angular/language-service": "~7.0.0",
32 | "@types/node": "~8.9.4",
33 | "@types/jasmine": "~2.8.8",
34 | "@types/jasminewd2": "~2.0.3",
35 | "codelyzer": "~4.5.0",
36 | "jasmine-core": "~2.99.1",
37 | "jasmine-spec-reporter": "~4.2.1",
38 | "karma": "~3.0.0",
39 | "karma-chrome-launcher": "~2.2.0",
40 | "karma-coverage-istanbul-reporter": "~2.0.1",
41 | "karma-jasmine": "~1.1.2",
42 | "karma-jasmine-html-reporter": "^0.2.2",
43 | "protractor": "~5.4.0",
44 | "ts-node": "~7.0.0",
45 | "tslint": "~5.11.0",
46 | "typescript": "~3.1.1"
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/frontend/src/app/dashboard/dashboard.component.ts:
--------------------------------------------------------------------------------
1 | import { Component, OnInit } from '@angular/core';
2 | import { ApiService } from '../api.service';
3 | import { Policy } from '../policy';
4 |
5 | @Component({
6 | selector: 'app-dashboard',
7 | templateUrl: './dashboard.component.html',
8 | styleUrls: ['./dashboard.component.css']
9 | })
10 | export class DashboardComponent implements OnInit {
11 |
12 | policies: Policy[];
13 | selectedPolicy: Policy = { id : null , number:null, amount: null};
14 | constructor(private apiService: ApiService) { }
15 |
16 | ngOnInit() {
17 | this.apiService.readPolicies().subscribe((policies: Policy[])=>{
18 | this.policies = policies;
19 | console.log(this.policies);
20 | })
21 | }
22 |
23 | createOrUpdatePolicy(form){
24 |
25 | if(this.selectedPolicy && this.selectedPolicy.id){
26 | form.value.id = this.selectedPolicy.id;
27 | this.apiService.updatePolicy(form.value).subscribe((policy: Policy)=>{
28 | console.log("Policy updated" , policy);
29 | });
30 | }
31 | else{
32 |
33 | this.apiService.createPolicy(form.value).subscribe((policy: Policy)=>{
34 | console.log("Policy created, ", policy);
35 | });
36 | }
37 |
38 | }
39 |
40 | selectPolicy(policy: Policy){
41 | this.selectedPolicy = policy;
42 | }
43 |
44 | deletePolicy(id){
45 | this.apiService.deletePolicy(id).subscribe((policy: Policy)=>{
46 | console.log("Policy deleted, ", policy);
47 | });
48 | }
49 |
50 | }
51 |
--------------------------------------------------------------------------------
/backend/api.php:
--------------------------------------------------------------------------------
1 | echo "hello";
2 |
3 | header("Access-Control-Allow-Origin: *");
4 | header("Access-Control-Allow-Methods: PUT, GET, POST");
5 | header("Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept");
6 |
7 | $localhost = "127.0.0.1";
8 | $username = "root";
9 | $password = "root";
10 | $dbname = "mydb";
11 |
12 | // get the HTTP method, path and body of the request
13 | $method = $_SERVER['REQUEST_METHOD'];
14 | $request = explode('/', trim($_SERVER['PATH_INFO'],'/'));
15 | //$input = json_decode(file_get_contents('php://input'),true);
16 | $id = ''
17 |
18 | // create connection to mysql
19 | $conn = new mysqli($localhost, $username, $password, $dbname);
20 | mysqli_set_charset($conn ,'utf8');
21 |
22 | if($conn->connect_error) {
23 | die("Error : " . $conn->connect_error);
24 | }
25 |
26 | switch ($method) {
27 | case 'GET':
28 | $id = $_GET['id'];
29 | $sql = "select * from policies".($id?" where id=$id":''); break;
30 | case 'PUT':
31 | $sql = "update policies (number, amount, creationDate, expireDate) ('$number', '$amount', '$creationDate', '$expireDate')"; break;
32 | case 'POST':
33 | $sql = "insert into policies (number, amount, creationDate, expireDate) ('$number', '$amount', '$creationDate', '$expireDate')"; break;
34 | case 'DELETE':
35 | $id = $_GET['id'];
36 | $sql = "delete policies where id=$id"; break;
37 | }
38 |
39 | // run SQL statement
40 | $result = mysqli_query($conn,$query);
41 |
42 | // die if SQL statement failed
43 | if (!$result) {
44 | http_response_code(404);
45 | die(mysqli_error());
46 | }
47 |
48 | // print results, insert id or affected row count
49 | if ($method == 'GET') {
50 | if (!$id) echo '[';
51 | for ($i=0;$i0?',':'').json_encode(mysqli_fetch_object($result));
53 | }
54 | if (!$id) echo ']';
55 | } elseif ($method == 'POST') {
56 | echo mysqli_insert_id($conn);
57 | } else {
58 | echo mysqli_affected_rows($conn);
59 | }
60 |
61 | $conn->close();
62 |
63 |
64 |
65 |
--------------------------------------------------------------------------------
/backend/index.php:
--------------------------------------------------------------------------------
1 | connect_error) {
26 | die("Error : " . $conn->connect_error);
27 | }
28 |
29 | switch ($method) {
30 | case 'GET':
31 | $id = $_GET['id'];
32 | $sql = "select * from policies".($id?" where id=$id":''); break;
33 | case 'PUT':
34 | $id = $input["id"];
35 | $number = $input["number"];
36 | $amount = $input["amount"];
37 |
38 | $sql = "update policies set number = '$number', amount = $amount where id=$id"; break;
39 | case 'POST':
40 | $number = $input["number"];
41 | $amount = $input["amount"];
42 |
43 | $sql = "insert into policies (number, amount) values ('$number', $amount)"; break;
44 | case 'DELETE':
45 | $id = $_GET['id'];
46 | $sql = "delete from policies where id=$id"; break;
47 | }
48 |
49 |
50 |
51 | // run SQL statement
52 | $result = mysqli_query($conn,$sql);
53 |
54 |
55 | // die if SQL statement failed
56 | if (!$result) {
57 | http_response_code(404);
58 | die(mysqli_error($conn));
59 | }
60 |
61 | // print results, insert id or affected row count
62 | if ($method == 'GET') {
63 | if (!$id) echo '[';
64 | for ($i=0;$i0?',':'').json_encode(mysqli_fetch_object($result));
66 | }
67 | if (!$id) echo ']';
68 | } elseif ($method == 'POST') {
69 | echo mysqli_insert_id($conn);
70 | } else {
71 | echo mysqli_affected_rows($conn);
72 | }
73 |
74 | $conn->close();
75 |
76 |
77 | ?>
78 |
--------------------------------------------------------------------------------
/frontend/tslint.json:
--------------------------------------------------------------------------------
1 | {
2 | "rulesDirectory": [
3 | "node_modules/codelyzer"
4 | ],
5 | "rules": {
6 | "arrow-return-shorthand": true,
7 | "callable-types": true,
8 | "class-name": true,
9 | "comment-format": [
10 | true,
11 | "check-space"
12 | ],
13 | "curly": true,
14 | "deprecation": {
15 | "severity": "warn"
16 | },
17 | "eofline": true,
18 | "forin": true,
19 | "import-blacklist": [
20 | true,
21 | "rxjs/Rx"
22 | ],
23 | "import-spacing": true,
24 | "indent": [
25 | true,
26 | "spaces"
27 | ],
28 | "interface-over-type-literal": true,
29 | "label-position": true,
30 | "max-line-length": [
31 | true,
32 | 140
33 | ],
34 | "member-access": false,
35 | "member-ordering": [
36 | true,
37 | {
38 | "order": [
39 | "static-field",
40 | "instance-field",
41 | "static-method",
42 | "instance-method"
43 | ]
44 | }
45 | ],
46 | "no-arg": true,
47 | "no-bitwise": true,
48 | "no-console": [
49 | true,
50 | "debug",
51 | "info",
52 | "time",
53 | "timeEnd",
54 | "trace"
55 | ],
56 | "no-construct": true,
57 | "no-debugger": true,
58 | "no-duplicate-super": true,
59 | "no-empty": false,
60 | "no-empty-interface": true,
61 | "no-eval": true,
62 | "no-inferrable-types": [
63 | true,
64 | "ignore-params"
65 | ],
66 | "no-misused-new": true,
67 | "no-non-null-assertion": true,
68 | "no-redundant-jsdoc": true,
69 | "no-shadowed-variable": true,
70 | "no-string-literal": false,
71 | "no-string-throw": true,
72 | "no-switch-case-fall-through": true,
73 | "no-trailing-whitespace": true,
74 | "no-unnecessary-initializer": true,
75 | "no-unused-expression": true,
76 | "no-use-before-declare": true,
77 | "no-var-keyword": true,
78 | "object-literal-sort-keys": false,
79 | "one-line": [
80 | true,
81 | "check-open-brace",
82 | "check-catch",
83 | "check-else",
84 | "check-whitespace"
85 | ],
86 | "prefer-const": true,
87 | "quotemark": [
88 | true,
89 | "single"
90 | ],
91 | "radix": true,
92 | "semicolon": [
93 | true,
94 | "always"
95 | ],
96 | "triple-equals": [
97 | true,
98 | "allow-null-check"
99 | ],
100 | "typedef-whitespace": [
101 | true,
102 | {
103 | "call-signature": "nospace",
104 | "index-signature": "nospace",
105 | "parameter": "nospace",
106 | "property-declaration": "nospace",
107 | "variable-declaration": "nospace"
108 | }
109 | ],
110 | "unified-signatures": true,
111 | "variable-name": false,
112 | "whitespace": [
113 | true,
114 | "check-branch",
115 | "check-decl",
116 | "check-operator",
117 | "check-separator",
118 | "check-type"
119 | ],
120 | "no-output-on-prefix": true,
121 | "use-input-property-decorator": true,
122 | "use-output-property-decorator": true,
123 | "use-host-property-decorator": true,
124 | "no-input-rename": true,
125 | "no-output-rename": true,
126 | "use-life-cycle-interface": true,
127 | "use-pipe-transform-interface": true,
128 | "component-class-suffix": true,
129 | "directive-class-suffix": true
130 | }
131 | }
132 |
--------------------------------------------------------------------------------
/frontend/src/polyfills.ts:
--------------------------------------------------------------------------------
1 | /**
2 | * This file includes polyfills needed by Angular and is loaded before the app.
3 | * You can add your own extra polyfills to this file.
4 | *
5 | * This file is divided into 2 sections:
6 | * 1. Browser polyfills. These are applied before loading ZoneJS and are sorted by browsers.
7 | * 2. Application imports. Files imported after ZoneJS that should be loaded before your main
8 | * file.
9 | *
10 | * The current setup is for so-called "evergreen" browsers; the last versions of browsers that
11 | * automatically update themselves. This includes Safari >= 10, Chrome >= 55 (including Opera),
12 | * Edge >= 13 on the desktop, and iOS 10 and Chrome on mobile.
13 | *
14 | * Learn more in https://angular.io/guide/browser-support
15 | */
16 |
17 | /***************************************************************************************************
18 | * BROWSER POLYFILLS
19 | */
20 |
21 | /** IE9, IE10 and IE11 requires all of the following polyfills. **/
22 | // import 'core-js/es6/symbol';
23 | // import 'core-js/es6/object';
24 | // import 'core-js/es6/function';
25 | // import 'core-js/es6/parse-int';
26 | // import 'core-js/es6/parse-float';
27 | // import 'core-js/es6/number';
28 | // import 'core-js/es6/math';
29 | // import 'core-js/es6/string';
30 | // import 'core-js/es6/date';
31 | // import 'core-js/es6/array';
32 | // import 'core-js/es6/regexp';
33 | // import 'core-js/es6/map';
34 | // import 'core-js/es6/weak-map';
35 | // import 'core-js/es6/set';
36 |
37 | /**
38 | * If the application will be indexed by Google Search, the following is required.
39 | * Googlebot uses a renderer based on Chrome 41.
40 | * https://developers.google.com/search/docs/guides/rendering
41 | **/
42 | // import 'core-js/es6/array';
43 |
44 | /** IE10 and IE11 requires the following for NgClass support on SVG elements */
45 | // import 'classlist.js'; // Run `npm install --save classlist.js`.
46 |
47 | /** IE10 and IE11 requires the following for the Reflect API. */
48 | // import 'core-js/es6/reflect';
49 |
50 | /**
51 | * Web Animations `@angular/platform-browser/animations`
52 | * Only required if AnimationBuilder is used within the application and using IE/Edge or Safari.
53 | * Standard animation support in Angular DOES NOT require any polyfills (as of Angular 6.0).
54 | **/
55 | // import 'web-animations-js'; // Run `npm install --save web-animations-js`.
56 |
57 | /**
58 | * By default, zone.js will patch all possible macroTask and DomEvents
59 | * user can disable parts of macroTask/DomEvents patch by setting following flags
60 | */
61 |
62 | // (window as any).__Zone_disable_requestAnimationFrame = true; // disable patch requestAnimationFrame
63 | // (window as any).__Zone_disable_on_property = true; // disable patch onProperty such as onclick
64 | // (window as any).__zone_symbol__BLACK_LISTED_EVENTS = ['scroll', 'mousemove']; // disable patch specified eventNames
65 |
66 | /*
67 | * in IE/Edge developer tools, the addEventListener will also be wrapped by zone.js
68 | * with the following flag, it will bypass `zone.js` patch for IE/Edge
69 | */
70 | // (window as any).__Zone_enable_cross_context_check = true;
71 |
72 | /***************************************************************************************************
73 | * Zone JS is required by default for Angular itself.
74 | */
75 | import 'zone.js/dist/zone'; // Included with Angular CLI.
76 |
77 |
78 | /***************************************************************************************************
79 | * APPLICATION IMPORTS
80 | */
81 |
--------------------------------------------------------------------------------
/frontend/angular.json:
--------------------------------------------------------------------------------
1 | {
2 | "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
3 | "version": 1,
4 | "newProjectRoot": "projects",
5 | "projects": {
6 | "frontend": {
7 | "root": "",
8 | "sourceRoot": "src",
9 | "projectType": "application",
10 | "prefix": "app",
11 | "schematics": {},
12 | "architect": {
13 | "build": {
14 | "builder": "@angular-devkit/build-angular:browser",
15 | "options": {
16 | "outputPath": "dist/frontend",
17 | "index": "src/index.html",
18 | "main": "src/main.ts",
19 | "polyfills": "src/polyfills.ts",
20 | "tsConfig": "src/tsconfig.app.json",
21 | "assets": [
22 | "src/favicon.ico",
23 | "src/assets"
24 | ],
25 | "styles": [
26 | "src/styles.css"
27 | ],
28 | "scripts": []
29 | },
30 | "configurations": {
31 | "production": {
32 | "fileReplacements": [
33 | {
34 | "replace": "src/environments/environment.ts",
35 | "with": "src/environments/environment.prod.ts"
36 | }
37 | ],
38 | "optimization": true,
39 | "outputHashing": "all",
40 | "sourceMap": false,
41 | "extractCss": true,
42 | "namedChunks": false,
43 | "aot": true,
44 | "extractLicenses": true,
45 | "vendorChunk": false,
46 | "buildOptimizer": true,
47 | "budgets": [
48 | {
49 | "type": "initial",
50 | "maximumWarning": "2mb",
51 | "maximumError": "5mb"
52 | }
53 | ]
54 | }
55 | }
56 | },
57 | "serve": {
58 | "builder": "@angular-devkit/build-angular:dev-server",
59 | "options": {
60 | "browserTarget": "frontend:build"
61 | },
62 | "configurations": {
63 | "production": {
64 | "browserTarget": "frontend:build:production"
65 | }
66 | }
67 | },
68 | "extract-i18n": {
69 | "builder": "@angular-devkit/build-angular:extract-i18n",
70 | "options": {
71 | "browserTarget": "frontend:build"
72 | }
73 | },
74 | "test": {
75 | "builder": "@angular-devkit/build-angular:karma",
76 | "options": {
77 | "main": "src/test.ts",
78 | "polyfills": "src/polyfills.ts",
79 | "tsConfig": "src/tsconfig.spec.json",
80 | "karmaConfig": "src/karma.conf.js",
81 | "styles": [
82 | "src/styles.css"
83 | ],
84 | "scripts": [],
85 | "assets": [
86 | "src/favicon.ico",
87 | "src/assets"
88 | ]
89 | }
90 | },
91 | "lint": {
92 | "builder": "@angular-devkit/build-angular:tslint",
93 | "options": {
94 | "tsConfig": [
95 | "src/tsconfig.app.json",
96 | "src/tsconfig.spec.json"
97 | ],
98 | "exclude": [
99 | "**/node_modules/**"
100 | ]
101 | }
102 | }
103 | }
104 | },
105 | "frontend-e2e": {
106 | "root": "e2e/",
107 | "projectType": "application",
108 | "prefix": "",
109 | "architect": {
110 | "e2e": {
111 | "builder": "@angular-devkit/build-angular:protractor",
112 | "options": {
113 | "protractorConfig": "e2e/protractor.conf.js",
114 | "devServerTarget": "frontend:serve"
115 | },
116 | "configurations": {
117 | "production": {
118 | "devServerTarget": "frontend:serve:production"
119 | }
120 | }
121 | },
122 | "lint": {
123 | "builder": "@angular-devkit/build-angular:tslint",
124 | "options": {
125 | "tsConfig": "e2e/tsconfig.e2e.json",
126 | "exclude": [
127 | "**/node_modules/**"
128 | ]
129 | }
130 | }
131 | }
132 | }
133 | },
134 | "defaultProject": "frontend"
135 | }
--------------------------------------------------------------------------------