1
0
Fork 0
mirror of synced 2024-07-05 06:31:08 +12:00
appwrite/app/sdks/server-go/users.go

138 lines
3.5 KiB
Go
Raw Normal View History

2020-01-29 03:22:13 +13:00
package appwrite
import (
"strings"
)
// Users service
type Users struct {
2020-01-29 09:24:42 +13:00
client Client
2020-01-29 03:22:13 +13:00
}
2020-01-29 18:08:39 +13:00
func NewUsers(clt Client) Users {
2020-01-29 12:14:30 +13:00
service := Users{
client: clt,
}
2020-01-29 10:01:07 +13:00
return service
}
2020-01-31 05:18:59 +13:00
// List get a list of all the project users. You can use the query params to
// filter your results.
func (srv *Users) List(Search string, Limit int, Offset int, OrderType string) (map[string]interface{}, error) {
2020-01-29 03:22:13 +13:00
path := "/users"
params := map[string]interface{}{
"search": Search,
"limit": Limit,
"offset": Offset,
"orderType": OrderType,
}
2020-01-29 11:56:24 +13:00
return srv.client.Call("GET", path, nil, params)
2020-01-29 03:22:13 +13:00
}
2020-01-31 05:18:59 +13:00
// Create create a new user.
func (srv *Users) Create(Email string, Password string, Name string) (map[string]interface{}, error) {
2020-01-29 03:22:13 +13:00
path := "/users"
params := map[string]interface{}{
"email": Email,
"password": Password,
"name": Name,
}
2020-01-29 11:56:24 +13:00
return srv.client.Call("POST", path, nil, params)
2020-01-29 03:22:13 +13:00
}
2020-01-31 05:18:59 +13:00
// Get get user by its unique ID.
func (srv *Users) Get(UserId string) (map[string]interface{}, error) {
2020-01-29 03:22:13 +13:00
r := strings.NewReplacer("{userId}", UserId)
path := r.Replace("/users/{userId}")
params := map[string]interface{}{
}
2020-01-29 11:56:24 +13:00
return srv.client.Call("GET", path, nil, params)
2020-01-29 03:22:13 +13:00
}
2020-01-31 05:18:59 +13:00
// GetLogs get user activity logs list by its unique ID.
func (srv *Users) GetLogs(UserId string) (map[string]interface{}, error) {
2020-01-29 03:22:13 +13:00
r := strings.NewReplacer("{userId}", UserId)
path := r.Replace("/users/{userId}/logs")
params := map[string]interface{}{
}
2020-01-29 11:56:24 +13:00
return srv.client.Call("GET", path, nil, params)
2020-01-29 03:22:13 +13:00
}
2020-01-31 05:18:59 +13:00
// GetPrefs get user preferences by its unique ID.
func (srv *Users) GetPrefs(UserId string) (map[string]interface{}, error) {
2020-01-29 03:22:13 +13:00
r := strings.NewReplacer("{userId}", UserId)
path := r.Replace("/users/{userId}/prefs")
params := map[string]interface{}{
}
2020-01-29 11:56:24 +13:00
return srv.client.Call("GET", path, nil, params)
2020-01-29 03:22:13 +13:00
}
2020-01-31 05:18:59 +13:00
// UpdatePrefs update user preferences by its unique ID. You can pass only the
// specific settings you wish to update.
2020-02-14 19:28:54 +13:00
func (srv *Users) UpdatePrefs(UserId string, Prefs object) (map[string]interface{}, error) {
2020-01-29 03:22:13 +13:00
r := strings.NewReplacer("{userId}", UserId)
path := r.Replace("/users/{userId}/prefs")
params := map[string]interface{}{
"prefs": Prefs,
}
2020-01-29 11:56:24 +13:00
return srv.client.Call("PATCH", path, nil, params)
2020-01-29 03:22:13 +13:00
}
2020-01-31 05:18:59 +13:00
// GetSessions get user sessions list by its unique ID.
func (srv *Users) GetSessions(UserId string) (map[string]interface{}, error) {
2020-01-29 03:22:13 +13:00
r := strings.NewReplacer("{userId}", UserId)
path := r.Replace("/users/{userId}/sessions")
params := map[string]interface{}{
}
2020-01-29 11:56:24 +13:00
return srv.client.Call("GET", path, nil, params)
2020-01-29 03:22:13 +13:00
}
2020-01-31 05:18:59 +13:00
// DeleteSessions delete all user sessions by its unique ID.
func (srv *Users) DeleteSessions(UserId string) (map[string]interface{}, error) {
2020-01-29 03:22:13 +13:00
r := strings.NewReplacer("{userId}", UserId)
path := r.Replace("/users/{userId}/sessions")
params := map[string]interface{}{
}
2020-01-29 11:56:24 +13:00
return srv.client.Call("DELETE", path, nil, params)
2020-01-29 03:22:13 +13:00
}
2020-01-31 05:18:59 +13:00
// DeleteSession delete user sessions by its unique ID.
func (srv *Users) DeleteSession(UserId string, SessionId string) (map[string]interface{}, error) {
2020-05-02 16:23:56 +12:00
r := strings.NewReplacer("{userId}", UserId, "{sessionId}", SessionId)
path := r.Replace("/users/{userId}/sessions/{sessionId}")
2020-01-29 03:22:13 +13:00
params := map[string]interface{}{
}
2020-01-29 11:56:24 +13:00
return srv.client.Call("DELETE", path, nil, params)
2020-01-29 03:22:13 +13:00
}
2020-01-31 05:18:59 +13:00
// UpdateStatus update user status by its unique ID.
func (srv *Users) UpdateStatus(UserId string, Status string) (map[string]interface{}, error) {
2020-01-29 03:22:13 +13:00
r := strings.NewReplacer("{userId}", UserId)
path := r.Replace("/users/{userId}/status")
params := map[string]interface{}{
"status": Status,
}
2020-01-29 11:56:24 +13:00
return srv.client.Call("PATCH", path, nil, params)
2020-01-29 03:22:13 +13:00
}