Add back unmerged stuff
parent
b24874b661
commit
ad7029f26a
|
@ -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 {
|
||||||
|
@ -263,12 +263,12 @@ func (h *Handler) CreateConversationMember(w http.ResponseWriter, r *http.Reques
|
||||||
// Check for existing DM
|
// Check for existing DM
|
||||||
var dmID string
|
var dmID string
|
||||||
err = h.db.QueryRow(`
|
err = h.db.QueryRow(`
|
||||||
SELECT "conversation".id FROM "conversation", "member"
|
SELECT "conversation".id FROM "conversation", "member"
|
||||||
WHERE
|
WHERE
|
||||||
"conversation".dm = TRUE
|
"conversation".dm = TRUE
|
||||||
AND "conversation".id = "member".conversation
|
AND "conversation".id = "member".conversation
|
||||||
AND "member".user = $1
|
AND "member".user = $1
|
||||||
`, member.ID).Scan(&dmID)
|
`, member.ID).Scan(&dmID)
|
||||||
if err != sql.ErrNoRows {
|
if err != sql.ErrNoRows {
|
||||||
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
|
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
|
@ -280,19 +280,19 @@ func (h *Handler) CreateConversationMember(w http.ResponseWriter, r *http.Reques
|
||||||
// Check for valid conversation and prevent duplicate entries
|
// Check for valid conversation and prevent duplicate entries
|
||||||
var test string
|
var test string
|
||||||
err = h.db.QueryRow(`
|
err = h.db.QueryRow(`
|
||||||
SELECT "conversation".id FROM "conversation", "member"
|
SELECT "conversation".id FROM "conversation", "member"
|
||||||
WHERE
|
WHERE
|
||||||
"conversation".id = $1
|
"conversation".id = $1
|
||||||
AND (
|
AND (
|
||||||
"conversation".dm = FALSE
|
"conversation".dm = FALSE
|
||||||
OR (SELECT
|
OR (SELECT
|
||||||
COUNT("member".user)
|
COUNT("member".user)
|
||||||
FROM "member"
|
FROM "member"
|
||||||
WHERE "member".conversation = $1)
|
WHERE "member".conversation = $1)
|
||||||
<= 2)
|
<= 2)
|
||||||
AND "member".conversation = "conversation".id
|
AND "member".conversation = "conversation".id
|
||||||
AND "member".user <> $2
|
AND "member".user <> $2
|
||||||
`, conversationID, member.ID).Scan(&test)
|
`, conversationID, member.ID).Scan(&test)
|
||||||
switch {
|
switch {
|
||||||
case err == sql.ErrNoRows:
|
case err == sql.ErrNoRows:
|
||||||
http.Error(w, http.StatusText(http.StatusNotFound), http.StatusNotFound)
|
http.Error(w, http.StatusText(http.StatusNotFound), http.StatusNotFound)
|
||||||
|
|
2
main.go
2
main.go
|
@ -52,7 +52,7 @@ func main() {
|
||||||
router.GET("/user/conversation/:conversation", AuthMiddleware(h.GetConversation)) // USER MEMBER CONVERSATION
|
router.GET("/user/conversation/:conversation", AuthMiddleware(h.GetConversation)) // USER MEMBER CONVERSATION
|
||||||
router.PATCH("/user/conversation/:conversation", AuthMiddleware(h.UpdateConversation)) // USER MEMBER CONVERSATION ADMIN=true -> update conversation title
|
router.PATCH("/user/conversation/:conversation", AuthMiddleware(h.UpdateConversation)) // USER MEMBER CONVERSATION ADMIN=true -> update conversation title
|
||||||
//router.DELETE("/user/:user/conversation/:conversation", h.DeleteConversation) // USER MEMBER CONVERSATION -> delete membership
|
//router.DELETE("/user/:user/conversation/:conversation", h.DeleteConversation) // USER MEMBER CONVERSATION -> delete membership
|
||||||
router.POST("/user/conversation/:conversation/pin", AuthMiddleware(h.PinConversation))
|
router.POST("/user/conversation/:conversation/pin", AuthMiddleware(h.PinConversation))
|
||||||
router.POST("/user/conversation/:conversation/member", AuthMiddleware(h.CreateConversationMember)) // USER MEMBER CONVERSATION ADMIN=true -> create new membership
|
router.POST("/user/conversation/:conversation/member", AuthMiddleware(h.CreateConversationMember)) // USER MEMBER CONVERSATION ADMIN=true -> create new membership
|
||||||
router.GET("/user/conversation/:conversation/member", AuthMiddleware(h.GetConversationMembers)) // USER MEMBER CONVERSATION
|
router.GET("/user/conversation/:conversation/member", AuthMiddleware(h.GetConversationMembers)) // USER MEMBER CONVERSATION
|
||||||
//router.DELETE("/user/:user/conversation/:conversation/member/:member", h.DeleteConversationMember) // USER MEMBER CONVERSATION ADMIN=true -> delete membership
|
//router.DELETE("/user/:user/conversation/:conversation/member/:member", h.DeleteConversationMember) // USER MEMBER CONVERSATION ADMIN=true -> delete membership
|
||||||
|
|
6
types.go
6
types.go
|
@ -3,9 +3,9 @@ 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
|
Picture string `json:"picture"` // picture
|
||||||
Pinned bool `json:"pinned"` // pinned
|
Pinned bool `json:"pinned"` // pinned
|
||||||
}
|
}
|
||||||
|
|
||||||
type User struct {
|
type User struct {
|
||||||
|
|
Loading…
Reference in New Issue