-
Notifications
You must be signed in to change notification settings - Fork 0
/
models.go
79 lines (65 loc) · 1.67 KB
/
models.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package main
import (
"github.com/golang-jwt/jwt/v5"
)
var schema = `
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
CREATE TABLE IF NOT EXISTS roles (
id uuid PRIMARY KEY DEFAULT uuid_generate_v4(),
permissions JSONB,
name text
);
CREATE TABLE IF NOT EXISTS users (
id uuid PRIMARY KEY DEFAULT uuid_generate_v4(),
email text,
username text,
password text
);
CREATE TABLE IF NOT EXISTS users_roles (
user_id uuid references users(id),
role_id uuid references roles(id)
);
`
// User used for creating struct for user data from database
type User struct {
ID string `json:"id" db:"users.id"`
Password string `json:"-" db:"users.password"`
Email string `json:"email" db:"users.email"`
Username string `json:"userName" db:"users.username"`
}
// UserRole used for containg the user and the associated role
type UserRole struct {
User
Role
}
// Role used for creating struct for role data from database
type Role struct {
UserID string `json:"-" db:"userId"`
Name string `json:"name" db:"roles.name"`
Permissions string `json:"-" db:"roles.permissions"`
}
// LoginDetails for the username and password coming from the request body
type LoginDetails struct {
Username string
Password string
}
// JwtResponse for the response when user is authenticated
type JwtResponse struct {
Token string `json:"token"`
}
// Payload contains the payload for the jwt token
type Payload struct {
Scope string `json:"scope"`
}
type Claims struct {
Data Payload `json:"data"`
jwt.RegisteredClaims
}
type GenericResponse struct {
Message string `json:"message"`
}
type APIError struct {
Path string
Status int
Msg string
}