Create service and first version of models

This commit is contained in:
Alphyron 2020-04-11 21:40:26 +02:00
parent 6bca1f453e
commit ce0f5bafa0
3 changed files with 63 additions and 0 deletions

21
logic/service.go Normal file
View File

@ -0,0 +1,21 @@
package logic
import "git.dragon-labs.de/alphyron/group_helper/models"
type GroupHelperService interface {
CreateGroup(*models.Group) (*models.Group, error)
UpdateGroup(*models.Group) (*models.Group, error)
GetGroupByID(int64) (*models.Group, error)
GetGroupDatabaseSize(int64) (int, error)
CreateUser(*models.User) (*models.User, error)
GetUserByID(int64) *models.User
UserJoinGroup(*models.User, *models.Group) (bool, error)
UserLeaveGroup(*models.User, *models.Group) (bool, error)
IsUserInGroup(*models.User, *models.Group) (bool, error)
ListGroups() ([]*models.Group, error)
ListUsers() ([]*models.User, error)
}

35
models/group.go Normal file
View File

@ -0,0 +1,35 @@
package models
type Group struct {
ID uint `gorm:"primary_key"`
GroupID int64
Size int
UserJoinMessage string `gorm:"column:msg_user_join;type:text"`
UserVerifiedMessage string `gorm:"column:msg_user_verified;type:text"`
UserLeaveMessage string `gorm:"column:msg_user_leave;type:text"`
UserKickMessage string `gorm:"column:msg_user_kick;type:text"`
ForbidWriting bool `gorm:"column:forbid_writing"`
OnlineCheck int `gorm:"column:kick_cooldown"`
}
func (group *Group) FillDefaultValues() {
if len(group.UserKickMessage) == 0 {
group.UserKickMessage = "[{{user.firstname}} {{user.lastname}}](tg://user?id={{user.id}}) did not verify!\n They are going to leave us."
}
if len(group.UserJoinMessage) == 0 {
group.UserJoinMessage = "[{{user.firstname}} {{user.lastname}}](tg://user?id={{user.id}}) joined us. Hello and Welcome! Please verify that you are not a bot."
}
if len(group.UserLeaveMessage) == 0 {
group.UserLeaveMessage = "[{{user.firstname}} {{user.lastname}}](tg://user?id={{user.id}}) left us."
}
if len(group.UserVerifiedMessage) == 0 {
group.UserVerifiedMessage = "[{{user.firstname}} {{user.lastname}}](tg://user?id={{user.id}}) is now permitted to stay in the chat!"
}
if group.OnlineCheck == 0 {
group.OnlineCheck = 5
}
}

7
models/user.go Normal file
View File

@ -0,0 +1,7 @@
package models
type User struct {
ID uint `gorm:"primary_key" json:"id"`
UserID int64 `json:"user_id"`
Groups []*Group `json:"groups" gorm:"many2many:GroupUser;"`
}