Skip to content

Commit

Permalink
refactor: [#670] changed DTOs and variable names
Browse files Browse the repository at this point in the history
  • Loading branch information
mario-nt committed Jun 4, 2024
1 parent 5a529cc commit 32416ee
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 26 deletions.
6 changes: 3 additions & 3 deletions src/console/clients/udp/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ use torrust_tracker_primitives::info_hash::InfoHash as TorrustInfoHash;
use url::Url;

use crate::console::clients::udp::checker;
use crate::console::clients::udp::responses::dto::ResponseDto;
use crate::console::clients::udp::responses::dto::SerializableResponse;
use crate::console::clients::udp::responses::json::ToJson;

const ASSIGNED_BY_OS: u16 = 0;
Expand Down Expand Up @@ -117,8 +117,8 @@ pub async fn run() -> anyhow::Result<()> {
} => handle_scrape(&tracker_socket_addr, &info_hashes).await?,
};

let response_dto: ResponseDto = response.into();
let response_json = response_dto.to_json_string()?;
let response: SerializableResponse = response.into();
let response_json = response.to_json_string()?;

print!("{response_json}");

Expand Down
42 changes: 21 additions & 21 deletions src/console/clients/udp/responses/dto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,33 +6,33 @@ use aquatic_udp_protocol::{AnnounceResponse, ConnectResponse, ErrorResponse, Ipv
use serde::Serialize;

#[derive(Serialize)]

Check warning on line 8 in src/console/clients/udp/responses/dto.rs

View check run for this annotation

Codecov / codecov/patch

src/console/clients/udp/responses/dto.rs#L8

Added line #L8 was not covered by tests
pub enum ResponseDto {
Connect(ConnectResponseDto),
AnnounceIpv4(AnnounceResponseDto),
AnnounceIpv6(AnnounceResponseDto),
Scrape(ScrapeResponseDto),
Error(ErrorResponseDto),
pub enum SerializableResponse {
Connect(ConnectSerializableResponse),
AnnounceIpv4(AnnounceSerializableResponse),
AnnounceIpv6(AnnounceSerializableResponse),
Scrape(ScrapeSerializableResponse),
Error(ErrorSerializableResponse),
}

impl From<Response> for ResponseDto {
impl From<Response> for SerializableResponse {
fn from(response: Response) -> Self {
match response {
Response::Connect(response) => ResponseDto::Connect(ConnectResponseDto::from(response)),
Response::AnnounceIpv4(response) => ResponseDto::AnnounceIpv4(AnnounceResponseDto::from(response)),
Response::AnnounceIpv6(response) => ResponseDto::AnnounceIpv6(AnnounceResponseDto::from(response)),
Response::Scrape(response) => ResponseDto::Scrape(ScrapeResponseDto::from(response)),
Response::Error(response) => ResponseDto::Error(ErrorResponseDto::from(response)),
Response::Connect(response) => SerializableResponse::Connect(ConnectSerializableResponse::from(response)),
Response::AnnounceIpv4(response) => SerializableResponse::AnnounceIpv4(AnnounceSerializableResponse::from(response)),
Response::AnnounceIpv6(response) => SerializableResponse::AnnounceIpv6(AnnounceSerializableResponse::from(response)),
Response::Scrape(response) => SerializableResponse::Scrape(ScrapeSerializableResponse::from(response)),
Response::Error(response) => SerializableResponse::Error(ErrorSerializableResponse::from(response)),

Check warning on line 24 in src/console/clients/udp/responses/dto.rs

View check run for this annotation

Codecov / codecov/patch

src/console/clients/udp/responses/dto.rs#L18-L24

Added lines #L18 - L24 were not covered by tests
}
}

Check warning on line 26 in src/console/clients/udp/responses/dto.rs

View check run for this annotation

Codecov / codecov/patch

src/console/clients/udp/responses/dto.rs#L26

Added line #L26 was not covered by tests
}

#[derive(Serialize)]

Check warning on line 29 in src/console/clients/udp/responses/dto.rs

View check run for this annotation

Codecov / codecov/patch

src/console/clients/udp/responses/dto.rs#L29

Added line #L29 was not covered by tests
pub struct ConnectResponseDto {
pub struct ConnectSerializableResponse {
transaction_id: i32,
connection_id: i64,
}

impl From<ConnectResponse> for ConnectResponseDto {
impl From<ConnectResponse> for ConnectSerializableResponse {
fn from(connect: ConnectResponse) -> Self {

Check warning on line 36 in src/console/clients/udp/responses/dto.rs

View check run for this annotation

Codecov / codecov/patch

src/console/clients/udp/responses/dto.rs#L36

Added line #L36 was not covered by tests
Self {
transaction_id: connect.transaction_id.0.into(),
Expand All @@ -42,15 +42,15 @@ impl From<ConnectResponse> for ConnectResponseDto {
}

#[derive(Serialize)]

Check warning on line 44 in src/console/clients/udp/responses/dto.rs

View check run for this annotation

Codecov / codecov/patch

src/console/clients/udp/responses/dto.rs#L44

Added line #L44 was not covered by tests
pub struct AnnounceResponseDto {
pub struct AnnounceSerializableResponse {
transaction_id: i32,
announce_interval: i32,
leechers: i32,
seeders: i32,
peers: Vec<String>,
}

impl From<AnnounceResponse<Ipv4AddrBytes>> for AnnounceResponseDto {
impl From<AnnounceResponse<Ipv4AddrBytes>> for AnnounceSerializableResponse {
fn from(announce: AnnounceResponse<Ipv4AddrBytes>) -> Self {
Self {
transaction_id: announce.fixed.transaction_id.0.into(),
Expand All @@ -66,7 +66,7 @@ impl From<AnnounceResponse<Ipv4AddrBytes>> for AnnounceResponseDto {
}

Check warning on line 66 in src/console/clients/udp/responses/dto.rs

View check run for this annotation

Codecov / codecov/patch

src/console/clients/udp/responses/dto.rs#L66

Added line #L66 was not covered by tests
}

impl From<AnnounceResponse<Ipv6AddrBytes>> for AnnounceResponseDto {
impl From<AnnounceResponse<Ipv6AddrBytes>> for AnnounceSerializableResponse {
fn from(announce: AnnounceResponse<Ipv6AddrBytes>) -> Self {
Self {
transaction_id: announce.fixed.transaction_id.0.into(),
Expand All @@ -83,12 +83,12 @@ impl From<AnnounceResponse<Ipv6AddrBytes>> for AnnounceResponseDto {
}

#[derive(Serialize)]

Check warning on line 85 in src/console/clients/udp/responses/dto.rs

View check run for this annotation

Codecov / codecov/patch

src/console/clients/udp/responses/dto.rs#L85

Added line #L85 was not covered by tests
pub struct ScrapeResponseDto {
pub struct ScrapeSerializableResponse {
transaction_id: i32,
torrent_stats: Vec<TorrentStats>,
}

impl From<ScrapeResponse> for ScrapeResponseDto {
impl From<ScrapeResponse> for ScrapeSerializableResponse {
fn from(scrape: ScrapeResponse) -> Self {
Self {
transaction_id: scrape.transaction_id.0.into(),
Expand All @@ -106,12 +106,12 @@ impl From<ScrapeResponse> for ScrapeResponseDto {
}

#[derive(Serialize)]

Check warning on line 108 in src/console/clients/udp/responses/dto.rs

View check run for this annotation

Codecov / codecov/patch

src/console/clients/udp/responses/dto.rs#L108

Added line #L108 was not covered by tests
pub struct ErrorResponseDto {
pub struct ErrorSerializableResponse {
transaction_id: i32,
message: String,
}

impl From<ErrorResponse> for ErrorResponseDto {
impl From<ErrorResponse> for ErrorSerializableResponse {
fn from(error: ErrorResponse) -> Self {
Self {
transaction_id: error.transaction_id.0.into(),
Expand Down
4 changes: 2 additions & 2 deletions src/console/clients/udp/responses/json.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use anyhow::Context;
use serde::Serialize;

use super::dto::ResponseDto;
use super::dto::SerializableResponse;

pub trait ToJson {
///
Expand All @@ -21,4 +21,4 @@ pub trait ToJson {
}

Check warning on line 21 in src/console/clients/udp/responses/json.rs

View check run for this annotation

Codecov / codecov/patch

src/console/clients/udp/responses/json.rs#L20-L21

Added lines #L20 - L21 were not covered by tests
}

impl ToJson for ResponseDto {}
impl ToJson for SerializableResponse {}

0 comments on commit 32416ee

Please sign in to comment.