Skip to content
This repository has been archived by the owner on Dec 5, 2023. It is now read-only.

Commit

Permalink
Merge branch 'master' into monitoring/prometheus
Browse files Browse the repository at this point in the history
  • Loading branch information
philwinder committed Sep 23, 2016
2 parents 3ae2015 + f5af6b3 commit b2b4063
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 13 deletions.
12 changes: 8 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ dockertravisbuild: build
docker login -u $(DOCKER_USER) -p $(DOCKER_PASS)
scripts/push.sh


mockservice:
docker run -d --name user-mock -h user-mock -v $(PWD)/apispec/mock.json:/data/db.json clue/json-server

dockertest: dockerruntest
scripts/testcontainer.sh
docker run -h openapi --rm --name $(OPENAPI) --link user-dev -v $(PWD)/apispec/:/tmp/specs/\
Expand All @@ -71,10 +75,10 @@ dockertest: dockerruntest
$(MAKE) cleandocker

cleandocker:
-docker stop $(INSTANCE)-dev
-docker stop my$(TESTDB)
-docker rm my$(TESTDB)
-docker rm $(INSTANCE)-dev
-docker rm -f my$(TESTDB)
-docker rm -f $(INSTANCE)-dev
-docker rm -f $(OPENAPI)
-docker rm -f user-mock

clean: cleandocker
rm -rf bin
Expand Down
10 changes: 6 additions & 4 deletions api/endpoints.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func MakeLoginEndpoint(s Service) endpoint.Endpoint {
func MakeRegisterEndpoint(s Service) endpoint.Endpoint {
return func(ctx context.Context, request interface{}) (response interface{}, err error) {
req := request.(registerRequest)
id, err := s.Register(req.Username, req.Password, req.Email)
id, err := s.Register(req.Username, req.Password, req.Email, req.FirstName, req.LastName)
return postResponse{ID: id}, err
}
}
Expand Down Expand Up @@ -204,9 +204,11 @@ type cardsResponse struct {
}

type registerRequest struct {
Username string `json:"username"`
Password string `json:"password"`
Email string `json:"email"`
Username string `json:"username"`
Password string `json:"password"`
Email string `json:"email"`
FirstName string `json:"firstName"`
LastName string `json:"lastName"`
}

type statusResponse struct {
Expand Down
4 changes: 2 additions & 2 deletions api/middlewares.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func (mw loggingMiddleware) Login(username, password string) (user users.User, e
return mw.next.Login(username, password)
}

func (mw loggingMiddleware) Register(username, password, email string) (string, error) {
func (mw loggingMiddleware) Register(username, password, email, first, last string) (string, error) {
defer func(begin time.Time) {
mw.logger.Log(
"method", "Register",
Expand All @@ -45,7 +45,7 @@ func (mw loggingMiddleware) Register(username, password, email string) (string,
"took", time.Since(begin),
)
}(time.Now())
return mw.next.Register(username, password, email)
return mw.next.Register(username, password, email, first, last)
}

func (mw loggingMiddleware) PostUser(user users.User) (id string, err error) {
Expand Down
6 changes: 4 additions & 2 deletions api/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ var (
// Service is the user service, providing operations for users to login, register, and retrieve customer information.
type Service interface {
Login(username, password string) (users.User, error) // GET /login
Register(username, password, email string) (string, error)
Register(username, password, email, first, last string) (string, error)
GetUsers(id string) ([]users.User, error)
PostUser(u users.User) (string, error)
GetAddresses(id string) ([]users.Address, error)
Expand Down Expand Up @@ -51,11 +51,13 @@ func (s *fixedService) Login(username, password string) (users.User, error) {

}

func (s *fixedService) Register(username, password, email string) (string, error) {
func (s *fixedService) Register(username, password, email, first, last string) (string, error) {
u := users.New()
u.Username = username
u.Password = calculatePassHash(password, u.Salt)
u.Email = email
u.FirstName = first
u.LastName = last
err := db.CreateUser(&u)
return u.UserID, err
}
Expand Down
2 changes: 1 addition & 1 deletion apispec/hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ hooks.before("/register > POST", function(transaction, done) {
transaction.request.headers['Content-Type'] = 'application/json';
transaction.request.body = JSON.stringify(
{
"username":"testuser",
"username": "testuser",
"password": "testpassword"
}
);
Expand Down
27 changes: 27 additions & 0 deletions apispec/mock.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"customers": [
{ "id": "57a98d98e4b00679b4a830af",
"firstName": "Test",
"lastname": "Test",
"username": "testymctestface"
}
],
"cards": [
{
"id": "57a98d98e4b00679b4a830ae",
"longNum": "23232*****2131",
"expires": "12/18",
"ccv": "940"
}
],
"addresses": [
{
"id": "57a98d98e4b00679b4a830ad",
"number": "12",
"street": "Cleverstreet",
"city": "Tinytown",
"postcode": "1923eq",
"country": "Cambodia"
}
]
}

0 comments on commit b2b4063

Please sign in to comment.