This repository has been archived by the owner on Sep 2, 2021. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add basic implementation for the tags endpoint.
- Loading branch information
Showing
6 changed files
with
151 additions
and
0 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 |
---|---|---|
|
@@ -6,3 +6,4 @@ DROP TABLE room_aliases; | |
DROP TABLE room_memberships; | ||
DROP TABLE rooms; | ||
DROP TABLE users; | ||
DROP TABLE room_tags; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
//! Endpoints for tags. | ||
use iron::{Chain, Handler, IronResult, Request, Response}; | ||
use iron::status::Status; | ||
|
||
use middleware::{AccessTokenAuth, JsonRequest, RoomIdParam, UserIdParam}; | ||
|
||
/// The `/user/:user_id/rooms/:room_id/tags` endpoint. | ||
pub struct GetTags; | ||
|
||
impl GetTags { | ||
/// Create a `GetTags` with all necessary middleware. | ||
pub fn chain() -> Chain { | ||
let mut chain = Chain::new(GetTags); | ||
|
||
chain.link_before(JsonRequest); | ||
chain.link_before(UserIdParam); | ||
chain.link_before(RoomIdParam); | ||
chain.link_before(AccessTokenAuth); | ||
|
||
chain | ||
} | ||
} | ||
|
||
impl Handler for GetTags { | ||
fn handle(&self, request: &mut Request) -> IronResult<Response> { | ||
let user_id = request.extensions.get::<UserIdParam>() | ||
.expect("UserIdParam should ensure a UserId").clone(); | ||
let room_id = request.extensions.get::<RoomIdParam>() | ||
.expect("RoomIdParam should ensure a RoomId").clone(); | ||
|
||
Ok(Response::with(Status::Ok)) | ||
} | ||
} | ||
|
||
/// The `/user/:user_id/rooms/:room_id/tags/:tag` endpoint. | ||
pub struct PutTag; | ||
|
||
impl PutTag { | ||
/// Create a `GetTags` with all necessary middleware. | ||
pub fn chain() -> Chain { | ||
let mut chain = Chain::new(PutTag); | ||
|
||
chain.link_before(JsonRequest); | ||
chain.link_before(UserIdParam); | ||
chain.link_before(RoomIdParam); | ||
chain.link_before(AccessTokenAuth); | ||
|
||
chain | ||
} | ||
} | ||
|
||
impl Handler for PutTag { | ||
fn handle(&self, request: &mut Request) -> IronResult<Response> { | ||
let user_id = request.extensions.get::<UserIdParam>() | ||
.expect("UserIdParam should ensure a UserId").clone(); | ||
let room_id = request.extensions.get::<RoomIdParam>() | ||
.expect("RoomIdParam should ensure a RoomId").clone(); | ||
|
||
Ok(Response::with(Status::Ok)) | ||
} | ||
} | ||
|
||
/// The `/user/:user_id/rooms/:room_id/tags/:tag` endpoint. | ||
pub struct DeleteTag; | ||
|
||
impl DeleteTag { | ||
/// Create a `GetTags` with all necessary middleware. | ||
pub fn chain() -> Chain { | ||
let mut chain = Chain::new(DeleteTag); | ||
|
||
chain.link_before(JsonRequest); | ||
chain.link_before(UserIdParam); | ||
chain.link_before(RoomIdParam); | ||
chain.link_before(AccessTokenAuth); | ||
|
||
chain | ||
} | ||
} | ||
|
||
impl Handler for DeleteTag { | ||
fn handle(&self, request: &mut Request) -> IronResult<Response> { | ||
let user_id = request.extensions.get::<UserIdParam>() | ||
.expect("UserIdParam should ensure a UserId").clone(); | ||
let room_id = request.extensions.get::<RoomIdParam>() | ||
.expect("RoomIdParam should ensure a RoomId").clone(); | ||
|
||
Ok(Response::with(Status::Ok)) | ||
} | ||
} | ||
|
||
|
||
#[cfg(test)] | ||
mod tests { | ||
use test::Test; | ||
use iron::status::Status; | ||
|
||
#[test] | ||
fn get_tag() { | ||
let test = Test::new(); | ||
let access_token = test.create_access_token(); // @carl:ruma.test | ||
|
||
let room_id = test.create_public_room(&access_token); | ||
|
||
let put_tag_path = format!( | ||
"/_matrix/client/r0/user/@carl:ruma.test/rooms/{}/tags/work?access_token={}", | ||
room_id, | ||
access_token | ||
); | ||
|
||
let response = test.put(&put_tag_path, r"{}"); | ||
assert_eq!(response.status, Status::Ok); | ||
|
||
let get_tag_path = format!( | ||
"/_matrix/client/r0/user/@carl:ruma.test/rooms/{}/tags?access_token={}", | ||
room_id, | ||
access_token | ||
); | ||
|
||
let response = test.put(&get_tag_path, r"{}"); | ||
assert_eq!(response.status, Status::Ok); | ||
} | ||
} |
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