forked from vieter-v/vieter
refactor: removed commented code & ran formatter
This commit is contained in:
parent
c818273790
commit
204144cee8
7 changed files with 17 additions and 193 deletions
|
|
@ -1,14 +1,10 @@
|
|||
module server
|
||||
|
||||
import web
|
||||
import git
|
||||
import net.http
|
||||
import rand
|
||||
import response { new_data_response, new_response }
|
||||
import db
|
||||
|
||||
const repos_file = 'repos.json'
|
||||
|
||||
// get_repos returns the current list of repos.
|
||||
['/api/repos'; get]
|
||||
fn (mut app App) get_repos() web.Result {
|
||||
|
|
@ -17,13 +13,6 @@ fn (mut app App) get_repos() web.Result {
|
|||
}
|
||||
|
||||
repos := app.db.get_git_repos()
|
||||
// repos := rlock app.git_mutex {
|
||||
// git.read_repos(app.conf.repos_file) or {
|
||||
// app.lerror('Failed to read repos file: $err.msg()')
|
||||
|
||||
// return app.status(http.Status.internal_server_error)
|
||||
// }
|
||||
//}
|
||||
|
||||
return app.json(http.Status.ok, new_data_response(repos))
|
||||
}
|
||||
|
|
@ -35,19 +24,6 @@ fn (mut app App) get_single_repo(id int) web.Result {
|
|||
return app.json(http.Status.unauthorized, new_response('Unauthorized.'))
|
||||
}
|
||||
|
||||
// repos := rlock app.git_mutex {
|
||||
// git.read_repos(app.conf.repos_file) or {
|
||||
// app.lerror('Failed to read repos file.')
|
||||
|
||||
// return app.status(http.Status.internal_server_error)
|
||||
// }
|
||||
//}
|
||||
|
||||
// if id !in repos {
|
||||
// return app.not_found()
|
||||
//}
|
||||
|
||||
// repo := repos[id]
|
||||
repo := app.db.get_git_repo(id) or { return app.not_found() }
|
||||
|
||||
return app.json(http.Status.ok, new_data_response(repo))
|
||||
|
|
@ -74,32 +50,6 @@ fn (mut app App) post_repo() web.Result {
|
|||
|
||||
app.db.add_git_repo(new_repo)
|
||||
|
||||
// id := rand.uuid_v4()
|
||||
|
||||
// mut repos := rlock app.git_mutex {
|
||||
// git.read_repos(app.conf.repos_file) or {
|
||||
// app.lerror('Failed to read repos file.')
|
||||
|
||||
// return app.status(http.Status.internal_server_error)
|
||||
// }
|
||||
//}
|
||||
// repos := app.db.get_git_repos()
|
||||
|
||||
//// We need to check for duplicates
|
||||
// for _, repo in repos {
|
||||
// if repo == new_repo {
|
||||
// return app.json(http.Status.bad_request, new_response('Duplicate repository.'))
|
||||
// }
|
||||
//}
|
||||
|
||||
// repos[id] = new_repo
|
||||
|
||||
// lock app.git_mutex {
|
||||
// git.write_repos(app.conf.repos_file, &repos) or {
|
||||
// return app.status(http.Status.internal_server_error)
|
||||
// }
|
||||
//}
|
||||
|
||||
return app.json(http.Status.ok, new_response('Repo added successfully.'))
|
||||
}
|
||||
|
||||
|
|
@ -110,25 +60,9 @@ fn (mut app App) delete_repo(id int) web.Result {
|
|||
return app.json(http.Status.unauthorized, new_response('Unauthorized.'))
|
||||
}
|
||||
|
||||
// mut repos := rlock app.git_mutex {
|
||||
// git.read_repos(app.conf.repos_file) or {
|
||||
// app.lerror('Failed to read repos file.')
|
||||
|
||||
// return app.status(http.Status.internal_server_error)
|
||||
// }
|
||||
//}
|
||||
|
||||
// if id !in repos {
|
||||
// return app.not_found()
|
||||
//}
|
||||
|
||||
// repos.delete(id)
|
||||
app.db.delete_git_repo(id)
|
||||
|
||||
// lock app.git_mutex {
|
||||
// git.write_repos(app.conf.repos_file, &repos) or { return app.server_error(500) }
|
||||
// }
|
||||
|
||||
return app.json(http.Status.ok, new_response('Repo removed successfully.'))
|
||||
}
|
||||
|
||||
|
|
@ -147,23 +81,5 @@ fn (mut app App) patch_repo(id int) web.Result {
|
|||
app.db.update_git_repo_archs(id, arch_objs)
|
||||
}
|
||||
|
||||
// mut repos := rlock app.git_mutex {
|
||||
// git.read_repos(app.conf.repos_file) or {
|
||||
// app.lerror('Failed to read repos file.')
|
||||
|
||||
// return app.status(http.Status.internal_server_error)
|
||||
// }
|
||||
// }
|
||||
|
||||
// if id !in repos {
|
||||
// return app.not_found()
|
||||
// }
|
||||
|
||||
// repos[id].patch_from_params(app.query)
|
||||
|
||||
// lock app.git_mutex {
|
||||
// git.write_repos(app.conf.repos_file, &repos) or { return app.server_error(500) }
|
||||
// }
|
||||
|
||||
return app.json(http.Status.ok, new_response('Repo updated successfully.'))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,9 +20,7 @@ pub:
|
|||
conf Config [required; web_global]
|
||||
pub mut:
|
||||
repo repo.RepoGroupManager [required; web_global]
|
||||
// This is used to claim the file lock on the repos file
|
||||
git_mutex shared util.Dummy
|
||||
db db.VieterDb
|
||||
db db.VieterDb
|
||||
}
|
||||
|
||||
// server starts the web server & starts listening for requests
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue