From e6f03d028302d30464feb4734c7f79afc6bcb5b7 Mon Sep 17 00:00:00 2001 From: Thea Hvalen Thodesen Date: Thu, 21 Dec 2023 12:50:01 +0100 Subject: [PATCH 1/3] KURSP-1042: Add column nedlagt to fylkes table and update the way we get active counties --- app/Fylke.php | 4 +-- app/Http/Controllers/SkolerController.php | 15 +-------- ..._12_21_115102_add_er_nedlagt_to_fylkes.php | 32 +++++++++++++++++++ 3 files changed, 35 insertions(+), 16 deletions(-) create mode 100644 database/migrations/2023_12_21_115102_add_er_nedlagt_to_fylkes.php diff --git a/app/Fylke.php b/app/Fylke.php index 6a4e2d39..bbae335d 100644 --- a/app/Fylke.php +++ b/app/Fylke.php @@ -10,13 +10,13 @@ class Fylke extends Model public static $annetFylkesNr = '99'; public $incrementing = false; protected $primaryKey = 'Fylkesnr'; - protected $fillable = ['Fylkesnr', 'Navn', 'OrgNr', 'OrgNrFylkesmann']; + protected $fillable = ['Fylkesnr', 'Navn', 'OrgNr', 'OrgNrFylkesmann', 'nedlagt']; public function CreateAnnetFylke() { $annetOrgNr = '999999999'; $key[$this->getKeyName()] = Fylke::$annetFylkesNr; - Fylke::updateOrCreate($key, ['Fylkesnr' => Fylke::$annetFylkesNr, 'Navn' => Fylke::$annetFylkesNavn, 'OrgNr' => $annetOrgNr, 'OrgNrFylkesmann' => $annetOrgNr]); + Fylke::updateOrCreate($key, ['Fylkesnr' => Fylke::$annetFylkesNr, 'Navn' => Fylke::$annetFylkesNavn, 'OrgNr' => $annetOrgNr, 'OrgNrFylkesmann' => $annetOrgNr, 'nedlagt' => false]); } public function UpdateFylke($county) { diff --git a/app/Http/Controllers/SkolerController.php b/app/Http/Controllers/SkolerController.php index 52a3a7bb..b86c9c53 100644 --- a/app/Http/Controllers/SkolerController.php +++ b/app/Http/Controllers/SkolerController.php @@ -10,18 +10,6 @@ use Illuminate\Http\Request; use Illuminate\Support\Facades\Artisan; -function filter_obsolete_counties($data) -{ - $obsolete_counties = ["01", "02", "04", "05", "06", "07", "08", "09", "10", "12", "13", "14", "16", "17", "19", "20"]; - $valid_counties = []; - foreach ($data as $county) { - if (!in_array($county->Fylkesnr, $obsolete_counties)) { - array_push($valid_counties, $county); - } - } - return $valid_counties; -} - function format_return_data($data) { return collect($data) @@ -43,8 +31,7 @@ class SkolerController extends Controller */ public function all_fylke() { - $all_fylke = Fylke::all(); - $all_fylke = filter_obsolete_counties($all_fylke); + $all_fylke = Fylke::where('nedlagt', false)->get(); return new SuccessResponse(format_return_data($all_fylke)); } diff --git a/database/migrations/2023_12_21_115102_add_er_nedlagt_to_fylkes.php b/database/migrations/2023_12_21_115102_add_er_nedlagt_to_fylkes.php new file mode 100644 index 00000000..67928bdb --- /dev/null +++ b/database/migrations/2023_12_21_115102_add_er_nedlagt_to_fylkes.php @@ -0,0 +1,32 @@ +boolean('nedlagt'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('fylkes', function (Blueprint $table) { + $table->dropColumn('nedlagt'); + }); + } +}; From 8e79cacfed431595be45dee9cb85e27f1d62102f Mon Sep 17 00:00:00 2001 From: Thea Hvalen Thodesen Date: Mon, 8 Jan 2024 19:54:47 +0100 Subject: [PATCH 2/3] KURSP-132: Move php files away from App root ddirectory into Models/ and Utils/ --- .../EnrollmentActivityController.php | 2 +- .../Controllers/KompetansepakkeController.php | 4 ++-- app/Http/Controllers/SkolerController.php | 8 ++++---- app/{ => Models}/Barnehage.php | 14 +++++++------- app/{ => Models}/Diploma.php | 2 +- app/{ => Models}/EnrollmentActivity.php | 2 +- app/{ => Models}/Fylke.php | 2 +- app/{ => Models}/Kommune.php | 12 ++++++------ app/{ => Models}/Kompetansepakke.php | 2 +- app/{ => Models}/Skole.php | 14 +++++++------- app/Services/DataNsrService.php | 17 ++++++++--------- app/Services/DiplomaService.php | 4 ++-- app/{ => Utils}/helpers.php | 0 composer.json | 3 ++- composer.json.dev | 3 ++- composer.json.prod | 3 ++- .../seeds/EnrollmentActivityTableSeeder.php | 2 +- 17 files changed, 48 insertions(+), 46 deletions(-) rename app/{ => Models}/Barnehage.php (83%) rename app/{ => Models}/Diploma.php (85%) rename app/{ => Models}/EnrollmentActivity.php (89%) rename app/{ => Models}/Fylke.php (97%) rename app/{ => Models}/Kommune.php (75%) rename app/{ => Models}/Kompetansepakke.php (81%) rename app/{ => Models}/Skole.php (81%) rename app/{ => Utils}/helpers.php (100%) diff --git a/app/Http/Controllers/EnrollmentActivityController.php b/app/Http/Controllers/EnrollmentActivityController.php index c85331a3..98377ec2 100644 --- a/app/Http/Controllers/EnrollmentActivityController.php +++ b/app/Http/Controllers/EnrollmentActivityController.php @@ -2,7 +2,7 @@ namespace App\Http\Controllers; -use App\EnrollmentActivity; +use App\Models\EnrollmentActivity; use Illuminate\Http\Request; class EnrollmentActivityController extends Controller diff --git a/app/Http/Controllers/KompetansepakkeController.php b/app/Http/Controllers/KompetansepakkeController.php index 840b01ef..bd14c78a 100644 --- a/app/Http/Controllers/KompetansepakkeController.php +++ b/app/Http/Controllers/KompetansepakkeController.php @@ -2,7 +2,7 @@ namespace App\Http\Controllers; -use App\Kompetansepakke; +use App\Models\Kompetansepakke; use Illuminate\Http\Request; class KompetansepakkeController extends Controller @@ -18,7 +18,7 @@ public function index() } /** - * Show the form for creating a new resource. + * Show the form for creating aClass App\Services\HistoryService located in ./app/Services/MatomoService.php does not comply with psr-4 autoloading standard. Skipping. new resource. * * @return \Illuminate\Http\Response */ diff --git a/app/Http/Controllers/SkolerController.php b/app/Http/Controllers/SkolerController.php index 52a3a7bb..518442c1 100644 --- a/app/Http/Controllers/SkolerController.php +++ b/app/Http/Controllers/SkolerController.php @@ -2,11 +2,11 @@ namespace App\Http\Controllers; -use App\Barnehage; -use App\Fylke; +use App\Models\Barnehage; +use App\Models\Fylke; use App\Http\Responses\SuccessResponse; -use App\Kommune; -use App\Skole; +use App\Models\Kommune; +use App\Models\Skole; use Illuminate\Http\Request; use Illuminate\Support\Facades\Artisan; diff --git a/app/Barnehage.php b/app/Models/Barnehage.php similarity index 83% rename from app/Barnehage.php rename to app/Models/Barnehage.php index be595cfb..71139ab9 100644 --- a/app/Barnehage.php +++ b/app/Models/Barnehage.php @@ -1,10 +1,10 @@ getKeyName()] = $annenOrgNr; - Barnehage::updateOrCreate($key, + Barnehage::updateOrCreate($key, [ - 'KommuneNr' => Kommune::$annetKommuneNr, - 'Navn' => Barnehage::$annetBarnehageNavn, + 'KommuneNr' => Kommune::$annetKommuneNr, + 'Navn' => Barnehage::$annetBarnehageNavn, 'FulltNavn' => Barnehage::$annetBarnehageNavn, - 'OrgNr' => $annenOrgNr, + 'OrgNr' => $annenOrgNr, 'NSRId' => $annenNsrId, 'FylkeNr' => Fylke::$annetFylkesNr, 'ErBarnehage' => true, diff --git a/app/Diploma.php b/app/Models/Diploma.php similarity index 85% rename from app/Diploma.php rename to app/Models/Diploma.php index bf72ed26..b4852048 100644 --- a/app/Diploma.php +++ b/app/Models/Diploma.php @@ -1,6 +1,6 @@ getKeyName()] = Kommune::$annetKommuneNr; Kommune::updateOrCreate($key, [ - 'Fylkesnr' => Fylke::$annetFylkesNr, - 'Navn' => Kommune::$annetKommuneNavn, - 'OrgNr' => '999999999', - 'Kommunenr' => Kommune::$annetKommuneNr, + 'Fylkesnr' => Fylke::$annetFylkesNr, + 'Navn' => Kommune::$annetKommuneNavn, + 'OrgNr' => '999999999', + 'Kommunenr' => Kommune::$annetKommuneNr, 'ErNedlagt' => false ]); diff --git a/app/Kompetansepakke.php b/app/Models/Kompetansepakke.php similarity index 81% rename from app/Kompetansepakke.php rename to app/Models/Kompetansepakke.php index 26fcf490..0eb3d83b 100644 --- a/app/Kompetansepakke.php +++ b/app/Models/Kompetansepakke.php @@ -1,6 +1,6 @@ getKeyName()] = $annenNsrId; - Skole::updateOrCreate($key, + Skole::updateOrCreate($key, [ - 'Kommunenr' => Kommune::$annetKommuneNr, - 'Navn' => Skole::$annetSkoleNavn, + 'Kommunenr' => Kommune::$annetKommuneNr, + 'Navn' => Skole::$annetSkoleNavn, 'FulltNavn' => Skole::$annetSkoleNavn, - 'OrgNr' => '999999999', + 'OrgNr' => '999999999', 'NSRId' => $annenNsrId, 'ErSkole' => true, 'ErSkoleEier' => false, @@ -49,6 +49,6 @@ public function CreateAnnenSkole() { public function UpdateSkole($school) { $key[$this->getKeyName()] = $school[$this->getKeyName()]; - Skole::updateOrCreate($key, $school); + Skole::updateOrCreate($key, $school); } } diff --git a/app/Services/DataNsrService.php b/app/Services/DataNsrService.php index 37d7b0e7..655d01f7 100644 --- a/app/Services/DataNsrService.php +++ b/app/Services/DataNsrService.php @@ -2,10 +2,10 @@ namespace App\Services; -use App\Barnehage; -use App\Fylke; -use App\Kommune; -use App\Skole; +use App\Models\Barnehage; +use App\Models\Fylke; +use App\Models\Kommune; +use App\Models\Skole; use Exception; use GuzzleHttp\Client; use GuzzleHttp\Exception\GuzzleException; @@ -38,7 +38,7 @@ public function getSchoolByOrgNr($orgnr) { try{ return $this->request($this->nsrDomain, "v3/enhet/$orgnr"); - } + } catch (\Exception $e){ throw new Exception("Could not find school with orgnr $orgnr"); } @@ -48,7 +48,7 @@ public function getKindergartenByOrgNr($orgnr) { try{ return $this->request($this->nbrDomain, "v3/enhet/$orgnr"); - } + } catch (\Exception $e) { throw new Exception("Could not find kindergarten with orgnr $orgnr"); } @@ -85,7 +85,7 @@ private function getEnheter(string $domain): array $fylkesnummer = array(); // Make an assosiative array of NSR id to enhet - // and find all fylkesnummers in use + // and find all fylkesnummers in use foreach ($enheter as $enhet) { $idToEnhet[$enhet->NSRId] = $enhet; $fylkesnummer[$enhet->FylkeNr] = true; @@ -106,7 +106,7 @@ private function getEnheter(string $domain): array if(!($i % 1000)) { logger("GetEnheter processed " . $i); } - + if (!isset($idToEnhet[$enhetInFylke->NSRId])) { continue; } @@ -237,4 +237,3 @@ public function store_kindergartens() logger("store_kindergartens complete."); } } - diff --git a/app/Services/DiplomaService.php b/app/Services/DiplomaService.php index 0ac75ee2..b09f3cb6 100644 --- a/app/Services/DiplomaService.php +++ b/app/Services/DiplomaService.php @@ -4,8 +4,8 @@ use App\Services\CanvasService; use GuzzleHttp\Client; use App\Exceptions\CanvasException; -use App\Kompetansepakke; -use App\Diploma; +use App\Models\Kompetansepakke; +use App\Models\Diploma; class DiplomaService { diff --git a/app/helpers.php b/app/Utils/helpers.php similarity index 100% rename from app/helpers.php rename to app/Utils/helpers.php diff --git a/composer.json b/composer.json index 2524ab94..dbf96a42 100644 --- a/composer.json +++ b/composer.json @@ -57,11 +57,12 @@ "autoload": { "psr-4": { "App\\": "app/", + "App\\Models\\": "app/Models/", "Database\\Factories\\": "database/factories/", "Database\\Seeders\\": "database/seeders/" }, "files": [ - "app/helpers.php" + "app/Utils/helpers.php" ] }, "autoload-dev": { diff --git a/composer.json.dev b/composer.json.dev index 7d8abdb3..86af6de7 100644 --- a/composer.json.dev +++ b/composer.json.dev @@ -56,11 +56,12 @@ "autoload": { "psr-4": { "App\\": "app/", + "App\\Models\\": "app/Models/", "Database\\Factories\\": "database/factories/", "Database\\Seeders\\": "database/seeders/" }, "files": [ - "app/helpers.php" + "app/Utils/helpers.php" ] }, "autoload-dev": { diff --git a/composer.json.prod b/composer.json.prod index 7d8abdb3..86af6de7 100644 --- a/composer.json.prod +++ b/composer.json.prod @@ -56,11 +56,12 @@ "autoload": { "psr-4": { "App\\": "app/", + "App\\Models\\": "app/Models/", "Database\\Factories\\": "database/factories/", "Database\\Seeders\\": "database/seeders/" }, "files": [ - "app/helpers.php" + "app/Utils/helpers.php" ] }, "autoload-dev": { diff --git a/database/seeds/EnrollmentActivityTableSeeder.php b/database/seeds/EnrollmentActivityTableSeeder.php index fecd5f24..1f9e36da 100644 --- a/database/seeds/EnrollmentActivityTableSeeder.php +++ b/database/seeds/EnrollmentActivityTableSeeder.php @@ -1,6 +1,6 @@ Date: Mon, 8 Jan 2024 19:57:16 +0100 Subject: [PATCH 3/3] remove comment mistake --- app/Http/Controllers/KompetansepakkeController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Http/Controllers/KompetansepakkeController.php b/app/Http/Controllers/KompetansepakkeController.php index bd14c78a..a43fb443 100644 --- a/app/Http/Controllers/KompetansepakkeController.php +++ b/app/Http/Controllers/KompetansepakkeController.php @@ -18,7 +18,7 @@ public function index() } /** - * Show the form for creating aClass App\Services\HistoryService located in ./app/Services/MatomoService.php does not comply with psr-4 autoloading standard. Skipping. new resource. + * Show the form for creating a new resource. * * @return \Illuminate\Http\Response */