Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor: rename peer.updated field in torrent detail endpoint #61

Closed
josecelano opened this issue Aug 11, 2022 · 1 comment · Fixed by #119
Closed

Refactor: rename peer.updated field in torrent detail endpoint #61

josecelano opened this issue Aug 11, 2022 · 1 comment · Fixed by #119
Labels
Code Cleanup / Refactoring Tidying and Making Neat

Comments

@josecelano
Copy link
Member

pub struct TorrentPeer {
    pub peer_id: PeerId,
    pub peer_addr: SocketAddr,
    #[serde(serialize_with = "ser_instant")]
    pub updated: std::time::Instant,
    #[serde(with = "NumberOfBytesDef")]
    pub uploaded: NumberOfBytes,
    #[serde(with = "NumberOfBytesDef")]
    pub downloaded: NumberOfBytes,
    #[serde(with = "NumberOfBytesDef")]
    pub left: NumberOfBytes,
    #[serde(with = "AnnounceEventDef")]
    pub event: AnnounceEvent,
}

@WarmBeer , would not it be nice to rename the updated field like this:

#[serde(serialize_with = "ser_instant")]
#[serde(rename(deserialize = "updated_milliseconds_ago", serialize = "updated_milliseconds_ago"))]
pub updated: std::time::Instant,

To get a json like this:

{
  "info_hash": "4beb7001cb833968582c67f55cc59dcc6c8d3fe5",
  "seeders": 1,
  "completed": 0,
  "leechers": 0,
  "peers": [
    {
      "peer_id": {
        "id": "2d7142343431302d7358376d33786d2877674179",
        "client": "qBittorrent"
      },
      "peer_addr": "192.168.1.88:17548",
      "updated_milliseconds_ago": 385,
      "uploaded": 0,
      "downloaded": 0,
      "left": 0,
      "event": "None"
    }
  ]
}

I generally like to add the units in the attribute name.

We can use any other name like: not_updated_duration_in_msecs, not_updated_duration_in_msecs, ...

Originally posted by @josecelano in #60 (comment)

@josecelano josecelano added the Code Cleanup / Refactoring Tidying and Making Neat label Aug 11, 2022
@josecelano
Copy link
Member Author

It seems the backend does not use it:

https://github.com/torrust/torrust-index-backend/blob/8fbbb5ba3a80d1206e56a82391cc49740e803f54/src/tracker.rs#L22

so it would be safe to rename it, at least for other projects in the organization. It's a breaking change for external projects using only this tracker.

@josecelano josecelano linked a pull request Nov 25, 2022 that will close this issue
4 tasks
josecelano added a commit that referenced this issue Nov 29, 2022
…point

e1b84f6 refactor: [#61] extract struct ApiClient for API testing (Jose Celano)
bc3d246 feat(api): in torrent endpoint rename field  to (Jose Celano)
7e03714 refactor: [#61] use StatsResource in API stats endpoint (Jose Celano)
b974ce0 refactor: [#61] use TorrentListItemResource in torrent list API endpoint (Jose Celano)
284c91b test: [#61] add e2e test for torrent list API endpoint (Jose Celano)
7298701 refactor: [#61] extract converter from TorrentPeer to TorrentPeerResource (Jose Celano)
801dfe6 refactor: [#61] use TorrentResource in torrent info API endpoint (Jose Celano)
ea92ceb test: [#61] add e2e test to API torrent info endpoint before refactoring (Jose Celano)

Pull request description:

  TODO:

  - [x] Add an e2e test before refactoring.
  - [x] Refactor the API endpoint to use the resource `TorrentResource` like `AuthKeyResource`.
  - [x] Refactor endpoint ` /api/torrents?offset=:u32&limit=:u32` to use `TorrentResource`.
  - [x] Add a new field (`updated_milliseconds_ago`) to the JSON response keeping the old one for backwards compatibility.

ACKs for top commit:
  josecelano:
    ACK e1b84f6
  da2ce7:
    ACK e1b84f6

Tree-SHA512: be96ae16aa4214e600d6679f35a47ec3b95132ee8243352a11f7aca579a2a000843591556b8279abd073a9cb1079d32b961ee3c71892d4d925fcd202be2826a8
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Code Cleanup / Refactoring Tidying and Making Neat
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

1 participant