Skip to content

Latest commit

 

History

History
206 lines (174 loc) · 6.66 KB

README.md

File metadata and controls

206 lines (174 loc) · 6.66 KB

SPREADSHEET MANAGEMENT SERVICE

The Spreadsheet Management Service is a Ruby on Rails application that integrates with Google Sheets using the Google Drive API. It provides an interface for managing records, offering a convenient way to perform CRUD operations on data stored in a Google Sheets document. This service is useful for teams or individuals who prefer to manage data in Google Sheets but need additional functionality and control through a Rails app.

Table of Contents

Features

  • Fetch Records: Fetches and returns paginated records from the Google Sheets document.
  • Create Record: Adds a new record to the Google Sheets document.
  • Delete Record: Deletes records from the Google Sheets document based on provided attributes.

Endpoints

Fetch Records

  • Endpoint: GET /records
  • Description: Fetches and returns paginated records from the Google Sheets document.
  • Parameters:
    • page (optional): The page number for pagination. Defaults to 1.
    • per_page (optional): The number of records per page. Defaults to PER_PAGE.
  • Response:
    • 200 OK: Returns the fetched records.
      {
          "records": [
              {
              "date": "2024-10-23",
              "description": "Sample record",
              "category": "Income",
              "sub_category": "Salary",
              "amount": 5000,
              "remark": "October salary"
              }
          ],
          "pagination": {
              "page": 1,
              "per_page": 10,
              "total_pages": 5
          }
      }

Create Record

  • Endpoint: POST /records
  • Description: Adds a new record to the Google Sheets document.
  • Parameters:
    • record (required): A JSON object containing the record attributes.
      • date: The date of the record.
      • description: The description of the record.
      • category: The category of the record.
      • sub_category: The sub-category of the record.
      • amount: The amount of the record.
      • remark: Any additional remarks for the record.
  • Response:
    • 201 Created: Returns a success message if the record is added successfully.
      {
          "message": "Record added successfully",
          "record": {
              "date": "2024-10-23",
              "description": "Sample record",
              "category": "Income",
              "sub_category": "Salary",
              "amount": 5000,
              "remark": "October salary"
          }
      }
    • 422 Unprocessable Entity: Returns an error message if the record could not be added.
      {
          "error": "Failed to add new row"
      }

Delete Record

  • Endpoint: DELETE /records
  • Description: Deletes records from the Google Sheets document based on provided attributes.
  • Parameters:
    • record (required): A JSON object containing the record attributes to match for deletion.
      • date: The date of the record.
      • description: The description of the record.
      • category: The category of the record.
      • sub_category: The sub-category of the record.
      • amount: The amount of the record.
      • remark: Any additional remarks for the record.
  • Response:
    • 200 OK: Returns a success message if the record is deleted successfully.
      {
          "message": "Record deleted successfully"
      }
    • 404 Not Found: Returns an error message if the record could not be found.
      {
          "error": "Record not found"
      }
    

Setup

Prerequisites

Installation

  1. Clone the repository:

    git clone https://github.com/faruqt/spreadsheet-management-service.git
    cd spreadsheet-management-service
  2. Install dependencies:

    bundle install
  3. Set up Google Sheets API credentials:

    • Create a .env file in the root directory and ensure it follows the structure of the env.sample file.
    • Add your Google Service Account json credentials obtained from the google console and other environment variables:
        GOOGLE_SHEET_KEY=<your-google-sheet-key>
        GOOGLE_SHEET_TITLE=<your-google-sheet-title>
        GOOGLE_SERVICE_ACCOUNT_CREDENTIALS=<your-service-account-credentials>
  4. Start the Rails server:

    rails server

Docker Setup (Optional)

If you prefer to use Docker, follow these steps:

  1. Build the Docker image and start the container using the development configuration:
    docker-compose -f docker-compose.dev.yml up
  • This command builds the Docker image and starts the application in a container using the docker-compose.dev.yml configuration file.

Linting

To ensure code quality and consistency, you can use RuboCop for linting.

  1. Run RuboCop to lint your code and see the files with issues:
rubocop
    1. To automatically fix linting issues, run RuboCop with the -A (auto-correct) option:
rubocop -A

Testing

To run the test suite, use the following command:

  1. Run all tests:
rails test  
  1. Run a specific test file:
rails test <path/to/test/file>

Example:

rails test test/controllers/records_controller_test.rb

Error Handling

  • StandardError: Triggered by unexpected system errors or issues in external API calls, returning a 500 Internal Server Error.
  • ArgumentError: Raised when provided parameters are invalid or missing, returning a 422 Unprocessable Entity.

Summary

  • Features: Describes the main features of the application.
  • Endpoints: Provides details about the available API endpoints, including parameters and responses.
  • Setup: Instructions for setting up the application, including prerequisites and installation steps.
  • Linting: Instructions for linting the code using RuboCop.
  • Testing: Instructions for running the test suite.
  • Error Handling: Describes how errors are handled in the application.

This README file provides a comprehensive overview of the application, its features, and how to set it up and use it.