Browse Source

bug fix + esg history api

parent
commit
a34ce42483
3 changed files with 45 additions and 1 deletions
  1. 39
    0
      app/Http/Controllers/Api/EsgController.php
  2. 1
    1
      app/Models/ProfilePart.php
  3. 5
    0
      routes/api.php

+ 39
- 0
app/Http/Controllers/Api/EsgController.php View File

@@ -0,0 +1,39 @@
1
+<?php
2
+
3
+namespace App\Http\Controllers\Api;
4
+
5
+use App\Http\Controllers\Controller;
6
+use App\Models\EsgHistory;
7
+use App\Supports\Response;
8
+use Carbon\Carbon;
9
+use Illuminate\Http\Request;
10
+use Illuminate\Support\Facades\DB;
11
+use Illuminate\Support\Facades\Log;
12
+
13
+/**
14
+ * @group Lottery Prize
15
+ */
16
+class EsgController extends Controller
17
+{
18
+    public function __construct(
19
+    )
20
+    {
21
+    }
22
+
23
+    public function histories($locale = 'tw')
24
+    {
25
+        $locale = $locale == "tw" ? "zh_TW" : $locale;
26
+        $data = EsgHistory::where("visible", 1)->orderByDesc("selected_year", "desc")->orderByDesc("selected_month")->get();
27
+        $yearList = EsgHistory::select("selected_year", \DB::raw("concat(selected_year, '年') as lable"))->distinct()->orderBy("selected_year", "desc")->pluck('lable', 'selected_year');
28
+        $result = [];
29
+        $result["yearList"] = $yearList;
30
+        foreach($data as $item){
31
+            $result["list"][$item->selected_year][] = [
32
+                "operateMonth " => $item->selected_year . "." . $item->selected_month,
33
+                "title" => $item->getTranslation("title", $locale),
34
+                "description" => $item->getTranslation("description", $locale)
35
+            ];
36
+        }
37
+        return Response::ok($result);
38
+    }
39
+}

+ 1
- 1
app/Models/ProfilePart.php View File

@@ -20,7 +20,7 @@ class ProfilePart extends Model
20 20
     protected function imgUrlLink(): Attribute
21 21
     {
22 22
         return Attribute::make(
23
-            get: fn ($value) => is_null($this->ing_url) ? null :Storage::url($this->ing_url),
23
+            get: fn ($value) => is_null($this->img_url) ? null :Storage::url($this->img_url),
24 24
         );
25 25
     }
26 26
 }

+ 5
- 0
routes/api.php View File

@@ -1,5 +1,6 @@
1 1
 <?php
2 2
 
3
+use App\Http\Controllers\Api\EsgController;
3 4
 use App\Http\Controllers\Api\HistoryController;
4 5
 use App\Http\Controllers\Api\HomePageController;
5 6
 use App\Http\Controllers\Api\NewsController;
@@ -35,4 +36,8 @@ Route::prefix('{locale}')->group(function (){
35 36
         Route::get('/{id}', [ProjectController::class, 'detail'])->whereIn('locale', ["tw", "en"])->where('id', '[0-9]+');
36 37
         Route::get('/badges', [ProjectController::class, 'badges']);
37 38
     });
39
+
40
+    Route::prefix("esg")->group(function () {
41
+        Route::get("histories", [EsgController::class, 'histories']);
42
+    });
38 43
 });