MingaudasVagonis / go-attractions-server

REST API, database & image handling in go used for collecting Lithuanian attractions.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

REST API, database & image handling in go

REST API used to help populate sqlite database with attractions in Lithuania. The program also handles images from an url.Used with frontend.

Retrieving data and images

see retrieve.go

merge [target database url] [optional: url used to post the images]

Merging process consists of the following steps:

  • Adding data from cache database to the target database
  • Downloading images
  • Processing images
  • Saving them locally or posting them to the url provided

API

see server.go

API has the following two routes

add [POST]

Used to add an attraction to the database Requst body must contain a json object with fields:

  • category string | must be one of: nature, heritage, museums
  • description json object
    • name string | must be longer than 3
    • hours json object
      • wkd string | must match ([0-9]{2}:[0-9]{2}-[0-9]{2}:[0-9]{2}) pattern
      • std string | must match ([0-9]{2}:[0-9]{2}-[0-9]{2}:[0-9]{2}) pattern
      • snd string | must match ([0-9]{2}:[0-9]{2}-[0-9]{2}:[0-9]{2}) pattern
    • info string | must be longer than 30 characters
  • location json object
    • city string | must be longet than 3 characters and contain only lithuanian alphabet
    • coordinates json object
      • latitude number | must fall between 53.53 and 56.27
      • longitude number | must fall between 20.56 and 26.5
  • image json object
    • url string | may be null
    • copyright string | may be null

check [GET]

Used to check whether the attraction allready exists in the database. Request must contain the following query paramters:

  • name string | name of the object

Otherwise response status will be 404.

Attractions' and database structure

see db.go attraction.go

Cache stores attraction objects in the following columns

  • id text, not null
  • category text, not null
  • description text, not null
    • description is a stringified json object that consits of:
      • name string
      • hours json object
      • info string
  • location text, not null
    • location is a stringified json object that consits of:
      • city string
      • coordinates json object
  • copyright text
  • url text

Target database schema does not contain url column

Cache stores data used to check whether an attraction already exists in the following columns

  • compare string | value used to compare the names a.k.a id
  • display string | value used to display results to the user

Libraries and usage

Following libraries are used

One time launch:

  git clone https://github.com/MingaudasVagonis/go-attractions-server.git
  cd go-attractions-server
  go run main.go db.go attraction.go server.go utils.go retrieve.go

Commands

merge [target database url] [optional: url used to post the images]

initialize [external database url]

  • Adds data used to check whether the attraction exists from an external database.

About

REST API, database & image handling in go used for collecting Lithuanian attractions.


Languages

Language:Go 100.0%