Skip to content
This repository has been archived by the owner on Dec 7, 2023. It is now read-only.

taiwan-voting-guide/backend

Repository files navigation

Backend

Setup Development Environment

  1. Install Docker Desktop
  2. Download Go 1.19
  3. Clone the repo
git clone git@github.com:taiwan-voting-guide/backend.git
cd backend
  1. Setup postgres
docker run \
-v `pwd`/init.sql:/docker-entrypoint-initdb.d/init.sql:ro \
--name pg \
-e POSTGRES_USER=backend_user \
-e POSTGRES_PASSWORD=password \
-e POSTGRES_DB=tvg \
-p 5432:5432 \
-d postgres
  1. Copy env file
cp .env.example .env
# copy google client id from slack #tech
  1. Start the server
go run main.go
  1. Init politicians testing
./scripts/init_politicians.sh
  1. (optional) Download pgAdmin

Staging APIs

Create a staging record

table: This refers to the target table to be processed.

searchBy: These are the fields used to search the target table. If the data already exists in the target table, a create record is created. If not, an update record is created.

fields: These are the individual fields used for the target table. If a field is a reference to another table, the reference's ID is searched for and replaced.

POST /workspace/staging

{
    "table": "parties",
    "searchBy": {
        "name": "民主進步黨" 
    },
    "fields": {
        "name": "民主進步黨",
        "chairman": "賴清德",
        "established_date": "2012-12-12",
        "filing_date": "2012-12-12",
        "main_office_address": "kkkkkkkk",
        "mailing_address": "aaaaaaaaaa",
        "phone_number": "091123321",
        "status": "三小"
    }
}
POST /workspace/staging

{
    "table": "politicians",
    "searchBy": {
        "name": "許淑華",
        "birthdate": "1975-05-22"
    },
    "fields": {
        "name": "許淑華",
        "birthdate": "1975-05-22",
        "sex": "female",
        "current_party_id": {
            "table": "parties",
            "searchBy": {
                "name": "中國國民黨"
            }
        }
    }
}

Troubleshoot

  1. Wired db connection/schema error: Try pulling the latest master and re-init pg.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages