Skip to content

Commit 95ab58c

Browse files
feat: implement posts
* feat: add posts prototype * style: fix code style * feat(posts): implement posts * feat(posts): implement postal code resource - Switch create/edit forms to use dialogs (same pattern as country) - Show country name with flag emoji in posts table - Enforce unique country+post-code key (DB migration + user-friendly UI error) - Add import script for SI and HR (prompt for country, run in background) - Extract all UI strings to lang files and add translations - Add tests for: • Posts CRUD • Access/permissions (mirror country resource tests) • Filtering by country • Preventing duplicate country+post-code combos * chore(posts): add missing factory to post model * chore(posts): add missing migration * chore(posts): rename signature * chore(posts): prepend country flag in the country column * chore(posts): remove unused translations * style: fix code style --------- Co-authored-by: SlimDeluxe <131700+SlimDeluxe@users.noreply.github.com> Co-authored-by: Kilian Trunk <hunterteammovies@gmail.com>
1 parent f8bdc62 commit 95ab58c

15 files changed

Lines changed: 1269 additions & 0 deletions

File tree

database/factories/PostFactory.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
namespace Eclipse\World\Factories;
4+
5+
use Eclipse\World\Models\Country;
6+
use Eclipse\World\Models\Post;
7+
use Illuminate\Database\Eloquent\Factories\Factory;
8+
use Illuminate\Support\Carbon;
9+
10+
class PostFactory extends Factory
11+
{
12+
protected $model = Post::class;
13+
14+
public function definition(): array
15+
{
16+
return [
17+
'code' => $this->faker->word(),
18+
'name' => $this->faker->name(),
19+
'created_at' => Carbon::now(),
20+
'updated_at' => Carbon::now(),
21+
22+
'country_id' => Country::factory(),
23+
];
24+
}
25+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
use Illuminate\Database\Migrations\Migration;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Support\Facades\Schema;
6+
7+
return new class extends Migration
8+
{
9+
public function up(): void
10+
{
11+
Schema::create('world_posts', function (Blueprint $table) {
12+
$table->id();
13+
$table->string('country_id', 2);
14+
$table->string('code');
15+
$table->string('name');
16+
$table->timestamps();
17+
$table->softDeletes();
18+
19+
$table->foreign('country_id')
20+
->references('id')
21+
->on('world_countries')
22+
->cascadeOnDelete()
23+
->cascadeOnUpdate();
24+
});
25+
}
26+
27+
public function down(): void
28+
{
29+
Schema::dropIfExists('world_posts');
30+
}
31+
};
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
use Illuminate\Database\Migrations\Migration;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Support\Facades\Schema;
6+
7+
return new class extends Migration
8+
{
9+
/**
10+
* Run the migrations.
11+
*/
12+
public function up(): void
13+
{
14+
Schema::table('world_posts', function (Blueprint $table) {
15+
$table->unique(['country_id', 'code'], 'unique_country_post_code');
16+
});
17+
}
18+
19+
/**
20+
* Reverse the migrations.
21+
*/
22+
public function down(): void
23+
{
24+
Schema::table('world_posts', function (Blueprint $table) {
25+
$table->dropUnique('unique_country_post_code');
26+
});
27+
}
28+
};

resources/lang/en/posts.php

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
<?php
2+
3+
return [
4+
'nav_label' => 'Posts',
5+
'breadcrumb' => 'Posts',
6+
'plural' => 'Posts',
7+
8+
'table' => [
9+
'country' => [
10+
'label' => 'Country',
11+
],
12+
'code' => [
13+
'label' => 'Code',
14+
],
15+
'name' => [
16+
'label' => 'Name',
17+
],
18+
],
19+
20+
'actions' => [
21+
'create' => [
22+
'label' => 'New post',
23+
'heading' => 'Create Post',
24+
],
25+
'edit' => [
26+
'label' => 'Edit',
27+
'heading' => 'Edit Post',
28+
],
29+
'delete' => [
30+
'label' => 'Delete',
31+
'heading' => 'Delete Post',
32+
],
33+
'restore' => [
34+
'label' => 'Restore',
35+
'heading' => 'Restore Post',
36+
],
37+
'force_delete' => [
38+
'label' => 'Permanent delete',
39+
'heading' => 'Permanent Deletion of Post',
40+
'description' => 'Are you sure you want to delete the post :name? This action cannot be undone.',
41+
],
42+
],
43+
44+
'form' => [
45+
'country_id' => [
46+
'label' => 'Country',
47+
],
48+
'code' => [
49+
'label' => 'Code',
50+
],
51+
'name' => [
52+
'label' => 'Name',
53+
],
54+
],
55+
56+
'filter' => [
57+
'country' => [
58+
'label' => 'Country',
59+
],
60+
],
61+
62+
'validation' => [
63+
'unique_country_code' => 'A post with this code already exists for the selected country.',
64+
],
65+
66+
'import' => [
67+
'action_label' => 'Import Posts',
68+
'modal_heading' => 'Import Posts',
69+
'country_label' => 'Select Country',
70+
'country_helper' => 'Choose the country for which you want to import postal data',
71+
'success_title' => 'Import Posts',
72+
'success_message' => 'The import posts job has been queued for :country.',
73+
'countries' => [
74+
'SI' => 'Slovenia',
75+
'HR' => 'Croatia',
76+
],
77+
],
78+
];

resources/lang/hr/posts.php

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
<?php
2+
3+
return [
4+
'nav_label' => 'Pošte',
5+
'breadcrumb' => 'Pošte',
6+
'plural' => 'Pošte',
7+
8+
'table' => [
9+
'country' => [
10+
'label' => 'Država',
11+
],
12+
'code' => [
13+
'label' => 'Šifra',
14+
],
15+
'name' => [
16+
'label' => 'Ime',
17+
],
18+
],
19+
20+
'actions' => [
21+
'create' => [
22+
'label' => 'Nova pošta',
23+
'heading' => 'Stvaranje pošte',
24+
],
25+
'edit' => [
26+
'label' => 'Uredi',
27+
'heading' => 'Uređivanje pošte',
28+
],
29+
'delete' => [
30+
'label' => 'Izbriši',
31+
'heading' => 'Brisanje pošte',
32+
],
33+
'restore' => [
34+
'label' => 'Obnovi',
35+
'heading' => 'Obnova pošte',
36+
],
37+
'force_delete' => [
38+
'label' => 'Trajno izbriši',
39+
'heading' => 'Trajno brisanje pošte',
40+
'description' => 'Jeste li sigurni da želite izbrisati poštu :name? Zapis više neće biti moguće obnoviti.',
41+
],
42+
],
43+
44+
'form' => [
45+
'country_id' => [
46+
'label' => 'Država',
47+
],
48+
'code' => [
49+
'label' => 'Šifra',
50+
],
51+
'name' => [
52+
'label' => 'Ime',
53+
],
54+
],
55+
56+
'filter' => [
57+
'country' => [
58+
'label' => 'Država',
59+
],
60+
],
61+
62+
'validation' => [
63+
'unique_country_code' => 'Pošta s ovom šifrom već postoji za odabranu državu.',
64+
],
65+
66+
'import' => [
67+
'action_label' => 'Uvezi pošte',
68+
'modal_heading' => 'Uvoz pošta',
69+
'country_label' => 'Odaberi državu',
70+
'country_helper' => 'Odaberi državu za koju želiš uvoziti poštanske podatke',
71+
'success_title' => 'Uvoz pošta',
72+
'success_message' => 'Zadatak za uvoz pošta je dodan u red čekanja za :country.',
73+
'countries' => [
74+
'SI' => 'Slovenija',
75+
'HR' => 'Hrvatska',
76+
],
77+
],
78+
];

resources/lang/sl/posts.php

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
<?php
2+
3+
return [
4+
'nav_label' => 'Pošte',
5+
'breadcrumb' => 'Pošte',
6+
'plural' => 'Pošte',
7+
8+
'table' => [
9+
'country' => [
10+
'label' => 'Država',
11+
],
12+
'code' => [
13+
'label' => 'Šifra',
14+
],
15+
'name' => [
16+
'label' => 'Ime',
17+
],
18+
],
19+
20+
'actions' => [
21+
'create' => [
22+
'label' => 'Nova pošta',
23+
'heading' => 'Ustvarjanje pošte',
24+
],
25+
'edit' => [
26+
'label' => 'Uredi',
27+
'heading' => 'Urejanje pošte',
28+
],
29+
'delete' => [
30+
'label' => 'Izbriši',
31+
'heading' => 'Brisanje pošte',
32+
],
33+
'restore' => [
34+
'label' => 'Obnovi',
35+
'heading' => 'Obnovitev pošte',
36+
],
37+
'force_delete' => [
38+
'label' => 'Trajno izbriši',
39+
'heading' => 'Trajen izbris pošte',
40+
'description' => 'Ste prepričani, da želite izbrisati pošto :name? Zapisa ne bo možno več obnoviti.',
41+
],
42+
],
43+
44+
'form' => [
45+
'country_id' => [
46+
'label' => 'Država',
47+
],
48+
'code' => [
49+
'label' => 'Šifra',
50+
],
51+
'name' => [
52+
'label' => 'Ime',
53+
],
54+
],
55+
56+
'filter' => [
57+
'country' => [
58+
'label' => 'Država',
59+
],
60+
],
61+
62+
'validation' => [
63+
'unique_country_code' => 'Pošta s to šifro že obstaja za izbrano državo.',
64+
],
65+
66+
'import' => [
67+
'action_label' => 'Uvozi pošte',
68+
'modal_heading' => 'Uvoz pošt',
69+
'country_label' => 'Izberi državo',
70+
'country_helper' => 'Izberi državo, za katero želiš uvoziti poštne podatke',
71+
'success_title' => 'Uvoz pošt',
72+
'success_message' => 'Naloga za uvoz pošt je bila dodana v čakalno vrsto za :country.',
73+
'countries' => [
74+
'SI' => 'Slovenija',
75+
'HR' => 'Hrvaška',
76+
],
77+
],
78+
];

0 commit comments

Comments
 (0)