Skip to content

Commit 6c8a18a

Browse files
authored
Merge pull request #33 from GRACENOBLE/24-feat-backend-completions
feat(backend): complete six template gaps for production readiness
2 parents daae38b + 4034ed4 commit 6c8a18a

32 files changed

Lines changed: 1109 additions & 47 deletions

‎backend/cmd/api/main.go‎

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ import (
1010
"syscall"
1111
"time"
1212

13-
"github.com/hibiken/asynq"
14-
1513
"backend/internal/bootstrap"
1614
"backend/internal/infrastructure/queue"
1715
"backend/internal/infrastructure/ws"
@@ -72,14 +70,35 @@ func main() {
7270
fmt.Fprintf(os.Stderr, "startup failed: %v\n", err)
7371
os.Exit(1)
7472
}
75-
worker.Register(queue.TypeWelcomeEmail, asynq.HandlerFunc(queue.HandleWelcomeEmail))
73+
worker.Register(queue.TypeWelcomeEmail, queue.NewHandleWelcomeEmail(app.EmailSender))
7674
go func() {
7775
if err := worker.Run(workerCtx); err != nil {
7876
slog.Error("queue: worker error", "err", err)
7977
}
8078
}()
8179
}
8280

81+
// --- Redis Streams consumer (unwired — add when you have a concrete use case) ---
82+
// The streams infrastructure (Producer, Consumer, events) is fully implemented.
83+
// Wire a consumer here following this pattern when you need it:
84+
//
85+
// streamCtx, streamCancel := context.WithCancel(context.Background())
86+
// consumer, err := streams.NewConsumer(app.Config.RedisURL, streams.StreamUserCreated, "api", "api-1")
87+
// if err != nil {
88+
// slog.Error("streams: failed to create consumer", "err", err)
89+
// } else {
90+
// go func() {
91+
// _ = consumer.Run(streamCtx, func(ctx context.Context, data []byte) error {
92+
// var evt streams.UserCreatedEvent
93+
// if err := json.Unmarshal(data, &evt); err != nil { return err }
94+
// payload, _ := json.Marshal(queue.WelcomeEmailPayload{UserID: evt.UserID, Email: evt.Email, Name: evt.Name})
95+
// return app.Enqueuer.Enqueue(ctx, queue.TypeWelcomeEmail, payload)
96+
// })
97+
// _ = consumer.Close()
98+
// }()
99+
// }
100+
// // In the shutdown sequence below, call: streamCancel()
101+
83102
srv, err := server.NewServer(app, hub)
84103
if err != nil {
85104
fmt.Fprintf(os.Stderr, "startup failed: %v\n", err)
@@ -111,5 +130,10 @@ func main() {
111130
slog.Error("enqueuer close error", "error", err)
112131
}
113132
}
133+
if app.StreamProducer != nil {
134+
if err := app.StreamProducer.Close(); err != nil {
135+
slog.Error("stream producer close error", "error", err)
136+
}
137+
}
114138
slog.Info("graceful shutdown complete")
115139
}

