gitlyx / repo / branch_routes.v
36 lines · 29 sloc · 908 bytes · 13ca859655a005b2a87a4935764694302b4f2fda
Raw
1module main
2
3import veb
4import api
5
6@['/api/v1/:user/:repo_name/branches/count']
7fn (mut app App) handle_branch_count(username string, repo_name string) veb.Result {
8 has_access := app.has_user_repo_read_access_by_repo_name(ctx, ctx.user.id, username, repo_name)
9
10 if !has_access {
11 return ctx.json_error('Not found')
12 }
13
14 repo := app.find_repo_by_name_and_username(repo_name, username) or {
15 return ctx.json_error('Not found')
16 }
17
18 count := app.get_count_repo_branches(repo.id)
19
20 return ctx.json(api.ApiBranchCount{
21 success: true
22 result: count
23 })
24}
25
26@['/:user/:repo/branches']
27pub fn (mut app App) branches(username string, repo_name string) veb.Result {
28 repo := app.find_repo_by_name_and_username(repo_name, username) or {
29 return ctx.json_error('Not found')
30 }
31 if !app.can_read_repo(ctx, repo) {
32 return ctx.not_found()
33 }
34 branches := app.get_all_repo_branches(repo.id)
35 return $veb.html()
36}
37