Skip to content

Commit

Permalink
firebase auth, implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
bhattaraibishal50 committed Aug 31, 2020
1 parent 71d8521 commit a83e48d
Show file tree
Hide file tree
Showing 11 changed files with 227 additions and 108 deletions.
2 changes: 2 additions & 0 deletions common/firebase.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// Package common - common packs
// References : https://github.com/firebase/firebase-admin-go
package common

import (
Expand Down
18 changes: 18 additions & 0 deletions common/httpUtil.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package common

import "github.com/gin-gonic/gin"

// NewHTTPError example
func NewHTTPError(ctx *gin.Context, status int, err error) {
er := HTTPError{
Code: status,
Message: err.Error(),
}
ctx.JSON(status, er)
}

// HTTPError example
type HTTPError struct {
Code int `json:"code" example:"400"`
Message string `json:"message" example:"Request Failure"`
}
82 changes: 50 additions & 32 deletions docs/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,63 +29,81 @@ var doc = `{
"host": "{{.Host}}",
"basePath": "{{.BasePath}}",
"paths": {
"/posts/create": {
"/users/login": {
"post": {
"description": "Add Posts",
"description": "Login user by email and password",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"summary": "Add Posts",
"tags": [
"users"
],
"summary": "Login user",
"parameters": [
{
"type": "string",
"description": "name search by q",
"name": "q",
"in": "query"
"description": "Login user",
"name": "Body",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/model.LoginUser"
}
}
],
"responses": {
"200": {
"description": "OK",
"400": {
"description": "Bad Request",
"schema": {
"$ref": "#/definitions/common.HTTPError"
}
},
"404": {
"description": "Not Found",
"schema": {
"$ref": "#/definitions/common.HTTPError"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"type": "array",
"items": {
"$ref": "#/definitions/model.Post"
}
},
"headers": {
"Token": {
"type": "string",
"description": "qwerty"
}
"$ref": "#/definitions/common.HTTPError"
}
}
}
}
}
},
"definitions": {
"model.Post": {
"common.HTTPError": {
"type": "object",
"properties": {
"code": {
"type": "integer",
"example": 400
},
"message": {
"type": "string",
"example": "Request Failure"
}
}
},
"model.LoginUser": {
"type": "object",
"required": [
"Description",
"Title"
"Email",
"Password"
],
"properties": {
"Description": {
"type": "string"
},
"Title": {
"type": "string"
},
"createdAt": {
"type": "string"
"Email": {
"type": "string",
"example": "email"
},
"id": {
"type": "string"
"Password": {
"type": "string",
"example": "password"
}
}
}
Expand Down
82 changes: 50 additions & 32 deletions docs/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,63 +9,81 @@
"license": {}
},
"paths": {
"/posts/create": {
"/users/login": {
"post": {
"description": "Add Posts",
"description": "Login user by email and password",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"summary": "Add Posts",
"tags": [
"users"
],
"summary": "Login user",
"parameters": [
{
"type": "string",
"description": "name search by q",
"name": "q",
"in": "query"
"description": "Login user",
"name": "Body",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/model.LoginUser"
}
}
],
"responses": {
"200": {
"description": "OK",
"400": {
"description": "Bad Request",
"schema": {
"$ref": "#/definitions/common.HTTPError"
}
},
"404": {
"description": "Not Found",
"schema": {
"$ref": "#/definitions/common.HTTPError"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"type": "array",
"items": {
"$ref": "#/definitions/model.Post"
}
},
"headers": {
"Token": {
"type": "string",
"description": "qwerty"
}
"$ref": "#/definitions/common.HTTPError"
}
}
}
}
}
},
"definitions": {
"model.Post": {
"common.HTTPError": {
"type": "object",
"properties": {
"code": {
"type": "integer",
"example": 400
},
"message": {
"type": "string",
"example": "Request Failure"
}
}
},
"model.LoginUser": {
"type": "object",
"required": [
"Description",
"Title"
"Email",
"Password"
],
"properties": {
"Description": {
"type": "string"
},
"Title": {
"type": "string"
},
"createdAt": {
"type": "string"
"Email": {
"type": "string",
"example": "email"
},
"id": {
"type": "string"
"Password": {
"type": "string",
"example": "password"
}
}
}
Expand Down
61 changes: 37 additions & 24 deletions docs/swagger.yaml
Original file line number Diff line number Diff line change
@@ -1,17 +1,24 @@
definitions:
model.Post:
common.HTTPError:
properties:
Description:
code:
example: 400
type: integer
message:
example: Request Failure
type: string
Title:
type: string
createdAt:
type: object
model.LoginUser:
properties:
Email:
example: email
type: string
id:
Password:
example: password
type: string
required:
- Description
- Title
- Email
- Password
type: object
info:
contact:
Expand All @@ -20,28 +27,34 @@ info:
url: http://readytowork.jp
license: {}
paths:
/posts/create:
/users/login:
post:
consumes:
- application/json
description: Add Posts
description: Login user by email and password
parameters:
- description: name search by q
in: query
name: q
type: string
- description: Login user
in: body
name: Body
required: true
schema:
$ref: '#/definitions/model.LoginUser'
produces:
- application/json
responses:
"200":
description: OK
headers:
Token:
description: qwerty
type: string
"400":
description: Bad Request
schema:
$ref: '#/definitions/common.HTTPError'
"404":
description: Not Found
schema:
$ref: '#/definitions/common.HTTPError'
"500":
description: Internal Server Error
schema:
items:
$ref: '#/definitions/model.Post'
type: array
summary: Add Posts
$ref: '#/definitions/common.HTTPError'
summary: Login user
tags:
- users
swagger: "2.0"
10 changes: 1 addition & 9 deletions post/usecase/postUsecase.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,7 @@ func GetPosts(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{"data": &posts})
}

// AddPosts godoc
// @Summary Add Posts
// @Description Add Posts
// @Accept json
// @Produce json
// @Param q query string false "name search by q"
// @Success 200 {array} model.Post
// @Header 200 {string} Token "qwerty"
// @Router /posts/create [post]
// AddPosts add the post
func AddPosts(c *gin.Context) {
// for json type data we need to bind with the struct references https://mholt.github.io/json-to-go/
//JSON BIND
Expand Down
Binary file modified tmp/runner-build
Binary file not shown.
22 changes: 14 additions & 8 deletions user/model/userModel.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
package model

// UserModel usermodel
type UserModel struct {
ID uint `gorm:"primary_key" json:"ID"`
Username string `gorm:"column:username" json:"Username" `
Email string `gorm:"column:email;unique_index" json:"Email"`
Bio string `gorm:"column:bio;size:1024" json:"Bio"`
Image string `gorm:"column:image" json:"Image"`
Password string `gorm:"column:password;not null" json:"Password"`
// User usermodel
type User struct {
ID uint `json:"ID"`
Username string `json:"Username"`
Email string `json:"Email"`
Bio string `json:"Bio"`
Image string `json:"Image"`
Password string `json:"Password" `
}

// LoginUser userModel
type LoginUser struct {
Email string `json:"Email" example:"email" binding:"required"`
Password string `json:"Password" example:"password" binding:"required"`
}
Loading

0 comments on commit a83e48d

Please sign in to comment.