Skip to content

Commit

Permalink
feat: reminders
Browse files Browse the repository at this point in the history
  • Loading branch information
piyush7833 committed Jun 27, 2024
1 parent 42cd7b9 commit 42c8592
Show file tree
Hide file tree
Showing 21 changed files with 452 additions and 57 deletions.
15 changes: 15 additions & 0 deletions config/Alias/tableAlias.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,18 @@ func GetUserRelationAlias() map[string]string {
"relatedUser": "u2",
}
}
func GetReminderAlias() map[string]string {
return map[string]string{
"reminder": mainAlias,
"sender": "s",
"receiver": "r",
}
}
func GetTagsAlias() map[string]string {
return map[string]string{
"tags": mainAlias,
"user": "u",
"message": "m",
"reminder": "r",
}
}
8 changes: 8 additions & 0 deletions config/defaultColumns.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,11 @@ func GetUserDefaultColumns() []string {
func GetDefaultUserRelationColumns() []string {
return []string{"id", "userId", "relatedUserId", "user_name", "related_user_name", "status", "createdAt", "updatedAt"}
}

func GetDefaultTagsColumns() []string {
return []string{"id", "userId", "user_name", "messageId", "message_content", "message_type", "reminderId", "reminder_title", "createdAt", "updatedAt"}
}

func GetDefaultReminderColumns() []string {
return []string{"id", "message", "time", "senderId", "sender_name", "receiverId", "reciever_name", "tune", "createdAt", "updatedAt"}
}
28 changes: 28 additions & 0 deletions config/joinColumns.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,31 @@ func GetJoinUserRelationColumns(ogAlias string, userAlias string, relatedUserAli
"updatedAt": ogAlias + ".updatedAt",
}
}
func GetJoinTagColumns(ogAlias string, userAlias string, messageAlias string, reminderAlias string) map[string]string {
return map[string]string{
"id": ogAlias + ".id",
"userId": ogAlias + ".userId",
"user_name": userAlias + ".name",
"messageId": ogAlias + ".messageId",
"message_content": messageAlias + ".content",
"message_type": messageAlias + ".type",
"reminderId": ogAlias + ".reminderId",
"reminder_title": reminderAlias + ".title",
"createdAt": ogAlias + ".createdAt",
"updatedAt": ogAlias + ".updatedAt",
}
}
func GetJoinReminderColumns(ogAlias string, senderAlias string, recieverrAlias string) map[string]string {
return map[string]string{
"id": ogAlias + ".id",
"message": ogAlias + ".message",
"time": ogAlias + ".time",
"senderId": ogAlias + ".senderId",
"sender_name": senderAlias + ".name",
"receiverId": ogAlias + ".receiverId",
"reciever_name": recieverrAlias + ".name",
"tune": ogAlias + ".tune",
"createdAt": ogAlias + ".createdAt",
"updatedAt": ogAlias + ".updatedAt",
}
}
37 changes: 37 additions & 0 deletions config/validColumns.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,40 @@ func GetValidUserRelationColumns() map[string]bool {
"updatedAt": true,
}
}
func GetValidTagsColumns() map[string]bool {
return map[string]bool{
"id": true,
"userId": true,
"user_name": true,
"messageId": true,
"message_content": true,
"message_type": true,
"reminderId": true,
"reminder_title": true,
"title": true,
"createdAt": true,
"updatedAt": true,
}
}

func GetValidReminderColumns() map[string]bool {
return map[string]bool{
"id": true,
"message": true,
"time": true,
"senderId": true,
"sender_name": true,
"receiverId": true,
"reciever_name": true,
"tune": true,
"createdAt": true,
"updatedAt": true,
}
}
func UpdateValidReminderColumns() map[string]bool {
return map[string]bool{
"message": true,
"time": true,
"tune": true,
}
}
14 changes: 0 additions & 14 deletions controllers/blocks.go

This file was deleted.

19 changes: 19 additions & 0 deletions controllers/group-users.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package controllers

import "net/http"

func CreateGroupUser(w http.ResponseWriter, r *http.Request) {

}
func DeleteGroupUser(w http.ResponseWriter, r *http.Request) {

}
func UpdateGroupUser(w http.ResponseWriter, r *http.Request) {

}
func GetGroupUser(w http.ResponseWriter, r *http.Request) {

}
func GetAllGroupUser(w http.ResponseWriter, r *http.Request) {

}
19 changes: 19 additions & 0 deletions controllers/groups.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package controllers

import "net/http"

func CreateGroup(w http.ResponseWriter, r *http.Request) {

}
func DeleteGroup(w http.ResponseWriter, r *http.Request) {

}
func UpdateGroup(w http.ResponseWriter, r *http.Request) {

}
func GetGroup(w http.ResponseWriter, r *http.Request) {

}
func GetAllGroup(w http.ResponseWriter, r *http.Request) {

}
95 changes: 90 additions & 5 deletions controllers/reminder.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,102 @@
package controllers

