Skip to content
This repository has been archived by the owner on Nov 24, 2021. It is now read-only.

monopayments/iban.im

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

IBAN.im

Shorten, create and share memorable links for IBANS

Purpose

Shorten IBAN numbers with url such as :

  • iban.im/user/alias
  • iban.im/fakturk/garanti

Stacks

Open in Gitpod

Features

  • New users should Sign Up & Sign In
  • Change a Password of user
  • Change a Profile of user
  • Delete a Profile of user
  • Get Profile of user
  • New IBAN add for user
  • Update IBAN for user
  • Delete IBAN for user
  • Get IBAN's of user
  • When adding new IBAN check if is it exist with same name (we can add with different names)
  • A user should add iban to only itself

How to Run

Initialize DB

  1. Create a database
postgres=# CREATE DATABASE ibanim;
  1. Create a user as owner of database
postgres=# CREATE USER ibanim WITH ENCRYPTED PASSWORD 'ibanim';

postgres=# ALTER DATABASE ibanim OWNER TO ibanim;
  1. Grant all privileges to user for the database
postgres=# GRANT ALL PRIVILEGES ON DATABASE ibanim TO ibanim;
  1. Configure the db in db.go
// ConnectDB : connecting DB
func ConnectDB() (*DB, error) {
	db, err := gorm.Open("postgres", "host=localhost port=5432 user=ibanim dbname=ibanim password=ibanim sslmode=disable")

	if err != nil {
		panic(err)
	}

	return &DB{db}, nil
}

or with Docker

host address should be edited to host.docker.internal to connect a host interface.

// ConnectDB : connecting DB
func ConnectDB() (*DB, error) {
	db, err := gorm.Open("postgres", "host=host.docker.internal port=5432 user=ibanim dbname=ibanim password=ibanim sslmode=disable")

	if err != nil {
		panic(err)
	}

	return &DB{db}, nil
}

Initial Migration

$ go run ./migrations/init.go

or with Docker

$ docker build -t ibanim .
$ docker run --rm ibanim migrate

This will generate the users table in the database as per the User Model declared in ./model/user.go

Run the server

$ go run server.go

or with Docker

$ docker run --rm -d -p 8080:8080 ibanim

GraphQL Playground

Connect to http://localhost:8080

Authentication : JWT

You need to set the Http request headers Authorization: {JWT_token}

Usage

Sign Up

mutation {
  signUp(
    email: "[email protected]"
    password: "12345678"
    firstName: "graphql"
    lastName: "go"
    handle:"test"
  ) {
    ok
    error
    user {
      id
      handle
      email
      firstName
      lastName
      bio
      avatar
      createdAt
      updatedAt
    }
  }
}

Sign In

mutation {
  signIn(email: "[email protected]", password: "12345678") {
    ok
    error
    token
  }
}

Change a Password

mutation {
  changePassword(password: "87654321") {
    ok
    error
    user {
      id
      handle
      email
      firstName
      lastName
      bio
      avatar
      createdAt
      updatedAt
    }
  }
}

Change a Profile

mutation {
  changeProfile(bio: "Go developer", avatar: "go-developer.png") {
    ok
    error
    user {
      id
      handle
      email
      firstName
      lastName
      bio
      avatar
      createdAt
      updatedAt
    }
  }
}

Get my profile

query {
  getMyProfile {
    ok
    error
    user {
      id
      handle
      email
      firstName
      lastName
      bio
      avatar
      createdAt
      updatedAt
    }
  }
}

Add new Iban

mutation {
  ibanNew(text:"TR320010009999901234567890",password:"fatih",handle:"fakturk"){
    ok
    error
    iban{
      id
      handle
      text
      password
      createdAt
      updatedAt
    }
  }
}

Update Iban

mutation {
  ibanUpdate(text:"TR420010009999901234567891",password:"fatih",handle:"garanti"){
    ok
    error
    iban{
      id
      handle
      text
      password
      createdAt
      updatedAt
    }
  }
}

Get User IBANs

query {
  getMyIbans {
    ok
    error
    iban {
       id
      handle
      text
      password
      createdAt
      updatedAt
      ownerId
    }
  }
}