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

<Gateway>|added product front store handler and category handler|<Pooja> #34

Open
wants to merge 47 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
44f8d6c
<Payment> | setup and add healthCheck | <nitesh>
nitesh585 Apr 9, 2022
25e454f
<Payment> | setup and add healthCheck | <nitesh>
nitesh585 Apr 12, 2022
f066856
<Payment> | setup infra and domain | <nitesh>
nitesh585 Apr 13, 2022
c1af9c0
Update README.md
nitesh585 Apr 13, 2022
5fd5678
Update README.md
nitesh585 Apr 13, 2022
61fa1b2
<Payment> | implement dynamo repository | <nitesh>
nitesh585 Apr 14, 2022
95c1a1a
Merge branch 'payment' of https://github.com/swiggy-2022-bootcamp/cdp…
nitesh585 Apr 14, 2022
81618df
<Payment> | add create payment record [post]:/pay/ | <nitesh>
nitesh585 Apr 14, 2022
5b76790
<Payment> | add get payment record by id [get]:/pay/:id | <nitesh>
nitesh585 Apr 14, 2022
c4f52df
<Payment> | update infra for paymentMethod services | <nitesh>
nitesh585 Apr 15, 2022
007055c
<Payment> | add all routes of paymentMethods, get and post | <nitesh>
nitesh585 Apr 15, 2022
81dd772
<Payment> | add domain services mocks | <nitesh>
nitesh585 Apr 15, 2022
9cda638
<Payment> | resturn payment link as response /pay | <nitesh>
nitesh585 Apr 16, 2022
dbd9a07
<Payment> | code refactor | <nitesh>
nitesh585 Apr 16, 2022
f818c1a
<Payment> | add testing [coverage - 56%] | <nitesh>
nitesh585 Apr 16, 2022
a63ddb7
<Checkout> | setup and add healthCheck | <nitesh>
nitesh585 Apr 16, 2022
4019fa0
<Checkout> | remove readme.md | <nitesh>
nitesh585 Apr 16, 2022
13d6004
<Checkout> | setup gRPC proto and code-gen | <nitesh>
nitesh585 Apr 16, 2022
fd3767c
<Checkout> | gRPC POC of orderOverview | <nitesh>
nitesh585 Apr 17, 2022
2784524
<Checkout> | add logger(logrus) and code refactor | <nitesh>
nitesh585 Apr 17, 2022
f4eb1fb
<Payment> | add logger [logrus] | <nitesh>
nitesh585 Apr 17, 2022
cd6ca92
<Payment> | add kafka and produce kafka message after payment done |…
nitesh585 Apr 17, 2022
a64a628
User (#8)
swastiksahoo153 Apr 17, 2022
4cd3793
<user> | renamed User to user | <Murtaza, Swastik>
murtaza896 Apr 17, 2022
d5d3c24
Merge pull request #2 from swiggy-2022-bootcamp/payment
nitesh585 Apr 18, 2022
7c022df
Merge pull request #3 from swiggy-2022-bootcamp/checkout
nitesh585 Apr 18, 2022
7100d1d
Create README.md
nitesh585 Apr 18, 2022
1492fb7
Update Dockerfile
nitesh585 Apr 18, 2022
9c874ea
<gateway> | First Commit | <Murtaza>
murtaza896 Apr 23, 2022
c6d389c
<gateway> | Second Commit | <Murtaza>
murtaza896 Apr 23, 2022
1344689
<Gateway> | Add validate function | <Murtaza, Swastik>
swastiksahoo153 Apr 23, 2022
a302641
<gateway> | Cleans validation logic | <Murtaza>
murtaza896 Apr 24, 2022
4fb2e8d
<gateway> | Cleans validation logic | <Murtaza>
murtaza896 Apr 24, 2022
c4509ca
<auth> | scaffolding for auth with gateway | <Murtaza>
murtaza896 Apr 24, 2022
ddc27e9
<auth> | scaffolding for auth with gateway | <Murtaza>
murtaza896 Apr 24, 2022
e93c36a
<auth> | scaffolding for auth with gateway | <Murtaza>
murtaza896 Apr 24, 2022
5b14c22
<gateway> | changed port to 8000 | <Murtaza>
murtaza896 Apr 24, 2022
7dd7c69
<Gateway> | Handle get user | <swastik>
swastiksahoo153 Apr 24, 2022
77760f9
<Gateway> | Added get and post user handler | <swastik>
swastiksahoo153 Apr 24, 2022
081a33d
<Gateway> | Added User handlers | <swastik>
swastiksahoo153 Apr 24, 2022
23c318c
Merge branch 'gateway' of https://github.com/swiggy-2022-bootcamp/cdp…
swastiksahoo153 Apr 24, 2022
c47d53f
<Gateway> | Added Order Handler | <Suhas>
suhassuhas Apr 25, 2022
8a0eeb4
<Gateway>|Added Product admin handler|<Pooja>
poojasethia Apr 26, 2022
19af6ed
<Gateway>|Added Payment handler|<Nitesh>
nitesh585 Apr 26, 2022
68fa59d
<Gateway>|added product front store handler and category handler|<Pooja>
poojasethia Apr 30, 2022
128d4c0
<gateway> | modifies router for products handler | <Murtaza>
murtaza896 Apr 30, 2022
131bc7a
<gateway> | dockerfile fix | <Murtaza>
murtaza896 Apr 30, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 0 additions & 15 deletions .gitignore

This file was deleted.

2 changes: 0 additions & 2 deletions README.md

This file was deleted.

9 changes: 9 additions & 0 deletions gateway/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
PORT=8000
AUTH_SERVICE_URI=http://34.228.112.42:8001
USER_SERVICE_URI=http://34.228.112.42:8002
PRODUCT_FRONT_STORE_SERVICE_URI=http://34.228.112.42:8003
PRODUCT_ADMIN_SERVICE_URI=http://34.228.112.42:8004
CATEGORY_SERVICE_URI=http://34.228.112.42:8005
ORDER_SERVICE_URI=http://34.228.112.42:8007
PAYMENT_SERVICE_URI=http://34.228.112.42:8008
SHIPPING_SERVICE_URI=http://34.228.112.42:8012
31 changes: 31 additions & 0 deletions gateway/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
##
## Build
##

FROM golang:1.18-alpine AS build

WORKDIR /app

COPY go.mod .
COPY go.sum .
RUN go mod download

COPY . .

RUN go build -o gateway-app main.go

##
## Deploy
##

FROM alpine

WORKDIR /

COPY --from=build /app/gateway-app /gateway-app

COPY .env .env

EXPOSE 8000

ENTRYPOINT ["/gateway-app"]
36 changes: 36 additions & 0 deletions gateway/app/app.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package app

import (
"fmt"
"log"
"os"

"github.com/joho/godotenv"
)

func Start() {
RegisterUserRoutes()
RegisterOrderRoutes()
RegisterShippingRoutes()
RegisterProductAdminRoutes()
RegisterProductFrontStoreRoutes()
RegisterCategoryRoutes()
RegisterPaymentRoutes()

err := godotenv.Load(".env")
if err != nil {
log.Fatal(err)
return
}

if err != nil {
log.Fatalf("Error loading .env file")
}
PORT := os.Getenv("PORT")
fmt.Print(PORT)

err = Router.Run(":8000")
if err != nil {
return
}
}
96 changes: 96 additions & 0 deletions gateway/app/authMiddleware.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
package app

import (
"context"
"encoding/json"
"github.com/gin-gonic/gin"
"github.com/swiggy-2022-bootcamp/cdp-team4/gateway/utils/errs"
"log"
"net/http"
"os"
"time"
)

type AuthModel struct {
UserId string
Role int
}

type ValidationDTO struct {
UserId string `json:"user_id"`
Role int `json:"role"`
}

func ValidateToken(authorizationHeader string) (*AuthModel, *errs.AppError) {
authServiceUri := os.Getenv("AUTH_SERVICE_URI")
validateTokenApi := "/api/v1/validate"

req, err := http.NewRequest("GET", authServiceUri+validateTokenApi, nil)
if err != nil {
log.Fatalf("%v", err)
}

ctx, cancel := context.WithTimeout(req.Context(), 1*time.Minute)
defer cancel()

req = req.WithContext(ctx)
req.Header.Set("Authorization", authorizationHeader)
client := http.DefaultClient
res, err := client.Do(req)
if err != nil {
//log.Fatalf("%v", err)
return nil, errs.NewAuthenticationError(err.Error())
}

var resDTO ResponseDTO
err = json.NewDecoder(res.Body).Decode(&resDTO)

if err != nil {
//log.Fatalf("unable to decode response %v", err)
return nil, errs.NewUnexpectedError(err.Error())
}

if resDTO.Status == http.StatusUnauthorized {
return nil, errs.NewAuthenticationError(resDTO.Message)
}

var valDTO ValidationDTO
marshalledData, _ := json.Marshal(resDTO.Data)
err = json.Unmarshal(marshalledData, &valDTO)
if err != nil {
return nil, errs.NewAuthenticationError(err.Error())
}

return &AuthModel{
UserId: valDTO.UserId,
Role: valDTO.Role,
}, nil
}

func ValidateAuthToken() gin.HandlerFunc {
return func(c *gin.Context) {
res, err := ValidateToken(c.Request.Header.Get("Authorization"))

if err != nil {
response := ResponseDTO{
Status: err.Code,
Message: err.Message,
}
c.JSON(response.Status, response)
c.Abort()
return
}

c.Params = append(c.Params, gin.Param{
Key: "userId",
Value: res.UserId,
})

isAdmin := "false"
if res.Role == 1 {
isAdmin = "true"
}

c.Request.Header.Set("admin", isAdmin)
}
}
Loading