Skip to content

Dev - #120

Open
shaileshkumar593 wants to merge 4 commits into
Robustrade:mainfrom
shaileshkumar593:dev
Open

Dev#120
shaileshkumar593 wants to merge 4 commits into
Robustrade:mainfrom
shaileshkumar593:dev

Conversation

@shaileshkumar593

Copy link
Copy Markdown

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

  1. What tool you used (Cursor, Claude Code, Antigratvity etc.)
  2. How you generally use the tool for your work.
  3. A transcript of your entire session with your AI tool of choice. You can add this to the repo or email it to us with your submission. If for some reason, this is not possible, give us all the prompts that you used with the AI.

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

  • Tests pass
  • Lint passes
  • Format check passes
  • README or notes updated
  • PR description explains schema, idempotency, and concurrency

Copilot AI review requested due to automatic review settings July 24, 2026 20:32

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 thread internal/db/db.go
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 thread cmd/main.go
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})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants