fix(server): account for world
This commit is contained in:
parent
13e5f1daf3
commit
581b4806ed
|
@ -0,0 +1,3 @@
|
|||
alter table messages
|
||||
add column world int;
|
||||
create index messages_world_idx on messages (world);
|
|
@ -23,6 +23,8 @@ pub struct Message {
|
|||
#[serde(default = "glyph_default")]
|
||||
pub glyph: i8,
|
||||
|
||||
#[serde(default)]
|
||||
pub world: Option<u32>,
|
||||
#[serde(default)]
|
||||
pub ward: Option<u16>,
|
||||
#[serde(default)]
|
||||
|
@ -57,6 +59,7 @@ pub struct RetrievedMessage {
|
|||
pub struct RetrievedMessageTerritory {
|
||||
pub id: String,
|
||||
pub territory: i64,
|
||||
pub world: Option<i64>,
|
||||
pub ward: Option<i64>,
|
||||
pub plot: Option<i64>,
|
||||
pub x: f64,
|
||||
|
@ -76,6 +79,7 @@ pub struct RetrievedMessageTerritory {
|
|||
pub struct OwnMessage {
|
||||
pub id: String,
|
||||
pub territory: i64,
|
||||
pub world: Option<i64>,
|
||||
pub ward: Option<i64>,
|
||||
pub plot: Option<i64>,
|
||||
pub x: f64,
|
||||
|
|
|
@ -73,7 +73,7 @@ pub enum WebError {
|
|||
TooManyMessages,
|
||||
NoSuchMessage,
|
||||
InvalidExtraCode,
|
||||
MissingWard,
|
||||
MissingHousingInfo,
|
||||
UnnecessaryHousingInfo,
|
||||
}
|
||||
|
||||
|
@ -94,7 +94,7 @@ async fn handle_rejection(err: Rejection) -> Result<impl Reply, Infallible> {
|
|||
WebError::TooManyMessages => (StatusCode::BAD_REQUEST, "too_many_messages", "you have run out of messages - delete one and try again".into()),
|
||||
WebError::NoSuchMessage => (StatusCode::NOT_FOUND, "no_such_message", "no message with that id was found".into()),
|
||||
WebError::InvalidExtraCode => (StatusCode::BAD_REQUEST, "invalid_extra_code", "that extra code was not found".into()),
|
||||
WebError::MissingWard => (StatusCode::BAD_REQUEST, "missing_ward", "a ward was not provided - try updating the plugin".into()),
|
||||
WebError::MissingHousingInfo => (StatusCode::BAD_REQUEST, "missing_housing_info", "housing info was not provided - try updating the plugin".into()),
|
||||
WebError::UnnecessaryHousingInfo => (StatusCode::BAD_REQUEST, "unnecessary_housing_info", "a ward/plot was provided but not necessary - try updating the plugin".into()),
|
||||
}
|
||||
} else if err.is_not_found() {
|
||||
|
|
|
@ -26,6 +26,8 @@ pub fn get_location(state: Arc<State>) -> BoxedFilter<(impl Reply, )> {
|
|||
|
||||
#[derive(Deserialize)]
|
||||
pub struct GetLocationQuery {
|
||||
#[serde(default)]
|
||||
world: Option<u32>,
|
||||
#[serde(default)]
|
||||
ward: Option<u32>,
|
||||
#[serde(default)]
|
||||
|
@ -34,14 +36,20 @@ pub struct GetLocationQuery {
|
|||
|
||||
async fn logic(state: Arc<State>, id: i64, location: u32, query: GetLocationQuery) -> Result<impl Reply, Rejection> {
|
||||
let housing = HOUSING_ZONES.contains(&location);
|
||||
if housing && query.ward.is_none() {
|
||||
return Err(warp::reject::custom(WebError::MissingWard));
|
||||
if housing && (query.world.is_none() || query.ward.is_none()) {
|
||||
return Err(warp::reject::custom(WebError::MissingHousingInfo));
|
||||
}
|
||||
|
||||
if !housing && (query.ward.is_some() || query.plot.is_some()) {
|
||||
return Err(warp::reject::custom(WebError::UnnecessaryHousingInfo));
|
||||
}
|
||||
|
||||
let world = if housing {
|
||||
query.world
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
let location = location as i64;
|
||||
let mut messages = sqlx::query_as!(
|
||||
RetrievedMessage,
|
||||
|
@ -64,10 +72,11 @@ async fn logic(state: Arc<State>, id: i64, location: u32, query: GetLocationQuer
|
|||
left join votes v on m.id = v.message
|
||||
left join votes v2 on m.id = v2.message and v2.user = ?
|
||||
inner join users u on m.user = u.id
|
||||
where m.territory = ? and m.ward is ? and m.plot is ?
|
||||
where m.territory = ? and m.world is ? and m.ward is ? and m.plot is ?
|
||||
group by m.id"#,
|
||||
id,
|
||||
location,
|
||||
world,
|
||||
query.ward,
|
||||
query.plot,
|
||||
)
|
||||
|
|
|
@ -27,6 +27,7 @@ async fn logic(state: Arc<State>, id: i64, message_id: Uuid) -> Result<impl Repl
|
|||
r#"
|
||||
select m.id,
|
||||
m.territory,
|
||||
m.world,
|
||||
m.ward,
|
||||
m.plot,
|
||||
m.x,
|
||||
|
|
|
@ -31,6 +31,7 @@ async fn logic(state: Arc<State>, id: i64, extra: i64, mut query: HashMap<String
|
|||
r#"
|
||||
select m.id,
|
||||
m.territory,
|
||||
m.world,
|
||||
m.ward,
|
||||
m.plot,
|
||||
m.x,
|
||||
|
|
|
@ -23,8 +23,8 @@ pub fn write(state: Arc<State>) -> BoxedFilter<(impl Reply, )> {
|
|||
|
||||
async fn logic(state: Arc<State>, id: i64, extra: i64, message: Message) -> Result<impl Reply, Rejection> {
|
||||
let housing = HOUSING_ZONES.contains(&message.territory);
|
||||
if housing && message.ward.is_none() {
|
||||
return Err(warp::reject::custom(WebError::MissingWard));
|
||||
if housing && (message.world.is_none() || message.ward.is_none()) {
|
||||
return Err(warp::reject::custom(WebError::MissingHousingInfo));
|
||||
}
|
||||
|
||||
if !housing && (message.ward.is_some() || message.plot.is_some()) {
|
||||
|
@ -67,10 +67,11 @@ async fn logic(state: Arc<State>, id: i64, extra: i64, message: Message) -> Resu
|
|||
|
||||
sqlx::query!(
|
||||
// language=sqlite
|
||||
"insert into messages (id, user, territory, ward, plot, x, y, z, yaw, message, glyph) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
|
||||
"insert into messages (id, user, territory, world, ward, plot, x, y, z, yaw, message, glyph) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
|
||||
message_id,
|
||||
id,
|
||||
territory,
|
||||
message.world,
|
||||
message.ward,
|
||||
message.plot,
|
||||
message.x,
|
||||
|
|
Loading…
Reference in New Issue