-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from prplnorangesoda/admin
Admin
- Loading branch information
Showing
15 changed files
with
322 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
[submodule "lucyleague-frontend"] | ||
path = lucyleague-frontend | ||
url = https://github.com/prplnorangesoda/lucyleague-frontend | ||
branch = main |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# LucyLeague | ||
|
||
Here's the backend for (hopefully [lucyleague.net](https://lucyleague.net) or [league.passtime.tf]). Please LET ME KNOW if there's anything stupid here like exposed API keys or insecure thingies. | ||
|
||
## Running locally | ||
|
||
This project is dockerized. Simply running `docker compose up` after cloning (AND MAKING A .env FILE!) should work out of the box. Submit an issue if this doesn't work! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
use std::str::FromStr; | ||
|
||
use actix_http::header::TryIntoHeaderValue; | ||
use actix_web::http::header; | ||
use actix_web::{get, http, post, web, Error, HttpResponse, Responder}; | ||
|
||
use crate::apiv1::apimodels::*; | ||
use crate::db; | ||
use crate::errors::MyError; | ||
use crate::models::*; | ||
use crate::AppState; | ||
use deadpool_postgres::Client; | ||
|
||
struct AuthHeader(String); | ||
|
||
impl TryIntoHeaderValue for AuthHeader { | ||
type Error = actix_web::error::HttpError; | ||
fn try_into_value(self) -> Result<header::HeaderValue, Self::Error> { | ||
Ok(header::HeaderValue::from_bytes(self.0.as_bytes())?) | ||
} | ||
} | ||
|
||
pub struct AuthHeaderStringError; | ||
|
||
impl FromStr for AuthHeader { | ||
type Err = AuthHeaderStringError; | ||
fn from_str(s: &str) -> Result<Self, Self::Err> { | ||
Ok(AuthHeader("Hi".to_owned())) | ||
} | ||
} | ||
impl http::header::Header for AuthHeader { | ||
fn name() -> header::HeaderName { | ||
header::AUTHORIZATION | ||
} | ||
fn parse<M: actix_web::HttpMessage>(msg: &M) -> Result<Self, actix_web::error::ParseError> { | ||
actix_http::header::from_one_raw_str(msg.headers().get(Self::name())) | ||
} | ||
} | ||
|
||
#[post("/api/v1/leagues")] | ||
pub async fn post_league( | ||
league: web::Json<MiniLeague>, | ||
state: web::Data<AppState>, | ||
authorization: web::Header<AuthHeader>, | ||
) -> Result<HttpResponse, Error> { | ||
println!("POST request at /api/v1/leagues"); | ||
let client: Client = state.pool.get().await.map_err(MyError::PoolError)?; | ||
let league = league.into_inner(); | ||
let response = db::add_league(&client, league).await?; | ||
|
||
Ok(HttpResponse::Ok().json(response)) | ||
} | ||
|
||
/// Set a user or multiple users to a team. | ||
#[post("/api/v1/users/setteam")] | ||
pub async fn post_users_team( | ||
user_team: web::Json<UserTeamBody>, | ||
state: web::Data<AppState>, | ||
) -> Result<HttpResponse, Error> { | ||
let client = state.pool.get().await.map_err(MyError::PoolError)?; | ||
let user_team = user_team.into_inner(); | ||
// fetch the team to get its id | ||
let team = db::get_team_from_id(&client, user_team.team_id).await?; | ||
let users = db::get_team_players(&client, team).await?; | ||
Ok(HttpResponse::Ok().json(users)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
use serde::{Serialize, Deserialize}; | ||
|
||
use crate::models::*; | ||
|
||
#[derive(Serialize, Deserialize)] | ||
pub struct UserTeamBody { | ||
pub league_id: i64, | ||
pub user_steamids: Vec<String>, | ||
pub team_id: i64, | ||
} | ||
|
||
#[derive(Serialize, Deserialize)] | ||
pub struct UserResponse { | ||
pub user: User, | ||
pub teams: Vec<Team>, | ||
} | ||
#[derive(Serialize, Deserialize)] | ||
pub struct LeagueResponse { | ||
pub info: League, | ||
pub teams: Vec<Team>, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.