POST:/users works

This commit is contained in:
2022-11-18 21:25:40 +01:00
parent 34a27d9ca4
commit 5991631bfa
44 changed files with 2131 additions and 737 deletions

View File

@@ -0,0 +1,23 @@
package models
import "time"
type ClientType string
const (
ClientTypeAndroid ClientType = "ANDROID"
ClientTypeIOS ClientType = "IOS"
)
type Client struct {
ClientID int64
UserID int64
Type ClientType
FCMToken *string
TimestampCreated time.Time
AgentModel string
AgentVersion string
}
type ClientJSON struct {
}

51
server/api/models/user.go Normal file
View File

@@ -0,0 +1,51 @@
package models
import "time"
type User struct {
UserID int64
Username *string
ReadKey string
SendKey string
AdminKey string
TimestampCreated time.Time
TimestampLastRead *time.Time
TimestampLastSent *time.Time
MessagesSent int
QuotaToday int
QuotaDay *string
IsPro bool
ProToken *string
}
func (u User) JSON() UserJSON {
return UserJSON{
UserID: u.UserID,
Username: u.Username,
ReadKey: u.ReadKey,
SendKey: u.SendKey,
AdminKey: u.AdminKey,
TimestampCreated: u.TimestampCreated.Format(time.RFC3339Nano),
TimestampLastRead: timeOptFmt(u.TimestampLastRead, time.RFC3339Nano),
TimestampLastSent: timeOptFmt(u.TimestampLastSent, time.RFC3339Nano),
MessagesSent: u.MessagesSent,
QuotaToday: u.QuotaToday,
QuotaDay: u.QuotaDay,
IsPro: u.IsPro,
}
}
type UserJSON struct {
UserID int64 `json:"user_id"`
Username *string `json:"username"`
ReadKey string `json:"read_key"`
SendKey string `json:"send_key"`
AdminKey string `json:"admin_key"`
TimestampCreated string `json:"timestamp_created"`
TimestampLastRead *string `json:"timestamp_last_read"`
TimestampLastSent *string `json:"timestamp_last_sent"`
MessagesSent int `json:"messages_sent"`
QuotaToday int `json:"quota_today"`
QuotaDay *string `json:"quota_day"`
IsPro bool `json:"is_pro"`
}

View File

@@ -0,0 +1,14 @@
package models
import (
"gogs.mikescher.com/BlackForestBytes/goext/langext"
"time"
)
func timeOptFmt(t *time.Time, fmt string) *string {
if t == nil {
return nil
} else {
return langext.Ptr(t.Format(fmt))
}
}