Skip to content

Commit 39e0fdb

Browse files
committed
To finish #2
1 parent e10fa6a commit 39e0fdb

File tree

12 files changed

+134
-16
lines changed

12 files changed

+134
-16
lines changed

job-board/app/Http/Controllers/MyJobApplicationController.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ public function index()
1515
'applications' => auth()->user()->jobApplications()
1616
->with([
1717
'job' => fn($query) => $query->withCount('jobApplications')
18-
->withAvg('jobApplications', 'expected_salary'),
18+
->withAvg('jobApplications', 'expected_salary')
19+
->withTrashed(),
1920
'job.employer'
2021
])
2122
->latest()->get()

job-board/app/Http/Controllers/MyJobController.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,11 @@ public function index()
1717
return view(
1818
'my_job.index',
1919
[
20-
'jobs' => auth()->user()->employer->jobs()->with('employer')->get()
20+
'jobs' => auth()->user()->employer
21+
->jobs()
22+
->with(['employer', 'jobApplications', 'jobApplications.user'])
23+
->withTrashed()
24+
->get()
2125
]
2226
);
2327
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
namespace App\Http\Controllers;
4+
5+
use App\Models\JobApplication;
6+
use Illuminate\Http\Request;
7+
use Illuminate\Http\Response;
8+
use Illuminate\Support\Facades\Storage;
9+
10+
class MyJobCvController extends Controller
11+
{
12+
public function show(JobApplication $jobApplication)
13+
{
14+
$this->authorize('downloadCv', $jobApplication->job);
15+
$path = $jobApplication->cv_path;
16+
17+
if (!Storage::disk('private')->exists($path)) {
18+
abort(Response::HTTP_NOT_FOUND, 'CV not found.');
19+
}
20+
21+
$downloadName = 'cv-' . $jobApplication->id . '.pdf';
22+
23+
return Storage::disk('private')->download($path, $downloadName);
24+
}
25+
}

job-board/app/Models/Job.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,12 @@
88
use Illuminate\Database\Eloquent\Builder;
99
use Illuminate\Database\Eloquent\Relations\BelongsTo;
1010
use Illuminate\Database\Eloquent\Relations\HasMany;
11+
use Illuminate\Database\Eloquent\SoftDeletes;
1112
use Illuminate\Database\Query\Builder as QueryBuilder;
1213

1314
class Job extends Model
1415
{
15-
use HasFactory;
16+
use HasFactory, SoftDeletes;
1617

1718
protected $fillable = ['title', 'experience', 'category', 'salary', 'description', 'location'];
1819

job-board/app/Policies/JobPolicy.php

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use App\Models\Job;
66
use App\Models\User;
7+
use Illuminate\Auth\Access\Response;
78

89
class JobPolicy
910
{
@@ -34,10 +35,17 @@ public function create(User $user): bool
3435
/**
3536
* Determine whether the user can update the model.
3637
*/
37-
public function update(User $user, Job $job): bool
38+
public function update(User $user, Job $job)
3839
{
39-
return $job->employer->user_id === $user->id
40-
&& $job->jobApplications()->count() === 0;
40+
if ($job->employer->user_id !== $user->id) {
41+
return false;
42+
}
43+
44+
if ($job->jobApplications()->count() > 0) {
45+
return Response::deny('Cannot change the job with applications.');
46+
}
47+
48+
return true;
4149
}
4250

4351
/**
@@ -68,4 +76,9 @@ public function apply(User $user, Job $job): bool
6876
{
6977
return !$job->hasUserApplied($user);
7078
}
79+
80+
public function downloadCv(User $user, Job $job)
81+
{
82+
return $job->employer->user_id === $user->id;
83+
}
7184
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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+
* Run the migrations.
10+
*/
11+
public function up(): void
12+
{
13+
Schema::table('jobs', function (Blueprint $table) {
14+
$table->softDeletes();
15+
});
16+
}
17+
18+
/**
19+
* Reverse the migrations.
20+
*/
21+
public function down(): void
22+
{
23+
Schema::table('jobs', function (Blueprint $table) {
24+
$table->dropSoftDeletes();
25+
});
26+
}
27+
};

job-board/resources/views/components/job-card.blade.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,12 @@
77
</div>
88

99
<div class="mb-4 flex items-center justify-between text-sm text-slate-500">
10-
<div class="flex space-x-4">
10+
<div class="flex items-center space-x-4">
1111
<div>{{ $job->employer->company_name }}</div>
1212
<div>{{ $job->location }}</div>
13+
@if ($job->deleted_at)
14+
<span class="text-xs text-red-500">Deleted</span>
15+
@endif
1316
</div>
1417
<div class="flex space-x-1 text-xs">
1518
<x-tag>

job-board/resources/views/components/radio-group.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
@endforeach
1717

1818
@error($name)
19-
<div class="mt-1 text-red-500">
19+
<div class="mt-1 text-xs text-red-500">
2020
{{ $message }}
2121
</div>
2222
@enderror

job-board/resources/views/components/text-input.blade.php

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,24 @@
1212
<input x-ref="input-{{ $name }}" type="{{ $type }}"
1313
placeholder="{{ $placeholder }}"
1414
name="{{ $name }}" value="{{ old($name, $value) }}" id="{{ $name }}"
15-
class="w-full rounded-md border-0 py-1.5 px-2.5 pr-8 text-sm ring-1 ring-slate-300 placeholder:text-slate-400 focus:ring-2" />
15+
@class([
16+
'w-full rounded-md border-0 py-1.5 px-2.5 text-sm ring-1 placeholder:text-slate-400 focus:ring-2',
17+
'pr-8' => $formRef,
18+
'ring-slate-300' => !$errors->has($name),
19+
'ring-red-300' => $errors->has($name),
20+
]) />
1621
@else
1722
<textarea
18-
class="w-full rounded-md border-0 py-1.5 px-2.5 pr-8 text-sm ring-1 ring-slate-300 placeholder:text-slate-400 focus:ring-2"
23+
@class([
24+
'w-full rounded-md border-0 py-1.5 px-2.5 text-sm ring-1 placeholder:text-slate-400 focus:ring-2',
25+
'pr-8' => $formRef,
26+
'ring-slate-300' => !$errors->has($name),
27+
'ring-red-300' => $errors->has($name),
28+
])
1929
id="{{ $name }}" name="{{ $name }}">{{ old($name, $value) }}</textarea>
2030
@endif
2131
@error($name)
22-
<div class="mt-1 text-red-500">
32+
<div class="mt-1 text-xs text-red-500">
2333
{{ $message }}
2434
</div>
2535
@enderror

job-board/resources/views/my_job/create.blade.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
<div>
2929
<x-label>Experience</x-label>
3030

31-
<x-radio-group name="experience" :all-option="false"
31+
<x-radio-group name="experience" :all-option="false" :value="old('experience')"
3232
:options="array_combine(
3333
array_map('ucfirst', \App\Models\Job::$experience),
3434
\App\Models\Job::$experience,
@@ -37,7 +37,7 @@
3737
<div>
3838
<x-label>Category</x-label>
3939

40-
<x-radio-group name="category" :all-option="false"
40+
<x-radio-group name="category" :all-option="false" :value="old('category')"
4141
:options="\App\Models\Job::$category" />
4242
</div>
4343
</div>

0 commit comments

Comments
 (0)