Skip to content

Aakash Onboarding - #238

Closed
aakashg00 wants to merge 6 commits into
mainfrom
aakash/onboarding26
Closed

aakashg00 wants to merge 6 commits into
mainfrom
aakash/onboarding26

Conversation

@aakashg00

Copy link
Copy Markdown
Collaborator

Implemented Counter prisma model along with counter modules and e2e testing in db-service and api-gateway

@greptile-apps

greptile-apps Bot commented Feb 7, 2026

Copy link
Copy Markdown
Contributor

Greptile Overview

Greptile Summary

This PR implements a complete Counter feature as an onboarding exercise, adding a new Prisma model with full CRUD operations through both gRPC (db-service) and REST API (api-gateway) layers. The implementation demonstrates proper separation of concerns with proto definitions, service layer, controller layer, and comprehensive e2e testing for both services.

Key changes:

  • Added Counter Prisma model with id (String) and value (Int) fields
  • Created proto definitions with 5 RPC methods: createCounter, getCounter, incrementCounter, decrementCounter, resetCounter
  • Implemented counter service with proper error handling for duplicate counters (ALREADY_EXISTS) and missing counters (NOT_FOUND)
  • Used upsert operations for increment/decrement/reset to handle non-existent counters gracefully
  • Added REST API endpoints with OpenAPI documentation
  • Implemented comprehensive e2e tests covering all operations and edge cases (15 test cases total)
  • Properly registered modules and proto files in both services

The implementation follows established patterns in the codebase, uses async/await consistently, includes proper error handling with try/catch blocks, and has clear separation between database operations and API endpoints.

Confidence Score: 5/5

  • This PR is safe to merge with no concerns
  • The implementation is clean, well-tested, and follows all established patterns in the codebase. All CRUD operations have proper error handling, the code uses async/await consistently, includes comprehensive e2e tests with 15 test cases covering all operations and edge cases, has no console.logs or commented code, properly handles duplicate entries and missing records, and maintains clear separation between service and controller layers. The PR meets all backend checklist requirements.
  • No files require special attention

Important Files Changed

Filename Overview
packages/proto/definitions/counter.proto Added Counter protobuf service definition with 5 RPC methods (create, get, increment, decrement, reset)
packages/db-service/prisma/schema.prisma Added Counter model with id (String) and value (Int) fields
packages/db-service/src/modules/counter/counter.service.ts Implemented counter service with create, get, increment, decrement, and reset operations using Prisma
packages/db-service/src/modules/counter/counter.controller.ts Implemented gRPC controller with proper error handling for duplicate counters and not found errors
packages/api-gateway/src/modules/counter/counter.controller.ts Implemented REST API controller with OpenAPI documentation for counter operations
packages/db-service/test/counter.e2e-spec.ts Added comprehensive e2e tests for gRPC counter service with 7 test cases covering all operations
packages/api-gateway/test/counter.e2e-spec.ts Added comprehensive e2e tests for REST API counter endpoints with 8 test cases

Sequence Diagram

sequenceDiagram
    participant Client
    participant API Gateway
    participant gRPC Client
    participant DB Service
    participant Counter Controller
    participant Counter Service
    participant Prisma
    participant PostgreSQL

    Note over Client,PostgreSQL: Create Counter Flow
    Client->>API Gateway: POST /counter {id, initialValue}
    API Gateway->>gRPC Client: createCounter(request)
    gRPC Client->>DB Service: gRPC createCounter
    DB Service->>Counter Controller: createCounter(request)
    Counter Controller->>Counter Service: createCounter(id, initialValue)
    Counter Service->>Prisma: counter.create({id, value})
    Prisma->>PostgreSQL: INSERT INTO Counter
    PostgreSQL-->>Prisma: Counter record
    Prisma-->>Counter Service: Counter object
    Counter Service-->>Counter Controller: Counter object
    Counter Controller-->>DB Service: {value}
    DB Service-->>gRPC Client: CreateCounterResponse
    gRPC Client-->>API Gateway: Observable response
    API Gateway-->>Client: 201 {value}

    Note over Client,PostgreSQL: Get Counter Flow
    Client->>API Gateway: GET /counter/:id
    API Gateway->>gRPC Client: getCounter(id)
    gRPC Client->>DB Service: gRPC getCounter
    DB Service->>Counter Controller: getCounter(request)
    Counter Controller->>Counter Service: getCounter(id)
    Counter Service->>Prisma: counter.findUnique({id})
    Prisma->>PostgreSQL: SELECT * FROM Counter
    PostgreSQL-->>Prisma: Counter record or null
    Prisma-->>Counter Service: Counter | null
    Counter Service-->>Counter Controller: Counter | null
    alt Counter not found
        Counter Controller-->>DB Service: RpcException NOT_FOUND
        DB Service-->>API Gateway: gRPC error
        API Gateway-->>Client: 404 Counter not found
    else Counter found
        Counter Controller-->>DB Service: {value}
        DB Service-->>gRPC Client: GetCounterResponse
        gRPC Client-->>API Gateway: Observable response
        API Gateway-->>Client: 200 {value}
    end

    Note over Client,PostgreSQL: Increment Counter Flow
    Client->>API Gateway: POST /counter/:id/increment
    API Gateway->>gRPC Client: incrementCounter(id)
    gRPC Client->>DB Service: gRPC incrementCounter
    DB Service->>Counter Controller: incrementCounter(request)
    Counter Controller->>Counter Service: incrementCounter(id)
    Counter Service->>Prisma: counter.upsert({increment: 1})
    Prisma->>PostgreSQL: UPDATE Counter SET value = value + 1
    PostgreSQL-->>Prisma: Updated Counter
    Prisma-->>Counter Service: Counter object
    Counter Service-->>Counter Controller: Counter object
    Counter Controller-->>DB Service: {value}
    DB Service-->>gRPC Client: IncrementCounterResponse
    gRPC Client-->>API Gateway: Observable response
    API Gateway-->>Client: 201 {value}
Loading

@greptile-apps greptile-apps Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

7 files reviewed, no comments

Edit Code Review Agent Settings | Greptile

@llam36 llam36 closed this Feb 27, 2026
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