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 the external package to use an interface #376

Merged
merged 13 commits into from
Mar 1, 2025

Conversation

ekefan
Copy link
Contributor

@ekefan ekefan commented Feb 27, 2025

Made request externally configurable to support integration with any external service in hng_boilerplate using the external interface SendExternalRequest

Description

Towards resolving #371:

  • Created an inteface for all external services.
  • Currently the only external service is implemented in ipstack/ but new external services can be defined in the external package and implemented following the SendExternalRequest interface
  • Updated ExternalRequest to function as a handler for all external services

Changes:

Modified

type ExternalRequest struct {
	Logger      *utility.Logger
	Test        bool
}

to

type ExternalRequest struct {
	Logger      *utility.Logger
	Test        bool
	Ipstack     *ipstack.IpstackRequest
	requestName string
}

Factory-based Initialization

New ExternalRequest will be created using a factory function, taking a logger and options.
Available options:

  • Use the ExternalRequest in test mode,
  • Use the ExternalRequest with ipstack as an external service for sending requests
  • Extendability: other external services can be defined, added as fields in ExternalRequest, and integrated as options during setup

Defined the interface for external services:

type SendExternalRequest interface {
   SetupExternalRequest(name string, data any) error
   SendRequest() (any, error)
}

Related Issue (Link to Github issue)

​Towards resolving #371

How Has This Been Tested?

Unit tested

Screenshots (if appropriate - Postman, etc):

Screenshot (18)
Screenshot (20)
Screenshot (21)

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My code follows the code style of this project.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

@samuelIkoli
Copy link

Looking good, you want to add proof of tests, screenshots

@ekefan ekefan marked this pull request as ready for review February 28, 2025 00:03
@ekefan
Copy link
Contributor Author

ekefan commented Feb 28, 2025

Looking good, you want to add proof of tests, screenshots

@samuelIkoli, I've added the tests, the changes I made did not affect endpoint handlers, so I don't think postman screenshots are necessary

@ihechiwilliams
Copy link

@ekefan Please add screenshot of existing functionalities still working after the refactor, like the calls going through

@ekefan
Copy link
Contributor Author

ekefan commented Mar 1, 2025

@ekefan Please add screenshot of existing functionalities still working after the refactor, like the calls going through

@ihechiwilliams, I have added screenshots of existing functionalities

@incredible-phoenix246 incredible-phoenix246 merged commit e177991 into hngprojects:dev Mar 1, 2025
4 checks passed
@ekefan ekefan deleted the interface-external branch March 1, 2025 16:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants