Support group picture in endpoints
parent
faa2076a43
commit
59c8e4a907
|
@ -253,6 +253,7 @@ Create a new conversation for a user.
|
||||||
| ---- | ---- | ----------- | -------- |
|
| ---- | ---- | ----------- | -------- |
|
||||||
| title | String | Title of the conversation | X |
|
| title | String | Title of the conversation | X |
|
||||||
| dm | Boolean | Whether the conversation is a DM or not | X |
|
| dm | Boolean | Whether the conversation is a DM or not | X |
|
||||||
|
| picture | String | URL of the group's picture | X |
|
||||||
|
|
||||||
#### Success Response (200 OK)
|
#### Success Response (200 OK)
|
||||||
|
|
||||||
|
@ -261,7 +262,8 @@ Conversation object.
|
||||||
```json
|
```json
|
||||||
{
|
{
|
||||||
"id": "<id>",
|
"id": "<id>",
|
||||||
"title": "<title>"
|
"title": "<title>",
|
||||||
|
"picture": "<picture>"
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -322,6 +324,7 @@ Update a conversation's details (mainly just title for now).
|
||||||
| Name | Type | Description | Required |
|
| Name | Type | Description | Required |
|
||||||
| ---- | ---- | ----------- | -------- |
|
| ---- | ---- | ----------- | -------- |
|
||||||
| title | String | New title of the conversation. | X |
|
| title | String | New title of the conversation. | X |
|
||||||
|
| picture | String | New URL of the group's picture | X |
|
||||||
|
|
||||||
#### Success Response (200 OK)
|
#### Success Response (200 OK)
|
||||||
|
|
||||||
|
@ -354,6 +357,7 @@ List of conversations.
|
||||||
{
|
{
|
||||||
"id": "<id>",
|
"id": "<id>",
|
||||||
"title": "<title>"
|
"title": "<title>"
|
||||||
|
"picture": "<picture>"
|
||||||
},
|
},
|
||||||
...
|
...
|
||||||
]
|
]
|
||||||
|
@ -389,7 +393,8 @@ Conversation object.
|
||||||
```json
|
```json
|
||||||
{
|
{
|
||||||
"id": "<id>",
|
"id": "<id>",
|
||||||
"title": "<title>"
|
"title": "<title>",
|
||||||
|
"picture": "<picture>"
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
22
handlers.go
22
handlers.go
|
@ -225,8 +225,8 @@ func (h *Handler) CreateConversation(w http.ResponseWriter, r *http.Request, p h
|
||||||
|
|
||||||
// Conversation
|
// Conversation
|
||||||
_, err1 := tx.Exec(`
|
_, err1 := tx.Exec(`
|
||||||
INSERT INTO "conversation" (id, title, dm) VALUES ($1, $2, $3)
|
INSERT INTO "conversation" (id, title, dm, picture) VALUES ($1, $2, $3, $4)
|
||||||
`, conversation.ID, conversation.Title, conversation.DM)
|
`, conversation.ID, conversation.Title, conversation.DM, conversation.Picture)
|
||||||
// First member
|
// First member
|
||||||
_, err2 := tx.Exec(`
|
_, err2 := tx.Exec(`
|
||||||
INSERT INTO member ("user", "conversation") VALUES ($1, $2)
|
INSERT INTO member ("user", "conversation") VALUES ($1, $2)
|
||||||
|
@ -262,7 +262,8 @@ func (h *Handler) GetConversations(w http.ResponseWriter, r *http.Request, p htt
|
||||||
SELECT id, CASE
|
SELECT id, CASE
|
||||||
WHEN dm THEN (SELECT CONCAT("user".first_name, ' ', "user".last_name) FROM "user", member WHERE "user".id <> $1 AND "user".id = member.user AND member.conversation = "conversation".id)
|
WHEN dm THEN (SELECT CONCAT("user".first_name, ' ', "user".last_name) FROM "user", member WHERE "user".id <> $1 AND "user".id = member.user AND member.conversation = "conversation".id)
|
||||||
ELSE title
|
ELSE title
|
||||||
END AS title
|
END AS title,
|
||||||
|
picture
|
||||||
FROM "conversation"
|
FROM "conversation"
|
||||||
INNER JOIN member
|
INNER JOIN member
|
||||||
ON member.conversation = "conversation".id AND member.user = $1
|
ON member.conversation = "conversation".id AND member.user = $1
|
||||||
|
@ -276,13 +277,13 @@ func (h *Handler) GetConversations(w http.ResponseWriter, r *http.Request, p htt
|
||||||
|
|
||||||
// Scan
|
// Scan
|
||||||
for rows.Next() {
|
for rows.Next() {
|
||||||
var id, title string
|
var id, title, picture string
|
||||||
if err := rows.Scan(&id, &title); err != nil {
|
if err := rows.Scan(&id, &title, &picture); err != nil {
|
||||||
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
|
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
|
||||||
log.Print(err)
|
log.Print(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
conversations = append(conversations, Conversation{ID:id, Title:title, DM:false})
|
conversations = append(conversations, Conversation{ID:id, Title:title, DM:false, Picture:picture})
|
||||||
}
|
}
|
||||||
|
|
||||||
// Respond
|
// Respond
|
||||||
|
@ -303,11 +304,12 @@ func (h *Handler) GetConversation(w http.ResponseWriter, r *http.Request, p http
|
||||||
SELECT id, CASE
|
SELECT id, CASE
|
||||||
WHEN dm THEN (SELECT CONCAT("user".first_name, ' ', "user".last_name) FROM "user", member WHERE "user".id <> $1 AND "user".id = member.user AND member.conversation = "conversation".id)
|
WHEN dm THEN (SELECT CONCAT("user".first_name, ' ', "user".last_name) FROM "user", member WHERE "user".id <> $1 AND "user".id = member.user AND member.conversation = "conversation".id)
|
||||||
ELSE title
|
ELSE title
|
||||||
END AS title
|
END AS title,
|
||||||
|
picture
|
||||||
FROM "conversation"
|
FROM "conversation"
|
||||||
INNER JOIN member
|
INNER JOIN member
|
||||||
ON member.conversation = "conversation".id AND member.user = $1 AND member.conversation = $2
|
ON member.conversation = "conversation".id AND member.user = $1 AND member.conversation = $2
|
||||||
`, userID, conversationID).Scan(&conversation.ID, &conversation.Title)
|
`, userID, conversationID).Scan(&conversation.ID, &conversation.Title, &conversation.Picture)
|
||||||
|
|
||||||
switch {
|
switch {
|
||||||
case err == sql.ErrNoRows:
|
case err == sql.ErrNoRows:
|
||||||
|
@ -357,9 +359,9 @@ func (h *Handler) UpdateConversation(w http.ResponseWriter, r *http.Request, p h
|
||||||
if len(conversation.Title) > 0 {
|
if len(conversation.Title) > 0 {
|
||||||
_, err = h.db.Exec(`
|
_, err = h.db.Exec(`
|
||||||
UPDATE "conversation"
|
UPDATE "conversation"
|
||||||
SET title = $2
|
SET title = $2, picture = $3
|
||||||
WHERE id = $1
|
WHERE id = $1
|
||||||
`, conversationID, conversation.Title)
|
`, conversationID, conversation.Title, conversation.Picture)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
|
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
|
||||||
log.Print(err)
|
log.Print(err)
|
||||||
|
|
7
types.go
7
types.go
|
@ -1,9 +1,10 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
type Conversation struct {
|
type Conversation struct {
|
||||||
ID string `json:"id"` // id
|
ID string `json:"id"` // id
|
||||||
Title string `json:"title"` // title
|
Title string `json:"title"` // title
|
||||||
DM bool `json:"dm"` // dm
|
DM bool `json:"dm"` // dm
|
||||||
|
Picture string `json:"picture"` // picture
|
||||||
}
|
}
|
||||||
|
|
||||||
type User struct {
|
type User struct {
|
||||||
|
|
Loading…
Reference in New Issue