1111 * See the License for the specific language governing permissions and
1212 * limitations under the License.
1313 **/
14+
1415use App \Models \Foundation \Main \CountryCodes ;
1516use Illuminate \Http \Response ;
16- use Illuminate \Support \Facades \Log ;
17- use models \exceptions \EntityNotFoundException ;
18- use models \exceptions \ValidationException ;
1917use OpenApi \Attributes as OA ;
2018use utils \PagingResponse ;
21- use Illuminate \Support \Facades \Request ;
2219
2320/**
2421 * Class CountriesApiController
2522 * @package App\Http\Controllers
2623 */
2724final class CountriesApiController extends JsonController
2825{
26+ use RequestProcessor;
27+
2928 #[OA \Get(
3029 path: "/api/public/v1/countries " ,
3130 description: "Get all countries with ISO codes " ,
3231 summary: 'Get all countries ' ,
3332 operationId: 'getAllCountries ' ,
34- tags: ['Country ' ],
35- parameters: [
36- new OA \Parameter (
37- name: 'expand ' ,
38- in: 'query ' ,
39- required: false ,
40- description: 'Parameter for expanding related entity properties through serialization. Note: Has no effect on this endpoint since countries are returned as simple arrays, not complex entities. Always returns iso_code and name regardless of this parameter. ' ,
41- schema: new OA \Schema (type: 'string ' , example: '' )
42- ),
43- ],
33+ tags: ['Countries ' ],
4434 responses: [
4535 new OA \Response (
4636 response: 200 ,
4737 description: 'Success - Returns paginated list of countries ' ,
48- content: new OA \JsonContent (
49- properties: [
50- 'total ' => new OA \Property (property: 'total ' , type: 'integer ' , example: 195 ),
51- 'per_page ' => new OA \Property (property: 'per_page ' , type: 'integer ' , example: 195 ),
52- 'current_page ' => new OA \Property (property: 'current_page ' , type: 'integer ' , example: 1 ),
53- 'last_page ' => new OA \Property (property: 'last_page ' , type: 'integer ' , example: 1 ),
54- 'data ' => new OA \Property (
55- property: 'data ' ,
56- type: 'array ' ,
57- items: new OA \Items (ref: "#/components/schemas/ISOElementSchema " )
58- )
59- ],
60- type: 'object '
61- )
38+ content: new OA \JsonContent (ref: '#/components/schemas/PaginatedISOCountryElementResponseSchema ' ),
6239 ),
6340 new OA \Response (response: Response::HTTP_PRECONDITION_FAILED , description: "Validation Error " ),
6441 new OA \Response (response: Response::HTTP_NOT_FOUND , description: "Not Found " ),
6542 new OA \Response (response: Response::HTTP_INTERNAL_SERVER_ERROR , description: "Server Error " )
6643 ]
6744 )]
68- public function getAll (){
69- try {
45+ public function getAll ()
46+ {
47+ return $ this ->processRequest (function () {
7048 $ countries = [];
71- foreach (CountryCodes::$ iso_3166_countryCodes as $ iso_code => $ name ){
49+ foreach (CountryCodes::$ iso_3166_countryCodes as $ iso_code => $ name ) {
7250 $ countries [] = [
7351 'iso_code ' => $ iso_code ,
7452 'name ' => $ name ,
7553 ];
7654 }
7755
78- $ response = new PagingResponse
56+ $ response = new PagingResponse
7957 (
8058 count ($ countries ),
8159 count ($ countries ),
@@ -84,20 +62,8 @@ public function getAll(){
8462 $ countries
8563 );
8664
87- return $ this ->ok ($ response ->toArray ($ expand = Request::input ('expand ' ,'' )));
88- }
89- catch (ValidationException $ ex1 ) {
90- Log::warning ($ ex1 );
91- return $ this ->error412 (array ($ ex1 ->getMessage ()));
92- }
93- catch (EntityNotFoundException $ ex2 )
94- {
95- Log::warning ($ ex2 );
96- return $ this ->error404 (array ('message ' => $ ex2 ->getMessage ()));
97- }
98- catch (\Exception $ ex ) {
99- Log::error ($ ex );
100- return $ this ->error500 ($ ex );
101- }
65+ return $ this ->ok ($ response ->toArray ());
66+ });
67+
10268 }
10369}
0 commit comments