summaryrefslogtreecommitdiff
path: root/src/commit
diff options
context:
space:
mode:
Diffstat (limited to 'src/commit')
-rw-r--r--src/commit/models.rs8
-rw-r--r--src/commit/routes.rs20
2 files changed, 14 insertions, 14 deletions
diff --git a/src/commit/models.rs b/src/commit/models.rs
index b2aa2d2..987bcd2 100644
--- a/src/commit/models.rs
+++ b/src/commit/models.rs
@@ -27,7 +27,7 @@ impl Commit {
pub async fn find_all(pool: Pool) -> Result<Vec<Commit>, AppError> {
let client = get_client(pool.clone()).await.unwrap();
let statement = client
- .prepare("SELECT * FROM commit ORDER BY date DESC")
+ .prepare("SELECT * FROM commit ORDER BY date DESC LIMIT 300")
.await?;
let commits = client
@@ -111,12 +111,12 @@ impl Commit {
"('{}', {}, E'{}', '{}', '{}', E'{}', '{}', E'{}', '{}'),",
commit.hash,
tree,
- commit.text.replace("'", "\\'"),
+ commit.text.replace("\\'", "'").replace("'", "\\'"),
commit.date,
commit.author_email,
- commit.author_name.replace("'", "\\'"),
+ commit.author_name.replace("\\'", "'").replace("'", "\\'"),
commit.committer_email,
- commit.committer_name.replace("'", "\\'"),
+ commit.committer_name.replace("\\'", "'").replace("'", "\\'"),
commit.repository_url
)[..]
}
diff --git a/src/commit/routes.rs b/src/commit/routes.rs
index e49f698..95c0faa 100644
--- a/src/commit/routes.rs
+++ b/src/commit/routes.rs
@@ -23,11 +23,11 @@ async fn index(state: web::Data<AppState>) -> impl Responder {
// Endpoint used for getting one commit
async fn get_commit(
state: web::Data<AppState>,
- hash: web::Path<(String,)>,
+ hash: web::Path<String>,
) -> impl Responder {
- info!(state.log, "GET /commit/{}/", &hash.0);
+ info!(state.log, "GET /commit/{}/", &hash);
- let result = Commit::find(state.pool.clone(), hash.0.clone()).await;
+ let result = Commit::find(state.pool.clone(), hash.clone()).await;
result
.map(|commit| HttpResponse::Ok().json(commit))
@@ -39,14 +39,14 @@ async fn get_commit(
async fn delete_commit(
req: HttpRequest,
state: web::Data<AppState>,
- hash: web::Path<(String,)>,
+ hash: web::Path<String>,
) -> impl Responder {
match req.headers().get(header::AUTHORIZATION) {
Some(x)
if x.to_str().unwrap()
!= env::var("SECRET_KEY").unwrap_or("".to_string()) =>
{
- info!(state.log, "DELETE /commit/{}/ 401", &hash.0);
+ info!(state.log, "DELETE /commit/{}/ 401", &hash);
return Err(AppError {
error_type: AppErrorType::AuthorizationError,
message: Some(
@@ -57,13 +57,13 @@ async fn delete_commit(
}
Some(_) => {}
None => {
- info!(state.log, "DELETE /commit/{}/ 400", &hash.0);
+ info!(state.log, "DELETE /commit/{}/ 400", &hash);
return Ok(HttpResponse::BadRequest().body(""));
}
};
- let result = Commit::delete(state.pool.clone(), &hash.0).await;
- info!(state.log, "DELETE /commit/{}/", &hash.0);
+ let result = Commit::delete(state.pool.clone(), &hash).await;
+ info!(state.log, "DELETE /commit/{}/", &hash);
result
.map(|_| HttpResponse::NoContent().body(""))
@@ -74,9 +74,9 @@ async fn delete_commit(
pub fn config(cfg: &mut web::ServiceConfig) {
cfg.service(
web::scope("/commit")
- .service(web::resource("{_:/?}").route(web::get().to(index)))
+ .service(web::resource("/").route(web::get().to(index)))
.service(
- web::resource("/{hash}{_:/?}")
+ web::resource("/{hash}/")
.route(web::get().to(get_commit))
.route(web::delete().to(delete_commit)),
),