1212 * limitations under the License.
1313 **/
1414use App \Models \Foundation \Main \Repositories \ILanguageRepository ;
15- use Illuminate \Support \Facades \Log ;
16- use models \exceptions \EntityNotFoundException ;
17- use models \exceptions \ValidationException ;
15+ use Illuminate \Http \Response ;
16+ use OpenApi \Attributes as OA ;
1817use utils \PagingResponse ;
19- use Illuminate \Support \Facades \Request ;
2018/**
2119 * Class LanguagesApiController
2220 * @package App\Http\Controllers
2321 */
2422final class LanguagesApiController extends JsonController
2523{
24+ use RequestProcessor;
2625 /**
2726 * @var ILanguageRepository
2827 */
@@ -37,13 +36,28 @@ public function __construct(ILanguageRepository $language_repository)
3736 $ this ->language_repository = $ language_repository ;
3837 }
3938
40- /**
41- * @return mixed
42- */
43- public function getAll (){
44- try {
45- $ languages = $ this ->language_repository ->getAll ();
46- $ response = new PagingResponse
39+ #[OA \Get(
40+ path: "/api/public/v1/languages " ,
41+ description: "Get all available languages with ISO codes " ,
42+ summary: 'Get all languages ' ,
43+ operationId: 'getAllLanguages ' ,
44+ tags: ['Languages ' ],
45+ responses: [
46+ new OA \Response (
47+ response: 200 ,
48+ description: 'Success - Returns paginated list of languages ' ,
49+ content: new OA \JsonContent (ref: '#/components/schemas/PaginatedISOLanguageElementResponseSchema ' ),
50+ ),
51+ new OA \Response (response: Response::HTTP_PRECONDITION_FAILED , description: "Validation Error " ),
52+ new OA \Response (response: Response::HTTP_NOT_FOUND , description: "Not Found " ),
53+ new OA \Response (response: Response::HTTP_INTERNAL_SERVER_ERROR , description: "Server Error " )
54+ ]
55+ )]
56+ public function getAll ()
57+ {
58+ return $ this ->processRequest (function () {
59+ $ languages = $ this ->language_repository ->getAll ();
60+ $ response = new PagingResponse
4761 (
4862 count ($ languages ),
4963 count ($ languages ),
@@ -52,20 +66,8 @@ public function getAll(){
5266 $ languages
5367 );
5468
55- return $ this ->ok ($ response ->toArray ($ expand = Request::input ('expand ' ,'' )));
56- }
57- catch (ValidationException $ ex1 ) {
58- Log::warning ($ ex1 );
59- return $ this ->error412 (array ($ ex1 ->getMessage ()));
60- }
61- catch (EntityNotFoundException $ ex2 )
62- {
63- Log::warning ($ ex2 );
64- return $ this ->error404 (array ('message ' => $ ex2 ->getMessage ()));
65- }
66- catch (\Exception $ ex ) {
67- Log::error ($ ex );
68- return $ this ->error500 ($ ex );
69- }
69+ return $ this ->ok ($ response ->toArray ());
70+ });
7071 }
71- }
72+
73+ }
0 commit comments