Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
f320274
Remove main branch code to put clean code here
Eclipsewebsite Jan 6, 2023
1e3467e
New fresh code added to dev branch
Jan 6, 2023
bd89bdd
Deploying to Heroku
Jan 6, 2023
90f09f9
env variable
Jan 6, 2023
4c2ca93
Update build.yml
EmmanuelEklipse Jan 24, 2023
edab13f
Update build.yml
EmmanuelEklipse Jan 24, 2023
19d73aa
Update build.yml
EmmanuelEklipse Jan 24, 2023
066ee5d
Update and rename build.yml to heroku-deploy-QA.yml
EmmanuelEklipse Jan 24, 2023
42db47a
Update heroku-deploy-QA.yml
EmmanuelEklipse Jan 25, 2023
460bcec
Create main.yml
EmmanuelEklipse Jan 25, 2023
febf42a
Rename main.yml to heroku-deploy-Prod.yml
EmmanuelEklipse Jan 25, 2023
a694dae
Merge branch 'main' into dev
Jan 27, 2023
243d97c
Update heroku-deploy-QA.yml
EmmanuelEklipse Jan 27, 2023
0b27f20
Update heroku-deploy-Prod.yml
EmmanuelEklipse Jan 27, 2023
704a839
.env removed
Jan 31, 2023
ed2b61a
feat(join,unjoin): Add join and unjoin endpoints
EmmanuelEklipse Feb 22, 2023
0ad26aa
fix join challenge function and also add check on unjoin function
EmmanuelEklipse Feb 28, 2023
db42492
Add mnemonic in challenge and also apply validation
EmmanuelEklipse Mar 5, 2023
99b56b7
add bet and steps endpoints
EmmanuelEklipse Mar 24, 2023
a6edfa1
complete reward endpoint
EmmanuelEklipse Mar 24, 2023
22c5f92
add new field of min bet amount on create challenge
EmmanuelEklipse Mar 27, 2023
e2a0a3d
modify winner endpoint and also modify update step endpoint
EmmanuelEklipse Apr 4, 2023
2b12abe
update list challenge api
EmmanuelEklipse May 20, 2023
d24674e
update
EmmanuelEklipse May 20, 2023
f2074a2
add bet in challenge
EmmanuelEklipse May 20, 2023
80325cd
update signup and token
EmmanuelEklipse Jul 15, 2023
6553416
modify join challenge api
EmmanuelEklipse Jul 16, 2023
d531d60
modify unjoin challenge
EmmanuelEklipse Jul 16, 2023
863647e
add two new apis
EmmanuelEklipse Jul 20, 2023
5736efc
fix bug
EmmanuelEklipse Jul 20, 2023
bb45815
update get api
EmmanuelEklipse Jul 23, 2023
0f47748
fix bug
EmmanuelEklipse Jul 23, 2023
cfae5fc
fix bug
EmmanuelEklipse Jul 23, 2023
c5e970c
setup docker
EmmanuelEklipse Jul 28, 2023
0ebdb93
setup docker
EmmanuelEklipse Jul 28, 2023
27bec0f
update create challenge response
EmmanuelEklipse Aug 2, 2023
29640e6
update create challenge response
EmmanuelEklipse Aug 2, 2023
a2b97ed
remove little bug
EmmanuelEklipse Aug 3, 2023
f5828a0
update username
EmmanuelEklipse Aug 4, 2023
2360de3
update username
EmmanuelEklipse Aug 4, 2023
e51c761
fix username bug
EmmanuelEklipse Aug 12, 2023
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
44 changes: 44 additions & 0 deletions .air.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
root = "."
testdata_dir = "testdata"
tmp_dir = ".bin"

[build]
args_bin = []
bin = "./.bin/main"
cmd = "go build -o ./.bin/main ."
delay = 0
exclude_dir = ["assets", ".bin", "vendor", "testdata"]
exclude_file = []
exclude_regex = ["_test.go"]
exclude_unchanged = false
follow_symlink = false
full_bin = ""
include_dir = []
include_ext = ["go", "tpl", "tmpl", "html"]
include_file = []
kill_delay = "0s"
log = "build-errors.log"
poll = false
poll_interval = 0
rerun = false
rerun_delay = 500
send_interrupt = false
stop_on_error = false

[color]
app = ""
build = "yellow"
main = "magenta"
runner = "green"
watcher = "cyan"

[log]
main_only = false
time = false

[misc]
clean_on_exit = false

[screen]
clear_on_rebuild = false
keep_scroll = true
3 changes: 3 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
PORT=8080
MONGO_URL=mongodb+srv://root:root@cluster0.jgltqbs.mongodb.net/?retryWrites=true&w=majority
JWT_SECRET=secret
36 changes: 0 additions & 36 deletions .github/workflows/build.yml

This file was deleted.

51 changes: 51 additions & 0 deletions .github/workflows/heroku-deploy-Prod.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: Prod - Heroku Deploy

on:
# Job Trigger automatically if any PR is closed for main branch
pull_request:
branches:
- dev
types: [ closed ]
# Enabled Manual Trigger
workflow_dispatch:
jobs:

