Skip to content

Commit

Permalink
1212 Evening: add some api
Browse files Browse the repository at this point in the history
  • Loading branch information
lazhenyi committed Dec 12, 2024
1 parent d7b5e0b commit 2d9a135
Show file tree
Hide file tree
Showing 36 changed files with 525 additions and 32 deletions.
15 changes: 15 additions & 0 deletions src/api/dto/repo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,19 @@ pub struct RepoBranchProtect{
pub struct RepoBranchMerge{
pub branch: String,
pub target: String,
}

#[derive(Deserialize,Serialize, ToSchema)]
pub struct RepoFilePath{
pub path: String,
}

#[derive(Deserialize,Serialize, ToSchema)]
pub struct RepoRename{
pub name: String,
}

#[derive(Deserialize,Serialize, ToSchema)]
pub struct RepoTopic{
pub topic: String
}
3 changes: 2 additions & 1 deletion src/api/handler/grand/mod.rs
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
pub mod repo_access;
pub mod repo_access;
pub mod repo_owner;
8 changes: 4 additions & 4 deletions src/api/handler/grand/repo_access.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ use crate::api::service::Service;
pub async fn check_repo_access(service: &Service, uid: Uuid, repo_id: Uuid) -> anyhow::Result<bool>{
let repo = service.repo.owner(uid).await?;
if repo.iter().any(|x| x.uid == repo_id){
return Ok(true)
Ok(true)
}else {
let groups = service.group.check_member(repo_id).await?;
let groups = service.group.check_member(repo_id,1).await?;
let group_ids = groups
.iter()
.map(|x| x.uid)
Expand All @@ -17,9 +17,9 @@ pub async fn check_repo_access(service: &Service, uid: Uuid, repo_id: Uuid) -> a
repos.extend(repo);
}
if repos.iter().any(|x| x.uid == repo_id){
return Ok(true)
Ok(true)
}else{
return Ok(false)
Ok(false)
}
}
}
25 changes: 25 additions & 0 deletions src/api/handler/grand/repo_owner.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
use uuid::Uuid;
use crate::api::service::Service;

