✨ Adds auth
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
use crate::auth::Authenticated;
|
||||
use crate::dtos::hit::HitDTO;
|
||||
use crate::models::AppState;
|
||||
use crate::models::hit::Hit;
|
||||
@@ -14,6 +15,7 @@ use uuid::Uuid;
|
||||
pub fn index(
|
||||
offset: Option<i64>,
|
||||
limit: Option<i64>,
|
||||
auth: Authenticated,
|
||||
state: &State<AppState>,
|
||||
) -> Result<Json<Vec<HitDTO>>, Status> {
|
||||
let mut db = state.db.lock().unwrap();
|
||||
@@ -35,7 +37,7 @@ pub fn index(
|
||||
}
|
||||
|
||||
#[get("/<id>")]
|
||||
pub fn get(id: &str, state: &State<AppState>) -> Result<Json<HitDTO>, Status> {
|
||||
pub fn get(id: &str, auth: Authenticated, state: &State<AppState>) -> Result<Json<HitDTO>, Status> {
|
||||
let mut db = state.db.lock().unwrap();
|
||||
|
||||
let id = match Uuid::parse_str(id).ok() {
|
||||
@@ -55,7 +57,7 @@ pub fn get(id: &str, state: &State<AppState>) -> Result<Json<HitDTO>, Status> {
|
||||
}
|
||||
|
||||
#[delete("/<id>")]
|
||||
pub fn delete(id: &str, state: &State<AppState>) -> Result<Status, Status> {
|
||||
pub fn delete(id: &str, auth: Authenticated, state: &State<AppState>) -> Result<Status, Status> {
|
||||
let mut db = state.db.lock().unwrap();
|
||||
|
||||
let id = match Uuid::parse_str(id).ok() {
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
use crate::auth::Authenticated;
|
||||
use crate::dtos::tracker::TrackerDTO;
|
||||
use crate::models::AppState;
|
||||
use crate::models::tracker::Tracker;
|
||||
@@ -15,6 +16,7 @@ use uuid::Uuid;
|
||||
pub fn index(
|
||||
offset: Option<i64>,
|
||||
limit: Option<i64>,
|
||||
auth: Authenticated,
|
||||
state: &State<AppState>,
|
||||
) -> Result<Json<Vec<TrackerDTO>>, Status> {
|
||||
let mut db = state.db.lock().unwrap();
|
||||
@@ -36,7 +38,11 @@ pub fn index(
|
||||
}
|
||||
|
||||
#[get("/<id>")]
|
||||
pub fn get(id: &str, state: &State<AppState>) -> Result<Json<TrackerDTO>, Status> {
|
||||
pub fn get(
|
||||
id: &str,
|
||||
auth: Authenticated,
|
||||
state: &State<AppState>,
|
||||
) -> Result<Json<TrackerDTO>, Status> {
|
||||
let mut db = state.db.lock().unwrap();
|
||||
|
||||
let id = match Uuid::parse_str(id).ok() {
|
||||
@@ -56,7 +62,7 @@ pub fn get(id: &str, state: &State<AppState>) -> Result<Json<TrackerDTO>, Status
|
||||
}
|
||||
|
||||
#[post("/")]
|
||||
pub fn create(state: &State<AppState>) -> Result<Json<TrackerDTO>, Status> {
|
||||
pub fn create(auth: Authenticated, state: &State<AppState>) -> Result<Json<TrackerDTO>, Status> {
|
||||
let mut db = state.db.lock().unwrap();
|
||||
|
||||
let new = Tracker {
|
||||
@@ -79,6 +85,7 @@ pub fn create(state: &State<AppState>) -> Result<Json<TrackerDTO>, Status> {
|
||||
pub fn delete(
|
||||
id: &str,
|
||||
delete_hits: Option<bool>,
|
||||
auth: Authenticated,
|
||||
state: &State<AppState>,
|
||||
) -> Result<Status, Status> {
|
||||
let mut db = state.db.lock().unwrap();
|
||||
|
||||
Reference in New Issue
Block a user