You've already forked AstralRinth
More mod info (#104)
* More mod info * Downloading mods * Run prepare * User editing + icon editing * Finish * Some fixes * Fix clippy errors
This commit is contained in:
@@ -2,10 +2,12 @@ use super::ApiError;
|
||||
use crate::auth::check_is_moderator_from_headers;
|
||||
use crate::database;
|
||||
use crate::models;
|
||||
use crate::models::mods::{ModStatus, VersionType};
|
||||
use crate::models::mods::{ModStatus, VersionType, ModId};
|
||||
use actix_web::{get, web, HttpRequest, HttpResponse};
|
||||
use serde::Deserialize;
|
||||
use serde::{Serialize, Deserialize};
|
||||
use sqlx::PgPool;
|
||||
use sqlx::types::chrono::{DateTime, Utc};
|
||||
use crate::models::teams::TeamId;
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub struct ResultCount {
|
||||
@@ -17,6 +19,42 @@ fn default_count() -> i16 {
|
||||
100
|
||||
}
|
||||
|
||||
/// A mod returned from the API moderation routes
|
||||
#[derive(Serialize)]
|
||||
pub struct ModerationMod {
|
||||
/// The ID of the mod, encoded as a base62 string.
|
||||
pub id: ModId,
|
||||
/// The slug of a mod, used for vanity URLs
|
||||
pub slug: Option<String>,
|
||||
/// The team of people that has ownership of this mod.
|
||||
pub team: TeamId,
|
||||
/// The title or name of the mod.
|
||||
pub title: String,
|
||||
/// A short description of the mod.
|
||||
pub description: String,
|
||||
/// The link to the long description of the mod.
|
||||
pub body_url: String,
|
||||
/// The date at which the mod was first published.
|
||||
pub published: DateTime<Utc>,
|
||||
/// The date at which the mod was first published.
|
||||
pub updated: DateTime<Utc>,
|
||||
/// The status of the mod
|
||||
pub status: ModStatus,
|
||||
|
||||
/// The total number of downloads the mod has had.
|
||||
pub downloads: u32,
|
||||
/// The URL of the icon of the mod
|
||||
pub icon_url: Option<String>,
|
||||
/// An optional link to where to submit bugs or issues with the mod.
|
||||
pub issues_url: Option<String>,
|
||||
/// An optional link to the source code for the mod.
|
||||
pub source_url: Option<String>,
|
||||
/// An optional link to the mod's wiki page or other relevant information.
|
||||
pub wiki_url: Option<String>,
|
||||
/// An optional link to the mod's discord
|
||||
pub discord_url: Option<String>,
|
||||
}
|
||||
|
||||
#[get("mods")]
|
||||
pub async fn mods(
|
||||
req: HttpRequest,
|
||||
@@ -41,15 +79,14 @@ pub async fn mods(
|
||||
)
|
||||
.fetch_many(&**pool)
|
||||
.try_filter_map(|e| async {
|
||||
Ok(e.right().map(|m| models::mods::Mod {
|
||||
Ok(e.right().map(|m| ModerationMod {
|
||||
id: database::models::ids::ModId(m.id).into(),
|
||||
slug: m.slug,
|
||||
team: database::models::ids::TeamId(m.team_id).into(),
|
||||
title: m.title,
|
||||
description: m.description,
|
||||
body_url: m.body_url,
|
||||
published: m.published,
|
||||
categories: vec![],
|
||||
versions: vec![],
|
||||
icon_url: m.icon_url,
|
||||
issues_url: m.issues_url,
|
||||
source_url: m.source_url,
|
||||
@@ -57,9 +94,10 @@ pub async fn mods(
|
||||
updated: m.updated,
|
||||
downloads: m.downloads as u32,
|
||||
wiki_url: m.wiki_url,
|
||||
discord_url: m.discord_url,
|
||||
}))
|
||||
})
|
||||
.try_collect::<Vec<models::mods::Mod>>()
|
||||
.try_collect::<Vec<ModerationMod>>()
|
||||
.await
|
||||
.map_err(|e| ApiError::DatabaseError(e.into()))?;
|
||||
|
||||
@@ -92,6 +130,7 @@ pub async fn versions(
|
||||
id: database::models::ids::VersionId(m.id).into(),
|
||||
mod_id: database::models::ids::ModId(m.mod_id).into(),
|
||||
author_id: database::models::ids::UserId(m.author_id).into(),
|
||||
featured: m.featured,
|
||||
name: m.name,
|
||||
version_number: m.version_number,
|
||||
changelog_url: m.changelog_url,
|
||||
|
||||
Reference in New Issue
Block a user