4
1
Fork 0

Add back unmerged stuff

pull/24/head
Ambrose Chua 2019-08-31 12:32:22 +08:00
parent b24874b661
commit ad7029f26a
3 changed files with 39 additions and 39 deletions

View File

@ -71,14 +71,14 @@ func (h *Handler) GetConversations(w http.ResponseWriter, r *http.Request, p htt
// Select // Select
rows, err := h.db.Query(` rows, err := h.db.Query(`
SELECT id, CASE SELECT "conversation".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 "conversation".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 "conversation".picture,
FROM "conversation" member.pinned
INNER JOIN member FROM "conversation", member
ON member.conversation = "conversation".id AND member.user = $1 WHERE member.conversation = "conversation".id AND member.user = $1
`, userID) `, userID)
if err != nil { if err != nil {
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError) http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
@ -113,14 +113,14 @@ func (h *Handler) GetConversation(w http.ResponseWriter, r *http.Request, p http
// Select // Select
err := h.db.QueryRow(` err := h.db.QueryRow(`
SELECT id, CASE SELECT "conversation".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 "conversation".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 "conversation" picture,
FROM "conversation" member.pinned
INNER JOIN member FROM "conversation", member
ON member.conversation = "conversation".id AND member.user = $1 AND member.conversation = $2 WHERE member.conversation = "conversation".id AND member.user = $1 AND member.conversation = $2
`, userID, conversationID).Scan(&conversation.ID, &conversation.Title, &conversation.Picture) `, userID, conversationID).Scan(&conversation.ID, &conversation.Title, &conversation.Picture)
switch { switch {