Coder Social home page Coder Social logo

golang-crud-api's Introduction

golang-crud-api

Quick Startup

docker-compose up --build

Quick Info

Made with Docker, Golang, and Postgresql

Write-Up

Within the first four hours, I was able to get the routes created, however that was without database interaction. Database interaction was added an hour or so after that initial 4 hours. I had a lot of issues getting Docker to work on windows, so I saved dockerizing the app for last.

The app makes an assumption that duplicate books are allowed.

I was also unable to do any package splitting(?). For some reason, when I created subfolders with different packages, I could not get the importing to work, so for the sake of time all the files are under the main package. My ideal structure would be something like this:

+-- _server
|   +-- server.go
|   +-- server_test.go
|   +-- server_integration_test.go
+-- _utils
|   +-- utils.go
|   +-- asserts.go
+-- _db
|   +-- database.go
|   +-- controller.go
+-- _models
|   +-- models.go
+-- main.go

Tests on the route functionality run when the container is built. This is due to being unable to cli into the container for some reason, so its set where the build fails if the unit tests fail. Integration tests are included and can be run locally, but because I could not cli into the container, I'm unable to run the integration tests manually. I'm sure the is a way to have the tests run after the database has been finished initializing, but I'm unsure how to write that functionality with docker.

Improvements

A couple things I would implement would be more descriptive error responses - currently I'm only sending back the status code.

Possibly adding a UUID lookup to allow for more accurate searches on books with duplicate titles but different meta data.

Getting the integration tests to run automatically after the postgres database is initialized and populated.

Book Model Structure

The books table is structured as follows:

id (uuid)
title (string)
author (string)
published_date (date)
publisher (string)
rating (int)
status (string)

Routes

GET

There are 2 get routes:

/books 
/books/[title]

/books returns all books in the DB

/books/[title] returns a book with a matching title

POST

/books

example body params:

  {
    "title": "title",
    "author": "author",
    "publishDate": "2009-01-20",
    "publisher": "publisher",
    "rating": 3,
    "status": "CheckedIn"
  }

PUT

/books/[title]

/books/[title] updates a book with matching title using supplied body params. Any number of params may be entered matching the POST example.

DELETE

/books/[title]

/books/[title] deletes a book matching the supplied title.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.