From a48a4f4e2d5656087a0ca5b4cfef0f04a712f28e Mon Sep 17 00:00:00 2001 From: orcas Date: Tue, 2 Jul 2019 23:01:44 +0800 Subject: [PATCH] Added option to specify created conversation is a DM --- README.md | 5 +++-- handlers.go | 4 ++-- types.go | 1 + 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index fb91f7a..2a3e26c 100644 --- a/README.md +++ b/README.md @@ -23,14 +23,14 @@ Supply environment variables by either exporting them or editing ```.env```. ## API -Unless otherwise noted, bodies and responses are with `Content-Type: application/json`. Endpoints marked with a `*` require a populated `X-User-Claim` header from `backend-auth`. +Unless otherwise noted, bodies and responses are with `Content-Type: application/json`. Endpoints marked with a ```*``` require a populated `X-User-Claim` header from `backend-auth`. | Contents | | -------- | | [Create User](#Create-User) | | [Get Users by Phone](#Get-Users-by-Phone) | | [Get User by ID](#Get-User-by-ID) | -| [Get User by Username(#Get-User-by-Username) ] +| [Get User by Username](#Get-User-by-Username) ] | [Update User](#Update-User) | | [Create Conversation](#Create-Conversation) | | [Delete Conversation](#Delete-Conversation) | @@ -252,6 +252,7 @@ Create a new conversation for a user. | Name | Type | Description | Required | | ---- | ---- | ----------- | -------- | | title | String | Title of the conversation | X | +| dm | Boolean | Whether the conversation is a DM or not | X | #### Success Response (200 OK) diff --git a/handlers.go b/handlers.go index f7233ce..5bc0a81 100644 --- a/handlers.go +++ b/handlers.go @@ -225,8 +225,8 @@ func (h *Handler) CreateConversation(w http.ResponseWriter, r *http.Request, p h // Conversation _, err1 := tx.Exec(` - INSERT INTO "conversation" (id, title) VALUES ($1, $2) - `, conversation.ID, conversation.Title) + INSERT INTO "conversation" (id, title, dm) VALUES ($1, $2, $3) + `, conversation.ID, conversation.Title, conversation.DM) // First member _, err2 := tx.Exec(` INSERT INTO member ("user", "conversation") VALUES ($1, $2) diff --git a/types.go b/types.go index 5a9524e..abd8b6d 100644 --- a/types.go +++ b/types.go @@ -3,6 +3,7 @@ package main type Conversation struct { ID string `json:"id"` // id Title string `json:"title"` // title + DM bool `json:"dm"` // dm } type User struct {