Skip to content

Commit 920b423

Browse files
authored
Merge pull request #245 from Real-Dev-Squad/develop
Dev to Main
2 parents e7d67d1 + 68a6049 commit 920b423

File tree

12 files changed

+1466
-175
lines changed

12 files changed

+1466
-175
lines changed

.gitignore

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,59 @@
22
.aws-sam/
33
env.json
44
samconfig.toml
5-
*/firestore-debug.log
5+
6+
# Firebase emulator logs (recursive)
7+
**/firestore-debug.log
8+
**/firebase-debug.log
9+
**/ui-debug.log
10+
11+
# Firebase cache
12+
.firebase/
13+
14+
# Go build artifacts
15+
*.exe
16+
*.exe~
17+
*.dll
18+
*.so
19+
*.dylib
20+
*.test
21+
*.out
22+
coverage.out
23+
coverage.html
24+
*.prof
25+
26+
# Go workspace files
27+
go.work
28+
go.work.sum
29+
30+
# IDE files
31+
.vscode/
32+
.idea/
33+
*.swp
34+
*.swo
35+
*~
36+
37+
# OS generated files
38+
.DS_Store
39+
.DS_Store?
40+
._*
41+
.Spotlight-V100
42+
.Trashes
43+
ehthumbs.db
44+
Thumbs.db
45+
46+
# Temporary files
47+
*.tmp
48+
*.temp
49+
/tmp/
50+
51+
# Environment files
52+
.env
53+
.env.local
54+
.env.*.local
55+
56+
# Node modules (if using any Node.js tools)
57+
node_modules/
58+
npm-debug.log*
59+
yarn-debug.log*
60+
yarn-error.log*

call-profile/main.go

Lines changed: 32 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,22 @@ import (
44
"context"
55
"fmt"
66
"identity-service/layer/utils"
7+
"log"
78
"net/http"
89
"time"
910

11+
"cloud.google.com/go/firestore"
12+
1013
"github.com/aws/aws-lambda-go/events"
1114
"github.com/aws/aws-lambda-go/lambda"
1215
)
1316

