Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vue front end #19

Open
wants to merge 2 commits into
base: vue-version
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 19 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,54 +42,61 @@ If you wish to run the app for the purpose of contributing or just for personal
cd restful-countries
```

4. Install packages with composer
4. Install laravel packages with composer
```bash
composer install
```
5. Install javascript packages with npm. Please make sure you have node.js installed on your PC
```bash
npm install
```

5. Make a copy of .env.example as .env
6. Make a copy of .env.example as .env
```bash
cp .env.example .env
```
verify that .env has key `APP_VERSION=1` or current api version.


6. Generate app key
7. Generate app key
```bash
php artisan key:generate
```

7. Create an empty database and add the database credentials to `.env` file
```angular2html
8. Create an empty database and add the database credentials to `.env` file
```
DB_DATABASE=your_database_name
DB_USERNAME=root
DB_PASSWORD=your_password
```

8. Run migration
9. Run migration
```bash
php artisan migrate
```

9. Run database seed to create sample data
10. Run database seed to create sample data
```bash
php artisan db:seed
```
10. Create a public folder for symbolic link
11. Create a public folder for symbolic link
```bash
mkdir storage/app/public
```

11. Create a symbolic link to storage for asset uploads
```angular2html
12. Create a symbolic link to storage for asset uploads
```bash
php artisan storage:link
```

12. Start laravel local server
```angular2html
```bash
php artisan serve
```

13. Compile Javascript
```bash
npm run dev
```
13. open http://127.0.0.1:8000/ in your browser, You should see the home page of restful countries.


Expand Down
12 changes: 8 additions & 4 deletions app/Country.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,23 @@ class Country extends Model
{
protected $guarded = ["id"];

public function states(){
public function states(): \Illuminate\Database\Eloquent\Relations\HasMany
{
return $this->hasMany(State::class);
}

public function president(){
public function president(): \Illuminate\Database\Eloquent\Relations\HasOne
{
return $this->hasOne(President::class);
}

public function presidents(){
public function presidents(): \Illuminate\Database\Eloquent\Relations\HasMany
{
return $this->hasMany(President::class);
}

public function covid19(){
public function covid19(): \Illuminate\Database\Eloquent\Relations\HasOne
{
return $this->hasOne(Covid19::class);
}
}
13 changes: 13 additions & 0 deletions app/Helpers/Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,19 @@ public function appOperations(){
];
}

public function listContinents(){
return [
"Africa",
"Antarctica",
"Asia",
"Australia",
"Europe",
"North America",
"South America"
];

}

/**
* This function will be used to check if user has the permission to perform any operation
* @param $operation
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/AdminController.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function loginAttempt(Request $request){
"status" => 1
],true)){

return redirect()->intended("administrator/profile");
return redirect()->intended("administrator/dashboard");
}

return redirect()->back()->with("error","Email or password incorrect");
Expand Down
11 changes: 6 additions & 5 deletions app/Http/Controllers/ApiTokenController.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,11 @@ public function generateApiToken(Request $request,Mailer $mail): \Illuminate\Htt
}catch (\Exception $e){
//$created_user->tokens()->delete();
//$created_user->delete();
//todo - better email failed message

//todo - this error should be avoided

return response()->json([
"success" => $e->getMessage(),
"success" => 'Your API key has been successfully created but there was as error while sending it to your mail. Please find your key in the field below.',
"api_token" => $api_token
],202);
}
Expand Down Expand Up @@ -84,11 +85,11 @@ public function regenerateApiToken(Request $request,Mailer $mail): \Illuminate\H
try {
$mail->to($validated_details["email"])->send(new AccessTokenMail( $api_token,$validated_details["email"],$mail_message));
}catch (\Exception $e){
//todo - why delete?

$existing_user->tokens()->delete();
//todo - better email failed message

return response()->json([
"error" => $e->getMessage(),
"error" =>'Oops! Failure regenerating your API key',
],409);

}
Expand Down
7 changes: 6 additions & 1 deletion database/factories/CountryFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@

$factory->define(App\Country::class, function (Faker $faker) {
$country = $faker->unique()->country;

$continent_array = helper::instance()->listContinents();
$key = array_rand($continent_array);
$continent = $continent_array[$key];

return [
'name' => $country,
'full_name' => $country,
Expand All @@ -19,7 +24,7 @@
'iso2' => $faker->countryISOAlpha3,
'iso3' => $faker->countryISOAlpha3,
'code' => $faker->countryCode,
'continent' => $faker->word,
'continent' => $continent,
'official_language' => $faker->word,
'independence_date' => $faker->date(),
];
Expand Down
14 changes: 4 additions & 10 deletions database/seeds/DatabaseSeeder.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
<?php

use App\Country;
use App\Covid19;
use Illuminate\Support\Facades\DB;
use App\Permission;
use App\Role;
use App\User;
use App\PersonalAccessToken;
use App\State;
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Seeder;

Expand Down Expand Up @@ -36,16 +29,17 @@ public function run()
Schema::enableForeignKeyConstraints();

//Test assumes Super Admin should always be id 1
$role = Role::create(["role"=> 'Super Admin']);
$role = App\Role::create(["role"=> 'Super Admin']);

//Create permissions for Super admin role
foreach (helper::instance()->appOperations() as $operation){
Permission::create([
App\Permission::create([
"role_id" => $role->id,
"permission" => $operation
]);
}
Role::create(["role"=> 'User']);

App\Role::create(["role"=> 'User']);


factory(App\User::class)->states('admin')->create();
Expand Down
5,417 changes: 5,416 additions & 1 deletion public/assets/admin/styles/style.min.css

Large diffs are not rendered by default.

Binary file added public/assets/images/loader.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions public/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -4291,6 +4291,7 @@ __webpack_require__.r(__webpack_exports__);
//
//
//
//


/* harmony default export */ __webpack_exports__["default"] = ({
Expand Down
4 changes: 2 additions & 2 deletions resources/css/app.css
Original file line number Diff line number Diff line change
Expand Up @@ -1343,8 +1343,8 @@ a.job-list[data-toggle=collapse].collapsed:before {

.error_message {
padding: 10px;
text-align: center;
color: #e43f52;

color: #ff4646;
border-radius: 5px;
font-size: 14px;
}
Expand Down
1 change: 1 addition & 0 deletions resources/js/views/docs/V1.vue
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
<div class="col-lg-8 col-md-12 ml-auto px-0">
<div class="row my-3">
<div class="ml-auto mr-6">
<!-- todo - this url will change after merging to main -->
<a href="https://github.com/Naterus/restful-countries/blob/main/resources/views/docs/v1.blade.php" target="_blank" >
<button class="btn btn-outline-dark btn-sm">
<i class="fa fa-github"></i> Edit this page
Expand Down
Empty file.
Loading