Skip to content

Commit

Permalink
feat: add register user rest endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
ochom committed Aug 27, 2021
1 parent 8fdf540 commit b28574d
Show file tree
Hide file tree
Showing 8 changed files with 593 additions and 91 deletions.
14 changes: 14 additions & 0 deletions pkg/onboarding/application/dto/input.go
Expand Up @@ -467,3 +467,17 @@ type RoleRevocationInput struct {
RoleID string
Reason string
}

// RegisterUserInput is the data required to creat a new user.
// this data can be used by cross service requests
type RegisterUserInput struct {
FirstName string `json:"lastName"`
LastName string `json:"firstName"`
Gender enumutils.Gender `json:"gender"`
PhoneNumber string `json:"phoneNumber"`
Email string `json:"email"`
DateOfBirth scalarutils.Date `json:"dateOfBirth"`
RoleIDs []string `json:"roleIDs"`
WelcomeMessage string `json:"welcomeMessage,omitempty"`
CreatedBy string `json:"createdBy,omitempty"`
}
8 changes: 8 additions & 0 deletions pkg/onboarding/application/dto/output.go
Expand Up @@ -161,3 +161,11 @@ type GroupedNavigationActions struct {
Primary []domain.NavigationAction `json:"primary,omitempty"`
Secondary []domain.NavigationAction `json:"secondary,omitempty"`
}

// RegisteredUserResponse is used to return by creating a new user in ISC
type RegisteredUserResponse struct {
ID string `json:"id,omitempty"`
DisplayName string `json:"displayName,omitempty"`
Email string `json:"email,omitempty"`
PhoneNumber string `json:"phoneNumber,omitempty"`
}
4 changes: 4 additions & 0 deletions pkg/onboarding/presentation/config.go
Expand Up @@ -336,6 +336,10 @@ func Router(ctx context.Context) (*mux.Router, error) {
// Interservice Authenticated routes
isc := r.PathPrefix("/internal").Subrouter()
isc.Use(interserviceclient.InterServiceAuthenticationMiddleware())
isc.Path("/register_user").Methods(
http.MethodPost,
http.MethodOptions).
HandlerFunc(h.RegisterUser())
isc.Path("/supplier").Methods(
http.MethodPost,
http.MethodOptions).
Expand Down
20 changes: 20 additions & 0 deletions pkg/onboarding/presentation/rest/handlers.go
Expand Up @@ -57,6 +57,8 @@ type HandlersInterfaces interface {
CreateRole() http.HandlerFunc
AssignRole() http.HandlerFunc
RemoveRoleByName() http.HandlerFunc

RegisterUser() http.HandlerFunc
}

// HandlersInterfacesImpl represents the usecase implementation object
Expand Down Expand Up @@ -1295,3 +1297,21 @@ func (h *HandlersInterfacesImpl) RemoveRoleByName() http.HandlerFunc {
serverutils.WriteJSONResponse(rw, nil, http.StatusOK)
}
}

// RegisterUser creates a new user profile using provided input
func (h *HandlersInterfacesImpl) RegisterUser() http.HandlerFunc {
return func(rw http.ResponseWriter, r *http.Request) {
ctx := r.Context()

input := &dto.RegisterUserInput{}
serverutils.DecodeJSONToTargetStruct(rw, r, input)

profile, err := h.interactor.Signup.RegisterUser(ctx, *input)
if err != nil {
serverutils.WriteJSONResponse(rw, err, http.StatusInternalServerError)
return
}

serverutils.WriteJSONResponse(rw, profile, http.StatusOK)
}
}

0 comments on commit b28574d

Please sign in to comment.