From 701b4e26a5348a3c07dab06a617a1091dce33829 Mon Sep 17 00:00:00 2001 From: Arnav Sankaran Date: Sun, 5 Aug 2018 15:11:23 -0500 Subject: [PATCH 1/2] Add created and updated timestamps to registration --- .../registration/controller/controller.go | 25 +++++++++++++++++++ .../models/mentor_registration.go | 2 ++ .../registration/models/user_registration.go | 2 ++ .../registration/tests/registration_test.go | 4 +++ 4 files changed, 33 insertions(+) diff --git a/services/registration/controller/controller.go b/services/registration/controller/controller.go index d2ae2d80..21532a4d 100644 --- a/services/registration/controller/controller.go +++ b/services/registration/controller/controller.go @@ -8,6 +8,7 @@ import ( "github.com/gorilla/mux" "github.com/justinas/alice" "net/http" + "time" ) func SetupController(route *mux.Route) { @@ -109,6 +110,9 @@ func CreateCurrentUserRegistration(w http.ResponseWriter, r *http.Request) { user_registration.FirstName = user_info.FirstName user_registration.LastName = user_info.LastName + user_registration.CreatedAt = time.Now().Unix() + user_registration.UpdatedAt = time.Now().Unix() + err = service.CreateUserRegistration(id, user_registration) if err != nil { @@ -165,11 +169,20 @@ func UpdateCurrentUserRegistration(w http.ResponseWriter, r *http.Request) { panic(errors.UnprocessableError(err.Error())) } + original_registration, err := service.GetUserRegistration(id) + + if err != nil { + panic(errors.UnprocessableError(err.Error())) + } + user_registration.GitHub = user_info.Username user_registration.Email = user_info.Email user_registration.FirstName = user_info.FirstName user_registration.LastName = user_info.LastName + user_registration.CreatedAt = original_registration.CreatedAt + user_registration.UpdatedAt = time.Now().Unix() + err = service.UpdateUserRegistration(id, user_registration) if err != nil { @@ -247,6 +260,9 @@ func CreateCurrentMentorRegistration(w http.ResponseWriter, r *http.Request) { mentor_registration.FirstName = user_info.FirstName mentor_registration.LastName = user_info.LastName + mentor_registration.CreatedAt = time.Now().Unix() + mentor_registration.UpdatedAt = time.Now().Unix() + err = service.CreateMentorRegistration(id, mentor_registration) if err != nil { @@ -289,11 +305,20 @@ func UpdateCurrentMentorRegistration(w http.ResponseWriter, r *http.Request) { panic(errors.UnprocessableError(err.Error())) } + original_registration, err := service.GetMentorRegistration(id) + + if err != nil { + panic(errors.UnprocessableError(err.Error())) + } + mentor_registration.GitHub = user_info.Username mentor_registration.Email = user_info.Email mentor_registration.FirstName = user_info.FirstName mentor_registration.LastName = user_info.LastName + mentor_registration.CreatedAt = original_registration.CreatedAt + mentor_registration.UpdatedAt = time.Now().Unix() + err = service.UpdateMentorRegistration(id, mentor_registration) if err != nil { diff --git a/services/registration/models/mentor_registration.go b/services/registration/models/mentor_registration.go index a2cccce1..d7dfc020 100644 --- a/services/registration/models/mentor_registration.go +++ b/services/registration/models/mentor_registration.go @@ -8,4 +8,6 @@ type MentorRegistration struct { ShirtSize string `json:"shirtSize" validate:"required,oneof=S M L XL"` GitHub string `json:"github" validate:"required"` Linkedin string `json:"linkedin" validate:"required"` + CreatedAt int64 `json:"createdAt" validate:"required"` + UpdatedAt int64 `json:"updatedAt" validate:"required"` } diff --git a/services/registration/models/user_registration.go b/services/registration/models/user_registration.go index 102fa212..5d91cdc0 100644 --- a/services/registration/models/user_registration.go +++ b/services/registration/models/user_registration.go @@ -24,6 +24,8 @@ type UserRegistration struct { ExtraInfos []UserExtraInfo `json:"extraInfos" validate:"required,dive,required"` OsContributors []UserOsContributor `json:"osContributors" validate:"required,dive,required"` Collaborators []UserCollaborator `json:"collaborators" validate:"required,dive,required"` + CreatedAt int64 `json:"createdAt" validate:"required"` + UpdatedAt int64 `json:"updatedAt" validate:"required"` } type UserLongForm struct { diff --git a/services/registration/tests/registration_test.go b/services/registration/tests/registration_test.go index 384d6c46..41f55d2b 100644 --- a/services/registration/tests/registration_test.go +++ b/services/registration/tests/registration_test.go @@ -349,6 +349,8 @@ var base_user_registration models.UserRegistration = models.UserRegistration{ Github: "collaboratorgithub", }, }, + CreatedAt: 10, + UpdatedAt: 15, } var base_mentor_registration models.MentorRegistration = models.MentorRegistration{ @@ -359,4 +361,6 @@ var base_mentor_registration models.MentorRegistration = models.MentorRegistrati ShirtSize: "M", GitHub: "githubusername", Linkedin: "linkedinusername", + CreatedAt: 10, + UpdatedAt: 15, } From b90e4326d77a5eb4946795bfa316e33ac634fbaa Mon Sep 17 00:00:00 2001 From: Arnav Sankaran Date: Sun, 5 Aug 2018 15:11:38 -0500 Subject: [PATCH 2/2] Fix issues with run script --- scripts/run.sh | 39 ++++++++++++--------------------------- 1 file changed, 12 insertions(+), 27 deletions(-) diff --git a/scripts/run.sh b/scripts/run.sh index ebcfbd38..34f7f7ae 100755 --- a/scripts/run.sh +++ b/scripts/run.sh @@ -4,25 +4,11 @@ trap cleanup INT function cleanup { echo "Cleaning up services" - pgrep "api" | xargs kill + pgrep "hackillinois-" | xargs kill rm -rf log/ exit 0 } -function install { - go install github.com/HackIllinois/api-gateway - go install github.com/HackIllinois/api-auth - go install github.com/HackIllinois/api-user - go install github.com/HackIllinois/api-registration - go install github.com/HackIllinois/api-decision - go install github.com/HackIllinois/api-rsvp - go install github.com/HackIllinois/api-checkin - go install github.com/HackIllinois/api-upload - go install github.com/HackIllinois/api-mail - go install github.com/HackIllinois/api-event - go install github.com/HackIllinois/api-stat -} - function auth { export GITHUB_CLIENT_ID= export GITHUB_CLIENT_SECRET= @@ -37,7 +23,7 @@ function auth { export AUTH_PORT=:8002 export USER_SERVICE=http://localhost:8003 - api-auth & + hackillinois-api-auth & } function user { @@ -45,7 +31,7 @@ function user { export USER_DB_NAME=user export USER_PORT=:8003 - api-user & + hackillinois-api-user & } function registration { @@ -57,7 +43,7 @@ function registration { export DECISION_SERVICE=http://localhost:8005 export MAIL_SERVICE=http://localhost:8009 - api-registration & + hackillinois-api-registration & } function decision { @@ -66,7 +52,7 @@ function decision { export DECISION_PORT=:8005 export MAIL_SERVICE=http://localhost:8009 - api-decision & + hackillinois-api-decision & } function rsvp { @@ -77,7 +63,7 @@ function rsvp { export DECISION_SERVICE=http://localhost:8005 export MAIL_SERVICE=http://localhost:8009 - api-rsvp & + hackillinois-api-rsvp & } function checkin { @@ -87,7 +73,7 @@ function checkin { export RSVP_SERVICE=http://localhost:8006 export REGISTRATION_SERVICE=http://localhost:8004 - api-checkin & + hackillinois-api-checkin & } function upload { @@ -95,7 +81,7 @@ function upload { export S3_REGION=us-east-1 export S3_BUCKET=hackillinois-upload-2019 - api-upload & + hackillinois-api-upload & } function mail { @@ -105,7 +91,7 @@ function mail { export USER_SERVICE=http://localhost:8003 export MAIL_PORT=:8009 - api-mail & + hackillinois-api-mail & } function event { @@ -114,7 +100,7 @@ function event { export EVENT_PORT=:8010 export CHECKIN_SERVICE=http://localhost:8007 - api-event & + hackillinois-api-event & } function stat { @@ -122,7 +108,7 @@ function stat { export STAT_DB_NAME=stat export STAT_PORT=:8011 - api-stat & + hackillinois-api-stat & } function gateway { @@ -142,10 +128,9 @@ function gateway { mkdir log/ touch log/access.log - api-gateway -u & + hackillinois-api-gateway -u & } -install auth user registration