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

feat: added network service - handler and receiver #403

Open
wants to merge 12 commits into
base: beckn-onix-v1.0-develop
Choose a base branch
from

Conversation

rupinder-syngh
Copy link

  • Added network handler
  • Added network receiver

@@ -0,0 +1,30 @@
package config
Copy link
Collaborator

Choose a reason for hiding this comment

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

this does not need to be a separate package. Move this file to the parent folder and change the package to be main.

log.Println("No .env file found, using default values")
}

return &Config{
Copy link
Collaborator

Choose a reason for hiding this comment

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

Config will be parsed from a confg.yaml file, please refer to Mayur's PR for reference.

"beckn-onix/cmd/networkSideHandler/config"
)

type CreateUserRequest struct {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why do we need to to this, please do the bare minimum need, for this change we should not do anything other than adding a asingle route which will only accpet post calls and return OK 200


func CreateUserHandler(w http.ResponseWriter, r *http.Request) {
if r.Method != http.MethodPost {
http.Error(w, "Invalid request method", http.StatusMethodNotAllowed)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why are we doing all this ?

{"Valid request", `{"name": "John Doe", "email": "[email protected]"}`, http.StatusCreated},
{"Missing name", `{"email": "[email protected]"}`, http.StatusBadRequest},
{"Missing email", `{"name": "John Doe"}`, http.StatusBadRequest},
{"Invalid JSON", `{name: "John Doe", email: "[email protected]"}`, http.StatusBadRequest},
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please format this so this is more readable. basically one line should have just one field.

rr := httptest.NewRecorder()
CreateUserHandler(rr, req)

require.Equal(t, tc.expectedStatus, rr.Code, "Unexpected response status")
Copy link
Collaborator

Choose a reason for hiding this comment

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

please avoid using third party libraries for testing, and stick to using explicit comparisons using standard library features, use this for reference https://golang.cafe/blog/golang-table-test-example

}

func main() {
cfg := config.LoadConfig()
Copy link
Collaborator

Choose a reason for hiding this comment

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

main function should only call run method.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Same as the comments for the handler service

@rupinder-syngh
Copy link
Author

@ashishkgGoogle Coverage is 88.2%

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.

3 participants