added user's plan / initial events configuration
parent
4b6e58d71a
commit
456a44dbcf
|
|
@ -5,7 +5,6 @@ import (
|
|||
"api/models"
|
||||
"api/utils"
|
||||
"log"
|
||||
"net/smtp"
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
|
@ -138,23 +137,6 @@ func AddUser(c *fiber.Ctx) error {
|
|||
"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)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -57,7 +57,6 @@ func AddEvent(c *fiber.Ctx) error {
|
|||
Name: data["name"],
|
||||
Description: data["description"],
|
||||
UserId: user.Id,
|
||||
Channel: user.Channel,
|
||||
ExpectedDate: startdt,
|
||||
EventType: data["eventtype"],
|
||||
}
|
||||
|
|
@ -89,3 +88,29 @@ func GetAllEvents(c *fiber.Ctx) error {
|
|||
|
||||
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)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,7 +8,6 @@ type Event struct {
|
|||
Description string `gorm:"not null" json:"description"`
|
||||
ExpectedDate time.Time `gorm:"not null" json:"startDt"`
|
||||
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
|
||||
Transmitted string `gorm:"size:1;not null;default:N" json:"transmitted"` // Y = Already transmitted, N = Not transmitted yet
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ type User struct {
|
|||
Password []byte `gorm:"size:100;not null;" json:"-"`
|
||||
Channel string `gorm:"size:40;not null" json:"channel"`
|
||||
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"`
|
||||
Cancelled string `gorm:"size:1;not null;default:N" json:"cancelled"`
|
||||
CreatedBy string `gorm:"size:15;not null;default:Manual" json:"createdby"`
|
||||
|
|
|
|||
|
|
@ -41,4 +41,6 @@ func Setup(app *fiber.App) {
|
|||
protected.Post("user", controllers.AddUser)
|
||||
|
||||
protected.Post("event", controllers.AddEvent)
|
||||
protected.Get("events", controllers.GetAllEvents)
|
||||
protected.Get("events/:id", controllers.GetEventsByUser)
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue