diff --git a/.gitignore b/.gitignore index 4a42061..d83913a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ .vscode/ vendor/ +.env diff --git a/controllers/chatcontrollers.go b/controllers/chatcontrollers.go index bd453ac..76f8b4d 100644 --- a/controllers/chatcontrollers.go +++ b/controllers/chatcontrollers.go @@ -13,7 +13,7 @@ import ( "strings" "time" - _ "github.com/cryptoKevinL/walletChatDocs" + _ "rest-go-demo/docs" "github.com/gorilla/mux" ) @@ -38,44 +38,10 @@ type NFTPortOwnerOf struct { Continuation interface{} `json:"continuation"` } -//auto-join to communities for newly acquired NFTs -// func CheckForNewNFTs(walletAddr string) { -// var bookmarks []entity.Bookmarkitem -// database.Connector.Where("walletaddr = ?", walletAddr).Where("chain = ?", "ethereum").Find(&bookmarks) - -// var ownerNFTs = GetOwnerNFTs(walletAddr, "ethereum") -// if len(ownerNFTs.Nfts) > len(bookmarks) { -// //assume the last entry is the new NFT: -// var bookmark entity.Bookmarkitem -// bookmark.Nftaddr = ownerNFTs.Nfts[len(ownerNFTs.Nfts)-1].ContractAddress -// bookmark.Walletaddr = walletAddr - -// fmt.Printf("Found New NFT!: %#v\n", bookmark.Nftaddr) - -// bookmark.Chain = "ethereum" -// database.Connector.Create(bookmark) -// } - -// database.Connector.Where("walletaddr = ?", walletAddr).Where("chain = ?", "polygon").Find(&bookmarks) -// ownerNFTs = GetOwnerNFTs(walletAddr, "polygon") -// if len(ownerNFTs.Nfts) > len(bookmarks) { -// //assume the last entry is the new NFT -// var bookmark entity.Bookmarkitem -// bookmark.Nftaddr = ownerNFTs.Nfts[len(ownerNFTs.Nfts)-1].ContractAddress -// bookmark.Walletaddr = walletAddr - -// fmt.Printf("Found New NFT!: %#v\n", bookmark.Nftaddr) - -// bookmark.Chain = "polygon" -// database.Connector.Create(bookmark) -// } -// //end check for new NFTs -// } - // GetInboxByOwner godoc // @Summary Get Inbox Summary With Last Message // @Description Get Each 1-on-1 Conversation, NFT and Community Chat For Display in Inbox -// @Tags inbox +// @Tags Inbox // @Accept json // @Produce json // @Param address path string true "Wallet Address" @@ -182,6 +148,10 @@ func GetInboxByOwner(w http.ResponseWriter, r *http.Request) { returnItem.Contexttype = entity.Nft returnItem.Chain = bookmarks[idx].Chain } + if strings.HasPrefix(returnItem.Nftaddr, "paop_") { + returnItem.Contexttype = entity.Nft + returnItem.Chain = bookmarks[idx].Chain + } userInbox = append(userInbox, returnItem) continue } @@ -235,6 +205,9 @@ func GetInboxByOwner(w http.ResponseWriter, r *http.Request) { if strings.HasPrefix(returnItem.Nftaddr, "0x") { returnItem.Contexttype = entity.Nft } + if strings.HasPrefix(returnItem.Nftaddr, "poap_") { + returnItem.Contexttype = entity.Nft + } returnItem.Sendername = "" if returnItem.Message == "" { @@ -264,24 +237,25 @@ func GetInboxByOwner(w http.ResponseWriter, r *http.Request) { json.NewEncoder(w).Encode(userInbox) } -// GetAllChatitems godoc -// @Summary Get All Chat Items (legacy - not used currently) -// @Description Get Entire Chatitems table -// @Tags inbox -// @Accept json -// @Produce json -// @Success 200 {array} entity.Chatitem -// @Router /getall_chatitems [get] -func GetAllChatitems(w http.ResponseWriter, r *http.Request) { - var chat []entity.Chatitem - database.Connector.Find(&chat) +//removed since this will take FOREVER and its not used +// func GetAllChatitems(w http.ResponseWriter, r *http.Request) { +// var chat []entity.Chatitem +// database.Connector.Find(&chat) - w.Header().Set("Content-Type", "application/json") - w.WriteHeader(http.StatusOK) - json.NewEncoder(w).Encode(chat) -} +// w.Header().Set("Content-Type", "application/json") +// w.WriteHeader(http.StatusOK) +// json.NewEncoder(w).Encode(chat) +// } -//Get all unread messages TO a specific user, used for total count notification at top notification bar +// GetUnreadMsgCntTotal godoc +// @Summary Get all unread messages TO a specific user, used for total count notification at top notification bar +// @Description Get Each 1-on-1 Conversation, NFT and Community Chat For Display in Inbox +// @Tags Inbox +// @Accept json +// @Produce json +// @Param address path string true "Wallet Address" +// @Success 200 {integer} int +// @Router /get_unread_cnt/{address} [get] func GetUnreadMsgCntTotal(w http.ResponseWriter, r *http.Request) { vars := mux.Vars(r) key := vars["address"] @@ -296,7 +270,16 @@ func GetUnreadMsgCntTotal(w http.ResponseWriter, r *http.Request) { json.NewEncoder(w).Encode(len(chat)) } -//Get all unread messages TO a specific user, used for total count notification at top notification bar +// GetUnreadMsgCntTotalByType godoc +// @Summary Get all unread messages TO a specific user, used for total count notification at top notification bar +// @Description Get Each 1-on-1 Conversation, NFT and Community Chat For Display in Inbox +// @Tags Unused/Legacy +// @Accept json +// @Produce json +// @Param address path string true "Wallet Address" +// @Param type path string true "Message Type - nft|community|dm|all" +// @Success 200 {integer} int +// @Router /get_unread_cnt_by_type/{address}/{type} [get] func GetUnreadMsgCntTotalByType(w http.ResponseWriter, r *http.Request) { vars := mux.Vars(r) key := vars["address"] @@ -365,7 +348,15 @@ func GetUnreadMsgCntTotalByType(w http.ResponseWriter, r *http.Request) { // json.NewEncoder(w).Encode(true) // } -//Get all unread messages TO a specific user, used for total count notification at top notification bar +// GetUnreadcnt godoc +// @Summary Get all unread messages TO a specific user, used for total count notification at top notification bar +// @Description Get Unread count just given an address +// @Tags Inbox +// @Accept json +// @Produce json +// @Param address path string true "Wallet Address" +// @Success 200 {integer} int +// @Router /unreadcount/{address} [get] func GetUnreadcnt(w http.ResponseWriter, r *http.Request) { vars := mux.Vars(r) key := vars["address"] @@ -408,9 +399,9 @@ func GetUnreadcnt(w http.ResponseWriter, r *http.Request) { //end get num unread messages if strings.HasPrefix(groupchat.Nftaddr, "0x") { - config.Nft = len(chatCnt) + config.Nft += len(chatCnt) } else { - config.Community = len(chatCnt) + config.Community += len(chatCnt) } } @@ -423,6 +414,17 @@ func GetUnreadcnt(w http.ResponseWriter, r *http.Request) { json.NewEncoder(w).Encode(config) } +// GetUnreadMsgCntNft godoc +// @Summary Get all unread messages for a specific NFT context +// @Description Get Unread count for specifc NFT context given a wallet address and specific NFT +// @Tags NFT +// @Accept json +// @Produce json +// @Param address path string true "Wallet Address" +// @Param nftaddr path string true "NFT Contract Address" +// @Param nftid path string true "NFT ID" +// @Success 200 {integer} int +// @Router /get_unread_cnt/{address}/{nftaddr}/{nftid} [get] func GetUnreadMsgCntNft(w http.ResponseWriter, r *http.Request) { vars := mux.Vars(r) key := vars["address"] @@ -437,6 +439,15 @@ func GetUnreadMsgCntNft(w http.ResponseWriter, r *http.Request) { json.NewEncoder(w).Encode(len(chat)) } +// GetUnreadMsgCntNft godoc +// @Summary Get all unread messages for all NFT related chats for given user +// @Description Get Unread count for all NFT contexts given a wallet address +// @Tags Unused/Legacy +// @Accept json +// @Produce json +// @Param address path string true "Wallet Address" +// @Success 200 {integer} int +// @Router /get_unread_cnt_nft/{address} [get] func GetUnreadMsgCntNftAllByAddr(w http.ResponseWriter, r *http.Request) { vars := mux.Vars(r) key := vars["address"] @@ -507,7 +518,16 @@ func GetUnreadMsgCntNftAllByAddr(w http.ResponseWriter, r *http.Request) { json.NewEncoder(w).Encode(nftretval) } -//unread count per conversation +// GetUnreadMsgCnt godoc +// @Summary Get all unread messages between two addresses +// @Description Get Unread count for DMs +// @Tags Unused/Legacy +// @Accept json +// @Produce json +// @Param toaddr path string true "TO: Wallet Address" +// @Param from path string true "FROM: Wallet Address" +// @Success 200 {integer} int +// @Router /get_unread_cnt/{fromaddr}/{toaddr} [get] func GetUnreadMsgCnt(w http.ResponseWriter, r *http.Request) { vars := mux.Vars(r) to := vars["toaddr"] @@ -521,7 +541,15 @@ func GetUnreadMsgCnt(w http.ResponseWriter, r *http.Request) { json.NewEncoder(w).Encode(len(chat)) } -//GetChatFromAddressToOwner returns all chat items from user to owner +// GetChatFromAddress godoc +// @Summary Get Chat Item For Given Wallet Address +// @Description Get all Chat Items for DMs for a given wallet address +// @Tags Unused/Legacy +// @Accept json +// @Produce json +// @Param toaddr path string true "Wallet Address" +// @Success 200 {array} entity.Chatitem +// @Router /getall_chatitems/{address} [get] func GetChatFromAddress(w http.ResponseWriter, r *http.Request) { vars := mux.Vars(r) key := vars["address"] @@ -532,6 +560,15 @@ func GetChatFromAddress(w http.ResponseWriter, r *http.Request) { json.NewEncoder(w).Encode(chat) } +// GetNftChatFromAddress godoc +// @Summary Get NFT Related Chat Items For Given Wallet Address +// @Description Get ALL NFT context items for a given wallet address +// @Tags Unused/Legacy +// @Accept json +// @Produce json +// @Param toaddr path string true "Wallet Address" +// @Success 200 {array} entity.Chatitem +// @Router /getnft_chatitems/{address} [get] func GetNftChatFromAddress(w http.ResponseWriter, r *http.Request) { vars := mux.Vars(r) key := vars["address"] @@ -543,7 +580,16 @@ func GetNftChatFromAddress(w http.ResponseWriter, r *http.Request) { json.NewEncoder(w).Encode(chat) } -//return both directions of this chat +// GetChatFromAddressToAddr godoc +// @Summary Get Chat Data Between Two Addresses +// @Description Get chat data between the given two addresses, TO and FROM and interchangable here +// @Tags DMs +// @Accept json +// @Produce json +// @Param toaddr path string true "TO: Wallet Address" +// @Param from path string true "FROM: Wallet Address" +// @Success 200 {array} entity.Chatitem +// @Router /getall_chatitems/{fromaddr}/{toaddr} [get] func GetChatFromAddressToAddr(w http.ResponseWriter, r *http.Request) { vars := mux.Vars(r) from := vars["fromaddr"] @@ -577,6 +623,16 @@ func GetChatFromAddressToAddr(w http.ResponseWriter, r *http.Request) { json.NewEncoder(w).Encode(chat) } +// GetChatNftContext godoc +// @Summary Get NFT Related Chat Items For Given NFT Contract and ID +// @Description Get ALL NFT context items for a given wallet address +// @Tags Unused/Legacy +// @Accept json +// @Produce json +// @Param nftaddr path string true "NFT Contract Address" +// @Param nftid path string true "NFT ID" +// @Success 200 {array} entity.Chatitem +// @Router /getnft_chatitems/{nftaddr}/{nftid} [get] func GetChatNftContext(w http.ResponseWriter, r *http.Request) { vars := mux.Vars(r) nftaddr := vars["nftaddr"] @@ -589,6 +645,18 @@ func GetChatNftContext(w http.ResponseWriter, r *http.Request) { json.NewEncoder(w).Encode(chat) } +// GetChatNftContext godoc +// @Summary Get NFT Related Chat Items For Given NFT Contract and ID, between two wallet addresses (TO and FROM are interchangable) +// @Description Get ALL NFT context items for a specifc NFT context convo between two wallets +// @Tags NFT +// @Accept json +// @Produce json +// @Param nftaddr path string true "NFT Contract Address" +// @Param nftid path string true "NFT ID" +// @Param toaddr path string true "TO: Wallet Address" +// @Param from path string true "FROM: Wallet Address" +// @Success 200 {array} entity.Chatitem +// @Router /getnft_chatitems/{fromaddr}/{toaddr}/{nftaddr}/{nftid} [get] func GetChatNftAllItemsFromAddrAndNFT(w http.ResponseWriter, r *http.Request) { vars := mux.Vars(r) from := vars["fromaddr"] @@ -628,6 +696,17 @@ func GetChatNftAllItemsFromAddrAndNFT(w http.ResponseWriter, r *http.Request) { json.NewEncoder(w).Encode(chat) } +// GetChatNftAllItemsFromAddr godoc +// @Summary Get NFT Related Chat Items For Given NFT Contract and ID, relating to one wallet +// @Description Get all specified NFT contract and ID items for a given wallet address +// @Tags Unused/Legacy +// @Accept json +// @Produce json +// @Param address path string true "Wallet Address" +// @Param nftaddr path string true "NFT Contract Address" +// @Param nftid path string true "NFT ID" +// @Success 200 {array} entity.Chatitem +// @Router /getnft_chatitems/{address}/{nftaddr}/{nftid} [get] func GetChatNftAllItemsFromAddr(w http.ResponseWriter, r *http.Request) { vars := mux.Vars(r) walletaddr := vars["address"] @@ -663,22 +742,51 @@ func GetChatNftAllItemsFromAddr(w http.ResponseWriter, r *http.Request) { json.NewEncoder(w).Encode(chat) } -//CreateChatitem creates Chatitem +// CreateChatitem godoc +// @Summary Create/Insert DM Chat Message (1-to-1 messaging) +// @Description For DMs, Chatitem data struct is used to store each message and associated info. +// @Description REQUIRED: fromaddr, toaddr, message (see data struct section at bottom of page for more detailed info on each paramter) +// @Description Other fields are generally filled in by the backed REST API and used as return parameters +// @Description ID is auto generated and should never be used as input. +// @Tags DMs +// @Accept json +// @Produce json +// @Param message body entity.Chatitem true "Direct Message Chat Data" +// @Success 200 {array} entity.Chatitem +// @Router /create_chatitem [post] func CreateChatitem(w http.ResponseWriter, r *http.Request) { requestBody, _ := ioutil.ReadAll(r.Body) var chat entity.Chatitem json.Unmarshal(requestBody, &chat) + //added this because from API doc it was throwing error w/o this + //TODO: we should sort out if we really need this as an input or output only + chat.Timestamp = time.Now().Format("2006-01-02T15:04:05.000Z") //I think can remove this too since Oliver added a DB trigger chat.Timestamp_dtm = time.Now() - database.Connector.Create(&chat) - w.Header().Set("Content-Type", "application/json") - w.WriteHeader(http.StatusCreated) - json.NewEncoder(w).Encode(chat) + dbQuery := database.Connector.Create(&chat) + if dbQuery.RowsAffected == 0 { + fmt.Println(dbQuery.Error) + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusBadRequest) + json.NewEncoder(w).Encode(dbQuery.Error) + } else { + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusCreated) + json.NewEncoder(w).Encode(chat) + } } -//CreateGroupChatitem creates GroupChatitem +// CreateGroupChatitem godoc +// @Summary Create/Insert chat message for Community/NFT/Group Messaging +// @Description Currently used for all messages outside of DMs +// @Tags GroupChat +// @Accept json +// @Produce json +// @Param message body entity.Groupchatitem true "Group Message Chat Data" +// @Success 200 {array} entity.Groupchatitem +// @Router /create_groupchatitem [post] func CreateGroupChatitem(w http.ResponseWriter, r *http.Request) { requestBody, _ := ioutil.ReadAll(r.Body) var chat entity.Groupchatitem @@ -697,7 +805,15 @@ func CreateGroupChatitem(w http.ResponseWriter, r *http.Request) { json.NewEncoder(w).Encode(chat) } -//CreateGroupChatitem creates GroupChatitem just with community tag (don't really need this separate anymore) +// CreateCommunityChatitem godoc +// @Summary CreateCommunityChatitem creates GroupChatitem just with community tag (likely could be consolidated) +// @Description Community Chat Data +// @Tags GroupChat +// @Accept json +// @Produce json +// @Param message body entity.Groupchatitem true "Community Message Chat Data" +// @Success 200 {array} entity.Groupchatitem +// @Router /community [post] func CreateCommunityChatitem(w http.ResponseWriter, r *http.Request) { requestBody, _ := ioutil.ReadAll(r.Body) var chat entity.Groupchatitem @@ -719,6 +835,15 @@ func CreateCommunityChatitem(w http.ResponseWriter, r *http.Request) { json.NewEncoder(w).Encode(chat) } +// GetGroupChatItems godoc +// @Summary GetGroupChatItems gets group chat data for a given NFT address +// @Description Community Chat Data +// @Tags NFT +// @Accept json +// @Produce json +// @Param message path string true "Get Group Chat Data By NFT Address" +// @Success 200 {array} entity.Groupchatitem +// @Router /get_groupchatitems/{address} [get] func GetGroupChatItems(w http.ResponseWriter, r *http.Request) { vars := mux.Vars(r) key := vars["address"] @@ -730,14 +855,30 @@ func GetGroupChatItems(w http.ResponseWriter, r *http.Request) { json.NewEncoder(w).Encode(chat) } +// CreateBookmarkItem godoc +// @Summary Join an NFT or Community group chat +// @Description Bookmarks keep an NFT/Community group chat in the sidebar +// @Tags GroupChat +// @Accept json +// @Produce json +// @Param message body entity.Bookmarkitem true "Add Bookmark from Community Group Chat" +// @Success 200 {array} entity.Bookmarkitem +// @Router /create_bookmark [post] func CreateBookmarkItem(w http.ResponseWriter, r *http.Request) { requestBody, _ := ioutil.ReadAll(r.Body) var bookmark entity.Bookmarkitem json.Unmarshal(requestBody, &bookmark) //fmt.Printf("Bookmark Item: %#v\n", chat) - bookmark.Chain = "none" + //0x check is a cheap hack right now since NFTPort.xyz is rate limiting us a lot + if strings.HasPrefix(bookmark.Nftaddr, "0x") { + bookmark.Chain = "ethereum" + } + if strings.HasPrefix(bookmark.Nftaddr, "poap_") { + bookmark.Chain = "xdai" + } + //end hack for limiting NFTport API var result = IsOnChain(bookmark.Nftaddr, "ethereum") if result { bookmark.Chain = "ethereum" @@ -754,6 +895,15 @@ func CreateBookmarkItem(w http.ResponseWriter, r *http.Request) { json.NewEncoder(w).Encode(bookmark) } +// DeleteBookmarkItem godoc +// @Summary Leave an NFT or Community group chat +// @Description Bookmarks keep an NFT/Community group chat in the sidebar +// @Tags GroupChat +// @Accept json +// @Produce json +// @Param message body entity.Bookmarkitem true "Remove Bookmark from Community Group Chat" +// @Success 200 {array} entity.Bookmarkitem +// @Router /delete_bookmark [post] func DeleteBookmarkItem(w http.ResponseWriter, r *http.Request) { requestBody, _ := ioutil.ReadAll(r.Body) var bookmark entity.Bookmarkitem @@ -787,6 +937,16 @@ func DeleteBookmarkItem(w http.ResponseWriter, r *http.Request) { json.NewEncoder(w).Encode(returnval) } +// IsBookmarkItem godoc +// @Summary Check if a wallet address has bookmarked/joined given NFT contract +// @Description This used for UI purposes, checking if a user/wallet has bookmarked a community. +// @Tags GroupChat +// @Accept json +// @Produce json +// @Param walletaddr path string true "Wallet Address" +// @Param nftaddr path string true "NFT Contract Address" +// @Success 200 {bool} bool +// @Router /get_bookmarks/{walletaddr}/{nftaddr} [get] func IsBookmarkItem(w http.ResponseWriter, r *http.Request) { vars := mux.Vars(r) walletaddr := vars["walletaddr"] @@ -805,6 +965,15 @@ func IsBookmarkItem(w http.ResponseWriter, r *http.Request) { json.NewEncoder(w).Encode(returnval) } +// GetBookmarkItems godoc +// @Summary Check if a wallet address has bookmarked/joined given NFT contract +// @Description This used for UI purposes, checking if a user/wallet has bookmarked a community. +// @Tags GroupChat +// @Accept json +// @Produce json +// @Param address path string true "Wallet Address" +// @Success 200 {array} entity.Bookmarkitem +// @Router /get_bookmarks/{address}/ [get] func GetBookmarkItems(w http.ResponseWriter, r *http.Request) { vars := mux.Vars(r) key := vars["address"] @@ -855,6 +1024,15 @@ func GetBookmarkItems(w http.ResponseWriter, r *http.Request) { json.NewEncoder(w).Encode(returnItems) } +// CreateImageItem godoc +// @Summary Store Image in DB for later user +// @Description Currently used for the WC HQ Logo, stores the base64 raw data of the profile image for a community +// @Tags Common +// @Accept json +// @Produce json +// @Param message body entity.Imageitem true "Profile Thumbnail Pic" +// @Success 200 {array} entity.Bookmarkitem +// @Router /image [post] func CreateImageItem(w http.ResponseWriter, r *http.Request) { requestBody, _ := ioutil.ReadAll(r.Body) var imgname entity.Imageitem @@ -866,6 +1044,15 @@ func CreateImageItem(w http.ResponseWriter, r *http.Request) { json.NewEncoder(w).Encode(imgname) } +// UpdateImageItem godoc +// @Summary Store Image in DB for later user (update existing photo) +// @Description Currently used for the WC HQ Logo, stores the base64 raw data of the profile image for a community +// @Tags Common +// @Accept json +// @Produce json +// @Param message body entity.Imageitem true "Profile Thumbnail Pic" +// @Success 200 {array} entity.Bookmarkitem +// @Router /image [put] func UpdateImageItem(w http.ResponseWriter, r *http.Request) { requestBody, _ := ioutil.ReadAll(r.Body) var imgname entity.Imageitem @@ -885,6 +1072,15 @@ func UpdateImageItem(w http.ResponseWriter, r *http.Request) { json.NewEncoder(w).Encode(returnval) } +// GetImageItem godoc +// @Summary Get Thumbnail Image Data +// @Description Retreive image data for use with user/community/nft group dislayed icon +// @Tags Common +// @Accept json +// @Produce json +// @Param name path string true "Common Name Mapped to User/Community" +// @Success 200 {array} entity.Imageitem +// @Router /image/{name} [get] func GetImageItem(w http.ResponseWriter, r *http.Request) { vars := mux.Vars(r) name := vars["name"] @@ -897,7 +1093,15 @@ func GetImageItem(w http.ResponseWriter, r *http.Request) { json.NewEncoder(w).Encode(imgname) } -//give a common name to a user address, or NFT collection +// CreateAddrNameItem godoc +// @Summary give a common name to a user address, or NFT collection +// @Description Give a common name (Kevin.eth, BillyTheKid, etc) to an Address +// @Tags Common +// @Accept json +// @Produce json +// @Param message body entity.Addrnameitem true "Address and Name to map together" +// @Success 200 {array} entity.Bookmarkitem +// @Router /name [post] func CreateAddrNameItem(w http.ResponseWriter, r *http.Request) { requestBody, _ := ioutil.ReadAll(r.Body) var addrname entity.Addrnameitem @@ -909,6 +1113,15 @@ func CreateAddrNameItem(w http.ResponseWriter, r *http.Request) { json.NewEncoder(w).Encode(addrname) } +// GetAddrNameItem godoc +// @Summary get the common name which has been mapped to an address +// @Description get the given a common name (Kevin.eth, BillyTheKid, etc) what has already been mapped to an Address +// @Tags Common +// @Accept json +// @Produce json +// @Param address path string true "Get Name for given address" +// @Success 200 {array} entity.Addrnameitem +// @Router /name/{name} [get] func GetAddrNameItem(w http.ResponseWriter, r *http.Request) { vars := mux.Vars(r) address := vars["address"] @@ -921,6 +1134,15 @@ func GetAddrNameItem(w http.ResponseWriter, r *http.Request) { json.NewEncoder(w).Encode(addrname) } +// CreateAddrNameItem godoc +// @Summary give a common name to a user address, or NFT collection (update exiting) +// @Description Give a common name (Kevin.eth, BillyTheKid, etc) to an Address +// @Tags Common +// @Accept json +// @Produce json +// @Param message body entity.Addrnameitem true "Address and Name to map together" +// @Success 200 {array} entity.Bookmarkitem +// @Router /name [put] func UpdateAddrNameItem(w http.ResponseWriter, r *http.Request) { requestBody, _ := ioutil.ReadAll(r.Body) var addrname entity.Addrnameitem @@ -940,6 +1162,16 @@ func UpdateAddrNameItem(w http.ResponseWriter, r *http.Request) { json.NewEncoder(w).Encode(returnval) } +// GetGroupChatItemsByAddr godoc +// @Summary Get group chat items, given a wallt FROM address and NFT Contract Address +// @Description Get all group chat items for a given wallet (useraddress) for a given NFT Contract Address (TODO: fix up var names) +// @Tags NFT +// @Accept json +// @Produce json +// @Param address path string true "NFT Address" +// @Param useraddress path string true "FROM: wallet address" +// @Success 200 {array} entity.Groupchatitem +// @Router /get_groupchatitems/{address}/{useraddress} [get] func GetGroupChatItemsByAddr(w http.ResponseWriter, r *http.Request) { vars := mux.Vars(r) nftaddr := vars["address"] @@ -975,6 +1207,17 @@ func GetGroupChatItemsByAddr(w http.ResponseWriter, r *http.Request) { json.NewEncoder(w).Encode(chat) } +// GetGroupChatItemsByAddrLen godoc +// @Summary Get Unread Groupchat Items (TODO: cleanup naming convention here) +// @Description For group chat unread counts, currently the database stores a timestamp for each time a user enters a group chat. +// @Description We though in the design it would be impractical to keep a read/unread count copy per user per message, but if this +// @Description method doesn't proof to be fine grained enough, we could add a boolean relational table of read messgages per user. +// @Tags Common +// @Accept json +// @Produce plain +// @Param name path string true "Common Name Mapped to User/Community" +// @Success 200 {integer} int +// @Router /get_groupchatitems_unreadcnt/{address}/{useraddress} [get] func GetGroupChatItemsByAddrLen(w http.ResponseWriter, r *http.Request) { vars := mux.Vars(r) nftaddr := vars["address"] @@ -997,7 +1240,17 @@ func GetGroupChatItemsByAddrLen(w http.ResponseWriter, r *http.Request) { json.NewEncoder(w).Encode(len(chat)) } -//UpdateInboxByOwner updates person with respective owner address +// CreateAddrNameItem godoc +// @Summary Update Message Read Status of a given DM chat message +// @Description Currently this only update the message read/unread status. It could update the entire JSON struct +// @Description upon request, however we only needed this functionality currently and it saved re-encryption of the data. +// @Description TODO: TO/FROM address in the URL is not needed/not used anymore. +// @Tags DMs +// @Accept json +// @Produce json +// @Param message body entity.Chatitem true "chat item JSON struct to update msg read status" +// @Success 200 {array} entity.Chatitem +// @Router /update_chatitem/{fromaddr}/{toaddr} [put] func UpdateChatitemByOwner(w http.ResponseWriter, r *http.Request) { requestBody, _ := ioutil.ReadAll(r.Body) var chat entity.Chatitem @@ -1022,6 +1275,16 @@ func UpdateChatitemByOwner(w http.ResponseWriter, r *http.Request) { json.NewEncoder(w).Encode(chat) } +// DeleteAllChatitemsToAddressByOwner godoc +// @Summary Delete All Chat Items (DMs) between FROM and TO given addresses +// @Description TODO: Need to protect this with JWT in addition to other API calls needed to use FROM addr from the JWT +// @Tags Unused/Legacy +// @Accept json +// @Produce json +// @Param toaddr path string true "TO: Address" +// @Param fromaddr path string true "FROM: Address" +// @Success 204 +// @Router /deleteall_chatitems/{fromaddr}/{toaddr} [delete] func DeleteAllChatitemsToAddressByOwner(w http.ResponseWriter, r *http.Request) { vars := mux.Vars(r) to := vars["toaddr"] @@ -1033,6 +1296,15 @@ func DeleteAllChatitemsToAddressByOwner(w http.ResponseWriter, r *http.Request) w.WriteHeader(http.StatusNoContent) } +// CreateSettings godoc +// @Summary Settings hold a user address and the public key used for encryption. +// @Description Currently this only updates the public key, could be expanded as needed. +// @Tags Common +// @Accept json +// @Produce json +// @Param message body entity.Settings true "update struct" +// @Success 200 {array} entity.Settings +// @Router /create_settings [post] func CreateSettings(w http.ResponseWriter, r *http.Request) { requestBody, _ := ioutil.ReadAll(r.Body) var settings entity.Settings @@ -1044,6 +1316,15 @@ func CreateSettings(w http.ResponseWriter, r *http.Request) { json.NewEncoder(w).Encode(settings) } +// UpdateSettings godoc +// @Summary Settings hold a user address and the public key used for encryption. +// @Description Currently this only updates the public key, could be expanded as needed. +// @Tags Common +// @Accept json +// @Produce json +// @Param message body entity.Settings true "update struct" +// @Success 200 {array} entity.Settings +// @Router /update_settings [put] func UpdateSettings(w http.ResponseWriter, r *http.Request) { requestBody, _ := ioutil.ReadAll(r.Body) var settings entity.Settings @@ -1056,6 +1337,15 @@ func UpdateSettings(w http.ResponseWriter, r *http.Request) { json.NewEncoder(w).Encode(settings) } +// DeleteSettings godoc +// @Summary Delete Settings Info +// @Description TODO: Need to protect this with JWT in addition to other API calls needed to use FROM addr from the JWT +// @Tags Unused/Legacy +// @Accept json +// @Produce json +// @Param address path string true "Wallet Address" +// @Success 204 +// @Router /delete_settings/{address} [delete] func DeleteSettings(w http.ResponseWriter, r *http.Request) { vars := mux.Vars(r) key := vars["address"] @@ -1066,6 +1356,15 @@ func DeleteSettings(w http.ResponseWriter, r *http.Request) { w.WriteHeader(http.StatusNoContent) } +// GetSettings godoc +// @Summary Get Settings Info +// @Description TODO: Need to protect this with JWT in addition to other API calls needed to use FROM addr from the JWT +// @Tags Unused/Legacy +// @Accept json +// @Produce json +// @Param address path string true "Wallet Address" +// @Success 200 {array} entity.Settings +// @Router /get_settings/{address} [get] func GetSettings(w http.ResponseWriter, r *http.Request) { vars := mux.Vars(r) key := vars["address"] @@ -1076,6 +1375,15 @@ func GetSettings(w http.ResponseWriter, r *http.Request) { json.NewEncoder(w).Encode(settings) } +// CreateComments godoc +// @Summary Comments are used within an NFT community chat +// @Description Comments are meant to be public, someday having an up/downvote method for auto-moderation +// @Tags NFT +// @Accept json +// @Produce json +// @Param message body entity.Comments true "create struct" +// @Success 200 {array} entity.Comments +// @Router /create_comments [post] func CreateComments(w http.ResponseWriter, r *http.Request) { requestBody, _ := ioutil.ReadAll(r.Body) var comment entity.Comments @@ -1099,6 +1407,17 @@ func CreateComments(w http.ResponseWriter, r *http.Request) { // json.NewEncoder(w).Encode(comment) // } +// DeleteComments godoc +// @Summary Delete Public Comments for given FROM wallet address, NFT Contract and ID +// @Description NFTs have a public comment section +// @Tags NFT +// @Accept json +// @Produce json +// @Param address path string true "FROM Wallet Address" +// @Param nftaddr path string true "NFT Contract Address" +// @Param nftid path string true "NFT ID" +// @Success 204 +// @Router /delete_comments/{fromaddr}/{nftaddr}/{nftid} [delete] func DeleteComments(w http.ResponseWriter, r *http.Request) { vars := mux.Vars(r) fromaddr := vars["address"] @@ -1111,6 +1430,15 @@ func DeleteComments(w http.ResponseWriter, r *http.Request) { w.WriteHeader(http.StatusNoContent) } +// GetComments godoc +// @Summary Get Public Comments for given NFT Contract and ID +// @Description NFTs have a public comment section +// @Tags NFT +// @Accept json +// @Produce json +// @Param address path string true "Wallet Address" +// @Success 200 {array} entity.Comments +// @Router /get_comments/{nftaddr}/{nftid} [get] func GetComments(w http.ResponseWriter, r *http.Request) { vars := mux.Vars(r) id := vars["nftid"] @@ -1123,6 +1451,16 @@ func GetComments(w http.ResponseWriter, r *http.Request) { json.NewEncoder(w).Encode(comment) } +// GetCommentsCount godoc +// @Summary Get Public Comments Count for given NFT Contract and ID +// @Description NFTs have a public comment section +// @Tags NFT +// @Accept json +// @Produce json +// @Param nftaddr path string true "NFT Contract Address" +// @Param nftid path string true "NFT ID" +// @Success 200 {integer} int +// @Router /get_comments_cnt/{nftaddr}/{nftid} [get] func GetCommentsCount(w http.ResponseWriter, r *http.Request) { vars := mux.Vars(r) id := vars["nftid"] @@ -1134,24 +1472,24 @@ func GetCommentsCount(w http.ResponseWriter, r *http.Request) { json.NewEncoder(w).Encode(len(comment)) } -func GetAllComments(w http.ResponseWriter, r *http.Request) { - var comment []entity.Comments - database.Connector.Find(&comment) +// func GetAllComments(w http.ResponseWriter, r *http.Request) { +// var comment []entity.Comments +// database.Connector.Find(&comment) - //make sure to get the name if it wasn't there (not there by default now) - var addrname entity.Addrnameitem - for i := 0; i < len(comment); i++ { - var result = database.Connector.Where("address = ?", comment[i].Fromaddr).Find(&addrname) - if result.RowsAffected > 0 { - comment[i].Name = addrname.Name - } - } - //end of adding names for fromaddr +// //make sure to get the name if it wasn't there (not there by default now) +// var addrname entity.Addrnameitem +// for i := 0; i < len(comment); i++ { +// var result = database.Connector.Where("address = ?", comment[i].Fromaddr).Find(&addrname) +// if result.RowsAffected > 0 { +// comment[i].Name = addrname.Name +// } +// } +// //end of adding names for fromaddr - w.Header().Set("Content-Type", "application/json") - w.WriteHeader(http.StatusOK) - json.NewEncoder(w).Encode(comment) -} +// w.Header().Set("Content-Type", "application/json") +// w.WriteHeader(http.StatusOK) +// json.NewEncoder(w).Encode(comment) +// } func GetTwitter(w http.ResponseWriter, r *http.Request) { vars := mux.Vars(r) @@ -1343,7 +1681,17 @@ func FormatTwitterData(data TwitterTweetsData) []TweetType { return tweets } -func GetWalletChat(w http.ResponseWriter, r *http.Request) { +// GetCommunityChat godoc +// @Summary Get Community Chat Landing Page Info +// @Description TODO: need a creation API for communities, which includes specificied welcome message text, Twitter handle, page title +// @Tags GroupChat +// @Accept json +// @Produce json +// @Param address path string true "Wallet Address" +// @Param address path string true "Wallet Address" +// @Success 200 {array} LandingPageItems +// @Router /community/{community}/{address} [get] +func GetCommunityChat(w http.ResponseWriter, r *http.Request) { vars := mux.Vars(r) community := vars["community"] key := vars["address"] @@ -1358,7 +1706,7 @@ func GetWalletChat(w http.ResponseWriter, r *http.Request) { landingData.Members = len(members) //name - landingData.Name = "WalletChat HQ" + landingData.Name = "WalletChat HQ" //TODO this should come from a table which stores info set in in a CREATE community chat table //logo base64 data (url requires other changes) var imgname entity.Imageitem @@ -1387,9 +1735,9 @@ func GetWalletChat(w http.ResponseWriter, r *http.Request) { newgroupchatuser.Contexttype = entity.Community newgroupchatuser.Fromaddr = key newgroupchatuser.Nftaddr = community - newgroupchatuser.Message = "Welcome " + key + " to Wallet Chat HQ!" + newgroupchatuser.Message = "Welcome " + key + " to Wallet Chat HQ!" //TODO end of this message should come from a table which stores info set in in a CREATE community chat table newgroupchatuser.Timestamp_dtm = time.Now() - newgroupchatuser.Timestamp = time.Now().Format(time.RFC3339) + newgroupchatuser.Timestamp = time.Now().Format("2006-01-02T15:04:05.000Z") //add it to the database database.Connector.Create(&newgroupchatuser) @@ -1398,7 +1746,7 @@ func GetWalletChat(w http.ResponseWriter, r *http.Request) { landingData.Joined = true } - //check messages read for this user address because this GetWalletChat is being called + //check messages read for this user address because this GetCommunityChat is being called //separately each time (I thought it would be filled from bookmarks) var groupchat []entity.Groupchatitem database.Connector.Where("nftaddr = ?", community).Where("fromaddr = ?", key).Find(&groupchat) @@ -1440,17 +1788,27 @@ func GetWalletChat(w http.ResponseWriter, r *http.Request) { //social data var twitterSocial SocialMsg twitterSocial.Type = "twitter" - twitterSocial.Username = "@wallet_chat" + twitterSocial.Username = "@wallet_chat" //TODO this should come from a table which stores info set in in a CREATE community chat table landingData.Social = append(landingData.Social, twitterSocial) var discordSocial SocialMsg discordSocial.Type = "discord" - discordSocial.Username = "WalletChat" + discordSocial.Username = "WalletChat" //TODO this should come from a table which stores info set in in a CREATE community chat table landingData.Social = append(landingData.Social, discordSocial) w.Header().Set("Content-Type", "application/json") json.NewEncoder(w).Encode(landingData) } +// IsOwner godoc +// @Summary Check if given wallet address owns an NFT from given contract address +// @Description API user could check this directly via any third party service like NFTPort, Moralis as well +// @Tags Common +// @Accept json +// @Produce json +// @Param contract path string true "NFT Contract Address" +// @Param wallet path string true "Wallet Address" +// @Success 200 {array} LandingPageItems +// @Router /is_owner/{contract}/{wallet} [get] func IsOwner(w http.ResponseWriter, r *http.Request) { vars := mux.Vars(r) contract := vars["contract"] @@ -1465,6 +1823,7 @@ func IsOwner(w http.ResponseWriter, r *http.Request) { json.NewEncoder(w).Encode(result) } +//internal func GetOwnerNFTs(walletAddr string, chain string) NFTPortOwnerOf { //url := "https://eth-mainnet.alchemyapi.io/v2/${process.env.REACT_APP_ALCHEMY_API_KEY}/getOwnersForToken" + contractAddr url := "https://api.nftport.xyz/v0/accounts/" + walletAddr + "?chain=" + chain @@ -1497,6 +1856,7 @@ func GetOwnerNFTs(walletAddr string, chain string) NFTPortOwnerOf { return result } +//internal use func IsOwnerOfNFT(contractAddr string, walletAddr string, chain string) bool { //url := "https://eth-mainnet.alchemyapi.io/v2/${process.env.REACT_APP_ALCHEMY_API_KEY}/getOwnersForToken" + contractAddr url := "https://api.nftport.xyz/v0/accounts/" + walletAddr + "?chain=" + chain + "&contract_address=" + contractAddr @@ -1565,6 +1925,7 @@ func IsOnChain(contractAddr string, chain string) bool { } //this was just used to fix up users info after adding new column +//not intended for extenal calls func FixUpBookmarks(w http.ResponseWriter, r *http.Request) { var bookmarks []entity.Bookmarkitem database.Connector.Find(&bookmarks) @@ -1584,6 +1945,7 @@ func FixUpBookmarks(w http.ResponseWriter, r *http.Request) { } } +//internal use only func AutoJoinCommunities(w http.ResponseWriter, r *http.Request) { vars := mux.Vars(r) walletAddr := vars["wallet"] @@ -1591,6 +1953,8 @@ func AutoJoinCommunities(w http.ResponseWriter, r *http.Request) { AutoJoinCommunitiesByChain(walletAddr, "polygon") AutoJoinPoapChats(walletAddr) } + +//internal use only func AutoJoinCommunitiesByChain(walletAddr string, chain string) { //TODO: OS is more accurate url := "https://api.nftport.xyz/v0/accounts/" + walletAddr + "?chain=" + chain @@ -1647,6 +2011,7 @@ func AutoJoinCommunitiesByChain(walletAddr string, chain string) { } } +//internal use only func AutoJoinPoapChats(walletAddr string) { //https://documentation.poap.tech/reference/getactionsscan-5 var poapInfo []POAPInfoByAddress = getPoapInfoByAddress(walletAddr) @@ -1654,7 +2019,7 @@ func AutoJoinPoapChats(walletAddr string) { for _, poap := range poapInfo { var bookmarkExists entity.Bookmarkitem - var poapAddr = "POAP_" + strconv.Itoa(poap.Event.ID) + var poapAddr = "poap_" + strconv.Itoa(poap.Event.ID) //fmt.Printf("POAP Event: %#v\n", poapAddr) var dbResult = database.Connector.Where("nftaddr = ?", poapAddr).Where("walletaddr = ?", walletAddr).Find(&bookmarkExists) @@ -1690,6 +2055,8 @@ func GetPoapsByAddr(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "application/json") json.NewEncoder(w).Encode(result) } + +//internal use only func getPoapInfoByAddress(walletAddr string) []POAPInfoByAddress { url := "https://api.poap.tech/actions/scan/" + walletAddr diff --git a/docs/docs.go b/docs/docs.go index 6cc9b1f..d451f8c 100644 --- a/docs/docs.go +++ b/docs/docs.go @@ -19,9 +19,1413 @@ const docTemplate = `{ "host": "{{.Host}}", "basePath": "{{.BasePath}}", "paths": { + "/community": { + "post": { + "description": "Community Chat Data", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "GroupChat" + ], + "summary": "CreateCommunityChatitem creates GroupChatitem just with community tag (likely could be consolidated)", + "parameters": [ + { + "description": "Community Message Chat Data", + "name": "message", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/entity.Groupchatitem" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "array", + "items": { + "$ref": "#/definitions/entity.Groupchatitem" + } + } + } + } + } + }, + "/community/{community}/{address}": { + "get": { + "description": "TODO: need a creation API for communities, which includes specificied welcome message text, Twitter handle, page title", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "GroupChat" + ], + "summary": "Get Community Chat Landing Page Info", + "parameters": [ + { + "type": "string", + "description": "Wallet Address", + "name": "address", + "in": "path", + "required": true + }, + { + "type": "string", + "description": "Wallet Address", + "name": "address", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "array", + "items": { + "$ref": "#/definitions/controllers.LandingPageItems" + } + } + } + } + } + }, + "/create_bookmark": { + "post": { + "description": "Bookmarks keep an NFT/Community group chat in the sidebar", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "GroupChat" + ], + "summary": "Join an NFT or Community group chat", + "parameters": [ + { + "description": "Add Bookmark from Community Group Chat", + "name": "message", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/entity.Bookmarkitem" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "array", + "items": { + "$ref": "#/definitions/entity.Bookmarkitem" + } + } + } + } + } + }, + "/create_chatitem": { + "post": { + "description": "For DMs, Chatitem data struct is used to store each message and associated info.\nREQUIRED: fromaddr, toaddr, message (see data struct section at bottom of page for more detailed info on each paramter)\nOther fields are generally filled in by the backed REST API and used as return parameters\nID is auto generated and should never be used as input.", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "DMs" + ], + "summary": "Create/Insert DM Chat Message (1-to-1 messaging)", + "parameters": [ + { + "description": "Direct Message Chat Data", + "name": "message", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/entity.Chatitem" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "array", + "items": { + "$ref": "#/definitions/entity.Chatitem" + } + } + } + } + } + }, + "/create_comments": { + "post": { + "description": "Comments are meant to be public, someday having an up/downvote method for auto-moderation", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "NFT" + ], + "summary": "Comments are used within an NFT community chat", + "parameters": [ + { + "description": "create struct", + "name": "message", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/entity.Comments" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "array", + "items": { + "$ref": "#/definitions/entity.Comments" + } + } + } + } + } + }, + "/create_groupchatitem": { + "post": { + "description": "Currently used for all messages outside of DMs", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "GroupChat" + ], + "summary": "Create/Insert chat message for Community/NFT/Group Messaging", + "parameters": [ + { + "description": "Group Message Chat Data", + "name": "message", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/entity.Groupchatitem" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "array", + "items": { + "$ref": "#/definitions/entity.Groupchatitem" + } + } + } + } + } + }, + "/create_settings": { + "post": { + "description": "Currently this only updates the public key, could be expanded as needed.", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Common" + ], + "summary": "Settings hold a user address and the public key used for encryption.", + "parameters": [ + { + "description": "update struct", + "name": "message", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/entity.Settings" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "array", + "items": { + "$ref": "#/definitions/entity.Settings" + } + } + } + } + } + }, + "/delete_bookmark": { + "post": { + "description": "Bookmarks keep an NFT/Community group chat in the sidebar", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "GroupChat" + ], + "summary": "Leave an NFT or Community group chat", + "parameters": [ + { + "description": "Remove Bookmark from Community Group Chat", + "name": "message", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/entity.Bookmarkitem" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "array", + "items": { + "$ref": "#/definitions/entity.Bookmarkitem" + } + } + } + } + } + }, + "/delete_comments/{fromaddr}/{nftaddr}/{nftid}": { + "delete": { + "description": "NFTs have a public comment section", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "NFT" + ], + "summary": "Delete Public Comments for given FROM wallet address, NFT Contract and ID", + "parameters": [ + { + "type": "string", + "description": "FROM Wallet Address", + "name": "address", + "in": "path", + "required": true + }, + { + "type": "string", + "description": "NFT Contract Address", + "name": "nftaddr", + "in": "path", + "required": true + }, + { + "type": "string", + "description": "NFT ID", + "name": "nftid", + "in": "path", + "required": true + } + ], + "responses": { + "204": { + "description": "No Content" + } + } + } + }, + "/delete_settings/{address}": { + "delete": { + "description": "TODO: Need to protect this with JWT in addition to other API calls needed to use FROM addr from the JWT", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Unused/Legacy" + ], + "summary": "Delete Settings Info", + "parameters": [ + { + "type": "string", + "description": "Wallet Address", + "name": "address", + "in": "path", + "required": true + } + ], + "responses": { + "204": { + "description": "No Content" + } + } + } + }, + "/deleteall_chatitems/{fromaddr}/{toaddr}": { + "delete": { + "description": "TODO: Need to protect this with JWT in addition to other API calls needed to use FROM addr from the JWT", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Unused/Legacy" + ], + "summary": "Delete All Chat Items (DMs) between FROM and TO given addresses", + "parameters": [ + { + "type": "string", + "description": "TO: Address", + "name": "toaddr", + "in": "path", + "required": true + }, + { + "type": "string", + "description": "FROM: Address", + "name": "fromaddr", + "in": "path", + "required": true + } + ], + "responses": { + "204": { + "description": "No Content" + } + } + } + }, + "/get_bookmarks/{address}/": { + "get": { + "description": "This used for UI purposes, checking if a user/wallet has bookmarked a community.", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "GroupChat" + ], + "summary": "Check if a wallet address has bookmarked/joined given NFT contract", + "parameters": [ + { + "type": "string", + "description": "Wallet Address", + "name": "address", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "array", + "items": { + "$ref": "#/definitions/entity.Bookmarkitem" + } + } + } + } + } + }, + "/get_bookmarks/{walletaddr}/{nftaddr}": { + "get": { + "description": "This used for UI purposes, checking if a user/wallet has bookmarked a community.", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "GroupChat" + ], + "summary": "Check if a wallet address has bookmarked/joined given NFT contract", + "parameters": [ + { + "type": "string", + "description": "Wallet Address", + "name": "walletaddr", + "in": "path", + "required": true + }, + { + "type": "string", + "description": "NFT Contract Address", + "name": "nftaddr", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "bool" + } + } + } + } + }, + "/get_comments/{nftaddr}/{nftid}": { + "get": { + "description": "NFTs have a public comment section", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "NFT" + ], + "summary": "Get Public Comments for given NFT Contract and ID", + "parameters": [ + { + "type": "string", + "description": "Wallet Address", + "name": "address", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "array", + "items": { + "$ref": "#/definitions/entity.Comments" + } + } + } + } + } + }, + "/get_comments_cnt/{nftaddr}/{nftid}": { + "get": { + "description": "NFTs have a public comment section", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "NFT" + ], + "summary": "Get Public Comments Count for given NFT Contract and ID", + "parameters": [ + { + "type": "string", + "description": "NFT Contract Address", + "name": "nftaddr", + "in": "path", + "required": true + }, + { + "type": "string", + "description": "NFT ID", + "name": "nftid", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "integer" + } + } + } + } + }, + "/get_groupchatitems/{address}": { + "get": { + "description": "Community Chat Data", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "NFT" + ], + "summary": "GetGroupChatItems gets group chat data for a given NFT address", + "parameters": [ + { + "type": "string", + "description": "Get Group Chat Data By NFT Address", + "name": "message", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "array", + "items": { + "$ref": "#/definitions/entity.Groupchatitem" + } + } + } + } + } + }, + "/get_groupchatitems/{address}/{useraddress}": { + "get": { + "description": "Get all group chat items for a given wallet (useraddress) for a given NFT Contract Address (TODO: fix up var names)", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "NFT" + ], + "summary": "Get group chat items, given a wallt FROM address and NFT Contract Address", + "parameters": [ + { + "type": "string", + "description": "NFT Address", + "name": "address", + "in": "path", + "required": true + }, + { + "type": "string", + "description": "FROM: wallet address", + "name": "useraddress", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "array", + "items": { + "$ref": "#/definitions/entity.Groupchatitem" + } + } + } + } + } + }, + "/get_groupchatitems_unreadcnt/{address}/{useraddress}": { + "get": { + "description": "For group chat unread counts, currently the database stores a timestamp for each time a user enters a group chat.\nWe though in the design it would be impractical to keep a read/unread count copy per user per message, but if this\nmethod doesn't proof to be fine grained enough, we could add a boolean relational table of read messgages per user.", + "consumes": [ + "application/json" + ], + "produces": [ + "text/plain" + ], + "tags": [ + "Common" + ], + "summary": "Get Unread Groupchat Items (TODO: cleanup naming convention here)", + "parameters": [ + { + "type": "string", + "description": "Common Name Mapped to User/Community", + "name": "name", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "integer" + } + } + } + } + }, "/get_inbox/{address}": { "get": { - "description": "Get Each 1-on-1 Conversation, NFT and Community Chat For Display in Inbox", + "description": "Get Each 1-on-1 Conversation, NFT and Community Chat For Display in Inbox", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Inbox" + ], + "summary": "Get Inbox Summary With Last Message", + "parameters": [ + { + "type": "string", + "description": "Wallet Address", + "name": "address", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "array", + "items": { + "$ref": "#/definitions/entity.Chatiteminbox" + } + } + } + } + } + }, + "/get_settings/{address}": { + "get": { + "description": "TODO: Need to protect this with JWT in addition to other API calls needed to use FROM addr from the JWT", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Unused/Legacy" + ], + "summary": "Get Settings Info", + "parameters": [ + { + "type": "string", + "description": "Wallet Address", + "name": "address", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "array", + "items": { + "$ref": "#/definitions/entity.Settings" + } + } + } + } + } + }, + "/get_unread_cnt/{address}": { + "get": { + "description": "Get Each 1-on-1 Conversation, NFT and Community Chat For Display in Inbox", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Inbox" + ], + "summary": "Get all unread messages TO a specific user, used for total count notification at top notification bar", + "parameters": [ + { + "type": "string", + "description": "Wallet Address", + "name": "address", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "integer" + } + } + } + } + }, + "/get_unread_cnt/{address}/{nftaddr}/{nftid}": { + "get": { + "description": "Get Unread count for specifc NFT context given a wallet address and specific NFT", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "NFT" + ], + "summary": "Get all unread messages for a specific NFT context", + "parameters": [ + { + "type": "string", + "description": "Wallet Address", + "name": "address", + "in": "path", + "required": true + }, + { + "type": "string", + "description": "NFT Contract Address", + "name": "nftaddr", + "in": "path", + "required": true + }, + { + "type": "string", + "description": "NFT ID", + "name": "nftid", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "integer" + } + } + } + } + }, + "/get_unread_cnt/{fromaddr}/{toaddr}": { + "get": { + "description": "Get Unread count for DMs", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Unused/Legacy" + ], + "summary": "Get all unread messages between two addresses", + "parameters": [ + { + "type": "string", + "description": "TO: Wallet Address", + "name": "toaddr", + "in": "path", + "required": true + }, + { + "type": "string", + "description": "FROM: Wallet Address", + "name": "from", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "integer" + } + } + } + } + }, + "/get_unread_cnt_by_type/{address}/{type}": { + "get": { + "description": "Get Each 1-on-1 Conversation, NFT and Community Chat For Display in Inbox", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Unused/Legacy" + ], + "summary": "Get all unread messages TO a specific user, used for total count notification at top notification bar", + "parameters": [ + { + "type": "string", + "description": "Wallet Address", + "name": "address", + "in": "path", + "required": true + }, + { + "type": "string", + "description": "Message Type - nft|community|dm|all", + "name": "type", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "integer" + } + } + } + } + }, + "/get_unread_cnt_nft/{address}": { + "get": { + "description": "Get Unread count for all NFT contexts given a wallet address", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Unused/Legacy" + ], + "summary": "Get all unread messages for all NFT related chats for given user", + "parameters": [ + { + "type": "string", + "description": "Wallet Address", + "name": "address", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "integer" + } + } + } + } + }, + "/getall_chatitems/{address}": { + "get": { + "description": "Get all Chat Items for DMs for a given wallet address", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Unused/Legacy" + ], + "summary": "Get Chat Item For Given Wallet Address", + "parameters": [ + { + "type": "string", + "description": "Wallet Address", + "name": "toaddr", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "array", + "items": { + "$ref": "#/definitions/entity.Chatitem" + } + } + } + } + } + }, + "/getall_chatitems/{fromaddr}/{toaddr}": { + "get": { + "description": "Get chat data between the given two addresses, TO and FROM and interchangable here", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "DMs" + ], + "summary": "Get Chat Data Between Two Addresses", + "parameters": [ + { + "type": "string", + "description": "TO: Wallet Address", + "name": "toaddr", + "in": "path", + "required": true + }, + { + "type": "string", + "description": "FROM: Wallet Address", + "name": "from", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "array", + "items": { + "$ref": "#/definitions/entity.Chatitem" + } + } + } + } + } + }, + "/getnft_chatitems/{address}": { + "get": { + "description": "Get ALL NFT context items for a given wallet address", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Unused/Legacy" + ], + "summary": "Get NFT Related Chat Items For Given Wallet Address", + "parameters": [ + { + "type": "string", + "description": "Wallet Address", + "name": "toaddr", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "array", + "items": { + "$ref": "#/definitions/entity.Chatitem" + } + } + } + } + } + }, + "/getnft_chatitems/{address}/{nftaddr}/{nftid}": { + "get": { + "description": "Get all specified NFT contract and ID items for a given wallet address", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Unused/Legacy" + ], + "summary": "Get NFT Related Chat Items For Given NFT Contract and ID, relating to one wallet", + "parameters": [ + { + "type": "string", + "description": "Wallet Address", + "name": "address", + "in": "path", + "required": true + }, + { + "type": "string", + "description": "NFT Contract Address", + "name": "nftaddr", + "in": "path", + "required": true + }, + { + "type": "string", + "description": "NFT ID", + "name": "nftid", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "array", + "items": { + "$ref": "#/definitions/entity.Chatitem" + } + } + } + } + } + }, + "/getnft_chatitems/{fromaddr}/{toaddr}/{nftaddr}/{nftid}": { + "get": { + "description": "Get ALL NFT context items for a specifc NFT context convo between two wallets", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "NFT" + ], + "summary": "Get NFT Related Chat Items For Given NFT Contract and ID, between two wallet addresses (TO and FROM are interchangable)", + "parameters": [ + { + "type": "string", + "description": "NFT Contract Address", + "name": "nftaddr", + "in": "path", + "required": true + }, + { + "type": "string", + "description": "NFT ID", + "name": "nftid", + "in": "path", + "required": true + }, + { + "type": "string", + "description": "TO: Wallet Address", + "name": "toaddr", + "in": "path", + "required": true + }, + { + "type": "string", + "description": "FROM: Wallet Address", + "name": "from", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "array", + "items": { + "$ref": "#/definitions/entity.Chatitem" + } + } + } + } + } + }, + "/getnft_chatitems/{nftaddr}/{nftid}": { + "get": { + "description": "Get ALL NFT context items for a given wallet address", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Unused/Legacy" + ], + "summary": "Get NFT Related Chat Items For Given NFT Contract and ID", + "parameters": [ + { + "type": "string", + "description": "NFT Contract Address", + "name": "nftaddr", + "in": "path", + "required": true + }, + { + "type": "string", + "description": "NFT ID", + "name": "nftid", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "array", + "items": { + "$ref": "#/definitions/entity.Chatitem" + } + } + } + } + } + }, + "/image": { + "put": { + "description": "Currently used for the WC HQ Logo, stores the base64 raw data of the profile image for a community", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Common" + ], + "summary": "Store Image in DB for later user (update existing photo)", + "parameters": [ + { + "description": "Profile Thumbnail Pic", + "name": "message", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/entity.Imageitem" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "array", + "items": { + "$ref": "#/definitions/entity.Bookmarkitem" + } + } + } + } + }, + "post": { + "description": "Currently used for the WC HQ Logo, stores the base64 raw data of the profile image for a community", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Common" + ], + "summary": "Store Image in DB for later user", + "parameters": [ + { + "description": "Profile Thumbnail Pic", + "name": "message", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/entity.Imageitem" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "array", + "items": { + "$ref": "#/definitions/entity.Bookmarkitem" + } + } + } + } + } + }, + "/image/{name}": { + "get": { + "description": "Retreive image data for use with user/community/nft group dislayed icon", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Common" + ], + "summary": "Get Thumbnail Image Data", + "parameters": [ + { + "type": "string", + "description": "Common Name Mapped to User/Community", + "name": "name", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "array", + "items": { + "$ref": "#/definitions/entity.Imageitem" + } + } + } + } + } + }, + "/is_owner/{contract}/{wallet}": { + "get": { + "description": "API user could check this directly via any third party service like NFTPort, Moralis as well", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Common" + ], + "summary": "Check if given wallet address owns an NFT from given contract address", + "parameters": [ + { + "type": "string", + "description": "NFT Contract Address", + "name": "contract", + "in": "path", + "required": true + }, + { + "type": "string", + "description": "Wallet Address", + "name": "wallet", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "array", + "items": { + "$ref": "#/definitions/controllers.LandingPageItems" + } + } + } + } + } + }, + "/name": { + "put": { + "description": "Give a common name (Kevin.eth, BillyTheKid, etc) to an Address", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Common" + ], + "summary": "give a common name to a user address, or NFT collection (update exiting)", + "parameters": [ + { + "description": "Address and Name to map together", + "name": "message", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/entity.Addrnameitem" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "array", + "items": { + "$ref": "#/definitions/entity.Bookmarkitem" + } + } + } + } + }, + "post": { + "description": "Give a common name (Kevin.eth, BillyTheKid, etc) to an Address", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Common" + ], + "summary": "give a common name to a user address, or NFT collection", + "parameters": [ + { + "description": "Address and Name to map together", + "name": "message", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/entity.Addrnameitem" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "array", + "items": { + "$ref": "#/definitions/entity.Bookmarkitem" + } + } + } + } + } + }, + "/name/{name}": { + "get": { + "description": "get the given a common name (Kevin.eth, BillyTheKid, etc) what has already been mapped to an Address", "consumes": [ "application/json" ], @@ -29,13 +1433,13 @@ const docTemplate = `{ "application/json" ], "tags": [ - "inbox" + "Common" ], - "summary": "Get Inbox Summary With Last Message", + "summary": "get the common name which has been mapped to an address", "parameters": [ { "type": "string", - "description": "Wallet Address", + "description": "Get Name for given address", "name": "address", "in": "path", "required": true @@ -47,16 +1451,48 @@ const docTemplate = `{ "schema": { "type": "array", "items": { - "$ref": "#/definitions/entity.Chatiteminbox" + "$ref": "#/definitions/entity.Addrnameitem" } } } } } }, - "/getall_chatitems": { + "/unreadcount/{address}": { "get": { - "description": "Get Entire Chatitems table", + "description": "Get Unread count just given an address", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Inbox" + ], + "summary": "Get all unread messages TO a specific user, used for total count notification at top notification bar", + "parameters": [ + { + "type": "string", + "description": "Wallet Address", + "name": "address", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "integer" + } + } + } + } + }, + "/update_chatitem/{fromaddr}/{toaddr}": { + "put": { + "description": "Currently this only update the message read/unread status. It could update the entire JSON struct\nupon request, however we only needed this functionality currently and it saved re-encryption of the data.\nTODO: TO/FROM address in the URL is not needed/not used anymore.", "consumes": [ "application/json" ], @@ -64,9 +1500,20 @@ const docTemplate = `{ "application/json" ], "tags": [ - "inbox" + "DMs" + ], + "summary": "Update Message Read Status of a given DM chat message", + "parameters": [ + { + "description": "chat item JSON struct to update msg read status", + "name": "message", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/entity.Chatitem" + } + } ], - "summary": "Get All Chat Items (legacy - not used currently)", "responses": { "200": { "description": "OK", @@ -79,47 +1526,250 @@ const docTemplate = `{ } } } + }, + "/update_settings": { + "put": { + "description": "Currently this only updates the public key, could be expanded as needed.", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Common" + ], + "summary": "Settings hold a user address and the public key used for encryption.", + "parameters": [ + { + "description": "update struct", + "name": "message", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/entity.Settings" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "array", + "items": { + "$ref": "#/definitions/entity.Settings" + } + } + } + } + } } }, "definitions": { + "controllers.Attachments": { + "type": "object", + "properties": { + "media_keys": { + "type": "array", + "items": { + "type": "string" + } + } + } + }, + "controllers.LandingPageItems": { + "type": "object", + "properties": { + "has_messaged": { + "description": "has user messaged in this group chat before? if not show \"Say hi\" button", + "type": "boolean" + }, + "is_verified": { + "description": "is this group verified? WalletChat's group is verified by default", + "type": "boolean" + }, + "joined": { + "description": "number of members of the group", + "type": "boolean" + }, + "logo": { + "description": "logo url, stored in backend", + "type": "string" + }, + "members": { + "type": "integer" + }, + "messages": { + "type": "array", + "items": { + "$ref": "#/definitions/entity.Groupchatitem" + } + }, + "name": { + "type": "string" + }, + "social": { + "type": "array", + "items": { + "$ref": "#/definitions/controllers.SocialMsg" + } + }, + "tweets": { + "description": "follow format of GET /get_twitter/{nftAddr}", + "type": "array", + "items": { + "$ref": "#/definitions/controllers.TweetType" + } + } + } + }, + "controllers.SocialMsg": { + "type": "object", + "properties": { + "type": { + "type": "string" + }, + "username": { + "type": "string" + } + } + }, + "controllers.TweetType": { + "type": "object", + "properties": { + "attachments": { + "type": "object", + "properties": { + "media_keys": { + "type": "array", + "items": { + "type": "string" + } + } + } + }, + "author_id": { + "type": "string" + }, + "created_at": { + "type": "string" + }, + "id": { + "type": "string" + }, + "media": { + "$ref": "#/definitions/controllers.Attachments" + }, + "text": { + "type": "string" + }, + "user": { + "type": "object", + "properties": { + "id": { + "type": "string" + }, + "name": { + "type": "string" + }, + "profile_image_url": { + "type": "string" + }, + "username": { + "type": "string" + } + } + } + } + }, + "entity.Addrnameitem": { + "type": "object", + "properties": { + "address": { + "type": "string" + }, + "id": { + "type": "integer" + }, + "name": { + "type": "string" + } + } + }, + "entity.Bookmarkitem": { + "type": "object", + "properties": { + "chain": { + "type": "string" + }, + "id": { + "type": "integer" + }, + "nftaddr": { + "type": "string" + }, + "walletaddr": { + "type": "string" + } + } + }, "entity.Chatitem": { "type": "object", + "required": [ + "fromaddr", + "message", + "toaddr" + ], "properties": { "fromaddr": { + "description": "*** REQUIRED INPUT ***", "type": "string" }, "id": { + "description": "AUTO-GENERATED (PRIMARY KEY)", "type": "integer" }, "message": { + "description": "*** REQUIRED INPUT ***", "type": "string" }, "nftaddr": { + "description": "ONLY USED FOR NFT DM CONTEXT", "type": "string" }, "nftid": { - "type": "integer" + "description": "ONLY USED FOR NFT DM CONTEXT", + "type": "string" }, "read": { + "description": "DEFAULT FALSE", "type": "boolean" }, "sender_name": { + "description": "AUTO-SET BY BACKED FOR RETURN VALUE", "type": "string" }, "timestamp": { + "description": "AUTO-SET BY REST API", "type": "string" }, "timestamp_dtm": { + "description": "USED FOR SORTING WHEN TIME FORMAT NEEDED", "type": "string" }, "toaddr": { + "description": "*** REQUIRED INPUT ***", "type": "string" } } }, "entity.Chatiteminbox": { + "description": "Used as Return Data Struct Only", "type": "object", "properties": { + "chain": { + "type": "string" + }, "context_type": { "type": "string" }, @@ -142,7 +1792,7 @@ const docTemplate = `{ "type": "string" }, "nftid": { - "type": "integer" + "type": "string" }, "read": { "type": "boolean" @@ -166,18 +1816,105 @@ const docTemplate = `{ "type": "integer" } } + }, + "entity.Comments": { + "type": "object", + "properties": { + "fromaddr": { + "type": "string" + }, + "id": { + "type": "integer" + }, + "message": { + "type": "string" + }, + "name": { + "type": "string" + }, + "nftaddr": { + "type": "string" + }, + "nftid": { + "type": "integer" + }, + "timestamp": { + "type": "string" + } + } + }, + "entity.Groupchatitem": { + "type": "object", + "properties": { + "context_type": { + "type": "string" + }, + "fromaddr": { + "type": "string" + }, + "id": { + "type": "integer" + }, + "message": { + "type": "string" + }, + "nftaddr": { + "type": "string" + }, + "sender_name": { + "type": "string" + }, + "timestamp": { + "type": "string" + }, + "timestamp_dtm": { + "type": "string" + }, + "type": { + "type": "string" + } + } + }, + "entity.Imageitem": { + "type": "object", + "properties": { + "base64data": { + "type": "string" + }, + "id": { + "type": "integer" + }, + "name": { + "type": "string" + } + } + }, + "entity.Settings": { + "type": "object", + "properties": { + "id": { + "type": "integer" + }, + "publickey": { + "description": "need this for encryption, don't want to get it over and over", + "type": "string" + }, + "walletaddr": { + "type": "string" + } + } } } }` // SwaggerInfo holds exported Swagger Info so clients can modify it var SwaggerInfo = &swag.Spec{ - Version: "1.0", - Host: "localhost:8080", + Version: "0.0", + Host: "api.v0.walletchat.fun", BasePath: "", Schemes: []string{}, Title: "WalletChat API", - Description: "This is the WalletChat messagez", + Description: "Wecome to the WalletChat API Documentation\n\nPlease make note that some JSON data structures are shared for both input/output.\nRequired input parameters will have a red * next to them in the data type outline at\nthe bottom of the page, along with a comment. This means when executing API functionality\nfrom this API page, some fields may need to be removed from the JSON struct before submitting.\nPlease email the developers with any issues.\nSome JSON data structures are output only, and will be marked as such as well.\n\nv0 of the API does not include encryption or authentication, nor does it need /v0 to be called.\nPlease as you are given access to this page, do not abuse this system and impersonate others, or submit offensive material.\nDevelopers monitor this data daily.\n\nv1 will include basic JWT Authentication, however some additional work is in progress to make this fully secure.\nexcept for AUTH functions, all endpoints must prefix /v1 and include Bearer: in all requests\n\nv2 will include encyrption for DMs, private keys will be stored locally on client PCs\nwith no way for us to recover any data which is encrypted.", InfoInstanceName: "swagger", SwaggerTemplate: docTemplate, } diff --git a/docs/swagger.json b/docs/swagger.json index 34342d0..4ebed5d 100644 --- a/docs/swagger.json +++ b/docs/swagger.json @@ -1,19 +1,1423 @@ { "swagger": "2.0", "info": { - "description": "This is the WalletChat messagez", + "description": "Wecome to the WalletChat API Documentation\n\nPlease make note that some JSON data structures are shared for both input/output.\nRequired input parameters will have a red * next to them in the data type outline at\nthe bottom of the page, along with a comment. This means when executing API functionality\nfrom this API page, some fields may need to be removed from the JSON struct before submitting.\nPlease email the developers with any issues.\nSome JSON data structures are output only, and will be marked as such as well.\n\nv0 of the API does not include encryption or authentication, nor does it need /v0 to be called.\nPlease as you are given access to this page, do not abuse this system and impersonate others, or submit offensive material.\nDevelopers monitor this data daily.\n\nv1 will include basic JWT Authentication, however some additional work is in progress to make this fully secure.\nexcept for AUTH functions, all endpoints must prefix /v1 and include Bearer: \u003cJWT\u003e in all requests\n\nv2 will include encyrption for DMs, private keys will be stored locally on client PCs\nwith no way for us to recover any data which is encrypted.", "title": "WalletChat API", "contact": { "url": "https://walletchat.fun", "email": "walletchatextension@gmail.com" }, - "version": "1.0" + "version": "0.0" }, - "host": "localhost:8080", + "host": "api.v0.walletchat.fun", "paths": { + "/community": { + "post": { + "description": "Community Chat Data", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "GroupChat" + ], + "summary": "CreateCommunityChatitem creates GroupChatitem just with community tag (likely could be consolidated)", + "parameters": [ + { + "description": "Community Message Chat Data", + "name": "message", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/entity.Groupchatitem" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "array", + "items": { + "$ref": "#/definitions/entity.Groupchatitem" + } + } + } + } + } + }, + "/community/{community}/{address}": { + "get": { + "description": "TODO: need a creation API for communities, which includes specificied welcome message text, Twitter handle, page title", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "GroupChat" + ], + "summary": "Get Community Chat Landing Page Info", + "parameters": [ + { + "type": "string", + "description": "Wallet Address", + "name": "address", + "in": "path", + "required": true + }, + { + "type": "string", + "description": "Wallet Address", + "name": "address", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "array", + "items": { + "$ref": "#/definitions/controllers.LandingPageItems" + } + } + } + } + } + }, + "/create_bookmark": { + "post": { + "description": "Bookmarks keep an NFT/Community group chat in the sidebar", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "GroupChat" + ], + "summary": "Join an NFT or Community group chat", + "parameters": [ + { + "description": "Add Bookmark from Community Group Chat", + "name": "message", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/entity.Bookmarkitem" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "array", + "items": { + "$ref": "#/definitions/entity.Bookmarkitem" + } + } + } + } + } + }, + "/create_chatitem": { + "post": { + "description": "For DMs, Chatitem data struct is used to store each message and associated info.\nREQUIRED: fromaddr, toaddr, message (see data struct section at bottom of page for more detailed info on each paramter)\nOther fields are generally filled in by the backed REST API and used as return parameters\nID is auto generated and should never be used as input.", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "DMs" + ], + "summary": "Create/Insert DM Chat Message (1-to-1 messaging)", + "parameters": [ + { + "description": "Direct Message Chat Data", + "name": "message", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/entity.Chatitem" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "array", + "items": { + "$ref": "#/definitions/entity.Chatitem" + } + } + } + } + } + }, + "/create_comments": { + "post": { + "description": "Comments are meant to be public, someday having an up/downvote method for auto-moderation", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "NFT" + ], + "summary": "Comments are used within an NFT community chat", + "parameters": [ + { + "description": "create struct", + "name": "message", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/entity.Comments" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "array", + "items": { + "$ref": "#/definitions/entity.Comments" + } + } + } + } + } + }, + "/create_groupchatitem": { + "post": { + "description": "Currently used for all messages outside of DMs", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "GroupChat" + ], + "summary": "Create/Insert chat message for Community/NFT/Group Messaging", + "parameters": [ + { + "description": "Group Message Chat Data", + "name": "message", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/entity.Groupchatitem" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "array", + "items": { + "$ref": "#/definitions/entity.Groupchatitem" + } + } + } + } + } + }, + "/create_settings": { + "post": { + "description": "Currently this only updates the public key, could be expanded as needed.", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Common" + ], + "summary": "Settings hold a user address and the public key used for encryption.", + "parameters": [ + { + "description": "update struct", + "name": "message", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/entity.Settings" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "array", + "items": { + "$ref": "#/definitions/entity.Settings" + } + } + } + } + } + }, + "/delete_bookmark": { + "post": { + "description": "Bookmarks keep an NFT/Community group chat in the sidebar", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "GroupChat" + ], + "summary": "Leave an NFT or Community group chat", + "parameters": [ + { + "description": "Remove Bookmark from Community Group Chat", + "name": "message", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/entity.Bookmarkitem" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "array", + "items": { + "$ref": "#/definitions/entity.Bookmarkitem" + } + } + } + } + } + }, + "/delete_comments/{fromaddr}/{nftaddr}/{nftid}": { + "delete": { + "description": "NFTs have a public comment section", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "NFT" + ], + "summary": "Delete Public Comments for given FROM wallet address, NFT Contract and ID", + "parameters": [ + { + "type": "string", + "description": "FROM Wallet Address", + "name": "address", + "in": "path", + "required": true + }, + { + "type": "string", + "description": "NFT Contract Address", + "name": "nftaddr", + "in": "path", + "required": true + }, + { + "type": "string", + "description": "NFT ID", + "name": "nftid", + "in": "path", + "required": true + } + ], + "responses": { + "204": { + "description": "No Content" + } + } + } + }, + "/delete_settings/{address}": { + "delete": { + "description": "TODO: Need to protect this with JWT in addition to other API calls needed to use FROM addr from the JWT", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Unused/Legacy" + ], + "summary": "Delete Settings Info", + "parameters": [ + { + "type": "string", + "description": "Wallet Address", + "name": "address", + "in": "path", + "required": true + } + ], + "responses": { + "204": { + "description": "No Content" + } + } + } + }, + "/deleteall_chatitems/{fromaddr}/{toaddr}": { + "delete": { + "description": "TODO: Need to protect this with JWT in addition to other API calls needed to use FROM addr from the JWT", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Unused/Legacy" + ], + "summary": "Delete All Chat Items (DMs) between FROM and TO given addresses", + "parameters": [ + { + "type": "string", + "description": "TO: Address", + "name": "toaddr", + "in": "path", + "required": true + }, + { + "type": "string", + "description": "FROM: Address", + "name": "fromaddr", + "in": "path", + "required": true + } + ], + "responses": { + "204": { + "description": "No Content" + } + } + } + }, + "/get_bookmarks/{address}/": { + "get": { + "description": "This used for UI purposes, checking if a user/wallet has bookmarked a community.", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "GroupChat" + ], + "summary": "Check if a wallet address has bookmarked/joined given NFT contract", + "parameters": [ + { + "type": "string", + "description": "Wallet Address", + "name": "address", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "array", + "items": { + "$ref": "#/definitions/entity.Bookmarkitem" + } + } + } + } + } + }, + "/get_bookmarks/{walletaddr}/{nftaddr}": { + "get": { + "description": "This used for UI purposes, checking if a user/wallet has bookmarked a community.", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "GroupChat" + ], + "summary": "Check if a wallet address has bookmarked/joined given NFT contract", + "parameters": [ + { + "type": "string", + "description": "Wallet Address", + "name": "walletaddr", + "in": "path", + "required": true + }, + { + "type": "string", + "description": "NFT Contract Address", + "name": "nftaddr", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "bool" + } + } + } + } + }, + "/get_comments/{nftaddr}/{nftid}": { + "get": { + "description": "NFTs have a public comment section", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "NFT" + ], + "summary": "Get Public Comments for given NFT Contract and ID", + "parameters": [ + { + "type": "string", + "description": "Wallet Address", + "name": "address", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "array", + "items": { + "$ref": "#/definitions/entity.Comments" + } + } + } + } + } + }, + "/get_comments_cnt/{nftaddr}/{nftid}": { + "get": { + "description": "NFTs have a public comment section", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "NFT" + ], + "summary": "Get Public Comments Count for given NFT Contract and ID", + "parameters": [ + { + "type": "string", + "description": "NFT Contract Address", + "name": "nftaddr", + "in": "path", + "required": true + }, + { + "type": "string", + "description": "NFT ID", + "name": "nftid", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "integer" + } + } + } + } + }, + "/get_groupchatitems/{address}": { + "get": { + "description": "Community Chat Data", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "NFT" + ], + "summary": "GetGroupChatItems gets group chat data for a given NFT address", + "parameters": [ + { + "type": "string", + "description": "Get Group Chat Data By NFT Address", + "name": "message", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "array", + "items": { + "$ref": "#/definitions/entity.Groupchatitem" + } + } + } + } + } + }, + "/get_groupchatitems/{address}/{useraddress}": { + "get": { + "description": "Get all group chat items for a given wallet (useraddress) for a given NFT Contract Address (TODO: fix up var names)", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "NFT" + ], + "summary": "Get group chat items, given a wallt FROM address and NFT Contract Address", + "parameters": [ + { + "type": "string", + "description": "NFT Address", + "name": "address", + "in": "path", + "required": true + }, + { + "type": "string", + "description": "FROM: wallet address", + "name": "useraddress", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "array", + "items": { + "$ref": "#/definitions/entity.Groupchatitem" + } + } + } + } + } + }, + "/get_groupchatitems_unreadcnt/{address}/{useraddress}": { + "get": { + "description": "For group chat unread counts, currently the database stores a timestamp for each time a user enters a group chat.\nWe though in the design it would be impractical to keep a read/unread count copy per user per message, but if this\nmethod doesn't proof to be fine grained enough, we could add a boolean relational table of read messgages per user.", + "consumes": [ + "application/json" + ], + "produces": [ + "text/plain" + ], + "tags": [ + "Common" + ], + "summary": "Get Unread Groupchat Items (TODO: cleanup naming convention here)", + "parameters": [ + { + "type": "string", + "description": "Common Name Mapped to User/Community", + "name": "name", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "integer" + } + } + } + } + }, "/get_inbox/{address}": { "get": { - "description": "Get Each 1-on-1 Conversation, NFT and Community Chat For Display in Inbox", + "description": "Get Each 1-on-1 Conversation, NFT and Community Chat For Display in Inbox", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Inbox" + ], + "summary": "Get Inbox Summary With Last Message", + "parameters": [ + { + "type": "string", + "description": "Wallet Address", + "name": "address", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "array", + "items": { + "$ref": "#/definitions/entity.Chatiteminbox" + } + } + } + } + } + }, + "/get_settings/{address}": { + "get": { + "description": "TODO: Need to protect this with JWT in addition to other API calls needed to use FROM addr from the JWT", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Unused/Legacy" + ], + "summary": "Get Settings Info", + "parameters": [ + { + "type": "string", + "description": "Wallet Address", + "name": "address", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "array", + "items": { + "$ref": "#/definitions/entity.Settings" + } + } + } + } + } + }, + "/get_unread_cnt/{address}": { + "get": { + "description": "Get Each 1-on-1 Conversation, NFT and Community Chat For Display in Inbox", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Inbox" + ], + "summary": "Get all unread messages TO a specific user, used for total count notification at top notification bar", + "parameters": [ + { + "type": "string", + "description": "Wallet Address", + "name": "address", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "integer" + } + } + } + } + }, + "/get_unread_cnt/{address}/{nftaddr}/{nftid}": { + "get": { + "description": "Get Unread count for specifc NFT context given a wallet address and specific NFT", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "NFT" + ], + "summary": "Get all unread messages for a specific NFT context", + "parameters": [ + { + "type": "string", + "description": "Wallet Address", + "name": "address", + "in": "path", + "required": true + }, + { + "type": "string", + "description": "NFT Contract Address", + "name": "nftaddr", + "in": "path", + "required": true + }, + { + "type": "string", + "description": "NFT ID", + "name": "nftid", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "integer" + } + } + } + } + }, + "/get_unread_cnt/{fromaddr}/{toaddr}": { + "get": { + "description": "Get Unread count for DMs", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Unused/Legacy" + ], + "summary": "Get all unread messages between two addresses", + "parameters": [ + { + "type": "string", + "description": "TO: Wallet Address", + "name": "toaddr", + "in": "path", + "required": true + }, + { + "type": "string", + "description": "FROM: Wallet Address", + "name": "from", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "integer" + } + } + } + } + }, + "/get_unread_cnt_by_type/{address}/{type}": { + "get": { + "description": "Get Each 1-on-1 Conversation, NFT and Community Chat For Display in Inbox", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Unused/Legacy" + ], + "summary": "Get all unread messages TO a specific user, used for total count notification at top notification bar", + "parameters": [ + { + "type": "string", + "description": "Wallet Address", + "name": "address", + "in": "path", + "required": true + }, + { + "type": "string", + "description": "Message Type - nft|community|dm|all", + "name": "type", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "integer" + } + } + } + } + }, + "/get_unread_cnt_nft/{address}": { + "get": { + "description": "Get Unread count for all NFT contexts given a wallet address", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Unused/Legacy" + ], + "summary": "Get all unread messages for all NFT related chats for given user", + "parameters": [ + { + "type": "string", + "description": "Wallet Address", + "name": "address", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "integer" + } + } + } + } + }, + "/getall_chatitems/{address}": { + "get": { + "description": "Get all Chat Items for DMs for a given wallet address", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Unused/Legacy" + ], + "summary": "Get Chat Item For Given Wallet Address", + "parameters": [ + { + "type": "string", + "description": "Wallet Address", + "name": "toaddr", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "array", + "items": { + "$ref": "#/definitions/entity.Chatitem" + } + } + } + } + } + }, + "/getall_chatitems/{fromaddr}/{toaddr}": { + "get": { + "description": "Get chat data between the given two addresses, TO and FROM and interchangable here", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "DMs" + ], + "summary": "Get Chat Data Between Two Addresses", + "parameters": [ + { + "type": "string", + "description": "TO: Wallet Address", + "name": "toaddr", + "in": "path", + "required": true + }, + { + "type": "string", + "description": "FROM: Wallet Address", + "name": "from", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "array", + "items": { + "$ref": "#/definitions/entity.Chatitem" + } + } + } + } + } + }, + "/getnft_chatitems/{address}": { + "get": { + "description": "Get ALL NFT context items for a given wallet address", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Unused/Legacy" + ], + "summary": "Get NFT Related Chat Items For Given Wallet Address", + "parameters": [ + { + "type": "string", + "description": "Wallet Address", + "name": "toaddr", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "array", + "items": { + "$ref": "#/definitions/entity.Chatitem" + } + } + } + } + } + }, + "/getnft_chatitems/{address}/{nftaddr}/{nftid}": { + "get": { + "description": "Get all specified NFT contract and ID items for a given wallet address", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Unused/Legacy" + ], + "summary": "Get NFT Related Chat Items For Given NFT Contract and ID, relating to one wallet", + "parameters": [ + { + "type": "string", + "description": "Wallet Address", + "name": "address", + "in": "path", + "required": true + }, + { + "type": "string", + "description": "NFT Contract Address", + "name": "nftaddr", + "in": "path", + "required": true + }, + { + "type": "string", + "description": "NFT ID", + "name": "nftid", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "array", + "items": { + "$ref": "#/definitions/entity.Chatitem" + } + } + } + } + } + }, + "/getnft_chatitems/{fromaddr}/{toaddr}/{nftaddr}/{nftid}": { + "get": { + "description": "Get ALL NFT context items for a specifc NFT context convo between two wallets", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "NFT" + ], + "summary": "Get NFT Related Chat Items For Given NFT Contract and ID, between two wallet addresses (TO and FROM are interchangable)", + "parameters": [ + { + "type": "string", + "description": "NFT Contract Address", + "name": "nftaddr", + "in": "path", + "required": true + }, + { + "type": "string", + "description": "NFT ID", + "name": "nftid", + "in": "path", + "required": true + }, + { + "type": "string", + "description": "TO: Wallet Address", + "name": "toaddr", + "in": "path", + "required": true + }, + { + "type": "string", + "description": "FROM: Wallet Address", + "name": "from", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "array", + "items": { + "$ref": "#/definitions/entity.Chatitem" + } + } + } + } + } + }, + "/getnft_chatitems/{nftaddr}/{nftid}": { + "get": { + "description": "Get ALL NFT context items for a given wallet address", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Unused/Legacy" + ], + "summary": "Get NFT Related Chat Items For Given NFT Contract and ID", + "parameters": [ + { + "type": "string", + "description": "NFT Contract Address", + "name": "nftaddr", + "in": "path", + "required": true + }, + { + "type": "string", + "description": "NFT ID", + "name": "nftid", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "array", + "items": { + "$ref": "#/definitions/entity.Chatitem" + } + } + } + } + } + }, + "/image": { + "put": { + "description": "Currently used for the WC HQ Logo, stores the base64 raw data of the profile image for a community", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Common" + ], + "summary": "Store Image in DB for later user (update existing photo)", + "parameters": [ + { + "description": "Profile Thumbnail Pic", + "name": "message", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/entity.Imageitem" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "array", + "items": { + "$ref": "#/definitions/entity.Bookmarkitem" + } + } + } + } + }, + "post": { + "description": "Currently used for the WC HQ Logo, stores the base64 raw data of the profile image for a community", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Common" + ], + "summary": "Store Image in DB for later user", + "parameters": [ + { + "description": "Profile Thumbnail Pic", + "name": "message", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/entity.Imageitem" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "array", + "items": { + "$ref": "#/definitions/entity.Bookmarkitem" + } + } + } + } + } + }, + "/image/{name}": { + "get": { + "description": "Retreive image data for use with user/community/nft group dislayed icon", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Common" + ], + "summary": "Get Thumbnail Image Data", + "parameters": [ + { + "type": "string", + "description": "Common Name Mapped to User/Community", + "name": "name", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "array", + "items": { + "$ref": "#/definitions/entity.Imageitem" + } + } + } + } + } + }, + "/is_owner/{contract}/{wallet}": { + "get": { + "description": "API user could check this directly via any third party service like NFTPort, Moralis as well", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Common" + ], + "summary": "Check if given wallet address owns an NFT from given contract address", + "parameters": [ + { + "type": "string", + "description": "NFT Contract Address", + "name": "contract", + "in": "path", + "required": true + }, + { + "type": "string", + "description": "Wallet Address", + "name": "wallet", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "array", + "items": { + "$ref": "#/definitions/controllers.LandingPageItems" + } + } + } + } + } + }, + "/name": { + "put": { + "description": "Give a common name (Kevin.eth, BillyTheKid, etc) to an Address", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Common" + ], + "summary": "give a common name to a user address, or NFT collection (update exiting)", + "parameters": [ + { + "description": "Address and Name to map together", + "name": "message", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/entity.Addrnameitem" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "array", + "items": { + "$ref": "#/definitions/entity.Bookmarkitem" + } + } + } + } + }, + "post": { + "description": "Give a common name (Kevin.eth, BillyTheKid, etc) to an Address", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Common" + ], + "summary": "give a common name to a user address, or NFT collection", + "parameters": [ + { + "description": "Address and Name to map together", + "name": "message", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/entity.Addrnameitem" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "array", + "items": { + "$ref": "#/definitions/entity.Bookmarkitem" + } + } + } + } + } + }, + "/name/{name}": { + "get": { + "description": "get the given a common name (Kevin.eth, BillyTheKid, etc) what has already been mapped to an Address", "consumes": [ "application/json" ], @@ -21,13 +1425,13 @@ "application/json" ], "tags": [ - "inbox" + "Common" ], - "summary": "Get Inbox Summary With Last Message", + "summary": "get the common name which has been mapped to an address", "parameters": [ { "type": "string", - "description": "Wallet Address", + "description": "Get Name for given address", "name": "address", "in": "path", "required": true @@ -39,16 +1443,48 @@ "schema": { "type": "array", "items": { - "$ref": "#/definitions/entity.Chatiteminbox" + "$ref": "#/definitions/entity.Addrnameitem" } } } } } }, - "/getall_chatitems": { + "/unreadcount/{address}": { "get": { - "description": "Get Entire Chatitems table", + "description": "Get Unread count just given an address", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Inbox" + ], + "summary": "Get all unread messages TO a specific user, used for total count notification at top notification bar", + "parameters": [ + { + "type": "string", + "description": "Wallet Address", + "name": "address", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "integer" + } + } + } + } + }, + "/update_chatitem/{fromaddr}/{toaddr}": { + "put": { + "description": "Currently this only update the message read/unread status. It could update the entire JSON struct\nupon request, however we only needed this functionality currently and it saved re-encryption of the data.\nTODO: TO/FROM address in the URL is not needed/not used anymore.", "consumes": [ "application/json" ], @@ -56,9 +1492,20 @@ "application/json" ], "tags": [ - "inbox" + "DMs" + ], + "summary": "Update Message Read Status of a given DM chat message", + "parameters": [ + { + "description": "chat item JSON struct to update msg read status", + "name": "message", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/entity.Chatitem" + } + } ], - "summary": "Get All Chat Items (legacy - not used currently)", "responses": { "200": { "description": "OK", @@ -71,47 +1518,250 @@ } } } + }, + "/update_settings": { + "put": { + "description": "Currently this only updates the public key, could be expanded as needed.", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Common" + ], + "summary": "Settings hold a user address and the public key used for encryption.", + "parameters": [ + { + "description": "update struct", + "name": "message", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/entity.Settings" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "array", + "items": { + "$ref": "#/definitions/entity.Settings" + } + } + } + } + } } }, "definitions": { + "controllers.Attachments": { + "type": "object", + "properties": { + "media_keys": { + "type": "array", + "items": { + "type": "string" + } + } + } + }, + "controllers.LandingPageItems": { + "type": "object", + "properties": { + "has_messaged": { + "description": "has user messaged in this group chat before? if not show \"Say hi\" button", + "type": "boolean" + }, + "is_verified": { + "description": "is this group verified? WalletChat's group is verified by default", + "type": "boolean" + }, + "joined": { + "description": "number of members of the group", + "type": "boolean" + }, + "logo": { + "description": "logo url, stored in backend", + "type": "string" + }, + "members": { + "type": "integer" + }, + "messages": { + "type": "array", + "items": { + "$ref": "#/definitions/entity.Groupchatitem" + } + }, + "name": { + "type": "string" + }, + "social": { + "type": "array", + "items": { + "$ref": "#/definitions/controllers.SocialMsg" + } + }, + "tweets": { + "description": "follow format of GET /get_twitter/{nftAddr}", + "type": "array", + "items": { + "$ref": "#/definitions/controllers.TweetType" + } + } + } + }, + "controllers.SocialMsg": { + "type": "object", + "properties": { + "type": { + "type": "string" + }, + "username": { + "type": "string" + } + } + }, + "controllers.TweetType": { + "type": "object", + "properties": { + "attachments": { + "type": "object", + "properties": { + "media_keys": { + "type": "array", + "items": { + "type": "string" + } + } + } + }, + "author_id": { + "type": "string" + }, + "created_at": { + "type": "string" + }, + "id": { + "type": "string" + }, + "media": { + "$ref": "#/definitions/controllers.Attachments" + }, + "text": { + "type": "string" + }, + "user": { + "type": "object", + "properties": { + "id": { + "type": "string" + }, + "name": { + "type": "string" + }, + "profile_image_url": { + "type": "string" + }, + "username": { + "type": "string" + } + } + } + } + }, + "entity.Addrnameitem": { + "type": "object", + "properties": { + "address": { + "type": "string" + }, + "id": { + "type": "integer" + }, + "name": { + "type": "string" + } + } + }, + "entity.Bookmarkitem": { + "type": "object", + "properties": { + "chain": { + "type": "string" + }, + "id": { + "type": "integer" + }, + "nftaddr": { + "type": "string" + }, + "walletaddr": { + "type": "string" + } + } + }, "entity.Chatitem": { "type": "object", + "required": [ + "fromaddr", + "message", + "toaddr" + ], "properties": { "fromaddr": { + "description": "*** REQUIRED INPUT ***", "type": "string" }, "id": { + "description": "AUTO-GENERATED (PRIMARY KEY)", "type": "integer" }, "message": { + "description": "*** REQUIRED INPUT ***", "type": "string" }, "nftaddr": { + "description": "ONLY USED FOR NFT DM CONTEXT", "type": "string" }, "nftid": { - "type": "integer" + "description": "ONLY USED FOR NFT DM CONTEXT", + "type": "string" }, "read": { + "description": "DEFAULT FALSE", "type": "boolean" }, "sender_name": { + "description": "AUTO-SET BY BACKED FOR RETURN VALUE", "type": "string" }, "timestamp": { + "description": "AUTO-SET BY REST API", "type": "string" }, "timestamp_dtm": { + "description": "USED FOR SORTING WHEN TIME FORMAT NEEDED", "type": "string" }, "toaddr": { + "description": "*** REQUIRED INPUT ***", "type": "string" } } }, "entity.Chatiteminbox": { + "description": "Used as Return Data Struct Only", "type": "object", "properties": { + "chain": { + "type": "string" + }, "context_type": { "type": "string" }, @@ -134,7 +1784,7 @@ "type": "string" }, "nftid": { - "type": "integer" + "type": "string" }, "read": { "type": "boolean" @@ -158,6 +1808,93 @@ "type": "integer" } } + }, + "entity.Comments": { + "type": "object", + "properties": { + "fromaddr": { + "type": "string" + }, + "id": { + "type": "integer" + }, + "message": { + "type": "string" + }, + "name": { + "type": "string" + }, + "nftaddr": { + "type": "string" + }, + "nftid": { + "type": "integer" + }, + "timestamp": { + "type": "string" + } + } + }, + "entity.Groupchatitem": { + "type": "object", + "properties": { + "context_type": { + "type": "string" + }, + "fromaddr": { + "type": "string" + }, + "id": { + "type": "integer" + }, + "message": { + "type": "string" + }, + "nftaddr": { + "type": "string" + }, + "sender_name": { + "type": "string" + }, + "timestamp": { + "type": "string" + }, + "timestamp_dtm": { + "type": "string" + }, + "type": { + "type": "string" + } + } + }, + "entity.Imageitem": { + "type": "object", + "properties": { + "base64data": { + "type": "string" + }, + "id": { + "type": "integer" + }, + "name": { + "type": "string" + } + } + }, + "entity.Settings": { + "type": "object", + "properties": { + "id": { + "type": "integer" + }, + "publickey": { + "description": "need this for encryption, don't want to get it over and over", + "type": "string" + }, + "walletaddr": { + "type": "string" + } + } } } } \ No newline at end of file diff --git a/docs/swagger.yaml b/docs/swagger.yaml index 6c5ac7a..06829c9 100644 --- a/docs/swagger.yaml +++ b/docs/swagger.yaml @@ -1,29 +1,144 @@ definitions: + controllers.Attachments: + properties: + media_keys: + items: + type: string + type: array + type: object + controllers.LandingPageItems: + properties: + has_messaged: + description: has user messaged in this group chat before? if not show "Say + hi" button + type: boolean + is_verified: + description: is this group verified? WalletChat's group is verified by default + type: boolean + joined: + description: number of members of the group + type: boolean + logo: + description: logo url, stored in backend + type: string + members: + type: integer + messages: + items: + $ref: '#/definitions/entity.Groupchatitem' + type: array + name: + type: string + social: + items: + $ref: '#/definitions/controllers.SocialMsg' + type: array + tweets: + description: follow format of GET /get_twitter/{nftAddr} + items: + $ref: '#/definitions/controllers.TweetType' + type: array + type: object + controllers.SocialMsg: + properties: + type: + type: string + username: + type: string + type: object + controllers.TweetType: + properties: + attachments: + properties: + media_keys: + items: + type: string + type: array + type: object + author_id: + type: string + created_at: + type: string + id: + type: string + media: + $ref: '#/definitions/controllers.Attachments' + text: + type: string + user: + properties: + id: + type: string + name: + type: string + profile_image_url: + type: string + username: + type: string + type: object + type: object + entity.Addrnameitem: + properties: + address: + type: string + id: + type: integer + name: + type: string + type: object + entity.Bookmarkitem: + properties: + chain: + type: string + id: + type: integer + nftaddr: + type: string + walletaddr: + type: string + type: object entity.Chatitem: properties: fromaddr: + description: '*** REQUIRED INPUT ***' type: string id: + description: AUTO-GENERATED (PRIMARY KEY) type: integer message: + description: '*** REQUIRED INPUT ***' type: string nftaddr: + description: ONLY USED FOR NFT DM CONTEXT type: string nftid: - type: integer + description: ONLY USED FOR NFT DM CONTEXT + type: string read: + description: DEFAULT FALSE type: boolean sender_name: + description: AUTO-SET BY BACKED FOR RETURN VALUE type: string timestamp: + description: AUTO-SET BY REST API type: string timestamp_dtm: + description: USED FOR SORTING WHEN TIME FORMAT NEEDED type: string toaddr: + description: '*** REQUIRED INPUT ***' type: string + required: + - fromaddr + - message + - toaddr type: object entity.Chatiteminbox: + description: Used as Return Data Struct Only properties: + chain: + type: string context_type: type: string fromaddr: @@ -39,7 +154,7 @@ definitions: nftaddr: type: string nftid: - type: integer + type: string read: type: boolean sender_name: @@ -55,22 +170,127 @@ definitions: unread: type: integer type: object -host: localhost:8080 + entity.Comments: + properties: + fromaddr: + type: string + id: + type: integer + message: + type: string + name: + type: string + nftaddr: + type: string + nftid: + type: integer + timestamp: + type: string + type: object + entity.Groupchatitem: + properties: + context_type: + type: string + fromaddr: + type: string + id: + type: integer + message: + type: string + nftaddr: + type: string + sender_name: + type: string + timestamp: + type: string + timestamp_dtm: + type: string + type: + type: string + type: object + entity.Imageitem: + properties: + base64data: + type: string + id: + type: integer + name: + type: string + type: object + entity.Settings: + properties: + id: + type: integer + publickey: + description: need this for encryption, don't want to get it over and over + type: string + walletaddr: + type: string + type: object +host: api.v0.walletchat.fun info: contact: email: walletchatextension@gmail.com url: https://walletchat.fun - description: This is the WalletChat messagez + description: |- + Wecome to the WalletChat API Documentation + + Please make note that some JSON data structures are shared for both input/output. + Required input parameters will have a red * next to them in the data type outline at + the bottom of the page, along with a comment. This means when executing API functionality + from this API page, some fields may need to be removed from the JSON struct before submitting. + Please email the developers with any issues. + Some JSON data structures are output only, and will be marked as such as well. + + v0 of the API does not include encryption or authentication, nor does it need /v0 to be called. + Please as you are given access to this page, do not abuse this system and impersonate others, or submit offensive material. + Developers monitor this data daily. + + v1 will include basic JWT Authentication, however some additional work is in progress to make this fully secure. + except for AUTH functions, all endpoints must prefix /v1 and include Bearer: in all requests + + v2 will include encyrption for DMs, private keys will be stored locally on client PCs + with no way for us to recover any data which is encrypted. title: WalletChat API - version: "1.0" + version: "0.0" paths: - /get_inbox/{address}: + /community: + post: + consumes: + - application/json + description: Community Chat Data + parameters: + - description: Community Message Chat Data + in: body + name: message + required: true + schema: + $ref: '#/definitions/entity.Groupchatitem' + produces: + - application/json + responses: + "200": + description: OK + schema: + items: + $ref: '#/definitions/entity.Groupchatitem' + type: array + summary: CreateCommunityChatitem creates GroupChatitem just with community tag + (likely could be consolidated) + tags: + - GroupChat + /community/{community}/{address}: get: consumes: - application/json - description: Get Each 1-on-1 Conversation, NFT and Community Chat For Display - in Inbox + description: 'TODO: need a creation API for communities, which includes specificied + welcome message text, Twitter handle, page title' parameters: + - description: Wallet Address + in: path + name: address + required: true + type: string - description: Wallet Address in: path name: address @@ -83,16 +303,51 @@ paths: description: OK schema: items: - $ref: '#/definitions/entity.Chatiteminbox' + $ref: '#/definitions/controllers.LandingPageItems' type: array - summary: Get Inbox Summary With Last Message + summary: Get Community Chat Landing Page Info tags: - - inbox - /getall_chatitems: - get: + - GroupChat + /create_bookmark: + post: + consumes: + - application/json + description: Bookmarks keep an NFT/Community group chat in the sidebar + parameters: + - description: Add Bookmark from Community Group Chat + in: body + name: message + required: true + schema: + $ref: '#/definitions/entity.Bookmarkitem' + produces: + - application/json + responses: + "200": + description: OK + schema: + items: + $ref: '#/definitions/entity.Bookmarkitem' + type: array + summary: Join an NFT or Community group chat + tags: + - GroupChat + /create_chatitem: + post: consumes: - application/json - description: Get Entire Chatitems table + description: |- + For DMs, Chatitem data struct is used to store each message and associated info. + REQUIRED: fromaddr, toaddr, message (see data struct section at bottom of page for more detailed info on each paramter) + Other fields are generally filled in by the backed REST API and used as return parameters + ID is auto generated and should never be used as input. + parameters: + - description: Direct Message Chat Data + in: body + name: message + required: true + schema: + $ref: '#/definitions/entity.Chatitem' produces: - application/json responses: @@ -102,7 +357,959 @@ paths: items: $ref: '#/definitions/entity.Chatitem' type: array - summary: Get All Chat Items (legacy - not used currently) + summary: Create/Insert DM Chat Message (1-to-1 messaging) + tags: + - DMs + /create_comments: + post: + consumes: + - application/json + description: Comments are meant to be public, someday having an up/downvote + method for auto-moderation + parameters: + - description: create struct + in: body + name: message + required: true + schema: + $ref: '#/definitions/entity.Comments' + produces: + - application/json + responses: + "200": + description: OK + schema: + items: + $ref: '#/definitions/entity.Comments' + type: array + summary: Comments are used within an NFT community chat + tags: + - NFT + /create_groupchatitem: + post: + consumes: + - application/json + description: Currently used for all messages outside of DMs + parameters: + - description: Group Message Chat Data + in: body + name: message + required: true + schema: + $ref: '#/definitions/entity.Groupchatitem' + produces: + - application/json + responses: + "200": + description: OK + schema: + items: + $ref: '#/definitions/entity.Groupchatitem' + type: array + summary: Create/Insert chat message for Community/NFT/Group Messaging + tags: + - GroupChat + /create_settings: + post: + consumes: + - application/json + description: Currently this only updates the public key, could be expanded as + needed. + parameters: + - description: update struct + in: body + name: message + required: true + schema: + $ref: '#/definitions/entity.Settings' + produces: + - application/json + responses: + "200": + description: OK + schema: + items: + $ref: '#/definitions/entity.Settings' + type: array + summary: Settings hold a user address and the public key used for encryption. + tags: + - Common + /delete_bookmark: + post: + consumes: + - application/json + description: Bookmarks keep an NFT/Community group chat in the sidebar + parameters: + - description: Remove Bookmark from Community Group Chat + in: body + name: message + required: true + schema: + $ref: '#/definitions/entity.Bookmarkitem' + produces: + - application/json + responses: + "200": + description: OK + schema: + items: + $ref: '#/definitions/entity.Bookmarkitem' + type: array + summary: Leave an NFT or Community group chat + tags: + - GroupChat + /delete_comments/{fromaddr}/{nftaddr}/{nftid}: + delete: + consumes: + - application/json + description: NFTs have a public comment section + parameters: + - description: FROM Wallet Address + in: path + name: address + required: true + type: string + - description: NFT Contract Address + in: path + name: nftaddr + required: true + type: string + - description: NFT ID + in: path + name: nftid + required: true + type: string + produces: + - application/json + responses: + "204": + description: No Content + summary: Delete Public Comments for given FROM wallet address, NFT Contract + and ID + tags: + - NFT + /delete_settings/{address}: + delete: + consumes: + - application/json + description: 'TODO: Need to protect this with JWT in addition to other API calls + needed to use FROM addr from the JWT' + parameters: + - description: Wallet Address + in: path + name: address + required: true + type: string + produces: + - application/json + responses: + "204": + description: No Content + summary: Delete Settings Info + tags: + - Unused/Legacy + /deleteall_chatitems/{fromaddr}/{toaddr}: + delete: + consumes: + - application/json + description: 'TODO: Need to protect this with JWT in addition to other API calls + needed to use FROM addr from the JWT' + parameters: + - description: 'TO: Address' + in: path + name: toaddr + required: true + type: string + - description: 'FROM: Address' + in: path + name: fromaddr + required: true + type: string + produces: + - application/json + responses: + "204": + description: No Content + summary: Delete All Chat Items (DMs) between FROM and TO given addresses + tags: + - Unused/Legacy + /get_bookmarks/{address}/: + get: + consumes: + - application/json + description: This used for UI purposes, checking if a user/wallet has bookmarked + a community. + parameters: + - description: Wallet Address + in: path + name: address + required: true + type: string + produces: + - application/json + responses: + "200": + description: OK + schema: + items: + $ref: '#/definitions/entity.Bookmarkitem' + type: array + summary: Check if a wallet address has bookmarked/joined given NFT contract + tags: + - GroupChat + /get_bookmarks/{walletaddr}/{nftaddr}: + get: + consumes: + - application/json + description: This used for UI purposes, checking if a user/wallet has bookmarked + a community. + parameters: + - description: Wallet Address + in: path + name: walletaddr + required: true + type: string + - description: NFT Contract Address + in: path + name: nftaddr + required: true + type: string + produces: + - application/json + responses: + "200": + description: OK + schema: + type: bool + summary: Check if a wallet address has bookmarked/joined given NFT contract + tags: + - GroupChat + /get_comments/{nftaddr}/{nftid}: + get: + consumes: + - application/json + description: NFTs have a public comment section + parameters: + - description: Wallet Address + in: path + name: address + required: true + type: string + produces: + - application/json + responses: + "200": + description: OK + schema: + items: + $ref: '#/definitions/entity.Comments' + type: array + summary: Get Public Comments for given NFT Contract and ID + tags: + - NFT + /get_comments_cnt/{nftaddr}/{nftid}: + get: + consumes: + - application/json + description: NFTs have a public comment section + parameters: + - description: NFT Contract Address + in: path + name: nftaddr + required: true + type: string + - description: NFT ID + in: path + name: nftid + required: true + type: string + produces: + - application/json + responses: + "200": + description: OK + schema: + type: integer + summary: Get Public Comments Count for given NFT Contract and ID + tags: + - NFT + /get_groupchatitems/{address}: + get: + consumes: + - application/json + description: Community Chat Data + parameters: + - description: Get Group Chat Data By NFT Address + in: path + name: message + required: true + type: string + produces: + - application/json + responses: + "200": + description: OK + schema: + items: + $ref: '#/definitions/entity.Groupchatitem' + type: array + summary: GetGroupChatItems gets group chat data for a given NFT address + tags: + - NFT + /get_groupchatitems/{address}/{useraddress}: + get: + consumes: + - application/json + description: 'Get all group chat items for a given wallet (useraddress) for + a given NFT Contract Address (TODO: fix up var names)' + parameters: + - description: NFT Address + in: path + name: address + required: true + type: string + - description: 'FROM: wallet address' + in: path + name: useraddress + required: true + type: string + produces: + - application/json + responses: + "200": + description: OK + schema: + items: + $ref: '#/definitions/entity.Groupchatitem' + type: array + summary: Get group chat items, given a wallt FROM address and NFT Contract Address + tags: + - NFT + /get_groupchatitems_unreadcnt/{address}/{useraddress}: + get: + consumes: + - application/json + description: |- + For group chat unread counts, currently the database stores a timestamp for each time a user enters a group chat. + We though in the design it would be impractical to keep a read/unread count copy per user per message, but if this + method doesn't proof to be fine grained enough, we could add a boolean relational table of read messgages per user. + parameters: + - description: Common Name Mapped to User/Community + in: path + name: name + required: true + type: string + produces: + - text/plain + responses: + "200": + description: OK + schema: + type: integer + summary: 'Get Unread Groupchat Items (TODO: cleanup naming convention here)' + tags: + - Common + /get_inbox/{address}: + get: + consumes: + - application/json + description: Get Each 1-on-1 Conversation, NFT and Community Chat For Display + in Inbox + parameters: + - description: Wallet Address + in: path + name: address + required: true + type: string + produces: + - application/json + responses: + "200": + description: OK + schema: + items: + $ref: '#/definitions/entity.Chatiteminbox' + type: array + summary: Get Inbox Summary With Last Message + tags: + - Inbox + /get_settings/{address}: + get: + consumes: + - application/json + description: 'TODO: Need to protect this with JWT in addition to other API calls + needed to use FROM addr from the JWT' + parameters: + - description: Wallet Address + in: path + name: address + required: true + type: string + produces: + - application/json + responses: + "200": + description: OK + schema: + items: + $ref: '#/definitions/entity.Settings' + type: array + summary: Get Settings Info + tags: + - Unused/Legacy + /get_unread_cnt/{address}: + get: + consumes: + - application/json + description: Get Each 1-on-1 Conversation, NFT and Community Chat For Display + in Inbox + parameters: + - description: Wallet Address + in: path + name: address + required: true + type: string + produces: + - application/json + responses: + "200": + description: OK + schema: + type: integer + summary: Get all unread messages TO a specific user, used for total count notification + at top notification bar + tags: + - Inbox + /get_unread_cnt/{address}/{nftaddr}/{nftid}: + get: + consumes: + - application/json + description: Get Unread count for specifc NFT context given a wallet address + and specific NFT + parameters: + - description: Wallet Address + in: path + name: address + required: true + type: string + - description: NFT Contract Address + in: path + name: nftaddr + required: true + type: string + - description: NFT ID + in: path + name: nftid + required: true + type: string + produces: + - application/json + responses: + "200": + description: OK + schema: + type: integer + summary: Get all unread messages for a specific NFT context + tags: + - NFT + /get_unread_cnt/{fromaddr}/{toaddr}: + get: + consumes: + - application/json + description: Get Unread count for DMs + parameters: + - description: 'TO: Wallet Address' + in: path + name: toaddr + required: true + type: string + - description: 'FROM: Wallet Address' + in: path + name: from + required: true + type: string + produces: + - application/json + responses: + "200": + description: OK + schema: + type: integer + summary: Get all unread messages between two addresses + tags: + - Unused/Legacy + /get_unread_cnt_by_type/{address}/{type}: + get: + consumes: + - application/json + description: Get Each 1-on-1 Conversation, NFT and Community Chat For Display + in Inbox + parameters: + - description: Wallet Address + in: path + name: address + required: true + type: string + - description: Message Type - nft|community|dm|all + in: path + name: type + required: true + type: string + produces: + - application/json + responses: + "200": + description: OK + schema: + type: integer + summary: Get all unread messages TO a specific user, used for total count notification + at top notification bar + tags: + - Unused/Legacy + /get_unread_cnt_nft/{address}: + get: + consumes: + - application/json + description: Get Unread count for all NFT contexts given a wallet address + parameters: + - description: Wallet Address + in: path + name: address + required: true + type: string + produces: + - application/json + responses: + "200": + description: OK + schema: + type: integer + summary: Get all unread messages for all NFT related chats for given user + tags: + - Unused/Legacy + /getall_chatitems/{address}: + get: + consumes: + - application/json + description: Get all Chat Items for DMs for a given wallet address + parameters: + - description: Wallet Address + in: path + name: toaddr + required: true + type: string + produces: + - application/json + responses: + "200": + description: OK + schema: + items: + $ref: '#/definitions/entity.Chatitem' + type: array + summary: Get Chat Item For Given Wallet Address + tags: + - Unused/Legacy + /getall_chatitems/{fromaddr}/{toaddr}: + get: + consumes: + - application/json + description: Get chat data between the given two addresses, TO and FROM and + interchangable here + parameters: + - description: 'TO: Wallet Address' + in: path + name: toaddr + required: true + type: string + - description: 'FROM: Wallet Address' + in: path + name: from + required: true + type: string + produces: + - application/json + responses: + "200": + description: OK + schema: + items: + $ref: '#/definitions/entity.Chatitem' + type: array + summary: Get Chat Data Between Two Addresses + tags: + - DMs + /getnft_chatitems/{address}: + get: + consumes: + - application/json + description: Get ALL NFT context items for a given wallet address + parameters: + - description: Wallet Address + in: path + name: toaddr + required: true + type: string + produces: + - application/json + responses: + "200": + description: OK + schema: + items: + $ref: '#/definitions/entity.Chatitem' + type: array + summary: Get NFT Related Chat Items For Given Wallet Address + tags: + - Unused/Legacy + /getnft_chatitems/{address}/{nftaddr}/{nftid}: + get: + consumes: + - application/json + description: Get all specified NFT contract and ID items for a given wallet + address + parameters: + - description: Wallet Address + in: path + name: address + required: true + type: string + - description: NFT Contract Address + in: path + name: nftaddr + required: true + type: string + - description: NFT ID + in: path + name: nftid + required: true + type: string + produces: + - application/json + responses: + "200": + description: OK + schema: + items: + $ref: '#/definitions/entity.Chatitem' + type: array + summary: Get NFT Related Chat Items For Given NFT Contract and ID, relating + to one wallet + tags: + - Unused/Legacy + /getnft_chatitems/{fromaddr}/{toaddr}/{nftaddr}/{nftid}: + get: + consumes: + - application/json + description: Get ALL NFT context items for a specifc NFT context convo between + two wallets + parameters: + - description: NFT Contract Address + in: path + name: nftaddr + required: true + type: string + - description: NFT ID + in: path + name: nftid + required: true + type: string + - description: 'TO: Wallet Address' + in: path + name: toaddr + required: true + type: string + - description: 'FROM: Wallet Address' + in: path + name: from + required: true + type: string + produces: + - application/json + responses: + "200": + description: OK + schema: + items: + $ref: '#/definitions/entity.Chatitem' + type: array + summary: Get NFT Related Chat Items For Given NFT Contract and ID, between two + wallet addresses (TO and FROM are interchangable) + tags: + - NFT + /getnft_chatitems/{nftaddr}/{nftid}: + get: + consumes: + - application/json + description: Get ALL NFT context items for a given wallet address + parameters: + - description: NFT Contract Address + in: path + name: nftaddr + required: true + type: string + - description: NFT ID + in: path + name: nftid + required: true + type: string + produces: + - application/json + responses: + "200": + description: OK + schema: + items: + $ref: '#/definitions/entity.Chatitem' + type: array + summary: Get NFT Related Chat Items For Given NFT Contract and ID + tags: + - Unused/Legacy + /image: + post: + consumes: + - application/json + description: Currently used for the WC HQ Logo, stores the base64 raw data of + the profile image for a community + parameters: + - description: Profile Thumbnail Pic + in: body + name: message + required: true + schema: + $ref: '#/definitions/entity.Imageitem' + produces: + - application/json + responses: + "200": + description: OK + schema: + items: + $ref: '#/definitions/entity.Bookmarkitem' + type: array + summary: Store Image in DB for later user + tags: + - Common + put: + consumes: + - application/json + description: Currently used for the WC HQ Logo, stores the base64 raw data of + the profile image for a community + parameters: + - description: Profile Thumbnail Pic + in: body + name: message + required: true + schema: + $ref: '#/definitions/entity.Imageitem' + produces: + - application/json + responses: + "200": + description: OK + schema: + items: + $ref: '#/definitions/entity.Bookmarkitem' + type: array + summary: Store Image in DB for later user (update existing photo) + tags: + - Common + /image/{name}: + get: + consumes: + - application/json + description: Retreive image data for use with user/community/nft group dislayed + icon + parameters: + - description: Common Name Mapped to User/Community + in: path + name: name + required: true + type: string + produces: + - application/json + responses: + "200": + description: OK + schema: + items: + $ref: '#/definitions/entity.Imageitem' + type: array + summary: Get Thumbnail Image Data + tags: + - Common + /is_owner/{contract}/{wallet}: + get: + consumes: + - application/json + description: API user could check this directly via any third party service + like NFTPort, Moralis as well + parameters: + - description: NFT Contract Address + in: path + name: contract + required: true + type: string + - description: Wallet Address + in: path + name: wallet + required: true + type: string + produces: + - application/json + responses: + "200": + description: OK + schema: + items: + $ref: '#/definitions/controllers.LandingPageItems' + type: array + summary: Check if given wallet address owns an NFT from given contract address + tags: + - Common + /name: + post: + consumes: + - application/json + description: Give a common name (Kevin.eth, BillyTheKid, etc) to an Address + parameters: + - description: Address and Name to map together + in: body + name: message + required: true + schema: + $ref: '#/definitions/entity.Addrnameitem' + produces: + - application/json + responses: + "200": + description: OK + schema: + items: + $ref: '#/definitions/entity.Bookmarkitem' + type: array + summary: give a common name to a user address, or NFT collection + tags: + - Common + put: + consumes: + - application/json + description: Give a common name (Kevin.eth, BillyTheKid, etc) to an Address + parameters: + - description: Address and Name to map together + in: body + name: message + required: true + schema: + $ref: '#/definitions/entity.Addrnameitem' + produces: + - application/json + responses: + "200": + description: OK + schema: + items: + $ref: '#/definitions/entity.Bookmarkitem' + type: array + summary: give a common name to a user address, or NFT collection (update exiting) + tags: + - Common + /name/{name}: + get: + consumes: + - application/json + description: get the given a common name (Kevin.eth, BillyTheKid, etc) what + has already been mapped to an Address + parameters: + - description: Get Name for given address + in: path + name: address + required: true + type: string + produces: + - application/json + responses: + "200": + description: OK + schema: + items: + $ref: '#/definitions/entity.Addrnameitem' + type: array + summary: get the common name which has been mapped to an address + tags: + - Common + /unreadcount/{address}: + get: + consumes: + - application/json + description: Get Unread count just given an address + parameters: + - description: Wallet Address + in: path + name: address + required: true + type: string + produces: + - application/json + responses: + "200": + description: OK + schema: + type: integer + summary: Get all unread messages TO a specific user, used for total count notification + at top notification bar + tags: + - Inbox + /update_chatitem/{fromaddr}/{toaddr}: + put: + consumes: + - application/json + description: |- + Currently this only update the message read/unread status. It could update the entire JSON struct + upon request, however we only needed this functionality currently and it saved re-encryption of the data. + TODO: TO/FROM address in the URL is not needed/not used anymore. + parameters: + - description: chat item JSON struct to update msg read status + in: body + name: message + required: true + schema: + $ref: '#/definitions/entity.Chatitem' + produces: + - application/json + responses: + "200": + description: OK + schema: + items: + $ref: '#/definitions/entity.Chatitem' + type: array + summary: Update Message Read Status of a given DM chat message + tags: + - DMs + /update_settings: + put: + consumes: + - application/json + description: Currently this only updates the public key, could be expanded as + needed. + parameters: + - description: update struct + in: body + name: message + required: true + schema: + $ref: '#/definitions/entity.Settings' + produces: + - application/json + responses: + "200": + description: OK + schema: + items: + $ref: '#/definitions/entity.Settings' + type: array + summary: Settings hold a user address and the public key used for encryption. tags: - - inbox + - Common swagger: "2.0" diff --git a/enableGoPath.sh b/enableGoPath.sh new file mode 100644 index 0000000..7119fc7 --- /dev/null +++ b/enableGoPath.sh @@ -0,0 +1 @@ +export PATH=$PATH:$(go env GOPATH)/bin diff --git a/entity/chatitem.go b/entity/chatitem.go index 0bfeb8d..23cb47a 100644 --- a/entity/chatitem.go +++ b/entity/chatitem.go @@ -2,6 +2,12 @@ package entity import "time" +//*** VARIABLE NAMING INFO DUE TO GORM FUNCTIONALITY *** +//CamelCase is not used for variable names due to GORM auto functionality. +//A struct named ChatItem would go into the database as chat_items - the case auto-adds _ chars +//table names within a database have an 's' auto-added to them +//...(Chatitem struct here will have a table named Chatitems in the DB) + //rename the type in GET /inbox to context_type: [nft, community, dm] and //retain variable name type in message objects in communities to be [welcome, message] instead of [communitymsg, communitywelcome] // string mapping @@ -25,16 +31,17 @@ type Unreadcountitem struct { } type Chatitem struct { - Id int `gorm:"primary_key"` - Fromaddr string `json:"fromaddr"` - Toaddr string `json:"toaddr"` - Timestamp string `json:"timestamp"` - Timestamp_dtm time.Time `json:"timestamp_dtm"` - Msgread bool `json:"read"` - Message string `json:"message"` - Nftaddr string `json:"nftaddr"` - Nftid string `json:"nftid"` - Name string `json:"sender_name"` + Id int `gorm:"primary_key"` //AUTO-GENERATED (PRIMARY KEY) + Fromaddr string `json:"fromaddr" binding:"required"` //*** REQUIRED INPUT *** + Toaddr string `json:"toaddr" validate:"required"` //*** REQUIRED INPUT *** + Timestamp string `json:"timestamp"` //AUTO-SET BY REST API + Timestamp_dtm time.Time `json:"timestamp_dtm"` //USED FOR SORTING WHEN TIME FORMAT NEEDED + Msgread bool `json:"read"` //DEFAULT FALSE + Message string `json:"message" validate:"required"` //*** REQUIRED INPUT *** + Nftaddr string `json:"nftaddr"` //ONLY USED FOR NFT DM CONTEXT + Nftid string `json:"nftid"` //ONLY USED FOR NFT DM CONTEXT + Name string `json:"sender_name"` //AUTO-SET BY BACKED FOR RETURN VALUE + Encryptsymkey string `json:"encrypted_sym_lit_key"` //USE IF USING LIT ENCRYPTION } //for olivers view function @@ -124,6 +131,8 @@ type Nftsidebar struct { Nftid string `json:"nftid"` } +// Chatiteminbox entity info +// @Description Used as Return Data Struct Only type Chatiteminbox struct { Id int `gorm:"primaryKey;autoIncrement"` Fromaddr string `json:"fromaddr"` diff --git a/go.mod b/go.mod index 331adf7..05a09e4 100644 --- a/go.mod +++ b/go.mod @@ -3,9 +3,6 @@ module rest-go-demo go 1.14 require ( - github.com/cryptoKevinL/walletChatDocs v0.0.0-20220723221334-0e64de3ce57b - github.com/go-openapi/spec v0.20.6 // indirect - github.com/go-openapi/swag v0.21.1 // indirect github.com/go-sql-driver/mysql v1.6.0 // indirect github.com/gorilla/mux v1.8.0 github.com/jinzhu/gorm v1.9.16 @@ -15,10 +12,9 @@ require ( github.com/swaggo/http-swagger v1.3.0 // indirect github.com/swaggo/http-swagger/example/go-chi v0.0.0-20220611072802-7af1c17f1a0f // indirect github.com/swaggo/swag v1.8.4 - github.com/urfave/cli/v2 v2.11.1 // indirect - golang.org/x/net v0.0.0-20220708220712-1185a9018129 // indirect - golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f // indirect - golang.org/x/tools v0.1.11 // indirect + github.com/urfave/cli/v2 v2.11.2 // indirect + golang.org/x/sys v0.0.0-20220818161305-2296e01440c6 // indirect + golang.org/x/tools v0.1.12 // indirect gorm.io/driver/mysql v1.3.5 // indirect gorm.io/gorm v1.23.8 // indirect ) diff --git a/go.sum b/go.sum index 064e931..ef26901 100644 --- a/go.sum +++ b/go.sum @@ -14,14 +14,6 @@ github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:ma github.com/cpuguy83/go-md2man/v2 v2.0.2 h1:p1EgwI/C7NhT0JmVkwCD2ZBK8j4aeHQX2pMHHBfMQ6w= github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= -github.com/cryptoKevinL/walletChatDocs v0.0.0-20220722155714-abc30812dd0a h1:6xw+wQQphvT5nlLxgdK/GcwIQmqUhK7SG/YxNbAO3+0= -github.com/cryptoKevinL/walletChatDocs v0.0.0-20220722155714-abc30812dd0a/go.mod h1:N7P+avZRKtOVOblih12xRpFE38T+NACbWRkqlJrpEds= -github.com/cryptoKevinL/walletChatDocs v0.0.0-20220723202057-c20db61ccb34 h1:TSxContgv/nu78DDnJQ5Iebuyo4YjWcuzAqF7vYjWEI= -github.com/cryptoKevinL/walletChatDocs v0.0.0-20220723202057-c20db61ccb34/go.mod h1:N7P+avZRKtOVOblih12xRpFE38T+NACbWRkqlJrpEds= -github.com/cryptoKevinL/walletChatDocs v0.0.0-20220723214938-02176ddade50 h1:ujUUwSH49EcJmV5jKSGoHXylEXm42nglNeGkOpUaGH0= -github.com/cryptoKevinL/walletChatDocs v0.0.0-20220723214938-02176ddade50/go.mod h1:N7P+avZRKtOVOblih12xRpFE38T+NACbWRkqlJrpEds= -github.com/cryptoKevinL/walletChatDocs v0.0.0-20220723221334-0e64de3ce57b h1:wOIccJAJ+MyfT1EUitHZK7vKN9zBmAeTR2taWH1lxIg= -github.com/cryptoKevinL/walletChatDocs v0.0.0-20220723221334-0e64de3ce57b/go.mod h1:N7P+avZRKtOVOblih12xRpFE38T+NACbWRkqlJrpEds= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/denisenkom/go-mssqldb v0.0.0-20191124224453-732737034ffd h1:83Wprp6ROGeiHFAP8WJdI2RoxALQYgdllERc3N5N2DM= @@ -40,14 +32,19 @@ github.com/go-openapi/jsonreference v0.20.0 h1:MYlu0sBgChmCfJxxUKZ8g1cPWFOB37YSZ github.com/go-openapi/jsonreference v0.20.0/go.mod h1:Ag74Ico3lPc+zR+qjn4XBUmXymS4zJbYVCZmcgkasdo= github.com/go-openapi/spec v0.20.4 h1:O8hJrt0UMnhHcluhIdUgCLRWyM2x7QkBXRvOs7m+O1M= github.com/go-openapi/spec v0.20.4/go.mod h1:faYFR1CvsJZ0mNsmsphTMSoRrNV3TEDoAM7FOEWeq8I= +github.com/go-openapi/spec v0.20.5 h1:skHa8av4VnAtJU5zyAUXrrdK/NDiVX8lchbG+BfcdrE= github.com/go-openapi/spec v0.20.5/go.mod h1:QbfOSIVt3/sac+a1wzmKbbcLXm5NdZnyBZYtCijp43o= github.com/go-openapi/spec v0.20.6 h1:ich1RQ3WDbfoeTqTAb+5EIxNmpKVJZWBNah9RAT0jIQ= github.com/go-openapi/spec v0.20.6/go.mod h1:2OpW+JddWPrpXSCIX8eOx7lZ5iyuWj3RYR6VaaBKcWA= +github.com/go-openapi/spec v0.20.7 h1:1Rlu/ZrOCCob0n+JKKJAWhNWMPW8bOZRg8FJaY+0SKI= +github.com/go-openapi/spec v0.20.7/go.mod h1:2OpW+JddWPrpXSCIX8eOx7lZ5iyuWj3RYR6VaaBKcWA= github.com/go-openapi/swag v0.19.5/go.mod h1:POnQmlKehdgb5mhVOsnJFsivZCEZ/vjK9gh66Z9tfKk= github.com/go-openapi/swag v0.19.15 h1:D2NRCBzS9/pEY3gP9Nl8aDqGUcPFrwG2p+CNFrLyrCM= github.com/go-openapi/swag v0.19.15/go.mod h1:QYRuS/SOXUCsnplDa677K7+DxSOj6IPNl/eQntq43wQ= github.com/go-openapi/swag v0.21.1 h1:wm0rhTb5z7qpJRHBdPOMuY4QjVUMbF6/kwoYeRAOrKU= github.com/go-openapi/swag v0.21.1/go.mod h1:QYRuS/SOXUCsnplDa677K7+DxSOj6IPNl/eQntq43wQ= +github.com/go-openapi/swag v0.22.3 h1:yMBqmnQ0gyZvEb/+KzuWZOXgllrXT4SADYbvDaXHv/g= +github.com/go-openapi/swag v0.22.3/go.mod h1:UzaqsxGiab7freDnrUUra0MwWfN/q7tE4j+VcZ0yl14= github.com/go-sql-driver/mysql v1.5.0 h1:ozyZYNQW3x3HtqT1jira07DN2PArx2v7/mN66gGcHOs= github.com/go-sql-driver/mysql v1.5.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg= github.com/go-sql-driver/mysql v1.6.0 h1:BCTh4TKNUYmOmMUcQ3IipzF5prigylS7XXjEkfCHuOE= @@ -72,6 +69,7 @@ github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8Hm github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y= github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= +github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= @@ -101,9 +99,12 @@ github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeV github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc= github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= github.com/swaggo/files v0.0.0-20210815190702-a29dd2bc99b2/go.mod h1:lKJPbtWzJ9JhsTN1k1gZgleJWY/cqq0psdoMmaThG3w= github.com/swaggo/files v0.0.0-20220610200504-28940afbdbfe h1:K8pHPVoTgxFJt1lXuIzzOX7zZhZFldJQK/CgKx9BFIc= github.com/swaggo/files v0.0.0-20220610200504-28940afbdbfe/go.mod h1:lKJPbtWzJ9JhsTN1k1gZgleJWY/cqq0psdoMmaThG3w= @@ -120,10 +121,13 @@ github.com/urfave/cli/v2 v2.3.0 h1:qph92Y649prgesehzOrQjdWyxFOp/QVM+6imKHad91M= github.com/urfave/cli/v2 v2.3.0/go.mod h1:LJmUH05zAU44vOAcrfzZQKsZbVcdbOG8rtL3/XcUArI= github.com/urfave/cli/v2 v2.11.1 h1:UKK6SP7fV3eKOefbS87iT9YHefv7iB/53ih6e+GNAsE= github.com/urfave/cli/v2 v2.11.1/go.mod h1:f8iq5LtQ/bLxafbdBSLPPNsgaW0l/2fYYEHhAyPlwvo= +github.com/urfave/cli/v2 v2.11.2 h1:FVfNg4m3vbjbBpLYxW//WjxUoHvJ9TlppXcqY9Q9ZfA= +github.com/urfave/cli/v2 v2.11.2/go.mod h1:f8iq5LtQ/bLxafbdBSLPPNsgaW0l/2fYYEHhAyPlwvo= github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 h1:bAn7/zixMGCfxrRTfdpNzjtPYqr8smhKouy9mxVdGPU= github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673/go.mod h1:N3UwUGtsrSj3ccvlPHLoLsHnpR27oXr4ZE984MbSER8= github.com/yuin/goldmark v1.4.0/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= github.com/yuin/goldmark v1.4.1/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= +github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20190325154230-a5d413f7728c/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= @@ -147,8 +151,11 @@ golang.org/x/net v0.0.0-20220425223048-2871e0cb64e4 h1:HVyaeDAYux4pnY+D/SiwmLOR3 golang.org/x/net v0.0.0-20220425223048-2871e0cb64e4/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk= golang.org/x/net v0.0.0-20220708220712-1185a9018129 h1:vucSRfWwTsoXro7P+3Cjlr6flUMtzCwzlvkxEQtHHB0= golang.org/x/net v0.0.0-20220708220712-1185a9018129/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= +golang.org/x/net v0.0.0-20220722155237-a158d28d115b h1:PxfKdU9lEEDYjdIzOtC4qFWgkU2rGHdKlKowJSMN9h0= +golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -165,6 +172,8 @@ golang.org/x/sys v0.0.0-20220721230656-c6bc011c0c49 h1:TMjZDarEwf621XDryfitp/8aw golang.org/x/sys v0.0.0-20220721230656-c6bc011c0c49/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f h1:v4INt8xihDGvnrfjMDVXGxw9wrfxYyCjk0KbXjhR55s= golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220818161305-2296e01440c6 h1:Sx/u41w+OwrInGdEckYmEuU5gHoGSL4QbDz3S9s6j4U= +golang.org/x/sys v0.0.0-20220818161305-2296e01440c6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= @@ -180,18 +189,22 @@ golang.org/x/tools v0.1.10 h1:QjFRCZxdOhBJ/UNgnBZLbNV13DlbnK0quyivTnXJM20= golang.org/x/tools v0.1.10/go.mod h1:Uh6Zz+xoGYZom868N8YTex3t7RhtHDBrE8Gzo9bV56E= golang.org/x/tools v0.1.11 h1:loJ25fNOEhSXfHrpoGj91eCUThwdNX6u24rO1xnNteY= golang.org/x/tools v0.1.11/go.mod h1:SgwaegtQh8clINPpECJMqnxLv9I09HLqnW3RMqW0CA4= +golang.org/x/tools v0.1.12 h1:VveCTK38A2rkS8ZqFY25HIDFscX5X9OoEhJd3quQmXU= +golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.3/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gorm.io/driver/mysql v1.3.5 h1:iWBTVW/8Ij5AG4e0G/zqzaJblYkBI1VIL1LG2HUGsvY= gorm.io/driver/mysql v1.3.5/go.mod h1:sSIebwZAVPiT+27jK9HIwvsqOGKx3YMPmrA3mBJR10c= diff --git a/main.go b/main.go index 3d897c2..bed306f 100644 --- a/main.go +++ b/main.go @@ -3,12 +3,14 @@ package main import ( "log" "net/http" + "os" "rest-go-demo/controllers" "rest-go-demo/database" "github.com/joho/godotenv" - _ "github.com/cryptoKevinL/walletChatDocs" // docs is generated by Swag CLI, you have to import it + _ "rest-go-demo/docs" // docs is generated by Swag CLI, you have to import it + httpSwagger "github.com/swaggo/http-swagger" "github.com/gorilla/mux" @@ -16,23 +18,39 @@ import ( ) // @title WalletChat API -// @version 1.0 -// @description This is the WalletChat messagez +// @version 0.0 +// @description Wecome to the WalletChat API Documentation +// @description +// @description Please make note that some JSON data structures are shared for both input/output. +// @description Required input parameters will have a red * next to them in the data type outline at +// @description the bottom of the page, along with a comment. This means when executing API functionality +// @description from this API page, some fields may need to be removed from the JSON struct before submitting. +// @description Please email the developers with any issues. +// @description Some JSON data structures are output only, and will be marked as such as well. +// @description +// @description v0 of the API does not include encryption or authentication, nor does it need /v0 to be called. +// @description Please as you are given access to this page, do not abuse this system and impersonate others, or submit offensive material. +// @description Developers monitor this data daily. +// @description +// @description v1 will include basic JWT Authentication, however some additional work is in progress to make this fully secure. +// @description except for AUTH functions, all endpoints must prefix /v1 and include Bearer: in all requests +// @description +// @description v2 will include encyrption for DMs, private keys will be stored locally on client PCs +// @description with no way for us to recover any data which is encrypted. // @wallet_chat API Support via Twitter // @contact.url https://walletchat.fun // @contact.email walletchatextension@gmail.com -// @host localhost:8080 +// @host api.v0.walletchat.fun // @BasePath func main() { + godotenv.Load(".env") initDB() log.Println("Starting the HTTP server on port 8080") - godotenv.Load(".env") - router := mux.NewRouter().StrictSlash(true) - router.PathPrefix("/swagger/").Handler(httpSwagger.WrapHandler) + router.PathPrefix("/docs").Handler(httpSwagger.WrapHandler) initaliseHandlers(router) log.Fatal(http.ListenAndServe(":8080", router)) } @@ -51,11 +69,11 @@ func initaliseHandlers(router *mux.Router) { router.HandleFunc("/getnft_chatitems/{nftaddr}/{nftid}", controllers.GetChatNftContext).Methods("GET") router.HandleFunc("/getnft_chatitems/{address}", controllers.GetNftChatFromAddress).Methods("GET") router.HandleFunc("/update_chatitem/{fromaddr}/{toaddr}", controllers.UpdateChatitemByOwner).Methods("PUT") - router.HandleFunc("/deleteall_chatitems/{address}", controllers.DeleteAllChatitemsToAddressByOwner).Methods("DELETE") + router.HandleFunc("/deleteall_chatitems/{fromaddr}/{toaddr}", controllers.DeleteAllChatitemsToAddressByOwner).Methods("DELETE") router.HandleFunc("/get_inbox/{address}", controllers.GetInboxByOwner).Methods("GET") router.HandleFunc("/create_chatitem", controllers.CreateChatitem).Methods("POST") //router.HandleFunc("/create_chatitem_tmp", controllers.CreateChatitemTmp).Methods("POST") - router.HandleFunc("/getall_chatitems", controllers.GetAllChatitems).Methods("GET") + //router.HandleFunc("/getall_chatitems", controllers.GetAllChatitems).Methods("GET") //unreadcnt per week4 requirements router.HandleFunc("/unreadcount/{address}", controllers.GetUnreadcnt).Methods("GET") @@ -68,7 +86,8 @@ func initaliseHandlers(router *mux.Router) { router.HandleFunc("/get_groupchatitems_unreadcnt/{address}/{useraddress}", controllers.GetGroupChatItemsByAddrLen).Methods("GET") //group chat - router.HandleFunc("/community/{community}/{address}", controllers.GetWalletChat).Methods("GET") //TODO: make common + //TODO: we need a create community API call, which provides twitter/discord handles, welcome message, Title/Name (see hardcoded items in GetCommunityChat) + router.HandleFunc("/community/{community}/{address}", controllers.GetCommunityChat).Methods("GET") //TODO: make common router.HandleFunc("/community", controllers.CreateCommunityChatitem).Methods("POST") //bookmarks @@ -95,7 +114,7 @@ func initaliseHandlers(router *mux.Router) { //comments on a specific NFT router.HandleFunc("/create_comments", controllers.CreateComments).Methods("POST") - router.HandleFunc("/get_comments", controllers.GetAllComments).Methods("GET") + //router.HandleFunc("/get_comments", controllers.GetAllComments).Methods("GET") //doubt we will need this router.HandleFunc("/get_comments/{nftaddr}/{nftid}", controllers.GetComments).Methods("GET") router.HandleFunc("/delete_comments/{fromaddr}/{nftaddr}/{nftid}", controllers.DeleteComments).Methods("DELETE") @@ -108,7 +127,7 @@ func initaliseHandlers(router *mux.Router) { //TODO: this would need a signature from holder to fully verify - ok for now router.HandleFunc("/is_owner/{contract}/{wallet}", controllers.IsOwner).Methods("GET") router.HandleFunc("/rejoin_all/{wallet}", controllers.AutoJoinCommunities).Methods("GET") - router.HandleFunc("/backfill_all_bookmarks", controllers.FixUpBookmarks).Methods("GET") + router.HandleFunc("/backfill_all_bookmarks", controllers.FixUpBookmarks).Methods("GET") //just meant for internal use - not for external use //POAP related stuff (some could be called client side directly but this protects the API key) router.HandleFunc("/get_poaps/{wallet}", controllers.GetPoapsByAddr).Methods("GET") @@ -118,8 +137,8 @@ func initDB() { config := database.Config{ User: "doadmin", - Password: "AVNS_7q8_Jqll_0sA9Fi", - ServerName: "db-mysql-nyc3-11937-do-user-11094376-0.b.db.ondigitalocean.com:25060", + Password: os.Getenv("DB_PASSWORD"), + ServerName: os.Getenv("DB_URL"), DB: "walletchat", } // database.Config{ diff --git a/rest-go-demo b/rest-go-demo deleted file mode 100755 index a2fa564..0000000 Binary files a/rest-go-demo and /dev/null differ