func CreateReminder() {
import (
"net/http"

"github.com/gorilla/context"
"github.com/piyush7833/Chat-Api/config"
"github.com/piyush7833/Chat-Api/functions"
"github.com/piyush7833/Chat-Api/helpers"
"github.com/piyush7833/Chat-Api/types"
)

func CreateReminder(w http.ResponseWriter, r *http.Request) {
JwtData := context.Get(r, "userId").(*helpers.Claims)
var reminder types.CreateReminderType
err := helpers.GetBodyInJson(r, &reminder)
if err != nil {
helpers.Error(w, 500, err.Error())
return
}
// fmt.Println("Reminder:", reminder)
reminder.SenderId = &JwtData.Id
res, error := functions.CreateReminder(reminder)

if error.StatusCode != 0 {
helpers.Error(w, error.StatusCode, error.Message)
return
}
helpers.Success(w, 201, res, "Reminder created successfully")
}
func UpdateReminder() {

func GetParticularReminder(w http.ResponseWriter, r *http.Request) {
queryValues := r.URL.Query()

JwtData := context.Get(r, "userId").(*helpers.Claims)
id := helpers.ProcessQuerryParams(queryValues["id"], []string{""}, "string").(string)
// fmt.Println(id)
page := helpers.ProcessQuerryParams(queryValues["page"], []string{"0"}, "number").(int)
selectedColumns := helpers.ProcessQuerryParams(queryValues["columns"], config.GetDefaultReminderColumns(), "array").([]string)
orderByColumns := helpers.ProcessQuerryParams(queryValues["orderBy"], []string{"createdAt"}, "array").([]string)
isDesc := helpers.ProcessQuerryParams(queryValues["isDesc"], []string{"true"}, "bool").(bool)

res, err := functions.GetParticularReminder(JwtData.Id, id, page, selectedColumns, orderByColumns, isDesc)
if err.StatusCode != 0 {
helpers.Error(w, err.StatusCode, err.Message)
return
}

helpers.Success(w, 200, res, "Reminder fetched successfully")

}
func DeleteReminder() {
func GetAllReminder(w http.ResponseWriter, r *http.Request) {
queryValues := r.URL.Query()

JwtData := context.Get(r, "userId").(*helpers.Claims)
page := helpers.ProcessQuerryParams(queryValues["page"], []string{"0"}, "number").(int)
reminder_type := helpers.ProcessQuerryParams(queryValues["type"], []string{"all"}, "string").(string)
selectedColumns := helpers.ProcessQuerryParams(queryValues["columns"], config.GetDefaultReminderColumns(), "array").([]string)
orderByColumns := helpers.ProcessQuerryParams(queryValues["orderBy"], []string{"createdAt"}, "array").([]string)
isDesc := helpers.ProcessQuerryParams(queryValues["isDesc"], []string{"true"}, "bool").(bool)

res, err := functions.GetAllReminder(JwtData.Id, page, reminder_type, selectedColumns, orderByColumns, isDesc)
if err.StatusCode != 0 {
helpers.Error(w, err.StatusCode, err.Message)
return
}

helpers.Success(w, 200, res, "Reminder fetched successfully")
}
func GetReminder() {
func UpdateReminder(w http.ResponseWriter, r *http.Request) {
JwtData := context.Get(r, "userId").(*helpers.Claims)
queryValues := r.URL.Query()

var reminder types.UpdateReminderType
id := helpers.ProcessQuerryParams(queryValues["id"], []string{""}, "string").(string)

err := helpers.GetBodyInJson(r, &reminder)
if err != nil {
helpers.Error(w, 500, err.Error())
return
}

res, error := functions.UpdateReminder(reminder, id, JwtData.Id)
if error.StatusCode != 0 {
helpers.Error(w, error.StatusCode, error.Message)
return
}
helpers.Success(w, 200, res, "Reminder updated successfully")
}
func GetAllReminder() {

func DeleteReminder(w http.ResponseWriter, r *http.Request) {
JwtData := context.Get(r, "userId").(*helpers.Claims)
queryValues := r.URL.Query()
id := helpers.ProcessQuerryParams(queryValues["id"], []string{""}, "string").(string)

res, error := functions.DeleteReminder(id, JwtData.Id)
if error.StatusCode != 0 {
helpers.Error(w, error.StatusCode, error.Message)
return
}
helpers.Success(w, 200, res, "Reminder deleted successfully")
}
14 changes: 8 additions & 6 deletions controllers/status.go
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
package controllers

func CreateStatus() {
import "net/http"

func CreateStatus(w http.ResponseWriter, r *http.Request) {

}
func UpdateStatus() {
func UpdateStatus(w http.ResponseWriter, r *http.Request) {

}
func DeleteStatus() {
func DeleteStatus(w http.ResponseWriter, r *http.Request) {

}
func GetStatus() {
func GetStatus(w http.ResponseWriter, r *http.Request) {

}
func GetAllStatusOfUser() {
func GetAllStatusOfUser(w http.ResponseWriter, r *http.Request) {

}
func GetAllStatusOfUsersFriend() {
func GetAllStatusOfUsersFriend(w http.ResponseWriter, r *http.Request) {

}
12 changes: 7 additions & 5 deletions controllers/tags.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
package controllers

func CreateTag() {
import "net/http"

func CreateTag(w http.ResponseWriter, r *http.Request) {

}
func DeleteTag() {
func DeleteTag(w http.ResponseWriter, r *http.Request) {

}
func UpdateTag() {
func UpdateTag(w http.ResponseWriter, r *http.Request) {

}
func GetTag() {
func GetTag(w http.ResponseWriter, r *http.Request) {

}
func GetAllTag() {
func GetAllTag(w http.ResponseWriter, r *http.Request) {

}
Loading

0 comments on commit 42c8592

Please sign in to comment.