added user's plan / initial events configuration

pull/1/head
Nilo Roberto C Paim 2023-09-07 11:01:09 -03:00
parent 4b6e58d71a
commit 456a44dbcf
5 changed files with 29 additions and 20 deletions

View File

@ -5,7 +5,6 @@ import (
"api/models" "api/models"
"api/utils" "api/utils"
"log" "log"
"net/smtp"
"os" "os"
"strconv" "strconv"
"strings" "strings"
@ -138,23 +137,6 @@ func AddUser(c *fiber.Ctx) error {
"message": "Erro ao criar usuário"}) "message": "Erro ao criar usuário"})
} }
from := "nilopaim@gmail.com"
pass := "@407Smc83722"
to := "nilo@scobol.com.br"
msg := "From: " + from + "\n" +
"To: " + to + "\n" +
"Subject: Hello there\n\n"
err := smtp.SendMail("smtp.gmail.com:587",
smtp.PlainAuth("", from, pass, "smtp.gmail.com"),
from, []string{to}, []byte(msg))
if err != nil {
log.Printf("smtp error: %s", err)
}
return c.JSON(user) return c.JSON(user)
} }

View File

@ -57,7 +57,6 @@ func AddEvent(c *fiber.Ctx) error {
Name: data["name"], Name: data["name"],
Description: data["description"], Description: data["description"],
UserId: user.Id, UserId: user.Id,
Channel: user.Channel,
ExpectedDate: startdt, ExpectedDate: startdt,
EventType: data["eventtype"], EventType: data["eventtype"],
} }
@ -89,3 +88,29 @@ func GetAllEvents(c *fiber.Ctx) error {
return c.JSON(events) return c.JSON(events)
} }
// GetEventsByUser - Returns all events from a user
func GetEventsByUser(c *fiber.Ctx) error {
var events []models.Event
var user models.User
_, err := utils.ProcessToken(c)
if err != nil {
return fiber.ErrUnauthorized
}
database.DB.Where("id = ?", c.Params("id")).First(&user)
if user.Id == 0 {
return fiber.ErrUnauthorized
}
database.DB.Where("user_id = ?", user.Id).Find(&events)
if len(events) == 0 {
return fiber.ErrNotFound
}
return c.JSON(events)
}

View File

@ -8,7 +8,6 @@ type Event struct {
Description string `gorm:"not null" json:"description"` Description string `gorm:"not null" json:"description"`
ExpectedDate time.Time `gorm:"not null" json:"startDt"` ExpectedDate time.Time `gorm:"not null" json:"startDt"`
UserId uint `gorm:"size:40;not null" json:"user"` UserId uint `gorm:"size:40;not null" json:"user"`
Channel string `gorm:"size:40;not null" json:"channel"`
EventType string `gorm:"size:1;not null;default:O" json:"eventtype"` // O = Open, C = Closed EventType string `gorm:"size:1;not null;default:O" json:"eventtype"` // O = Open, C = Closed
Transmitted string `gorm:"size:1;not null;default:N" json:"transmitted"` // Y = Already transmitted, N = Not transmitted yet Transmitted string `gorm:"size:1;not null;default:N" json:"transmitted"` // Y = Already transmitted, N = Not transmitted yet
} }

View File

@ -8,6 +8,7 @@ type User struct {
Password []byte `gorm:"size:100;not null;" json:"-"` Password []byte `gorm:"size:100;not null;" json:"-"`
Channel string `gorm:"size:40;not null" json:"channel"` Channel string `gorm:"size:40;not null" json:"channel"`
UserType string `gorm:"size:1;not null;default:U" json:"usertype"` UserType string `gorm:"size:1;not null;default:U" json:"usertype"`
Plan string `gorm:"size:1;not null;default:1" json:"T"`
Blocked string `gorm:"size:1;not null;default:N" json:"blocked"` Blocked string `gorm:"size:1;not null;default:N" json:"blocked"`
Cancelled string `gorm:"size:1;not null;default:N" json:"cancelled"` Cancelled string `gorm:"size:1;not null;default:N" json:"cancelled"`
CreatedBy string `gorm:"size:15;not null;default:Manual" json:"createdby"` CreatedBy string `gorm:"size:15;not null;default:Manual" json:"createdby"`

View File

@ -41,4 +41,6 @@ func Setup(app *fiber.App) {
protected.Post("user", controllers.AddUser) protected.Post("user", controllers.AddUser)
protected.Post("event", controllers.AddEvent) protected.Post("event", controllers.AddEvent)
protected.Get("events", controllers.GetAllEvents)
protected.Get("events/:id", controllers.GetEventsByUser)
} }