Skip to content

Commit

Permalink
start of web ui leaderboard
Browse files Browse the repository at this point in the history
  • Loading branch information
fatfingers23 committed Nov 3, 2023
1 parent 462a545 commit 84b811e
Show file tree
Hide file tree
Showing 20 changed files with 358 additions and 357 deletions.
33 changes: 33 additions & 0 deletions trackscape-discord-api/src/controllers/clan_controller.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
use actix_web::{get, web, Error, HttpResponse, Scope};
use serde::{Deserialize, Serialize};
use trackscape_discord_shared::database::BotMongoDb;
use web::Data;

#[derive(Deserialize, Serialize)]
struct ClanViewModel {
id: String,
name: String,
}

#[get("/list")]
async fn list_clans(mongodb: Data<BotMongoDb>) -> Result<HttpResponse, Error> {
let result = mongodb.guilds.list_clans().await;

match result {
Ok(clans) => {
let view_models: Vec<ClanViewModel> = clans
.into_iter()
.map(|clan| ClanViewModel {
id: clan.id.to_string(),
name: clan.clan_name.unwrap(),
})
.collect();
Ok(HttpResponse::Ok().json(view_models))
}
Err(_) => Ok(HttpResponse::InternalServerError().body("Failed to list clans.")),
}
}

pub fn clan_controller() -> Scope {
web::scope("/clans").service(list_clans)
}
1 change: 1 addition & 0 deletions trackscape-discord-api/src/controllers/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
pub mod bot_info_controller;
pub mod chat_controller;
pub mod clan_controller;
pub mod drop_log_controller;
4 changes: 3 additions & 1 deletion trackscape-discord-api/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ use trackscape_discord_shared::ge_api::ge_api::{get_item_mapping, GeItemMapping}
use uuid::Uuid;

pub use self::websocket_server::{ChatServer, ChatServerHandle};
use crate::controllers::clan_controller::clan_controller;
use crate::controllers::drop_log_controller::drop_log_controller;
use actix_files::{Files, NamedFile};
use log::{error, info};
Expand Down Expand Up @@ -113,7 +114,8 @@ async fn actix_web(
web::scope("/api")
.service(chat_controller())
.service(info_controller())
.service(drop_log_controller()),
.service(drop_log_controller())
.service(clan_controller()),
)
.service(Files::new("/", "./trackscape-discord-api/ui/").index_file("index.html"))
.app_data(web::Data::new(server_tx.clone()))
Expand Down
1 change: 1 addition & 0 deletions trackscape-discord-api/ui/assets/index-2c18a9aa.css

Large diffs are not rendered by default.

9 changes: 9 additions & 0 deletions trackscape-discord-api/ui/assets/index-4d8bb280.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions trackscape-discord-api/ui/assets/index-c22bc2ef.css

Large diffs are not rendered by default.

9 changes: 9 additions & 0 deletions trackscape-discord-api/ui/assets/index-dff543f3.js

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions trackscape-discord-api/ui/index.html
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<!DOCTYPE html>
<html lang="en" data-theme="dracula">
<html lang="en">
<head>
<meta charset="UTF-8">
<link rel="icon" href="/favicon.ico">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>TrackScape</title>
<script type="module" crossorigin src="/assets/index-95baca75.js"></script>
<link rel="stylesheet" href="/assets/index-d145a158.css">
<script type="module" crossorigin src="/assets/index-dff543f3.js"></script>
<link rel="stylesheet" href="/assets/index-c22bc2ef.css">
</head>
<body>
<div id="app"></div>
Expand Down
23 changes: 21 additions & 2 deletions trackscape-discord-shared/src/database/guilds_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,21 @@ use crate::helpers::hash_string;
use crate::osrs_broadcast_extractor::osrs_broadcast_extractor::{
BroadcastType, DiaryTier, QuestDifficulty,
};
use anyhow::Result;
use anyhow::{Error, Result};

Check warning on line 6 in trackscape-discord-shared/src/database/guilds_db.rs

