-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstorage.go
51 lines (39 loc) · 1.72 KB
/
storage.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
package account
// UpdatePasswordRequest is used to pass the request data to Storage.UpdatePassword.
type UpdatePasswordRequest struct {
CurrentPassword string `json:"currentPassword" valid:"required"`
NewPassword string `json:"newPassword" valid:"required"`
}
// UpdateUsernameRequest is used to pass the request data to Storage.UpdateUsername.
type UpdateUsernameRequest struct {
Password string `json:"password" valid:"required"`
Username string `json:"username" valid:"required"`
}
// UpdateDataRequest is used to pass an accounts data to Storage.UpdateData.
type UpdateDataRequest struct {
Data string `json:"data" valid:"json,required"`
}
// CreateAccountRequest is used to pass an accounts data to Storage.Create.
type CreateAccountRequest struct {
ID string `json:"id" valid:"uuid4"`
Username string `json:"username" valid:"required"`
Password string `json:"password" valid:"required"`
Data string `json:"data" valid:"json"`
}
// Storage manages accounts in a persistent fashion.
type Storage interface {
// Create creates a new account
Create(r CreateAccountRequest) (Account, error)
// Get fetches an account by its ID.
Get(id string) (Account, error)
// Delete deletes an account by its ID.
Delete(id string) error
// UpdatePassword updates an account's password.
UpdatePassword(id string, r UpdatePasswordRequest) (Account, error)
// UpdateUsername updates an account's username.
UpdateUsername(id string, r UpdateUsernameRequest) (Account, error)
// UpdateData updates an account's extra data (e.g. profile picture)
UpdateData(id string, r UpdateDataRequest) (Account, error)
// Authenticate fetches an account by its username and password
Authenticate(username, password string) (Account, error)
}