This repository has been archived by the owner on Dec 13, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat/fix: adds player handlers,dockerfiles & minor fixes
- Loading branch information
Showing
23 changed files
with
230 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
auth/internal/render_engine.go → auth/internal/utils/render_engine.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package internal | ||
package utils | ||
|
||
func RenderEngine(OTP int) string { | ||
return ` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package internal | ||
package utils | ||
|
||
import ( | ||
"bytes" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package security | ||
|
||
import "golang.org/x/crypto/bcrypt" | ||
|
||
func HashPassword(password string) ([]byte, error) { | ||
return bcrypt.GenerateFromPassword([]byte(password), 10) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,15 @@ | ||
package main | ||
|
||
func main() { | ||
import ( | ||
"fmt" | ||
"net/http" | ||
|
||
"github.com/p-society/gc-server/core/internal" | ||
"github.com/p-society/gc-server/core/internal/db" | ||
) | ||
|
||
func main() { | ||
db.Init() | ||
fmt.Println("core live @ 127.0.0.1:8080") | ||
http.ListenAndServe(":8080", internal.Router()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,51 @@ | ||
package handlers | ||
|
||
import "net/http" | ||
import ( | ||
"context" | ||
"encoding/json" | ||
"net/http" | ||
"time" | ||
|
||
"github.com/p-society/gc-server/auth/pkg/security" | ||
"github.com/p-society/gc-server/core/internal/db" | ||
errors "github.com/p-society/gc-server/errors/pkg" | ||
model "github.com/p-society/gc-server/schemas/pkg/models" | ||
"go.mongodb.org/mongo-driver/bson" | ||
) | ||
|
||
func DeleteHandler(w http.ResponseWriter, r *http.Request) { | ||
w.Header().Set("Content-Type", "application/json") | ||
|
||
token, err := security.ExtractTokenFromHeader(r) | ||
if err != nil { | ||
errors.SendErrorJson(w, err) | ||
} | ||
|
||
p := security.ParseAccessToken(token) | ||
|
||
p.IsDeleted = true | ||
p.DeletedBy = p.ID | ||
|
||
update := bson.M{ | ||
"$set": bson.M{ | ||
"isDeleted": true, | ||
"deletedBy": p.ID, //for now ... | ||
"deletedAt": time.Now(), | ||
}, | ||
} | ||
|
||
filter := bson.M{"_id": p.ID} | ||
|
||
var x model.Player | ||
res := db.PlayerCollection.FindOneAndUpdate(context.Background(), filter, update) | ||
|
||
if err := res.Decode(&x); err != nil { | ||
errors.SendErrorJson(w, err) | ||
return | ||
} | ||
|
||
json.NewEncoder(w).Encode(map[string]interface{}{ | ||
"updated": true, | ||
}) | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package handlers | ||
|
||
import "net/http" | ||
|
||
func GetHandler(w http.ResponseWriter, r *http.Request) { | ||
w.Header().Set("Content-Type", "application/json") | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,57 @@ | ||
package handlers | ||
|
||
import "net/http" | ||
import ( | ||
"context" | ||
"encoding/json" | ||
"fmt" | ||
"net/http" | ||
|
||
"github.com/p-society/gc-server/auth/pkg/security" | ||
"github.com/p-society/gc-server/core/internal/db" | ||
errors "github.com/p-society/gc-server/errors/pkg" | ||
model "github.com/p-society/gc-server/schemas/pkg/models" | ||
"go.mongodb.org/mongo-driver/bson" | ||
) | ||
|
||
func UpdateHandler(w http.ResponseWriter, r *http.Request) { | ||
var ( | ||
p map[string]interface{} | ||
) | ||
token, _ := security.ExtractTokenFromHeader(r) | ||
reqP := security.ParseAccessToken(token) | ||
id := reqP.ID | ||
if err := json.NewDecoder(r.Body).Decode(&p); err != nil { | ||
errors.SendErrorJson(w, err) | ||
return | ||
} | ||
|
||
filter := bson.M{"_id": id} | ||
|
||
// Prepare update operation | ||
update := bson.M{ | ||
"$set": p, | ||
} | ||
|
||
if p["email"] != nil { | ||
w.WriteHeader(http.StatusBadRequest) | ||
errors.SendErrorJson(w, fmt.Errorf("email can't be changed")) | ||
return | ||
} | ||
|
||
var x model.Player | ||
res := db.PlayerCollection.FindOneAndUpdate(context.Background(), filter, update) | ||
if res.Err() != nil { | ||
errors.SendErrorJson(w, res.Err()) | ||
return | ||
} | ||
|
||
// Decode the result into x | ||
if err := res.Decode(&x); err != nil { | ||
errors.SendErrorJson(w, err) | ||
return | ||
} | ||
|
||
json.NewEncoder(w).Encode(map[string]interface{}{ | ||
"updated": true, | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
FROM golang:latest | ||
|
||
WORKDIR /go/src/app | ||
|
||
COPY . . | ||
|
||
RUN go mod download | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
FROM golang:latest |
Empty file.
Oops, something went wrong.