| 1 | module main |
| 2 | |
| 3 | import veb |
| 4 | import api |
| 5 | |
| 6 | @['/api/v1/:user/:repo_name/branches/count'] |
| 7 | fn (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'] |
| 27 | pub 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 | branches := app.get_all_repo_branches(repo.id) |
| 32 | return $veb.html() |
| 33 | } |
| 34 | |