Przeglądaj źródła

add communityTerm

visuddhinanda 2 dni temu
rodzic
commit
5026268486
1 zmienionych plików z 33 dodań i 1 usunięć
  1. 33 1
      api-v12/app/Services/TermService.php

+ 33 - 1
api-v12/app/Services/TermService.php

@@ -4,6 +4,7 @@ namespace App\Services;
 
 
 use App\Models\DhammaTerm;
 use App\Models\DhammaTerm;
 use App\Http\Api\ChannelApi;
 use App\Http\Api\ChannelApi;
+use App\Http\Resources\TermResource;
 
 
 
 
 class TermService
 class TermService
@@ -31,9 +32,40 @@ class TermService
         return ['items' => $result, 'total' => count($result)];
         return ['items' => $result, 'total' => count($result)];
     }
     }
 
 
-    public function get($id)
+    public function getRaw($id)
     {
     {
         $result = DhammaTerm::find($id);
         $result = DhammaTerm::find($id);
         return $result;
         return $result;
     }
     }
+
+    public function communityTerm(string $word, string $lang)
+    {
+        $localTermChannel = ChannelApi::getSysChannel(
+            "_community_term_" . strtolower($lang) . "_"
+        );
+        $result = DhammaTerm::where('word', $word)
+            ->where('channal', $localTermChannel)
+            ->first();
+        if ($result) {
+            return new TermResource($result);
+        } else {
+            return null;
+        }
+    }
+    public function communityTerms(string $lang)
+    {
+        $localTermChannel = ChannelApi::getSysChannel(
+            "_community_term_" . strtolower($lang) . "_"
+        );
+        $result = DhammaTerm::where('channal', $localTermChannel)
+            ->whereNotNull('note')
+            ->where('note', '<>', '')
+            ->take(10)
+            ->orderBy('updated_at', 'desc')
+            ->get();
+        return [
+            "data" => TermResource::collection($result),
+            "count" => 10
+        ];
+    }
 }
 }