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

Add 'Link' Field to Information in API Responses (Fixes #381) #398

Open
wants to merge 34 commits into
base: main
Choose a base branch
from

Conversation

Kai-Animator
Copy link

This pull request addresses Issue #381 by adding the Link field to the Information section in all API responses. The Link field provides a direct URL to the source data on the official Tibia website.

Changes Overview:

  • Updated Information Struct:
    • Added a new Link field to the Information struct in webserver.go:
      type Information struct {
          APIDetails APIDetails `json:"api"`       // The API details.
          Timestamp  string     `json:"timestamp"` // The timestamp from when the data was processed.
          Link       string     `json:"link"`      // The link to the source of the data.
          Status     Status     `json:"status"`    // The response status information.
      }
  • Modified API Handlers:
    • Updated all API endpoint handlers to populate the Link field with the appropriate URL pointing to the source data.

    • Example from TibiaWorldsWorld.go:

      return WorldResponse{
          World: World{
              // ... existing fields ...
          },
          Information: Information{
              APIDetails: TibiaDataAPIDetails,
              Timestamp:  TibiaDataDatetime(""),
              Link:       "https://www.tibia.com/community/?subtopic=worlds&world=" + world,
              Status: Status{
                  HTTPCode: http.StatusOK,
              },
          },
      }, nil

Testing:

  • Tested all modified endpoints to ensure the Link field is correctly populated.
  • Verified that the URLs are accurate and lead to the correct pages on Tibia.com.

Notes:

  • NewsList was kind of tricky to handle the different patterns so I decided to sum all different URLs into only "https://www.tibia.com/news/?subtopic=newsarchive"

  • This is my first PR in the project so I am open to feedback and willing to make any necessary changes to meet the project's standards.

@tobiasehlert tobiasehlert linked an issue Oct 15, 2024 that may be closed by this pull request
@tobiasehlert tobiasehlert self-requested a review October 15, 2024 18:11
@tobiasehlert tobiasehlert added enhancement New feature or request good first issue Good for newcomers go Pull requests that update Go code labels Oct 15, 2024
Copy link
Member

@tobiasehlert tobiasehlert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR @Kai-Animator, this is a good start!
There are some things that I'd like to be adjusted.

One of them is that there is already a link for every endpoints source available, so hardcoding the line in the "Link" field is not optimal. It would be better to have it being populated by the value set in "tibiadataRequest.URL" before being sent to tibiaDataRequestHandler.

For instance here:

func tibiaFansites(c *gin.Context) {
tibiadataRequest := TibiaDataRequestStruct{
Method: resty.MethodGet,
URL: "https://www.tibia.com/community/?subtopic=fansites",
}
tibiaDataRequestHandler(
c,
tibiadataRequest,
func(BoxContentHTML string) (interface{}, error) {
return TibiaFansitesImpl(BoxContentHTML)
},
"TibiaFansites")
}

I'd also like the "Link" to be named "TibiaURL" instead, since that's a slightly better description of that it is.
Also, we should probably want to have a []string as well, in case we add multi-upstream sources.

src/webserver.go Outdated
@@ -47,6 +47,7 @@ type OutInformation struct {
type Information struct {
APIDetails APIDetails `json:"api"` // The API details.
Timestamp string `json:"timestamp"` // The timestamp from when the data was processed.
Link string `json:"link"` // The link to the source of the data.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Link string `json:"link"` // The link to the source of the data.
TibiaURL []string `json:"tibia_url"` // The links to the sources of the data on tibia.com.

src/webserver.go Outdated
@@ -121,6 +122,7 @@ func runWebServer() {
data := Information{
APIDetails: TibiaDataAPIDetails,
Timestamp: TibiaDataDatetime(""),
Link: "-",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Link: "-",
TibiaURL: []string{},

src/webserver.go Outdated
@@ -1089,6 +1091,7 @@ func TibiaDataErrorHandler(c *gin.Context, err error, httpCode int) {
info := Information{
APIDetails: TibiaDataAPIDetails,
Timestamp: TibiaDataDatetime(""),
Link: "-",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Link: "-",
TibiaURL: []string{},

@Kai-Animator
Copy link
Author

Thanks for the review @tobiasehlert . I will work on it 👍

@Kai-Animator
Copy link
Author

Hi @tobiasehlert 👋

I’ve implemented the changes you requested:

  • The "Link" field is now populated using the value from tibiadataRequest.URL before it's sent to tibiaDataRequestHandler, rather than hardcoding the URL. (Newslist and HousesOverview might need refactor)
  • Renamed "Link" to "TibiaURL".
  • I've also updated the field to support a []string for multi-upstream sources in the future (HousesOverview is using multiple URLs now).

Please let me know if there’s anything else :]

@phenpessoa
Copy link
Contributor

Since this is now slice, I think it should probably be named TibiaURLs, plural.

@tobiasehlert
Copy link
Member

Yeah good input @phenpessoa. 👍

@phenpessoa
Copy link
Contributor

The field name was updated but the json is still called tibia_url. I think it should probably be tibia_urls.

@Kai-Animator
Copy link
Author

The field name was updated but the json is still called tibia_url. I think it should probably be tibia_urls.

Hey @phenpessoa, thanks for looking at the code, is this the change that you mentioned?

@phenpessoa
Copy link
Contributor

Yup! Looks good.

Copy link
Member

@tobiasehlert tobiasehlert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are getting closer! 🚀
The news endpoints just need some adjustment, but then we should be really to rock.

src/TibiaNews.go Outdated Show resolved Hide resolved
src/TibiaNews.go Outdated Show resolved Hide resolved
src/TibiaNews_test.go Outdated Show resolved Hide resolved
src/TibiaNews_test.go Outdated Show resolved Hide resolved
src/TibiaNews_test.go Outdated Show resolved Hide resolved
src/TibiaNews_test.go Outdated Show resolved Hide resolved
src/TibiaNewslist.go Outdated Show resolved Hide resolved
src/TibiaNewslist.go Outdated Show resolved Hide resolved
src/TibiaNewslist_test.go Outdated Show resolved Hide resolved
Copy link

sonarcloud bot commented Oct 28, 2024

@Kai-Animator
Copy link
Author

Thanks for the feedback @tobiasehlert, sorry search and replace all because I though you weren't using TibiaURL in other files. 🙇 Hope this revisions are satisfying.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request go Pull requests that update Go code good first issue Good for newcomers
Development

Successfully merging this pull request may close these issues.

Feature: Add link Property for Character from tibia.com Website
3 participants