pub async fn check_repo_owner(service: &Service, uid: Uuid, repo_id: Uuid) -> anyhow::Result<bool>{
let repo = service.repo.owner(uid).await?;
if repo.iter().any(|x| x.uid == repo_id){
Ok(true)
}else {
let groups = service.group.check_member(repo_id,2).await?;
let group_ids = groups
.iter()
.map(|x| x.uid)
.collect::<Vec<_>>();
let mut repos = vec![];
for group_id in group_ids {
let repo = service.repo.repo_by_group(group_id).await?;
repos.extend(repo);
}
if repos.iter().any(|x| x.uid == repo_id){
Ok(true)
}else{
Ok(false)
}
}
}
3 changes: 3 additions & 0 deletions src/api/handler/group/info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ use crate::utils::r::R;
get,
tag = "group",
path = "/api/v1/group/{group}/info",
params(
("group" = Uuid, description = "group Uid"),
),
responses(
(status = 200, description = "Group found successfully"),
(status = 400, description = "Group Not Found"),
Expand Down
5 changes: 4 additions & 1 deletion src/api/handler/group/member.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ use crate::utils::r::R;
#[utoipa::path(
get,
tag = "group",
path = "/api/v1/group/{group}/member",
path = "/api/v1/group/{group}/member",
params(
("group" = Uuid, description = "group Uid"),
),
responses(
(status = 200, description = "Group found successfully"),
(status = 400, description = "Group Not Found"),
Expand Down
3 changes: 3 additions & 0 deletions src/api/handler/group/repo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ use uuid::Uuid;
get,
tag = "group",
path = "/api/v1/group/{group}/repo",
params(
("group" = Uuid, description = "group Uid"),
),
responses(
(status = 200, description = "Group found successfully"),
(status = 400, description = "Group Not Found"),
Expand Down
3 changes: 3 additions & 0 deletions src/api/handler/group/team.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ use crate::utils::r::R;
get,
tag = "group",
path = "/api/v1/group/{group}/team",
params(
("group" = Uuid, description = "group Uid"),
),
responses(
(status = 200, description = "Group found successfully"),
(status = 400, description = "Group Not Found"),
Expand Down
3 changes: 3 additions & 0 deletions src/api/handler/repo/branchs/branch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ use crate::api::service::Service;
get,
tag = "repos",
path = "/api/v1/repo/{repo}/branch",
params(
("repo" = Uuid, description = "Repo Uid"),
),
responses(
(status = 200, description = "Repo found successfully"),
(status = 400, description = "Repo Not Found"),
Expand Down
3 changes: 3 additions & 0 deletions src/api/handler/repo/branchs/conflicts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ use uuid::Uuid;
tag = "repos",
path = "/api/v1/repo/{repo}/branch/check_merge",
request_body = RepoBranchMerge,
params(
("repo" = Uuid, description = "Repo Uid"),
),
responses(
(status = 200, description = "Repo found successfully", body = Vec<ConflictsFiles>),
(status = 400, description = "Repo Not Found"),
Expand Down
3 changes: 3 additions & 0 deletions src/api/handler/repo/branchs/del.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ use crate::utils::r::R;
tag = "repos",
path = "/api/v1/repo/{repo}/branch/del",
request_body = RepoBranchDel,
params(
("repo" = Uuid, description = "Repo Uid"),
),
responses(
(status = 200, description = "Repo found successfully"),
(status = 400, description = "Repo Not Found"),
Expand Down
3 changes: 3 additions & 0 deletions src/api/handler/repo/branchs/merge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ use crate::utils::r::R;
tag = "repos",
path = "/api/v1/repo/{repo}/branch/merge",
request_body = RepoBranchMerge,
params(
("repo" = Uuid, description = "Repo Uid"),
),
responses(
(status = 200, description = "Repo found successfully"),
(status = 400, description = "Repo Not Found"),
Expand Down
3 changes: 3 additions & 0 deletions src/api/handler/repo/branchs/new.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ use crate::utils::r::R;
tag = "repos",
path = "/api/v1/repo/{repo}/branch/new",
request_body = RepoBranchNew,
params(
("repo" = Uuid, description = "Repo Uid"),
),
responses(
(status = 200, description = "Repo found successfully"),
(status = 400, description = "Repo Not Found"),
Expand Down
3 changes: 3 additions & 0 deletions src/api/handler/repo/branchs/protect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ use crate::utils::r::R;
tag = "repos",
path = "/api/v1/repo/{repo}/branch/protect",
request_body = RepoBranchProtect,
params(
("repo" = Uuid, description = "Repo Uid"),
),
responses(
(status = 200, description = "Repo found successfully"),
(status = 400, description = "Repo Not Found"),
Expand Down
10 changes: 6 additions & 4 deletions src/api/handler/repo/branchs/rename.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
use crate::api::handler::repo::branchs::branch::__path_api_repo_branch;
use actix_session::Session;
use actix_web::{web, Responder};
use uuid::Uuid;
use crate::api::dto::repo::RepoBranchRename;
use crate::api::handler::grand::repo_access::check_repo_access;
use crate::api::service::Service;
use crate::utils::r::R;
use actix_session::Session;
use actix_web::{web, Responder};
use uuid::Uuid;

#[utoipa::path(
post,
tag = "repos",
path = "/api/v1/repo/{repo}/branch/rename",
request_body = RepoBranchRename,
params(
("repo" = Uuid, description = "Repo Uid"),
),
responses(
(status = 200, description = "Repo found successfully"),
(status = 400, description = "Repo Not Found"),
Expand Down
43 changes: 43 additions & 0 deletions src/api/handler/repo/commits/history.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
use crate::api::service::Service;
use crate::store::dto::CommitDto;
use crate::utils::r::R;
use actix_web::{web, Responder};
use uuid::Uuid;

#[utoipa::path(
get,
path = "/api/repo/{repo_id}/commit/{commit_id}/history",
tag = "repo",
params(
("repo_id" = String, description = "repo id"),
("commit_id" = String, description = "commit id"),
),
responses(
(status = 200, description = "success", body = Vec<CommitDto>),
(status = 500, description = "error", body = String)
)
)]
pub async fn api_repo_commit_history(
path: web::Path<(Uuid,String)>,
service: web::Data<Service>
)
-> impl Responder
{
let (repo_id, commit_id) = path.into_inner();
match service.repo.commit_history(repo_id, commit_id){
Ok(commits)=>{
R::<Vec<CommitDto>>{
code: 200,
data: Option::from(commits),
msg: Option::from("success".to_string())
}
},
Err(e)=>{
R::<Vec<CommitDto>>{
code: 500,
data: None,
msg: Option::from(e.to_string())
}
}
}
}
1 change: 1 addition & 0 deletions src/api/handler/repo/commits/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub mod history;
3 changes: 3 additions & 0 deletions src/api/handler/repo/info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ use crate::utils::r::R;
get,
tag = "repos",
path = "/api/v1/repo/{repo}/info",
params(
("repo" = Uuid, description = "Repo Uid"),
),
responses(
(status = 200, description = "Repo found successfully"),
(status = 400, description = "Repo Not Found"),
Expand Down
7 changes: 5 additions & 2 deletions src/api/handler/repo/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
pub mod create;
pub mod object;
pub mod info;
pub mod branchs;
pub mod branchs;
pub mod commits;
pub mod objects;
pub mod rename;
pub mod topic;
2 changes: 2 additions & 0 deletions src/api/handler/repo/objects/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pub mod object;
pub mod once;
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ use crate::utils::r::R;
#[utoipa::path(
get,
tag = "repos",
path = "/api/v1/repo/tree/{repo}/{branch}",
path = "/api/v1/repo/tree/{repo}/{branch}/tree",
params(
("repo" = String, description = "repo id"),
("branch" = String, description = "branch name"),
),
responses(
(status = 200, description = "Ok", body = Vec<ObjectFile>),
(status = 401, description = "Unauthorized"),
Expand All @@ -16,7 +20,7 @@ use crate::utils::r::R;
)]
pub async fn api_repo_object_tree(
service: web::Data<Service>,
rb: web::Path<(Uuid, Uuid)>,
rb: web::Path<(Uuid, String)>,
) -> impl Responder
{
let (repo, branch) = rb.into_inner();
Expand Down
45 changes: 45 additions & 0 deletions src/api/handler/repo/objects/once.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
use actix_web::web;
use uuid::Uuid;
use crate::api::dto::repo::RepoFilePath;
use crate::api::service::Service;
use crate::utils::r::R;

#[utoipa::path(
get,
tag = "repo",
path = "/api/repo/{repo_id}/object/{branch}/{ref}/once",
params(
("repo_id" = String, description = "repo id"),
("branch" = String, description = "branch name"),
("hash" = String, description = "hash"),
),
request_body = RepoFilePath,
responses(
(status = 200, description = "success", body= Vec<u8>),
(status = 500, description = "error", body = String)
)
)]
pub async fn api_repo_object_once(
service: web::Data<Service>,
path: web::Path<(Uuid,String,String)>,
dto: web::Json<RepoFilePath>
) -> impl actix_web::Responder
{
let (repo_id, branch, hash) = path.into_inner();
match service.repo.once_files(repo_id, branch, hash, dto.path.to_string()).await{
Ok(byte)=>{
R::<Vec<u8>>{
code: 200,
data: Option::from(byte),
msg: Option::from("success".to_string())
}
},
Err(e)=>{
R{
code: 500,
data: None,
msg: Option::from(e.to_string())
}
}
}
}
Loading

0 comments on commit 2d9a135

Please sign in to comment.