Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
57 changes: 56 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,59 @@
.aws-sam/
env.json
samconfig.toml
*/firestore-debug.log

# Firebase emulator logs (recursive)
**/firestore-debug.log
**/firebase-debug.log
**/ui-debug.log

# Firebase cache
.firebase/

# Go build artifacts
*.exe
*.exe~
*.dll
*.so
*.dylib
*.test
*.out
coverage.out
coverage.html
*.prof

# Go workspace files
go.work
go.work.sum

# IDE files
.vscode/
.idea/
*.swp
*.swo
*~

# OS generated files
.DS_Store
.DS_Store?
._*
.Spotlight-V100
.Trashes
ehthumbs.db
Thumbs.db

# Temporary files
*.tmp
*.temp
/tmp/

# Environment files
.env
.env.local
.env.*.local

# Node modules (if using any Node.js tools)
node_modules/
npm-debug.log*
yarn-debug.log*
yarn-error.log*
52 changes: 32 additions & 20 deletions call-profile/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,22 @@ import (
"context"
"fmt"
"identity-service/layer/utils"
"log"
"net/http"
"time"

"cloud.google.com/go/firestore"

"github.com/aws/aws-lambda-go/events"
"github.com/aws/aws-lambda-go/lambda"
)

func handler(request events.APIGatewayProxyRequest) (events.APIGatewayProxyResponse, error) {
ctx := context.Background()
client, err := utils.InitializeFirestoreClient(ctx)
if err != nil {
return events.APIGatewayProxyResponse{}, err
}
type deps struct {
client *firestore.Client
ctx context.Context
}

func (d *deps) handler(request events.APIGatewayProxyRequest) (events.APIGatewayProxyResponse, error) {
var userId, sessionId string = utils.GetDataFromBody([]byte(request.Body))
if userId == "" {
return events.APIGatewayProxyResponse{
Expand All @@ -26,7 +28,7 @@ func handler(request events.APIGatewayProxyRequest) (events.APIGatewayProxyRespo
}, nil
}

dsnap, err := client.Collection("users").Doc(userId).Get(ctx)
dsnap, err := d.client.Collection("users").Doc(userId).Get(d.ctx)

var userUrl string
var chaincode string
Expand All @@ -41,8 +43,8 @@ func handler(request events.APIGatewayProxyRequest) (events.APIGatewayProxyRespo
if str, ok := dsnap.Data()["profileURL"].(string); ok {
userUrl = str
} else {
utils.LogProfileSkipped(client, ctx, userId, "Profile URL not available", sessionId)
utils.SetProfileStatusBlocked(client, ctx, userId, "Profile URL not available", sessionId, discordId)
utils.LogProfileSkipped(d.client, d.ctx, userId, "Profile URL not available", sessionId)
utils.SetProfileStatusBlocked(d.client, d.ctx, userId, "Profile URL not available", sessionId, discordId)
return events.APIGatewayProxyResponse{
Body: "Profile Skipped No Profile URL",
StatusCode: 200,
Expand All @@ -51,17 +53,17 @@ func handler(request events.APIGatewayProxyRequest) (events.APIGatewayProxyRespo

if str, ok := dsnap.Data()["chaincode"].(string); ok {
if str == "" {
utils.LogProfileSkipped(client, ctx, userId, "Profile Service Blocked or Chaincode is empty", sessionId)
utils.SetProfileStatusBlocked(client, ctx, userId, "Profile Service Blocked or Chaincode is empty", sessionId, discordId)
utils.LogProfileSkipped(d.client, d.ctx, userId, "Profile Service Blocked or Chaincode is empty", sessionId)
utils.SetProfileStatusBlocked(d.client, d.ctx, userId, "Profile Service Blocked or Chaincode is empty", sessionId, discordId)
return events.APIGatewayProxyResponse{
Body: "Profile Skipped Profile Service Blocked",
StatusCode: 200,
}, nil
}
chaincode = str
} else {
utils.LogProfileSkipped(client, ctx, userId, "Chaincode Not Found", sessionId)
utils.SetProfileStatusBlocked(client, ctx, userId, "Chaincode Not Found", sessionId, discordId)
utils.LogProfileSkipped(d.client, d.ctx, userId, "Chaincode Not Found", sessionId)
utils.SetProfileStatusBlocked(d.client, d.ctx, userId, "Chaincode Not Found", sessionId, discordId)
return events.APIGatewayProxyResponse{
Body: "Profile Skipped Chaincode Not Found",
StatusCode: 200,
Expand All @@ -71,7 +73,7 @@ func handler(request events.APIGatewayProxyRequest) (events.APIGatewayProxyRespo
var userData utils.Diff
err = dsnap.DataTo(&userData)
if err != nil {
utils.LogProfileSkipped(client, ctx, userId, "UserData Type Error: "+fmt.Sprintln(err), sessionId)
utils.LogProfileSkipped(d.client, d.ctx, userId, "UserData Type Error: "+fmt.Sprintln(err), sessionId)
return events.APIGatewayProxyResponse{
Body: "Profile Skipped No User Data",
StatusCode: 200,
Expand All @@ -92,31 +94,41 @@ func handler(request events.APIGatewayProxyRequest) (events.APIGatewayProxyRespo
isServiceRunning = true
}

utils.LogHealth(client, ctx, userId, isServiceRunning, sessionId)
utils.LogHealth(d.client, d.ctx, userId, isServiceRunning, sessionId)
if !isServiceRunning {
utils.LogProfileSkipped(client, ctx, userId, "Profile Service Down", sessionId)
utils.SetProfileStatusBlocked(client, ctx, userId, "Profile Service Down", sessionId, discordId)
utils.LogProfileSkipped(d.client, d.ctx, userId, "Profile Service Down", sessionId)
utils.SetProfileStatusBlocked(d.client, d.ctx, userId, "Profile Service Down", sessionId, discordId)
return events.APIGatewayProxyResponse{
Body: "Profile Skipped Service Down",
StatusCode: 200,
}, nil
}

dataErr := utils.Getdata(client, ctx, userId, userUrl, chaincode, utils.DiffToRes(userData), sessionId, discordId)
dataErr := utils.Getdata(d.client, d.ctx, userId, userUrl, chaincode, utils.DiffToRes(userData), sessionId, discordId)
if dataErr != "" {
return events.APIGatewayProxyResponse{
Body: "Profile Skipped " + dataErr,
StatusCode: 200,
}, nil
}

defer client.Close()
return events.APIGatewayProxyResponse{
Body: "Profile Saved",
StatusCode: 200,
}, nil
}

func main() {
lambda.Start(handler)
ctx := context.Background()
client, err := utils.InitializeFirestoreClient(ctx)
if err != nil {
log.Fatalf("Failed to initialize Firestore client: %v", err)
}

d := deps{
client: client,
ctx: ctx,
}

lambda.Start(d.handler)
}
Loading
Loading