100 Words in 100 Days 9/100: An evolving API (9)

1 minute read

In last article, the team has put in new coding standard to make our code easier to understand and modify. In the next few weeks, they started to realize they can boost their number of service requests by giving out discount code. And after a few iterations of the discount code, the logic of the discount code module became complex, just like this.

class Api::ServiceRequestController
    # ... some other Concerns
    include ServiceRequestParamsSanitizer
    # ... some other Concerns
    # POST v10/service_request
    def place_request_of_service_v13
            sanitized_service_request_params = sanitize(service_request_params)
            @service_request = ServiceRequest.new(sanitized_service_request_params)
            if (@service_request.has_valid_discount_code?) do
                #some other logics for discount_code such as mark the discount code as used
                @service_request.price -= @service_request.discount_code.price
            # ... some other update
            render(json: { id: @service_request.id }, status: :created)

From the first glance there is no big problem when the application was small. But whenever iteration on discount_code, it would always trigger tests on place_request_of_service_v13 to fail. Moreover, there were 2 different developers working on the APIs and the discount_code implementation, there were a lot of code merge errors. It has slowed the iteration speed.

In the next article, the team has to come up with a way to decouple the development and speed up the team.