‎backend/docs/swagger/docs.go‎

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,108 @@ const docTemplate = `{
244244
}
245245
}
246246
}
247+
},
248+
"delete": {
249+
"security": [
250+
{
251+
"BearerAuth": []
252+
}
253+
],
254+
"description": "Removes the authenticated user's profile record from the database. The Firebase account is not deleted.",
255+
"produces": [
256+
"application/json"
257+
],
258+
"tags": [
259+
"users"
260+
],
261+
"summary": "Delete current user account",
262+
"responses": {
263+
"204": {
264+
"description": "No Content"
265+
},
266+
"401": {
267+
"description": "Unauthorized",
268+
"schema": {
269+
"type": "object",
270+
"additionalProperties": {
271+
"type": "string"
272+
}
273+
}
274+
},
275+
"500": {
276+
"description": "Internal Server Error",
277+
"schema": {
278+
"type": "object",
279+
"additionalProperties": {
280+
"type": "string"
281+
}
282+
}
283+
}
284+
}
285+
},
286+
"patch": {
287+
"security": [
288+
{
289+
"BearerAuth": []
290+
}
291+
],
292+
"description": "Upserts the authenticated user's profile record. Requires a valid Firebase ID token.",
293+
"consumes": [
294+
"application/json"
295+
],
296+
"produces": [
297+
"application/json"
298+
],
299+
"tags": [
300+
"users"
301+
],
302+
"summary": "Update current user profile",
303+
"parameters": [
304+
{
305+
"description": "Profile update",
306+
"name": "body",
307+
"in": "body",
308+
"required": true,
309+
"schema": {
310+
"$ref": "#/definitions/handlers.updateMeRequest"
311+
}
312+
}
313+
],
314+
"responses": {
315+
"200": {
316+
"description": "OK",
317+
"schema": {
318+
"$ref": "#/definitions/handlers.UserAlias"
319+
}
320+
},
321+
"400": {
322+
"description": "Bad Request",
323+
"schema": {
324+
"type": "object",
325+
"additionalProperties": {
326+
"type": "string"
327+
}
328+
}
329+
},
330+
"401": {
331+
"description": "Unauthorized",
332+
"schema": {
333+
"type": "object",
334+
"additionalProperties": {
335+
"type": "string"
336+
}
337+
}
338+
},
339+
"500": {
340+
"description": "Internal Server Error",
341+
"schema": {
342+
"type": "object",
343+
"additionalProperties": {
344+
"type": "string"
345+
}
346+
}
347+
}
348+
}
247349
}
248350
},
249351
"/api/v1/storage/presign": {
@@ -479,6 +581,32 @@ const docTemplate = `{
479581
}
480582
}
481583
},
584+
"handlers.UserAlias": {
585+
"type": "object",
586+
"properties": {
587+
"created_at": {
588+
"type": "string"
589+
},
590+
"email": {
591+
"type": "string"
592+
},
593+
"firebase_uid": {
594+
"type": "string"
595+
},
596+
"id": {
597+
"type": "integer"
598+
},
599+
"name": {
600+
"type": "string"
601+
},
602+
"photo_url": {
603+
"type": "string"
604+
},
605+
"updated_at": {
606+
"type": "string"
607+
}
608+
}
609+
},
482610
"handlers.presignRequest": {
483611
"type": "object",
484612
"required": [
@@ -535,6 +663,17 @@ const docTemplate = `{
535663
"type": "string"
536664
}
537665
}
666+
},
667+
"handlers.updateMeRequest": {
668+
"type": "object",
669+
"required": [
670+
"name"
671+
],
672+
"properties": {
673+
"name": {
674+
"type": "string"
675+
}
676+
}
538677
}
539678
},
540679
"securityDefinitions": {

‎backend/docs/swagger/swagger.json‎

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,108 @@
238238
}
239239
}
240240
}
241+
},
242+
"delete": {
243+
"security": [
244+
{
245+
"BearerAuth": []
246+
}
247+
],
248+
"description": "Removes the authenticated user's profile record from the database. The Firebase account is not deleted.",
249+
"produces": [
250+
"application/json"
251+
],
252+
"tags": [
253+
"users"
254+
],
255+
"summary": "Delete current user account",
256+
"responses": {
257+
"204": {
258+
"description": "No Content"
259+
},
260+
"401": {
261+
"description": "Unauthorized",
262+
"schema": {
263+
"type": "object",
264+
"additionalProperties": {
265+
"type": "string"
266+
}
267+
}
268+
},
269+
"500": {
270+
"description": "Internal Server Error",
271+
"schema": {
272+
"type": "object",
273+
"additionalProperties": {
274+
"type": "string"
275+
}
276+
}
277+
}
278+
}
279+
},
280+
"patch": {
281+
"security": [
282+
{
283+
"BearerAuth": []
284+
}
285+
],
286+
"description": "Upserts the authenticated user's profile record. Requires a valid Firebase ID token.",
287+
"consumes": [
288+
"application/json"
289+
],
290+
"produces": [
291+
"application/json"
292+
],
293+
"tags": [
294+
"users"
295+
],
296+
"summary": "Update current user profile",
297+
"parameters": [
298+
{
299+
"description": "Profile update",
300+
"name": "body",
301+
"in": "body",
302+
"required": true,
303+
"schema": {
304+
"$ref": "#/definitions/handlers.updateMeRequest"
305+
}
306+
}
307+
],
308+
"responses": {
309+
"200": {
310+
"description": "OK",
311+
"schema": {
312+
"$ref": "#/definitions/handlers.UserAlias"
313+
}
314+
},
315+
"400": {
316+
"description": "Bad Request",
317+
"schema": {
318+
"type": "object",
319+
"additionalProperties": {
320+
"type": "string"
321+
}
322+
}
323+
},
324+
"401": {
325+
"description": "Unauthorized",
326+
"schema": {
327+
"type": "object",
328+
"additionalProperties": {
329+
"type": "string"
330+
}
331+
}
332+
},
333+
"500": {
334+
"description": "Internal Server Error",
335+
"schema": {
336+
"type": "object",
337+
"additionalProperties": {
338+
"type": "string"
339+
}
340+
}
341+
}
342+
}
241343
}
242344
},
243345
"/api/v1/storage/presign": {
@@ -473,6 +575,32 @@
473575
}
474576
}
475577
},
578+
"handlers.UserAlias": {
579+
"type": "object",
580+
"properties": {
581+
"created_at": {
582+
"type": "string"
583+
},
584+
"email": {
585+
"type": "string"
586+
},
587+
"firebase_uid": {
588+
"type": "string"
589+
},
590+
"id": {
591+
"type": "integer"
592+
},
593+
"name": {
594+
"type": "string"
595+
},
596+
"photo_url": {
597+
"type": "string"
598+
},
599+
"updated_at": {
600+
"type": "string"
601+
}
602+
}
603+
},
476604
"handlers.presignRequest": {
477605
"type": "object",
478606
"required": [
@@ -529,6 +657,17 @@
529657
"type": "string"
530658
}
531659
}
660+
},
661+
"handlers.updateMeRequest": {
662+
"type": "object",
663+
"required": [
664+
"name"
665+
],
666+
"properties": {
667+
"name": {
668+
"type": "string"
669+
}
670+
}
532671
}
533672
},
534673
"securityDefinitions": {

0 commit comments

Comments
 (0)