-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainController.php
More file actions
184 lines (151 loc) · 5.07 KB
/
Copy pathMainController.php
File metadata and controls
184 lines (151 loc) · 5.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
<?php
namespace App\Http\Controllers;
use App\Models\FrozenRepository;
use App\Models\GithubApi;
use App\Models\ProLang;
use App\Models\YearGroup;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Session;
use Inertia\Inertia;
class MainController extends Controller {
private GithubApi $client;
public function __construct() {
$this->client = new GithubApi();
}
/**
* Homepage show oldest and starred repositories
*/
public function index(): \Inertia\Response {
$repositories = FrozenRepository::orderBy('year')
->orderBy('githubCreatedAt', 'asc')
->get()
->groupBy('year')
->toArray();
$allLangs = ProLang::pluck('name')->toArray();
shuffle($allLangs);
return Inertia::render('HomePage', array(
'oldestRepos' => $repositories,
'allLangs' => $allLangs,
));
}
/**
* Show result of search repository by name
*/
public function search(Request $req): \Inertia\Response {
$value = $req->get('name');
$repositories = $this->client->searchRepositories($value);
Log::info('action=search_repositories, value='.$value);
return Inertia::render('SearchResults', array(
'repositories' => $repositories,
));
}
/**
* Show organization history / details
*/
public function showOrganizationHistory(string $org) {
$details = $this->client->getOrganizationDetails($org);
Log::info('action=show_organization, name='.$org);
return Inertia::render('OrgHistory', $details);
}
/**
* Show user history
*/
public function showUserHistory(string $name) {
$userHistory = $this->client->getUserHistory($name);
Log::info('action=show_user, name='.$name);
return Inertia::render('UserHistory', $userHistory);
}
/**
* Show repository history
*/
public function showRepositoryHistory(string $org, string $repo) {
$repository = $this->client->getRepository($org, $repo);
Log::info("action=show_repository, org=$org, repo=$repo");
return Inertia::render('RepositoryHistory', $repository);
}
/**
* Handle Github API rate limit
*/
public function rateLimit() {
return Inertia::render('RateLimit', array(
'nextReset' => Session::get('nextReset'),
));
}
/**
* Search oldest repository by language
*/
public function searchOldestRepository(Request $r) {
$lang = $r->json()->get('lang');
$data = $this->client->getOldestRepository($lang);
return response()->json(
$data
);
}
/**
* Search recent repository by language
*/
public function searchRecentRepository(Request $r) {
$lang = $r->json()->get('lang');
$data = $this->client->getRecentRepository($lang);
return response()->json(
$data
);
}
/**
* Search starred repository by lang
*/
public function searchStarredRepository(Request $r) {
$lang = $r->json()->get('lang');
$data = $this->client->getStarredRepository($lang);
return response()->json(
$data
);
}
/**
* Show lang history page
*/
public function langHistory() {
$groups = YearGroup::with('languages.authors')
->with('languages.parents')
->with('languages.children')
->orderBy('position', 'ASC')
->get();
return Inertia::render('LangHistory', array(
'groups' => $groups,
));
}
public function langFamily() {
$groups = ProLang::with('authors')
->with('parents')
->with('children')
->get();
return Inertia::render('LangFamily', array(
'langs' => $groups,
));
}
public function road() {
Log::info('action=show_road');
return Inertia::render('Road', array(
'beautifulCode' => FrozenRepository::whereIn('fullName', array(
'biomejs/biome', 'laravel/pint', 'zed-industries/zed',
))->get()->toArray(),
'builtOn' => FrozenRepository::whereIn('fullName', array(
'laravel/laravel', 'vuejs/core', 'sqlite/sqlite', 'inertiajs/inertia', 'nanostores/nanostores',
))->get()->toArray(),
'UiUx' => FrozenRepository::whereIn('fullName', array(
'shoelace-style/webawesome', 'DerYeger/yeger', 'hackernoon/pixel-icon-library',
))->get()->toArray(),
'cleanRepo' => FrozenRepository::whereIn('fullName', array(
'evilmartians/lefthook',
'conventional-changelog/commitlint',
'pestphp/pest',
))->get()->toArray(),
'surprises' => FrozenRepository::whereIn('fullName', array(
'vwh/sqlite-online',
'htzh/leanproved',
'withastro/astro',
))->get()->toArray(),
));
}
}