View workflow job for this annotation

GitHub Actions / Test Suite

unused import: `Error`

Check warning on line 6 in trackscape-discord-shared/src/database/guilds_db.rs

View workflow job for this annotation

GitHub Actions / Check

unused import: `Error`
use async_recursion::async_recursion;
use futures::TryStreamExt;
use mockall::predicate::*;
use mongodb::bson::{doc, DateTime};
use mongodb::{bson, Database};
use mongodb::options::FindOptions;
use mongodb::{bson, Cursor, Database};

Check warning on line 12 in trackscape-discord-shared/src/database/guilds_db.rs

View workflow job for this annotation

GitHub Actions / Test Suite

unused import: `Cursor`

Check warning on line 12 in trackscape-discord-shared/src/database/guilds_db.rs

View workflow job for this annotation

GitHub Actions / Check

unused import: `Cursor`
use rand::Rng;
use serde::{Deserialize, Serialize};
use std::string::ToString;

#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct RegisteredGuildModel {
#[serde(rename = "_id")]
pub id: bson::oid::ObjectId,
pub guild_id: u64,
//Channel to send broadcast messages
pub clan_name: Option<String>,
Expand All @@ -37,6 +41,7 @@ impl RegisteredGuildModel {
let verification_code = Self::generate_code();
let hashed_verification_code = hash_string(verification_code.clone());
Self {
id: bson::oid::ObjectId::new(),
guild_id,
clan_name: None,
broadcast_channel: None,
Expand Down Expand Up @@ -205,4 +210,18 @@ impl GuildsDb {
.await
.expect("Failed to delete document for the Discord guild.");
}

pub async fn list_clans(&self) -> Result<Vec<RegisteredGuildModel>, anyhow::Error> {
let collection = self
.db
.collection::<RegisteredGuildModel>(RegisteredGuildModel::COLLECTION_NAME);
let opts = FindOptions::builder().sort(doc! { "clan_name": 1 }).build();
let filter = doc! {"clan_name": {"$ne": ""}};
let result = collection.find(filter, opts).await;

return match result {
Ok(cursor) => Ok(cursor.try_collect().await.unwrap()),
Err(e) => Err(anyhow::Error::new(e)),
};
}
}
2 changes: 1 addition & 1 deletion trackscape-discord-ui/index.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!DOCTYPE html>
<html lang="en" data-theme="dracula">
<html lang="en">
<head>
<meta charset="UTF-8">
<link rel="icon" href="/favicon.ico">
Expand Down
22 changes: 20 additions & 2 deletions trackscape-discord-ui/src/App.vue
Original file line number Diff line number Diff line change
@@ -1,11 +1,29 @@
<script setup lang="ts">
import { RouterLink, RouterView } from 'vue-router'
import HelloWorld from './components/HelloWorld.vue'
import NavMenu from "@/components/nav-menu.vue";
</script>

<template>
<nav-menu/>
<main class="bg-base-200">
<RouterView />
<footer class="
footer
p-10
bg-neutral
text-neutral-content">
<div>
<div class="w-10 rounded-full">
<img class="rounded-full"
src="@/assets/img/Trackscape_Logo_icon.png"/>
</div>
<p>Trackscape.<br>OSRS tooling for clans!</p>
</div>

</footer>
</main>

<RouterView />
</template>

<style scoped>
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
41 changes: 0 additions & 41 deletions trackscape-discord-ui/src/components/HelloWorld.vue

This file was deleted.

88 changes: 0 additions & 88 deletions trackscape-discord-ui/src/components/TheWelcome.vue

This file was deleted.

87 changes: 0 additions & 87 deletions trackscape-discord-ui/src/components/WelcomeItem.vue

This file was deleted.

11 changes: 0 additions & 11 deletions trackscape-discord-ui/src/components/__tests__/HelloWorld.spec.ts

This file was deleted.

Loading

0 comments on commit 84b811e

Please sign in to comment.