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

Update gorm to v2 #36

Merged
merged 4 commits into from
Oct 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion action/organisation/details.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
// @Param X-User header string true "User ID"
// @Param organisation_id path string true "Organisation ID"
// @Success 200 {object} orgWithRole
// @Router /organisaion/{organisation_id} [get]
// @Router /organisations/{organisation_id} [get]
func details(w http.ResponseWriter, r *http.Request) {

organisationID := chi.URLParam(r, "organisation_id")
Expand Down
2 changes: 1 addition & 1 deletion action/organisation/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
// @Produce json
// @Param X-User header string true "User ID"
// @Success 200 {array} []orgWithRole
// @Router /organisations [get]
// @Router /organisations/my [get]
func list(w http.ResponseWriter, r *http.Request) {
organisationUser := make([]model.OrganisationUser, 0)

Expand Down
19 changes: 14 additions & 5 deletions action/organisation/user/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,23 @@ func create(w http.ResponseWriter, r *http.Request) {

tx := model.DB.Begin()

invitee := model.User{}

tx.FirstOrCreate(&invitee, &model.User{
invitee := model.User{
Email: req.Email,
})
}

err = tx.Where(&invitee).First(&invitee).Error

if err != nil {
tx.Create(&invitee)
}

// * FirstOrCreate method giving error right now
// tx.FirstOrCreate(&invitee, model.User{
// Email: req.Email,
// })

// Check if invitee already exist in organisation
var totPermissions int
var totPermissions int64
permission := &model.OrganisationUser{}
permission.OrganisationID = uint(orgID)
permission.UserID = invitee.ID
Expand Down
2 changes: 1 addition & 1 deletion action/organisation/user/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func delete(w http.ResponseWriter, r *http.Request) {
}

// Check if the user to delete is not last owner of organisation
var totalOwners int
var totalOwners int64
model.DB.Model(&model.OrganisationUser{}).Where(&model.OrganisationUser{
Role: "owner",
OrganisationID: uint(orgID),
Expand Down
17 changes: 13 additions & 4 deletions action/user/checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,23 @@ func checker(w http.ResponseWriter, r *http.Request) {
return
}

user := &model.User{}

identity := payload.Extra["identity"].(map[string]interface{})
traits := identity["traits"].(map[string]interface{})

model.DB.FirstOrCreate(user, &model.User{
user := model.User{
Email: traits["email"].(string),
})
}

err = model.DB.Where(&user).First(&user).Error

if err != nil {
model.DB.Create(&user)
}

// * FirstOrCreate method giving error right now
// model.DB.FirstOrCreate(user, &model.User{
// Email: traits["email"].(string),
// })

payload.Header.Add("X-User", fmt.Sprint(user.ID))
renderx.JSON(w, http.StatusOK, payload)
Expand Down
78 changes: 39 additions & 39 deletions docs/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,17 @@ var doc = `{
"host": "{{.Host}}",
"basePath": "{{.BasePath}}",
"paths": {
"/organisaion/{organisation_id}": {
"get": {
"description": "Get organisation by ID",
"/organisations": {
"post": {
"description": "Create organisation",
"produces": [
"application/json"
],
"tags": [
"Organisation"
],
"summary": "Show a organisation by id",
"operationId": "get-organisation-by-id",
"summary": "Create organisation",
"operationId": "add-organisation",
"parameters": [
{
"type": "string",
Expand All @@ -52,24 +52,35 @@ var doc = `{
"required": true
},
{
"type": "string",
"description": "Organisation ID",
"name": "organisation_id",
"in": "path",
"required": true
"description": "Organisation Object",
"name": "Organisation",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/organisation.organisation"
}
}
],
"responses": {
"200": {
"description": "OK",
"201": {
"description": "Created",
"schema": {
"$ref": "#/definitions/organisation.orgWithRole"
}
},
"400": {
"description": "Bad Request",
"schema": {
"type": "array",
"items": {
"type": "string"
}
}
}
}
}
},
"/organisations": {
"/organisations/my": {
"get": {
"description": "Get all organisations",
"produces": [
Expand Down Expand Up @@ -103,17 +114,19 @@ var doc = `{
}
}
}
},
"post": {
"description": "Create organisation",
}
},
"/organisations/{organisation_id}": {
"get": {
"description": "Get organisation by ID",
"produces": [
"application/json"
],
"tags": [
"Organisation"
],
"summary": "Create organisation",
"operationId": "add-organisation",
"summary": "Show a organisation by id",
"operationId": "get-organisation-by-id",
"parameters": [
{
"type": "string",
Expand All @@ -123,35 +136,22 @@ var doc = `{
"required": true
},
{
"description": "Organisation Object",
"name": "Organisation",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/organisation.organisation"
}
"type": "string",
"description": "Organisation ID",
"name": "organisation_id",
"in": "path",
"required": true
}
],
"responses": {
"201": {
"description": "Created",
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/organisation.orgWithRole"
}
},
"400": {
"description": "Bad Request",
"schema": {
"type": "array",
"items": {
"type": "string"
}
}
}
}
}
},
"/organisations/{organisation_id}": {
},
"put": {
"description": "Update organisation by ID",
"produces": [
Expand Down
78 changes: 39 additions & 39 deletions docs/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,17 @@
"host": "localhost:5000",
"basePath": "/",
"paths": {
"/organisaion/{organisation_id}": {
"get": {
"description": "Get organisation by ID",
"/organisations": {
"post": {
"description": "Create organisation",
"produces": [
"application/json"
],
"tags": [
"Organisation"
],
"summary": "Show a organisation by id",
"operationId": "get-organisation-by-id",
"summary": "Create organisation",
"operationId": "add-organisation",
"parameters": [
{
"type": "string",
Expand All @@ -37,24 +37,35 @@
"required": true
},
{
"type": "string",
"description": "Organisation ID",
"name": "organisation_id",
"in": "path",
"required": true
"description": "Organisation Object",
"name": "Organisation",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/organisation.organisation"
}
}
],
"responses": {
"200": {
"description": "OK",
"201": {
"description": "Created",
"schema": {
"$ref": "#/definitions/organisation.orgWithRole"
}
},
"400": {
"description": "Bad Request",
"schema": {
"type": "array",
"items": {
"type": "string"
}
}
}
}
}
},
"/organisations": {
"/organisations/my": {
"get": {
"description": "Get all organisations",
"produces": [
Expand Down Expand Up @@ -88,17 +99,19 @@
}
}
}
},
"post": {
"description": "Create organisation",
}
},
"/organisations/{organisation_id}": {
"get": {
"description": "Get organisation by ID",
"produces": [
"application/json"
],
"tags": [
"Organisation"
],
"summary": "Create organisation",
"operationId": "add-organisation",
"summary": "Show a organisation by id",
"operationId": "get-organisation-by-id",
"parameters": [
{
"type": "string",
Expand All @@ -108,35 +121,22 @@
"required": true
},
{
"description": "Organisation Object",
"name": "Organisation",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/organisation.organisation"
}
"type": "string",
"description": "Organisation ID",
"name": "organisation_id",
"in": "path",
"required": true
}
],
"responses": {
"201": {
"description": "Created",
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/organisation.orgWithRole"
}
},
"400": {
"description": "Bad Request",
"schema": {
"type": "array",
"items": {
"type": "string"
}
}
}
}
}
},
"/organisations/{organisation_id}": {
},
"put": {
"description": "Update organisation by ID",
"produces": [
Expand Down
Loading