Skip to content

Commit

Permalink
Merge pull request #119 from Real-Dev-Squad/develop
Browse files Browse the repository at this point in the history
Dev to Main sync
  • Loading branch information
iamitprakash authored Jul 21, 2024
2 parents 25f377c + b5c89e5 commit e9e7f49
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ jobs:
docker run -d -p ${{vars.PORT}}:${{vars.PORT}} \
--name ${{ github.event.repository.name }}-${{vars.ENV}} \
--network=${{vars.DOCKER_NETWORK}} \
-e ENV=${{vars.ENV}} \
-e GIN_MODE=${{vars.GIN_MODE}} \
-e JWT_SECRET=${{secrets.JWT_SECRET}} \
-e JWT_VALIDITY_IN_HOURS=${{vars.JWT_VALIDITY_IN_HOURS}} \
Expand All @@ -66,4 +67,6 @@ jobs:
-e GOOGLE_CLIENT_SECRET=${{secrets.GOOGLE_CLIENT_SECRET}} \
-e GOOGLE_REDIRECT_URL=${{vars.GOOGLE_REDIRECT_URL}} \
-e ALLOWED_ORIGINS=${{vars.ALLOWED_ORIGINS}} \
-e TOKEN_VALIDITY_IN_SECONDS=${{vars.TOKEN_VALIDITY_IN_SECONDS}} \
-e USER_MAX_URL_COUNT=${{vars.USER_MAX_URL_COUNT}} \
${{ secrets.DOCKERHUB_USERNAME }}/${{ github.event.repository.name }}
1 change: 0 additions & 1 deletion cmd/bun/migrations/20240215113820_initial-setup.up.sql
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ CREATE TABLE users (
updated_at timestamp DEFAULT (NOW() AT TIME ZONE 'UTC'),
is_deleted boolean DEFAULT false,
is_onboarding BOOLEAN NOT NULL DEFAULT TRUE
url_count int NOT NULL DEFAULT 0
);

--bun:split
Expand Down
9 changes: 9 additions & 0 deletions cmd/bun/migrations/20240630181359_add_url_count.up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
BEGIN;

--bun:split

ALTER TABLE USERS ADD url_count int NOT NULL DEFAULT 0;

--bun:split

COMMIT;
7 changes: 7 additions & 0 deletions cmd/bun/migrations/20240630181359_remove_url_count.down.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
BEGIN;
--bun:split

ALTER TABLE USERS DROP COLUMN url_count;
--bun:split

COMMIT;
8 changes: 4 additions & 4 deletions config/core-config.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ import (

var (
Env string
MaxUrlCount int
UserMaxUrlCount int
Domain string
AuthRedirectUrl string
DbUrl string
DbMaxOpenConnections int
GoogleClientId string
GoogleClientSecret string
GoogleRedirectUrl string
TokenExpiration int
TokenValidity int
JwtSecret string
JwtValidity int
JwtIssuer string
Expand Down Expand Up @@ -96,8 +96,8 @@ func loadConfig() {
GoogleClientSecret = getEnvVar("GOOGLE_CLIENT_SECRET")
GoogleRedirectUrl = getEnvVar("GOOGLE_REDIRECT_URL")

MaxUrlCount = getEnvInt("Max_Url_Count")
TokenExpiration = getEnvInt("TokenExpiration")
UserMaxUrlCount = getEnvInt("USER_MAX_URL_COUNT")
TokenValidity = getEnvInt("TOKEN_VALIDITY_IN_SECONDS")

AllowedOrigin = getEnvVar("ALLOWED_ORIGINS")

Expand Down
2 changes: 1 addition & 1 deletion controllers/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ func GoogleCallback(ctx *gin.Context, db *bun.DB) {
ctx.JSON(http.StatusInternalServerError, gin.H{"message": "error"})
return
}
ctx.SetCookie("token", token, config.TokenExpiration, "/", domain, true, true)
ctx.SetCookie("token", token, config.TokenValidity, "/", domain, true, true)
ctx.Redirect(http.StatusFound, authRedirectUrl)
}

Expand Down
4 changes: 2 additions & 2 deletions controllers/url.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,9 @@ func CreateTinyURL(ctx *gin.Context, db *bun.DB) {
return
}

if count >= config.MaxUrlCount {
if count >= config.UserMaxUrlCount {
ctx.JSON(http.StatusForbidden, dtos.URLCreationResponse{
Message: "You've reached the limit of " + strconv.Itoa(config.MaxUrlCount) + " for URLs. Delete one to add a new one !!",
Message: "You've reached the limit of " + strconv.Itoa(config.UserMaxUrlCount) + " for URLs. Delete one to add a new one !!",
})
return
}
Expand Down
4 changes: 2 additions & 2 deletions environments/test.env
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ GOOGLE_CLIENT_ID="google-client-id"
GOOGLE_CLIENT_SECRET="google-client-secret"
GOOGLE_REDIRECT_URL="http://localhost:8000/v1/auth/google/callback"

Max_Url_Count=10
TokenExpiration=3600
USER_MAX_URL_COUNT=10
TOKEN_VALIDITY_IN_SECONDS=3600
ALLOWED_ORIGINS=*
PORT=8000

0 comments on commit e9e7f49

Please sign in to comment.