Skip to content

Commit cb7cf97

Browse files
authored
Develop (#407)
* chore: update local development readme and db seeder (#404) * chore: update development readme * chore: add about and faq pages to db seeder * chore: readme tiny change * hotfix: filter out projects with invalid dates (#406) * fix: apply HasValidDates scope to Project and BCRProject queries * chore: rename for readability fix
1 parent 6d49b33 commit cb7cf97

8 files changed

Lines changed: 125 additions & 12 deletions

File tree

.env.example

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
APP_NAME=Bursa binelui
1+
APP_NAME="Bursa binelui"
22
APP_ENV=local
33
APP_KEY=
44
APP_DEBUG=true
@@ -14,7 +14,7 @@ DB_CONNECTION=mysql
1414
DB_HOST=mariadb
1515
DB_PORT=3306
1616
DB_DATABASE=bursa_binelui
17-
DB_USERNAME=bursa_binelui
17+
DB_USERNAME=
1818
DB_PASSWORD=
1919

2020
BROADCAST_DRIVER=log

README.md

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,63 @@ If you would like to suggest new functionality, open an Issue and mark it as a _
3636

3737
Mention all related repos and projects.
3838

39+
## Development
40+
41+
### Running the app
42+
- After initial setup (below), run `npm run dev`
43+
- If using Laravel Herd/Valet, access your app in the browser at `https://bursabinelui.test`
44+
- If using the built-in PHP server:
45+
- run `php artisan:serve`
46+
- access your app in the browser at `http://127.0.0.1:8000`
47+
48+
### Initial setup
49+
<details>
50+
<summary>See initial setup</strong></summary>
51+
52+
#### 1. Create local database `bursa_binelui`
53+
54+
#### 2. Copy `.env.example`, rename it to `.env` and fill in your database information
55+
56+
#### 3. Install composer dependencies
57+
```bash
58+
composer install
59+
```
60+
61+
#### 4. Install npm dependencies
62+
```bash
63+
npm install
64+
```
65+
66+
#### 5. Generate the app secret key
67+
```bash
68+
php artisan key:generate
69+
```
70+
71+
#### 6. Migrate and seed the database
72+
```bash
73+
php artisan migrate:fresh --seed
74+
```
75+
> **Note:** Seeding may fail due to underlying issues with Faker date generation. If that happens, just rerun `php artisan migrate:fresh --seed`. Also, seeding can take a while, so be patient.
76+
77+
#### 7. Add the following line to your `.env` file to disable CSP locally
78+
```bash
79+
CSP_ENABLED=false
80+
```
81+
82+
> **Note:** Only for local development!
83+
84+
#### 8. Configure local development URL
85+
#### 8.1. If using Laravel Herd (macOS, Windows)
86+
- **Install Laravel Herd**
87+
Visit [https://herd.laravel.com](https://herd.laravel.com) and download the installer for macOS or Windows
88+
- **Open your project with Herd**
89+
- Launch Herd. Go to `Sites`. Go to `Add Sites`. Go to `Link existing project`. Select the project. Select the `PHP version` and `enable HTTPS`. Click `Next`
90+
- ![](https://i.imgur.com/YYhxeVK.png)
91+
92+
#### 8.2. If using the built-in PHP server
93+
- In your `.env` file, update `APP_URL` to `APP_URL=http://127.0.0.1:8000`
94+
</details>
95+
3996
## Deployment
4097

4198
Guide users through getting your code up and running on their own system. In this section you can talk about:

app/Http/Controllers/HomeController.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ public function index()
2929

3030
'projects' => ProjectCardResource::collection(
3131
Project::whereIsOpen()
32+
->whereHasValidDates('start','end')
3233
->latest()
3334
->limit(12)
3435
->get()
@@ -37,6 +38,7 @@ public function index()
3738
'bcr_projects' => BCRProjectCardResource::collection(
3839
BCRProject::query()
3940
->where('status', ProjectStatus::approved)
41+
->whereHasValidDates()
4042
->latest()
4143
->with('county')
4244
->limit(12)

app/Http/Controllers/ProjectController.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ protected function projectList(Request $request, string $view): Response
6262
AllowedSort::custom('donations_count', new ProjectDonationsCountSort),
6363
])
6464
->defaultSort('-id')
65-
->whereIsPublished();
65+
->whereIsPublished()
66+
->whereHasValidDates('start', 'end');
6667

6768
return Inertia::render('Public/Projects/Index', [
6869
'view' => $view,

app/Models/BCRProject.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use App\Concerns\HasSlug;
99
use App\Enums\ProjectStatus;
1010
use App\Traits\HasProjectStatus;
11+
use App\Traits\HasValidDates;
1112
use Embed\Embed;
1213
use Illuminate\Database\Eloquent\Builder;
1314
use Illuminate\Database\Eloquent\Factories\HasFactory;
@@ -23,6 +24,7 @@ class BCRProject extends Model implements HasMedia
2324
{
2425
use HasFactory;
2526
use HasLocation;
27+
use HasValidDates;
2628
use InteractsWithMedia;
2729
use HasProjectStatus;
2830
use HasSlug;
@@ -90,12 +92,12 @@ public function getEmbeddedVideosAttribute(): array
9092
{
9193
return collect($this->videos)
9294
->pluck('link')
93-
->filter(fn ($video) => ! blank($video))
95+
->filter(fn($video) => ! blank($video))
9496
->map(
95-
fn (string $videoUrl) => Cache::remember(
97+
fn(string $videoUrl) => Cache::remember(
9698
'video-' . hash('sha256', $videoUrl),
9799
MONTH_IN_SECONDS,
98-
fn () => rescue(fn () => (new Embed)->get($videoUrl)->code, '', false)
100+
fn() => rescue(fn() => (new Embed)->get($videoUrl)->code, '', false)
99101
)
100102
)
101103
->filter()

app/Models/Project.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use App\Enums\EuPlatescStatus;
1212
use App\Enums\ProjectStatus;
1313
use App\Traits\HasProjectStatus;
14+
use App\Traits\HasValidDates;
1415
use Embed\Embed;
1516
use Illuminate\Database\Eloquent\Builder;
1617
use Illuminate\Database\Eloquent\Factories\HasFactory;
@@ -39,6 +40,7 @@ class Project extends Model implements HasMedia
3940
use HasVolunteers;
4041
use InteractsWithMedia;
4142
use HasProjectStatus;
43+
use HasValidDates;
4244
use HasSlug;
4345
use LogsActivity;
4446
use LogsActivityForApproval;
@@ -192,14 +194,14 @@ public function getIsDraftAttribute(): bool
192194

193195
public function getIsPeriodActiveAttribute(): bool
194196
{
195-
return $this->start->isPast() && $this->end->isFuture();
197+
return $this->start?->isPast() && $this->end?->isFuture();
196198
}
197199

198200
public function getIsActiveAttribute(): bool
199201
{
200202
return $this->status == ProjectStatus::approved
201-
&& $this->start->isPast()
202-
&& $this->end->isFuture();
203+
&& $this->start?->isPast()
204+
&& $this->end?->isFuture();
203205
}
204206

205207
public function getCanBeArchivedAttribute(): bool
@@ -249,7 +251,7 @@ public function markAsApproved(): bool
249251
$slug .= '-' . ($count + 1);
250252
}
251253

252-
$this->activities->map(fn (Activity $activity) => $activity->approve());
254+
$this->activities->map(fn(Activity $activity) => $activity->approve());
253255

254256
return $this->update([
255257
'status' => ProjectStatus::approved,
@@ -280,10 +282,10 @@ public function getEmbeddedVideosAttribute(): array
280282
->pluck('url')
281283
->filter()
282284
->map(
283-
fn (string $videoUrl) => Cache::remember(
285+
fn(string $videoUrl) => Cache::remember(
284286
'video-' . hash('sha256', $videoUrl),
285287
MONTH_IN_SECONDS,
286-
fn () => rescue(fn () => (new Embed)->get($videoUrl)->code, report: false)
288+
fn() => rescue(fn() => (new Embed)->get($videoUrl)->code, report: false)
287289
)
288290
)
289291
->filter()

app/Traits/HasValidDates.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
namespace App\Traits;
4+
5+
use Illuminate\Database\Eloquent\Builder;
6+
7+
trait HasValidDates
8+
{
9+
public function scopeWhereHasValidDates(Builder $query, string $startColumn = 'start_date', string $endColumn = 'end_date'): Builder
10+
{
11+
return $query
12+
->whereNotNull($startColumn)
13+
->whereNotNull($endColumn)
14+
->whereColumn($startColumn, '<=', $endColumn);
15+
}
16+
}

database/seeders/DatabaseSeeder.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ public function run(): void
7171

7272
Page::factory()->count(10)->create();
7373

74+
$this->seedSpecificAboutAndFaqsPages();
75+
7476
Edition::factory(['active' => true])
7577
->count(1)
7678
->create();
@@ -153,4 +155,35 @@ private function seedBadges(): void
153155
->create();
154156
}
155157
}
158+
159+
private function seedSpecificAboutAndFaqsPages(): void
160+
{
161+
// Add the /about page
162+
Page::create([
163+
'title' => ['ro' => 'Despre BB'],
164+
'slug' => ['ro' => 'about'],
165+
'description' => ['ro' => 'Răspunsuri la întrebările frecvente despre Bursa Binelui.'],
166+
'content' => ['ro' => '<p>Bursa Binelui, singura platformă online de donații fără comision dedicată ONG-urilor din România, este un proiect creat și susținut de Banca Comercială Română (BCR) și coordonat în parteneriat Grupul PONT. Platforma aduce împreună organizațiile care au nevoie de sprijin pentru a-și desfășura activitatea și oamenii care vor să investească în faptele bune din comunitatea lor.</p>'],
167+
]);
168+
169+
// Add the /faqs page
170+
Page::create([
171+
'title' => ['ro' => 'Întrebări frecvente'],
172+
'slug' => ['ro' => 'faqs'],
173+
'description' => ['ro' => 'Răspunsuri la întrebările frecvente despre Bursa Binelui.'],
174+
'content' => ['ro' => '
175+
<h2>Întrebări frecvente</h2>
176+
<p>Aici găsiți răspunsuri la cele mai frecvente întrebări referitoare la Bursa Binelui.</p>
177+
178+
<h3>1. Ce este Bursa Binelui?</h3>
179+
<p>Bursa Binelui este o platformă dedicată strângerii de fonduri și voluntariatului pentru cauze sociale.</p>
180+
181+
<h3>2. Cum pot dona?</h3>
182+
<p>Puteți dona prin intermediul proiectelor disponibile pe platformă, folosind metoda de plată preferată.</p>
183+
184+
<h3>3. Cum mă pot înscrie ca voluntar?</h3>
185+
<p>Accesați pagina proiectului și folosiți formularul de înscriere voluntar pentru a vă oferi sprijinul.</p>
186+
'],
187+
]);
188+
}
156189
}

0 commit comments

Comments
 (0)