Dev - #120
Open
shaileshkumar593 wants to merge 4 commits into
Open
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adds a minimal wallet transfer service implementation (HTTP handler + GORM/SQLite persistence) with idempotency records, a double-entry ledger, Docker packaging, and service-level tests.
Changes:
- Introduces transfer service logic that updates wallet balances, creates transfers, and writes ledger/idempotency records.
- Adds an HTTP API (
POST /transfers) and a small runnable binary with SQLite auto-migration. - Adds Docker/Docker Compose assets and expands repo documentation/templates.
Reviewed changes
Copilot reviewed 13 out of 14 changed files in this pull request and generated 16 comments.
Show a summary per file
| File | Description |
|---|---|
| README.md | Adds “Wallet Service” usage section (run/docker/test instructions). |
| LICENSE | Removes the repository license file. |
| internal/service/transfer_service.go | Implements transfer creation with balance updates, ledger entries, and idempotency storage. |
| internal/service/transfer_service_test.go | Adds unit tests for success, idempotency, balances, ledger entries, and concurrency. |
| internal/handler/handler.go | Adds HTTP handler for /transfers. |
| internal/domain/models.go | Adds GORM models for Wallet, Transfer, LedgerEntry, and IdempotencyRecord. |
| internal/db/db.go | Adds SQLite initialization + AutoMigrate. |
| go.mod | Adds module definition and Go version + dependencies. |
| go.sum | Adds dependency checksums. |
| Dockerfile | Adds multi-stage build + runtime image for the service. |
| docker-compose.yml | Adds compose setup with persisted SQLite volume. |
| cmd/main.go | Adds executable wiring DB + handler + health endpoint. |
| .github/pull_request_template.md | Expands PR template content (schema/idempotency/concurrency/run/test sections). |
| .github/CODEOWNERS | Updates CODEOWNERS ownership entry. |
Comments suppressed due to low confidence (3)
internal/service/transfer_service_test.go:74
- This test ignores the error from CreateTransfer; errcheck will flag it and the test should fail fast if the transfer unexpectedly fails.
_, _ = svc.CreateTransfer(context.Background(), "key3", "w1", "w2", 40)
internal/service/transfer_service_test.go:93
- This test ignores the error from CreateTransfer; errcheck will flag it and failures will become harder to diagnose.
transferID, _ := svc.CreateTransfer(context.Background(), "key4", "w1", "w2", 20)
internal/service/transfer_service_test.go:107
- This test ignores the error from CreateTransfer; errcheck will flag it and the assertions below assume the transfer succeeded.
id, _ := svc.CreateTransfer(context.Background(), "key5", "w1", "w2", 10)
Comment on lines
+3
to
+13
| import ( | ||
| "log" | ||
|
|
||
| "gorm.io/driver/sqlite" | ||
| "gorm.io/gorm" | ||
| "wallet-assignment/internal/domain" | ||
| ) | ||
|
|
||
| func Init() *gorm.DB { | ||
| db, err := gorm.Open(sqlite.Open("/app/data/wallet.db"), &gorm.Config{}) | ||
| if err != nil { |
Comment on lines
+90
to
+94
| if err := tx.Create(&domain.LedgerEntry{WalletID: from, Type: "DEBIT", Amount: amount, TransferID: transfer.ID}).Error; err != nil { | ||
| return err | ||
| } | ||
|
|
||
| if err := tx.Create(&domain.LedgerEntry{WalletID: to, Type: "CREDIT", Amount: amount, TransferID: transfer.ID}).Error; err != nil { |
Comment on lines
+98
to
+103
| resp := map[string]string{"transferId": transfer.ID} | ||
| b, _ := json.Marshal(resp) | ||
|
|
||
| if err := tx.Create(&domain.IdempotencyRecord{Key: key, Response: string(b)}).Error; err != nil { | ||
| return err | ||
| } |
Comment on lines
+36
to
+37
| var existing domain.IdempotencyRecord | ||
| if err := s.db.First(&existing, "key = ?", key).Error; err == nil { |
Comment on lines
+51
to
+56
| id1, _ := svc.CreateTransfer(context.Background(), "same-key", "w1", "w2", 30) | ||
| id2, _ := svc.CreateTransfer(context.Background(), "same-key", "w1", "w2", 30) | ||
|
|
||
| if id1 != id2 { | ||
| t.Fatalf("expected same transfer id, got %s and %s", id1, id2) | ||
| } |
Comment on lines
+15
to
+36
| go fmt ./... | ||
| internal\db\db.go | ||
| internal\domain\models.go | ||
| internal\service\transfer_service.go | ||
| internal\service\transfer_service_test.go | ||
|
|
||
|
|
||
| golangci-lint run --build-tags "sqlite" | ||
| internal\service\transfer_service_test.go:113:16: Error return value of `json.Unmarshal` is not checked (errcheck) | ||
| json.Unmarshal([]byte(record.Response), &resp) | ||
| ^ | ||
| internal\service\transfer_service_test.go:130:22: Error return value of `svc.CreateTransfer` is not checked (errcheck) | ||
| svc.CreateTransfer(context.Background(), string(rune(i)), "w1", "w2", 5) | ||
| ^ | ||
| cmd\main.go:24:16: Error return value of `w.Write` is not checked (errcheck) | ||
| w.Write([]byte("OK")) | ||
| ^ | ||
| cmd\main.go:27:24: Error return value of `http.ListenAndServe` is not checked (errcheck) | ||
| http.ListenAndServe(":8080", nil) | ||
|
|
||
|
|
||
| write code to satisfy all condition mentioned in code.This code is for lead level developer. Also add unit testing of code block, Dockerfile. Give production ready code which run without fail. And handle all cases and edge cases. Complete downlodable folder with all mentioned requirement satisfied. |
Comment on lines
+276
to
+280
| - [pass ] Tests pass | ||
| - [pass ] Lint passes | ||
| - [ pass] Format check passes | ||
| - [ pass] README or notes updated | ||
| - [ pass] PR description explains schema, idempotency, and concurrency |
Comment on lines
+54
to
+56
| if err := tx.Clauses(clause.Locking{Strength: "UPDATE"}). | ||
| First(&fromWallet, "id = ?", from).Error; err != nil { | ||
| return err |
Comment on lines
+54
to
+61
| if err != nil { | ||
| w.WriteHeader(http.StatusBadRequest) | ||
| if err := json.NewEncoder(w).Encode(map[string]string{ | ||
| "error": err.Error(), | ||
| }); err != nil { | ||
| log.Println("encode error:", err) | ||
| } | ||
| return |
Comment on lines
+15
to
+16
| database.FirstOrCreate(&domain.Wallet{ID: "wallet_1"}, domain.Wallet{Balance: 1000}) | ||
| database.FirstOrCreate(&domain.Wallet{ID: "wallet_2"}, domain.Wallet{Balance: 1000}) |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Describe your solution briefly.
AI disclosure
Detail how you used AI to help with your submission (including the tools you used, how
you used them and what your prompts were).
Include these points in detail
Schema Design
Describe the tables, constraints, and indexes you introduced.
Idempotency Strategy
Explain how duplicate requests are handled safely.
Concurrency Strategy
Explain how you prevent race conditions and double spending.
How to Run
How to Test
Tradeoffs / Assumptions
Checklist