build-deploy:
name: Deploy
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: 1.19

- name: Cache
uses: actions/cache@v3
with:
# In order:
# * Module download cache
# * Build cache (Linux)
path: |
~/go/pkg/mod
~/.cache/go-build
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-

- name: Build
run: go build -v ./...

- name: Test
run: go test -v ./...

- name: Deploy API -> Prod
uses: akhileshns/heroku-deploy@v3.12.12
with:
heroku_api_key: ${{secrets.HEROKU_API_KEY}}
heroku_app_name: "challenge-api"
heroku_email: ${{secrets.HEROKU_EMAIL}}
branch: dev
# env_file: .env.default
50 changes: 50 additions & 0 deletions .github/workflows/heroku-deploy-QA.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: QA - Heroku Deploy

on:
# Job Trigger automatically if any code push/PR to QA branch
push:
branches:
- QA
# Enabled Manual Trigger
workflow_dispatch:

jobs:
build-deploy:
name: Deploy
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: 1.19

- name: Cache
uses: actions/cache@v3
with:
# In order:
# * Module download cache
# * Build cache (Linux)
path: |
~/go/pkg/mod
~/.cache/go-build
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-

- name: Build
run: go build -v ./...

- name: Test
run: go test -v ./...

- name: Deploy API -> QA
uses: akhileshns/heroku-deploy@v3.12.12
with:
heroku_api_key: ${{secrets.HEROKU_API_KEY}}
heroku_app_name: "challenge-api-qa"
heroku_email: ${{secrets.HEROKU_EMAIL}}
branch: QA
# env_file: .env
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
main
gin-bin

.env
# .env

# exclude everything
uploaded/*
Expand Down
32 changes: 24 additions & 8 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,28 @@
# FROM golang:latest

# ENV GO111MODULE=on
# ENV PORT=8080
# WORKDIR /app
# COPY go.mod /app
# COPY go.sum /app

# RUN go mod download
# RUN go install -mod=mod github.com/githubnemo/CompileDaemon
# COPY . /app
# ENTRYPOINT CompileDaemon --build="go build -o main" --command=./main

FROM golang:latest

ENV GO111MODULE=on
ENV PORT=8080
WORKDIR /app
COPY go.mod /app
COPY go.sum /app
RUN mkdir /golang

RUN go install github.com/cosmtrek/air@latest

ADD . /golang/

RUN go install github.com/cosmtrek/air@latest

WORKDIR /golang

RUN go mod download
RUN go get github.com/githubnemo/CompileDaemon
COPY . /app
ENTRYPOINT CompileDaemon --build="go build -o main" --command=./main

CMD ["air", "-c", ".air.toml"]
1 change: 1 addition & 0 deletions Procfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
web: challenge-platform-api
80 changes: 80 additions & 0 deletions controllers/betController.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
package controllers

import (
"context"
"encoding/json"
"fmt"
"log"
"net/http"
"time"

middlewares "github.com/chattertechno/challenge-platform-api/handlers"
"github.com/chattertechno/challenge-platform-api/models"
"github.com/dgrijalva/jwt-go"
"github.com/gorilla/mux"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/bson/primitive"
)

var AddBetChallenge = http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
var bet models.Bet
err := json.NewDecoder(r.Body).Decode(&bet)
if err != nil {
middlewares.ServerErrResponse(err.Error(), rw)
return
}
ChallengeID, _ := primitive.ObjectIDFromHex(bet.ChallengeID)

var challenge models.Challenge
collection := client.Database("challenge").Collection("challenges")
err = collection.FindOne(context.TODO(), bson.D{primitive.E{Key: "_id", Value: ChallengeID}}).Decode(&challenge)
if err != nil {
middlewares.ServerErrResponse(fmt.Sprintf("challenge %v not found", bet.ChallengeID), rw)
return
}

if challenge.MinBetAmount > bet.Amount {
middlewares.ErrorResponse(fmt.Sprintf("bet must be greater than %v", challenge.MinBetAmount), rw)
return
}

props, _ := r.Context().Value("props").(jwt.MapClaims)
identity := props["identity"].(string)
bet.Identity = identity
bet.CreatedAt = time.Now().UTC()

betCollection := client.Database("challenge").Collection("bets")
result, err := betCollection.InsertOne(context.TODO(), bet)
if err != nil {
middlewares.ServerErrResponse(err.Error(), rw)
return
}
middlewares.SuccessRespond(result, rw)
})

var GetAllBetsForChallenge = http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
params := mux.Vars(r)
var bets []*models.Bet

betCollection := client.Database("challenge").Collection("bets")

cursor, err := betCollection.Find(context.TODO(), bson.D{primitive.E{Key: "challenge_id", Value: params["id"]}})
if err != nil {
middlewares.ServerErrResponse(err.Error(), rw)
return
}
for cursor.Next(context.TODO()) {
var bet models.Bet
err := cursor.Decode(&bet)
if err != nil {
log.Fatal(err)
}
bets = append(bets, &bet)
}

if err := cursor.Err(); err != nil {
middlewares.ServerErrResponse(err.Error(), rw)
return
}
middlewares.SuccessRespond(bets, rw)
})
Loading