14-
func handler(request events.APIGatewayProxyRequest) (events.APIGatewayProxyResponse, error) {
15-
ctx := context.Background()
16-
client, err := utils.InitializeFirestoreClient(ctx)
17-
if err != nil {
18-
return events.APIGatewayProxyResponse{}, err
19-
}
17+
type deps struct {
18+
client *firestore.Client
19+
ctx context.Context
20+
}
2021

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

29-
dsnap, err := client.Collection("users").Doc(userId).Get(ctx)
31+
dsnap, err := d.client.Collection("users").Doc(userId).Get(d.ctx)
3032

3133
var userUrl string
3234
var chaincode string
@@ -41,8 +43,8 @@ func handler(request events.APIGatewayProxyRequest) (events.APIGatewayProxyRespo
4143
if str, ok := dsnap.Data()["profileURL"].(string); ok {
4244
userUrl = str
4345
} else {
44-
utils.LogProfileSkipped(client, ctx, userId, "Profile URL not available", sessionId)
45-
utils.SetProfileStatusBlocked(client, ctx, userId, "Profile URL not available", sessionId, discordId)
46+
utils.LogProfileSkipped(d.client, d.ctx, userId, "Profile URL not available", sessionId)
47+
utils.SetProfileStatusBlocked(d.client, d.ctx, userId, "Profile URL not available", sessionId, discordId)
4648
return events.APIGatewayProxyResponse{
4749
Body: "Profile Skipped No Profile URL",
4850
StatusCode: 200,
@@ -51,17 +53,17 @@ func handler(request events.APIGatewayProxyRequest) (events.APIGatewayProxyRespo
5153

5254
if str, ok := dsnap.Data()["chaincode"].(string); ok {
5355
if str == "" {
54-
utils.LogProfileSkipped(client, ctx, userId, "Profile Service Blocked or Chaincode is empty", sessionId)
55-
utils.SetProfileStatusBlocked(client, ctx, userId, "Profile Service Blocked or Chaincode is empty", sessionId, discordId)
56+
utils.LogProfileSkipped(d.client, d.ctx, userId, "Profile Service Blocked or Chaincode is empty", sessionId)
57+
utils.SetProfileStatusBlocked(d.client, d.ctx, userId, "Profile Service Blocked or Chaincode is empty", sessionId, discordId)
5658
return events.APIGatewayProxyResponse{
5759
Body: "Profile Skipped Profile Service Blocked",
5860
StatusCode: 200,
5961
}, nil
6062
}
6163
chaincode = str
6264
} else {
63-
utils.LogProfileSkipped(client, ctx, userId, "Chaincode Not Found", sessionId)
64-
utils.SetProfileStatusBlocked(client, ctx, userId, "Chaincode Not Found", sessionId, discordId)
65+
utils.LogProfileSkipped(d.client, d.ctx, userId, "Chaincode Not Found", sessionId)
66+
utils.SetProfileStatusBlocked(d.client, d.ctx, userId, "Chaincode Not Found", sessionId, discordId)
6567
return events.APIGatewayProxyResponse{
6668
Body: "Profile Skipped Chaincode Not Found",
6769
StatusCode: 200,
@@ -71,7 +73,7 @@ func handler(request events.APIGatewayProxyRequest) (events.APIGatewayProxyRespo
7173
var userData utils.Diff
7274
err = dsnap.DataTo(&userData)
7375
if err != nil {
74-
utils.LogProfileSkipped(client, ctx, userId, "UserData Type Error: "+fmt.Sprintln(err), sessionId)
76+
utils.LogProfileSkipped(d.client, d.ctx, userId, "UserData Type Error: "+fmt.Sprintln(err), sessionId)
7577
return events.APIGatewayProxyResponse{
7678
Body: "Profile Skipped No User Data",
7779
StatusCode: 200,
@@ -92,31 +94,41 @@ func handler(request events.APIGatewayProxyRequest) (events.APIGatewayProxyRespo
9294
isServiceRunning = true
9395
}
9496

95-
utils.LogHealth(client, ctx, userId, isServiceRunning, sessionId)
97+
utils.LogHealth(d.client, d.ctx, userId, isServiceRunning, sessionId)
9698
if !isServiceRunning {
97-
utils.LogProfileSkipped(client, ctx, userId, "Profile Service Down", sessionId)
98-
utils.SetProfileStatusBlocked(client, ctx, userId, "Profile Service Down", sessionId, discordId)
99+
utils.LogProfileSkipped(d.client, d.ctx, userId, "Profile Service Down", sessionId)
100+
utils.SetProfileStatusBlocked(d.client, d.ctx, userId, "Profile Service Down", sessionId, discordId)
99101
return events.APIGatewayProxyResponse{
100102
Body: "Profile Skipped Service Down",
101103
StatusCode: 200,
102104
}, nil
103105
}
104106

105-
dataErr := utils.Getdata(client, ctx, userId, userUrl, chaincode, utils.DiffToRes(userData), sessionId, discordId)
107+
dataErr := utils.Getdata(d.client, d.ctx, userId, userUrl, chaincode, utils.DiffToRes(userData), sessionId, discordId)
106108
if dataErr != "" {
107109
return events.APIGatewayProxyResponse{
108110
Body: "Profile Skipped " + dataErr,
109111
StatusCode: 200,
110112
}, nil
111113
}
112114

113-
defer client.Close()
114115
return events.APIGatewayProxyResponse{
115116
Body: "Profile Saved",
116117
StatusCode: 200,
117118
}, nil
118119
}
119120

120121
func main() {
121-
lambda.Start(handler)
122+
ctx := context.Background()
123+
client, err := utils.InitializeFirestoreClient(ctx)
124+
if err != nil {
125+
log.Fatalf("Failed to initialize Firestore client: %v", err)
126+
}
127+
128+
d := deps{
129+
client: client,
130+
ctx: ctx,
131+
}
132+
133+
lambda.Start(d.handler)
122134
}

0 commit comments

Comments
 (0)