Git Product home page Git Product logo

cardshark's Introduction

Card Shark

Build Status

Join the chat at https://gitter.im/brisbane-elixir/cardshark

Run locally

Install dependencies

mix deps.get

Set Database URL

export DATABASE_URL="postgres://$(whoami):@localhost/card_shark_dev"

Create database

mix ecto.create

Run database migrations

mix ecto.migrate

Install node dependencies

npm install
bower install

Start server in foreground

mix phoenix.server

Now you can visit card_shark.

Interactive console

iex -S mix phoenix.server

You can execute database actions:

alias CardShark.Repo
alias CardShark.User

users = Repo.all User

changeset = User.changeset(%User{}, %{:email => "[email protected]", :password => "1"})
changeset.valid?
user = Repo.insert changeset

changeset = User.changeset(user, %{:password => "2"})
changeset.valid?
user = Repo.update! changeset

user = Repo.get User, 1
Map.get user, :email
Map.get user, :inserted_at

CardShark.Endpoint.broadcast! "stream", "userevent", %{
  event: "created",
  user: %{
    username: "mark",
    content: "content"
  }
}

CardShark.Endpoint.broadcast! "stream", "cardevent", %{
  event: "created",
  card: %{
    summary: "manage cards",
    detail: "crud operations for managing cards",
    estimate: "1",
    assignee: "mark"
  }
}

Run in docker container

Install docker and docker compose.

fig build
fig up
fig run api mix ecto.create
fig run api mix ecto.migrate

Deploy to heroku

heroku apps:create $NAME
heroku buildpack:set https://github.com/HashNuke/heroku-buildpack-elixir
git push heroku master
heroku config:add DATABASE_USERNAME=$USER DATABASE_PASSWORD=$PASSWORD DATABASE_DATABASE=$DATABASE DATABASE_HOSTNAME=$HOSTNAME
heroku run mix ecto.migrate

You can get the values for the required DATABASE environment variables by splitting the heroku generated DATABASE_URL:

heroku config

DATABASE_URL=postgres://$USER:$PASSWORD@$HOSTNAME:5432/$DATABASE

Now you can visit http//$NAME.herokuapp.com.

API

export CARD_SHARK_URL=http://127.0.0.1:4000

Cards

The cards model, controller, views were initially created with the following generator:

mix phoenix.gen.json Card cards summary:string detail:text estimate:integer assignee:integer

Create card

curl $CARD_SHARK_URL/api/cards \
  -H 'Content-Type: application/json' \
  -X POST \
  -d @/dev/stdin <<JSON
{
  "card": {
    "summary": "manage cards",
    "detail": "crud operations for managing cards",
    "estimate": "1",
    "assignee": "1",
    "priority": "30.0",
    "status": "todo"
  }
}
JSON

List cards

curl $CARD_SHARK_URL/api/cards

http $CARD_SHARK_URL/api/cards

Show card

curl $CARD_SHARK_URL/api/cards/1

http $CARD_SHARK_URL/api/cards/1

Update card

curl $CARD_SHARK_URL/api/cards/1 \
  -H 'Content-Type: application/json' \
  -X PUT \
  -d @/dev/stdin <<JSON
{
  "card": {
    "summary": "create, read, update, and delete cards"
  }
}
JSON

Delete card

curl $CARD_SHARK_URL/api/cards/1 -X DELETE

Users

Create user

curl $CARD_SHARK_URL/api/users \
  -H 'Content-Type: application/json' \
  -X POST \
  -d @/dev/stdin <<JSON
{
  "user": {
    "email": "[email protected]",
    "password": "1"
  }
}
JSON

List users

curl $CARD_SHARK_URL/api/users

Show user

curl $CARD_SHARK_URL/api/users/1

Update user

curl $CARD_SHARK_URL/api/users/1 \
  -H 'Content-Type: application/json' \
  -X PUT \
  -d @/dev/stdin <<JSON
{
  "user": {
    "password": "2"
  }
}
JSON

Delete user

curl $CARD_SHARK_URL/api/users/1 -X DELETE

cardshark's People

Contributors

colinbankier avatar gitter-badger avatar markryall avatar

Watchers

 avatar  avatar

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.