REST API endpoints cleanup
This commit is contained in:
@@ -20,7 +20,6 @@
|
||||
"name": "Field"
|
||||
}
|
||||
],
|
||||
"Parameters": null,
|
||||
"Protocol": "",
|
||||
"Authentication": [],
|
||||
"Path": "/field",
|
||||
|
||||
@@ -42,7 +42,6 @@
|
||||
"name": "ModuleContentRow"
|
||||
}
|
||||
],
|
||||
"Parameters": null,
|
||||
"Protocol": "",
|
||||
"Authentication": [],
|
||||
"Path": "/module",
|
||||
|
||||
@@ -135,7 +135,7 @@ An organisation may have many teams. Teams may have many channels available. Acc
|
||||
|
||||
| Parameter | Type | Method | Description | Default | Required? |
|
||||
| --------- | ---- | ------ | ----------- | ------- | --------- |
|
||||
| id | uint64 | PATH | Team ID | N/A | YES |
|
||||
| teamId | uint64 | PATH | Team ID | N/A | YES |
|
||||
| name | string | POST | Name of Team | N/A | NO |
|
||||
| members | []uint64 | POST | Team member IDs | N/A | NO |
|
||||
|
||||
@@ -151,7 +151,7 @@ An organisation may have many teams. Teams may have many channels available. Acc
|
||||
|
||||
| Parameter | Type | Method | Description | Default | Required? |
|
||||
| --------- | ---- | ------ | ----------- | ------- | --------- |
|
||||
| id | uint64 | PATH | Organisation ID | N/A | YES |
|
||||
| teamId | uint64 | PATH | Organisation ID | N/A | YES |
|
||||
|
||||
## Remove team
|
||||
|
||||
@@ -165,7 +165,7 @@ An organisation may have many teams. Teams may have many channels available. Acc
|
||||
|
||||
| Parameter | Type | Method | Description | Default | Required? |
|
||||
| --------- | ---- | ------ | ----------- | ------- | --------- |
|
||||
| id | uint64 | PATH | Organisation ID | N/A | YES |
|
||||
| teamId | uint64 | PATH | Organisation ID | N/A | YES |
|
||||
|
||||
## Archive team
|
||||
|
||||
@@ -179,7 +179,7 @@ An organisation may have many teams. Teams may have many channels available. Acc
|
||||
|
||||
| Parameter | Type | Method | Description | Default | Required? |
|
||||
| --------- | ---- | ------ | ----------- | ------- | --------- |
|
||||
| id | uint64 | PATH | Organisation ID | N/A | YES |
|
||||
| teamId | uint64 | PATH | Organisation ID | N/A | YES |
|
||||
|
||||
## Move team to different organisation
|
||||
|
||||
@@ -193,7 +193,7 @@ An organisation may have many teams. Teams may have many channels available. Acc
|
||||
|
||||
| Parameter | Type | Method | Description | Default | Required? |
|
||||
| --------- | ---- | ------ | ----------- | ------- | --------- |
|
||||
| id | uint64 | PATH | Organisation ID | N/A | YES |
|
||||
| teamId | uint64 | PATH | Organisation ID | N/A | YES |
|
||||
| organisation_id | uint64 | POST | Organisation ID | N/A | YES |
|
||||
|
||||
## Merge one team into another
|
||||
@@ -208,7 +208,7 @@ An organisation may have many teams. Teams may have many channels available. Acc
|
||||
|
||||
| Parameter | Type | Method | Description | Default | Required? |
|
||||
| --------- | ---- | ------ | ----------- | ------- | --------- |
|
||||
| id | uint64 | PATH | Source Channel ID | N/A | YES |
|
||||
| teamId | uint64 | PATH | Source Channel ID | N/A | YES |
|
||||
| destination | uint64 | POST | Destination Channel ID | N/A | YES |
|
||||
|
||||
|
||||
@@ -253,13 +253,13 @@ A channel is a representation of a sequence of messages. It has meta data like c
|
||||
|
||||
| URI | Protocol | Method | Authentication |
|
||||
| --- | -------- | ------ | -------------- |
|
||||
| `/channel/edit` | HTTP/S | POST | Client ID, Session ID |
|
||||
| `/channel/{channelId}` | HTTP/S | POST | Client ID, Session ID |
|
||||
|
||||
#### Request parameters
|
||||
|
||||
| Parameter | Type | Method | Description | Default | Required? |
|
||||
| --------- | ---- | ------ | ----------- | ------- | --------- |
|
||||
| id | uint64 | POST | Channel ID | N/A | YES |
|
||||
| channelId | uint64 | PATH | Channel ID | N/A | YES |
|
||||
| name | string | POST | Name of Channel | N/A | NO |
|
||||
| topic | string | POST | Subject of Channel | N/A | NO |
|
||||
| archive | bool | POST | Request channel to be archived or unarchived | N/A | NO |
|
||||
@@ -271,13 +271,13 @@ A channel is a representation of a sequence of messages. It has meta data like c
|
||||
|
||||
| URI | Protocol | Method | Authentication |
|
||||
| --- | -------- | ------ | -------------- |
|
||||
| `/channel/read` | HTTP/S | GET | Client ID, Session ID |
|
||||
| `/channel/{channelId}` | HTTP/S | GET | Client ID, Session ID |
|
||||
|
||||
#### Request parameters
|
||||
|
||||
| Parameter | Type | Method | Description | Default | Required? |
|
||||
| --------- | ---- | ------ | ----------- | ------- | --------- |
|
||||
| id | uint64 | GET | Channel ID | N/A | YES |
|
||||
| channelId | uint64 | PATH | Channel ID | N/A | YES |
|
||||
|
||||
## Remove channel
|
||||
|
||||
@@ -285,13 +285,13 @@ A channel is a representation of a sequence of messages. It has meta data like c
|
||||
|
||||
| URI | Protocol | Method | Authentication |
|
||||
| --- | -------- | ------ | -------------- |
|
||||
| `/channel/delete` | HTTP/S | DELETE | Client ID, Session ID |
|
||||
| `/channel/{channelId}` | HTTP/S | DELETE | Client ID, Session ID |
|
||||
|
||||
#### Request parameters
|
||||
|
||||
| Parameter | Type | Method | Description | Default | Required? |
|
||||
| --------- | ---- | ------ | ----------- | ------- | --------- |
|
||||
| id | uint64 | GET | Channel ID | N/A | YES |
|
||||
| channelId | uint64 | PATH | Channel ID | N/A | YES |
|
||||
|
||||
|
||||
|
||||
@@ -324,7 +324,7 @@ The following event types may be sent with a message event:
|
||||
|
||||
| URI | Protocol | Method | Authentication |
|
||||
| --- | -------- | ------ | -------------- |
|
||||
| `/channels/{channelId}/messages/` | HTTP/S | POST | Client ID, Session ID |
|
||||
| `/message/` | HTTP/S | POST | Client ID, Session ID |
|
||||
|
||||
#### Request parameters
|
||||
|
||||
@@ -338,7 +338,7 @@ The following event types may be sent with a message event:
|
||||
|
||||
| URI | Protocol | Method | Authentication |
|
||||
| --- | -------- | ------ | -------------- |
|
||||
| `/channels/{channelId}/messages/{messageId}` | HTTP/S | PUT | Client ID, Session ID |
|
||||
| `/message/{messageId}` | HTTP/S | PUT | Client ID, Session ID |
|
||||
|
||||
#### Request parameters
|
||||
|
||||
@@ -353,7 +353,7 @@ The following event types may be sent with a message event:
|
||||
|
||||
| URI | Protocol | Method | Authentication |
|
||||
| --- | -------- | ------ | -------------- |
|
||||
| `/channels/{channelId}/messages/{messageId}` | HTTP/S | DELETE | Client ID, Session ID |
|
||||
| `/message/{messageId}` | HTTP/S | DELETE | Client ID, Session ID |
|
||||
|
||||
#### Request parameters
|
||||
|
||||
@@ -367,7 +367,7 @@ The following event types may be sent with a message event:
|
||||
|
||||
| URI | Protocol | Method | Authentication |
|
||||
| --- | -------- | ------ | -------------- |
|
||||
| `/channels/{channelId}/messages/{messageId}/attach` | HTTP/S | PUT | Client ID, Session ID |
|
||||
| `/message/{messageId}/attach` | HTTP/S | PUT | Client ID, Session ID |
|
||||
|
||||
#### Request parameters
|
||||
|
||||
@@ -380,7 +380,7 @@ The following event types may be sent with a message event:
|
||||
|
||||
| URI | Protocol | Method | Authentication |
|
||||
| --- | -------- | ------ | -------------- |
|
||||
| `/channels/{channelId}/messages/search` | HTTP/S | GET | Client ID, Session ID |
|
||||
| `/message/search` | HTTP/S | GET | Client ID, Session ID |
|
||||
|
||||
#### Request parameters
|
||||
|
||||
@@ -395,7 +395,7 @@ The following event types may be sent with a message event:
|
||||
|
||||
| URI | Protocol | Method | Authentication |
|
||||
| --- | -------- | ------ | -------------- |
|
||||
| `/channels/{channelId}/messages/{messageId}/pin` | HTTP/S | POST | Client ID, Session ID |
|
||||
| `/message/{messageId}/pin` | HTTP/S | POST | Client ID, Session ID |
|
||||
|
||||
#### Request parameters
|
||||
|
||||
@@ -409,7 +409,7 @@ The following event types may be sent with a message event:
|
||||
|
||||
| URI | Protocol | Method | Authentication |
|
||||
| --- | -------- | ------ | -------------- |
|
||||
| `/channels/{channelId}/messages/{messageId}/pin` | HTTP/S | DELETE | Client ID, Session ID |
|
||||
| `/message/{messageId}/pin` | HTTP/S | DELETE | Client ID, Session ID |
|
||||
|
||||
#### Request parameters
|
||||
|
||||
@@ -423,7 +423,7 @@ The following event types may be sent with a message event:
|
||||
|
||||
| URI | Protocol | Method | Authentication |
|
||||
| --- | -------- | ------ | -------------- |
|
||||
| `/channels/{channelId}/messages/{messageId}/flag` | HTTP/S | POST | Client ID, Session ID |
|
||||
| `/message/{messageId}/flag` | HTTP/S | POST | Client ID, Session ID |
|
||||
|
||||
#### Request parameters
|
||||
|
||||
@@ -437,7 +437,7 @@ The following event types may be sent with a message event:
|
||||
|
||||
| URI | Protocol | Method | Authentication |
|
||||
| --- | -------- | ------ | -------------- |
|
||||
| `/channels/{channelId}/messages/{messageId}/flag` | HTTP/S | DELETE | Client ID, Session ID |
|
||||
| `/message/{messageId}/flag` | HTTP/S | DELETE | Client ID, Session ID |
|
||||
|
||||
#### Request parameters
|
||||
|
||||
@@ -451,7 +451,7 @@ The following event types may be sent with a message event:
|
||||
|
||||
| URI | Protocol | Method | Authentication |
|
||||
| --- | -------- | ------ | -------------- |
|
||||
| `/channels/{channelId}/messages/{messageId}/react` | HTTP/S | POST | Client ID, Session ID |
|
||||
| `/message/{messageId}/react` | HTTP/S | POST | Client ID, Session ID |
|
||||
|
||||
#### Request parameters
|
||||
|
||||
@@ -466,7 +466,7 @@ The following event types may be sent with a message event:
|
||||
|
||||
| URI | Protocol | Method | Authentication |
|
||||
| --- | -------- | ------ | -------------- |
|
||||
| `/channels/{channelId}/messages/{messageId}/react/{reactionId}` | HTTP/S | DELETE | Client ID, Session ID |
|
||||
| `/message/{messageId}/react/{reactionId}` | HTTP/S | DELETE | Client ID, Session ID |
|
||||
|
||||
#### Request parameters
|
||||
|
||||
@@ -480,21 +480,6 @@ The following event types may be sent with a message event:
|
||||
|
||||
# Users
|
||||
|
||||
## User login
|
||||
|
||||
#### Method
|
||||
|
||||
| URI | Protocol | Method | Authentication |
|
||||
| --- | -------- | ------ | -------------- |
|
||||
| `/user/login` | HTTP/S | POST | Client ID, Session ID |
|
||||
|
||||
#### Request parameters
|
||||
|
||||
| Parameter | Type | Method | Description | Default | Required? |
|
||||
| --------- | ---- | ------ | ----------- | ------- | --------- |
|
||||
| username | string | POST | Username or email | N/A | YES |
|
||||
| password | string | POST | Password for user | N/A | YES |
|
||||
|
||||
## Search users (Directory)
|
||||
|
||||
#### Method
|
||||
@@ -507,4 +492,26 @@ The following event types may be sent with a message event:
|
||||
|
||||
| Parameter | Type | Method | Description | Default | Required? |
|
||||
| --------- | ---- | ------ | ----------- | ------- | --------- |
|
||||
| query | string | GET | Search query to match against users | N/A | NO |
|
||||
| query | string | GET | Search query to match against users | N/A | NO |
|
||||
|
||||
|
||||
|
||||
|
||||
# Authentication
|
||||
|
||||
## User login
|
||||
|
||||
#### Method
|
||||
|
||||
| URI | Protocol | Method | Authentication |
|
||||
| --- | -------- | ------ | -------------- |
|
||||
| `/auth/login` | HTTP/S | POST |
|
||||
Warning: implode(): Invalid arguments passed in /private/tmp/README.tpl on line 22
|
||||
|
|
||||
|
||||
#### Request parameters
|
||||
|
||||
| Parameter | Type | Method | Description | Default | Required? |
|
||||
| --------- | ---- | ------ | ----------- | ------- | --------- |
|
||||
| username | string | POST | Username or email | N/A | YES |
|
||||
| password | string | POST | Password for user | N/A | YES |
|
||||
@@ -3,6 +3,7 @@
|
||||
"title": "Organisations",
|
||||
"description": "Organisations represent a top-level grouping entity. There may be many organisations defined in a single deployment.",
|
||||
"package": "sam",
|
||||
"path": "/organisations",
|
||||
"entrypoint": "organisation",
|
||||
"authentication": ["Client ID", "Session ID"],
|
||||
"struct": [
|
||||
@@ -93,6 +94,7 @@
|
||||
"title": "Teams",
|
||||
"description": "An organisation may have many teams. Teams may have many channels available. Access to channels may be shared between teams.",
|
||||
"package": "sam",
|
||||
"path": "/teams",
|
||||
"entrypoint": "team",
|
||||
"authentication": ["Client ID", "Session ID"],
|
||||
"struct": [
|
||||
@@ -140,7 +142,7 @@
|
||||
"path": "/{id}",
|
||||
"parameters": {
|
||||
"path": [
|
||||
{ "type": "uint64", "name": "id", "required": true, "title": "Team ID" }
|
||||
{ "type": "uint64", "name": "teamId", "required": true, "title": "Team ID" }
|
||||
],
|
||||
"post": [
|
||||
{ "type": "string", "name": "name", "required": false, "title": "Name of Team" },
|
||||
@@ -155,7 +157,7 @@
|
||||
"path": "/{id}",
|
||||
"parameters": {
|
||||
"path": [
|
||||
{ "type": "uint64", "name": "id", "required": true, "title": "Organisation ID" }
|
||||
{ "type": "uint64", "name": "teamId", "required": true, "title": "Organisation ID" }
|
||||
]
|
||||
}
|
||||
},
|
||||
@@ -166,7 +168,7 @@
|
||||
"path": "/{id}",
|
||||
"parameters": {
|
||||
"path": [
|
||||
{ "type": "uint64", "name": "id", "required": true, "title": "Organisation ID" }
|
||||
{ "type": "uint64", "name": "teamId", "required": true, "title": "Organisation ID" }
|
||||
]
|
||||
}
|
||||
},
|
||||
@@ -177,7 +179,7 @@
|
||||
"path": "/{id}/archive",
|
||||
"parameters": {
|
||||
"path": [
|
||||
{ "type": "uint64", "name": "id", "required": true, "title": "Organisation ID" }
|
||||
{ "type": "uint64", "name": "teamId", "required": true, "title": "Organisation ID" }
|
||||
]
|
||||
}
|
||||
},
|
||||
@@ -188,7 +190,7 @@
|
||||
"path": "/{id}/move",
|
||||
"parameters": {
|
||||
"path": [
|
||||
{ "type": "uint64", "name": "id", "required": true, "title": "Organisation ID" }
|
||||
{ "type": "uint64", "name": "teamId", "required": true, "title": "Organisation ID" }
|
||||
],
|
||||
"post": [
|
||||
{ "type": "uint64", "name": "organisation_id", "required": true, "title": "Organisation ID" }
|
||||
@@ -202,7 +204,7 @@
|
||||
"path": "/{id}/merge",
|
||||
"parameters": {
|
||||
"path": [
|
||||
{ "type": "uint64", "name": "id", "required": true, "title": "Source Channel ID" }
|
||||
{ "type": "uint64", "name": "teamId", "required": true, "title": "Source Channel ID" }
|
||||
],
|
||||
"post": [
|
||||
{ "type": "uint64", "name": "destination", "required": true, "title": "Destination Channel ID" }
|
||||
@@ -216,6 +218,7 @@
|
||||
"description": "A channel is a representation of a sequence of messages. It has meta data like channel subject. Channels may be public, private or direct (between two users).",
|
||||
"package": "sam",
|
||||
"entrypoint": "channel",
|
||||
"path": "/channels",
|
||||
"authentication": ["Client ID", "Session ID"],
|
||||
"struct": [
|
||||
{
|
||||
@@ -262,10 +265,13 @@
|
||||
{
|
||||
"name": "edit",
|
||||
"method": "POST",
|
||||
"path": "/{channelId}",
|
||||
"title": "Update channel details",
|
||||
"parameters": {
|
||||
"path": [
|
||||
{ "type": "uint64", "name": "channelId", "required": true, "title": "Channel ID" }
|
||||
],
|
||||
"post": [
|
||||
{ "type": "uint64", "name": "id", "required": true, "title": "Channel ID" },
|
||||
{ "type": "string", "name": "name", "required": false, "title": "Name of Channel" },
|
||||
{ "type": "string", "name": "topic", "required": false, "title": "Subject of Channel" },
|
||||
{ "type": "bool", "name": "archive", "required": false, "title": "Request channel to be archived or unarchived" },
|
||||
@@ -276,20 +282,22 @@
|
||||
{
|
||||
"name": "read",
|
||||
"method": "GET",
|
||||
"path": "/{channelId}",
|
||||
"title": "Read channel details",
|
||||
"parameters": {
|
||||
"get": [
|
||||
{ "type": "uint64", "name": "id", "required": true, "title": "Channel ID" }
|
||||
"path": [
|
||||
{ "type": "uint64", "name": "channelId", "required": true, "title": "Channel ID" }
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "delete",
|
||||
"method": "DELETE",
|
||||
"path": "/{channelId}",
|
||||
"title": "Remove channel",
|
||||
"parameters": {
|
||||
"get": [
|
||||
{ "type": "uint64", "name": "id", "required": true, "title": "Channel ID" }
|
||||
"path": [
|
||||
{ "type": "uint64", "name": "channelId", "required": true, "title": "Channel ID" }
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -491,6 +499,7 @@
|
||||
{
|
||||
"title": "Users",
|
||||
"package": "sam",
|
||||
"path": "/users",
|
||||
"entrypoint": "user",
|
||||
"authentication": ["Client ID", "Session ID"],
|
||||
"struct": [
|
||||
@@ -509,17 +518,6 @@
|
||||
}
|
||||
],
|
||||
"apis": [
|
||||
{
|
||||
"name": "login",
|
||||
"method": "POST",
|
||||
"title": "User login",
|
||||
"parameters": {
|
||||
"post": [
|
||||
{ "type": "string", "name": "username", "required": true, "title": "Username or email" },
|
||||
{ "type": "string", "name": "password", "required": true, "title": "Password for user" }
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "search",
|
||||
"method": "GET",
|
||||
@@ -531,5 +529,25 @@
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"title": "Authentication",
|
||||
"package": "sam",
|
||||
"path": "/auth",
|
||||
"entrypoint": "auth",
|
||||
"struct": [],
|
||||
"apis": [
|
||||
{
|
||||
"name": "login",
|
||||
"method": "POST",
|
||||
"title": "User login",
|
||||
"parameters": {
|
||||
"post": [
|
||||
{ "type": "string", "name": "username", "required": true, "title": "Username or email" },
|
||||
{ "type": "string", "name": "password", "required": true, "title": "Password for user" }
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
|
||||
33
sam/docs/src/spec/auth.json
Normal file
33
sam/docs/src/spec/auth.json
Normal file
@@ -0,0 +1,33 @@
|
||||
{
|
||||
"Title": "Authentication",
|
||||
"Package": "sam",
|
||||
"Interface": "Auth",
|
||||
"Struct": [],
|
||||
"Protocol": "",
|
||||
"Authentication": null,
|
||||
"Path": "/auth",
|
||||
"APIs": [
|
||||
{
|
||||
"Name": "login",
|
||||
"Method": "POST",
|
||||
"Title": "User login",
|
||||
"Path": "/login",
|
||||
"Parameters": {
|
||||
"post": [
|
||||
{
|
||||
"name": "username",
|
||||
"required": true,
|
||||
"title": "Username or email",
|
||||
"type": "string"
|
||||
},
|
||||
{
|
||||
"name": "password",
|
||||
"required": true,
|
||||
"title": "Password for user",
|
||||
"type": "string"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -50,7 +50,6 @@
|
||||
"name": "Channel"
|
||||
}
|
||||
],
|
||||
"Parameters": null,
|
||||
"Protocol": "",
|
||||
"Authentication": [
|
||||
"Client ID",
|
||||
@@ -100,15 +99,17 @@
|
||||
"Name": "edit",
|
||||
"Method": "POST",
|
||||
"Title": "Update channel details",
|
||||
"Path": "/edit",
|
||||
"Path": "/{channelId}",
|
||||
"Parameters": {
|
||||
"post": [
|
||||
"path": [
|
||||
{
|
||||
"name": "id",
|
||||
"name": "channelId",
|
||||
"required": true,
|
||||
"title": "Channel ID",
|
||||
"type": "uint64"
|
||||
},
|
||||
}
|
||||
],
|
||||
"post": [
|
||||
{
|
||||
"name": "name",
|
||||
"required": false,
|
||||
@@ -140,11 +141,11 @@
|
||||
"Name": "read",
|
||||
"Method": "GET",
|
||||
"Title": "Read channel details",
|
||||
"Path": "/read",
|
||||
"Path": "/{channelId}",
|
||||
"Parameters": {
|
||||
"get": [
|
||||
"path": [
|
||||
{
|
||||
"name": "id",
|
||||
"name": "channelId",
|
||||
"required": true,
|
||||
"title": "Channel ID",
|
||||
"type": "uint64"
|
||||
@@ -156,11 +157,11 @@
|
||||
"Name": "delete",
|
||||
"Method": "DELETE",
|
||||
"Title": "Remove channel",
|
||||
"Path": "/delete",
|
||||
"Path": "/{channelId}",
|
||||
"Parameters": {
|
||||
"get": [
|
||||
"path": [
|
||||
{
|
||||
"name": "id",
|
||||
"name": "channelId",
|
||||
"required": true,
|
||||
"title": "Channel ID",
|
||||
"type": "uint64"
|
||||
|
||||
@@ -127,22 +127,12 @@
|
||||
"name": "Attachment"
|
||||
}
|
||||
],
|
||||
"Parameters": {
|
||||
"path": [
|
||||
{
|
||||
"name": "channelId",
|
||||
"required": true,
|
||||
"title": "Channel ID",
|
||||
"type": "uint64"
|
||||
}
|
||||
]
|
||||
},
|
||||
"Protocol": "",
|
||||
"Authentication": [
|
||||
"Client ID",
|
||||
"Session ID"
|
||||
],
|
||||
"Path": "/channels/{channelId}/messages",
|
||||
"Path": "/message",
|
||||
"APIs": [
|
||||
{
|
||||
"Name": "create",
|
||||
|
||||
@@ -33,7 +33,6 @@
|
||||
"name": "Organisation"
|
||||
}
|
||||
],
|
||||
"Parameters": null,
|
||||
"Protocol": "",
|
||||
"Authentication": [
|
||||
"Client ID",
|
||||
|
||||
@@ -45,7 +45,6 @@
|
||||
"name": "Team"
|
||||
}
|
||||
],
|
||||
"Parameters": null,
|
||||
"Protocol": "",
|
||||
"Authentication": [
|
||||
"Client ID",
|
||||
@@ -99,7 +98,7 @@
|
||||
"Parameters": {
|
||||
"path": [
|
||||
{
|
||||
"name": "id",
|
||||
"name": "teamId",
|
||||
"required": true,
|
||||
"title": "Team ID",
|
||||
"type": "uint64"
|
||||
@@ -129,7 +128,7 @@
|
||||
"Parameters": {
|
||||
"path": [
|
||||
{
|
||||
"name": "id",
|
||||
"name": "teamId",
|
||||
"required": true,
|
||||
"title": "Organisation ID",
|
||||
"type": "uint64"
|
||||
@@ -145,7 +144,7 @@
|
||||
"Parameters": {
|
||||
"path": [
|
||||
{
|
||||
"name": "id",
|
||||
"name": "teamId",
|
||||
"required": true,
|
||||
"title": "Organisation ID",
|
||||
"type": "uint64"
|
||||
@@ -161,7 +160,7 @@
|
||||
"Parameters": {
|
||||
"path": [
|
||||
{
|
||||
"name": "id",
|
||||
"name": "teamId",
|
||||
"required": true,
|
||||
"title": "Organisation ID",
|
||||
"type": "uint64"
|
||||
@@ -177,7 +176,7 @@
|
||||
"Parameters": {
|
||||
"path": [
|
||||
{
|
||||
"name": "id",
|
||||
"name": "teamId",
|
||||
"required": true,
|
||||
"title": "Organisation ID",
|
||||
"type": "uint64"
|
||||
@@ -201,7 +200,7 @@
|
||||
"Parameters": {
|
||||
"path": [
|
||||
{
|
||||
"name": "id",
|
||||
"name": "teamId",
|
||||
"required": true,
|
||||
"title": "Source Channel ID",
|
||||
"type": "uint64"
|
||||
|
||||
@@ -48,7 +48,6 @@
|
||||
"name": "User"
|
||||
}
|
||||
],
|
||||
"Parameters": null,
|
||||
"Protocol": "",
|
||||
"Authentication": [
|
||||
"Client ID",
|
||||
@@ -56,28 +55,6 @@
|
||||
],
|
||||
"Path": "/user",
|
||||
"APIs": [
|
||||
{
|
||||
"Name": "login",
|
||||
"Method": "POST",
|
||||
"Title": "User login",
|
||||
"Path": "/login",
|
||||
"Parameters": {
|
||||
"post": [
|
||||
{
|
||||
"name": "username",
|
||||
"required": true,
|
||||
"title": "Username or email",
|
||||
"type": "string"
|
||||
},
|
||||
{
|
||||
"name": "password",
|
||||
"required": true,
|
||||
"title": "Password for user",
|
||||
"type": "string"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"Name": "search",
|
||||
"Method": "GET",
|
||||
|
||||
@@ -1,31 +1,30 @@
|
||||
package rest
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"context"
|
||||
"github.com/crusttech/crust/sam/rest/server"
|
||||
"github.com/crusttech/crust/sam/service"
|
||||
"github.com/crusttech/crust/sam/types"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
var pass = func(next http.Handler) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
next.ServeHTTP(w, r)
|
||||
})
|
||||
var _ = errors.Wrap
|
||||
|
||||
type (
|
||||
Auth struct {
|
||||
service authUserService
|
||||
}
|
||||
|
||||
authUserService interface {
|
||||
ValidateCredentials(context.Context, string, string) (*types.User, error)
|
||||
}
|
||||
)
|
||||
|
||||
func (Auth) New() *Auth {
|
||||
return &Auth{service: service.User()}
|
||||
}
|
||||
|
||||
func (*Organisation) Authenticator() func(http.Handler) http.Handler {
|
||||
return pass
|
||||
}
|
||||
func (ctrl *Auth) Login(ctx context.Context, r *server.AuthLoginRequest) (interface{}, error) {
|
||||
return ctrl.service.ValidateCredentials(ctx, r.Username, r.Password)
|
||||
|
||||
func (*Team) Authenticator() func(http.Handler) http.Handler {
|
||||
return pass
|
||||
}
|
||||
|
||||
func (*Message) Authenticator() func(http.Handler) http.Handler {
|
||||
return pass
|
||||
}
|
||||
|
||||
func (*Channel) Authenticator() func(http.Handler) http.Handler {
|
||||
return pass
|
||||
}
|
||||
|
||||
func (*User) Authenticator() func(http.Handler) http.Handler {
|
||||
return pass
|
||||
}
|
||||
|
||||
35
sam/rest/authenticators.go
Normal file
35
sam/rest/authenticators.go
Normal file
@@ -0,0 +1,35 @@
|
||||
package rest
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
)
|
||||
|
||||
var pass = func(next http.Handler) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
next.ServeHTTP(w, r)
|
||||
})
|
||||
}
|
||||
|
||||
func (*Auth) Authenticator() func(http.Handler) http.Handler {
|
||||
return pass
|
||||
}
|
||||
|
||||
func (*Organisation) Authenticator() func(http.Handler) http.Handler {
|
||||
return pass
|
||||
}
|
||||
|
||||
func (*Team) Authenticator() func(http.Handler) http.Handler {
|
||||
return pass
|
||||
}
|
||||
|
||||
func (*Message) Authenticator() func(http.Handler) http.Handler {
|
||||
return pass
|
||||
}
|
||||
|
||||
func (*Channel) Authenticator() func(http.Handler) http.Handler {
|
||||
return pass
|
||||
}
|
||||
|
||||
func (*User) Authenticator() func(http.Handler) http.Handler {
|
||||
return pass
|
||||
}
|
||||
@@ -56,11 +56,11 @@ func (ctrl *Channel) Edit(ctx context.Context, r *server.ChannelEditRequest) (in
|
||||
}
|
||||
|
||||
func (ctrl *Channel) Delete(ctx context.Context, r *server.ChannelDeleteRequest) (interface{}, error) {
|
||||
return nil, ctrl.service.Delete(ctx, r.ID)
|
||||
return nil, ctrl.service.Delete(ctx, r.ChannelId)
|
||||
}
|
||||
|
||||
func (ctrl *Channel) Read(ctx context.Context, r *server.ChannelReadRequest) (interface{}, error) {
|
||||
return ctrl.service.FindById(ctx, r.ID)
|
||||
return ctrl.service.FindById(ctx, r.ChannelId)
|
||||
}
|
||||
|
||||
func (ctrl *Channel) List(ctx context.Context, r *server.ChannelListRequest) (interface{}, error) {
|
||||
|
||||
@@ -22,24 +22,31 @@ import (
|
||||
)
|
||||
|
||||
func MountRoutes(r chi.Router) {
|
||||
auth := &server.AuthHandlers{Auth: Auth{}.New()}
|
||||
channel := &server.ChannelHandlers{Channel: Channel{}.New()}
|
||||
message := &server.MessageHandlers{Message: Message{}.New()}
|
||||
organisation := &server.OrganisationHandlers{Organisation: Organisation{}.New()}
|
||||
team := &server.TeamHandlers{Team: Team{}.New()}
|
||||
user := &server.UserHandlers{User: User{}.New()}
|
||||
r.Group(func(r chi.Router) {
|
||||
r.Use(auth.Auth.Authenticator())
|
||||
r.Route("/auth", func(r chi.Router) {
|
||||
r.Post("/login", auth.Login)
|
||||
})
|
||||
})
|
||||
r.Group(func(r chi.Router) {
|
||||
r.Use(channel.Channel.Authenticator())
|
||||
r.Route("/channel", func(r chi.Router) {
|
||||
r.Get("/", channel.List)
|
||||
r.Put("/", channel.Create)
|
||||
r.Post("/edit", channel.Edit)
|
||||
r.Get("/read", channel.Read)
|
||||
r.Delete("/delete", channel.Delete)
|
||||
r.Post("/{channelId}", channel.Edit)
|
||||
r.Get("/{channelId}", channel.Read)
|
||||
r.Delete("/{channelId}", channel.Delete)
|
||||
})
|
||||
})
|
||||
r.Group(func(r chi.Router) {
|
||||
r.Use(message.Message.Authenticator())
|
||||
r.Route("/channels/{channelId}/messages", func(r chi.Router) {
|
||||
r.Route("/message", func(r chi.Router) {
|
||||
r.Post("/", message.Create)
|
||||
r.Put("/{messageId}", message.Edit)
|
||||
r.Delete("/{messageId}", message.Delete)
|
||||
@@ -80,7 +87,6 @@ func MountRoutes(r chi.Router) {
|
||||
r.Group(func(r chi.Router) {
|
||||
r.Use(user.User.Authenticator())
|
||||
r.Route("/user", func(r chi.Router) {
|
||||
r.Post("/login", user.Login)
|
||||
r.Get("/search", user.Search)
|
||||
})
|
||||
})
|
||||
|
||||
39
sam/rest/server/auth.go
Normal file
39
sam/rest/server/auth.go
Normal file
@@ -0,0 +1,39 @@
|
||||
package server
|
||||
|
||||
/*
|
||||
Hello! This file is auto-generated from `docs/src/spec.json`.
|
||||
|
||||
For development:
|
||||
In order to update the generated files, edit this file under the location,
|
||||
add your struct fields, imports, API definitions and whatever you want, and:
|
||||
|
||||
1. run [spec](https://github.com/titpetric/spec) in the same folder,
|
||||
2. run `./_gen.php` in this folder.
|
||||
|
||||
You may edit `auth.go`, `auth.util.go` or `auth_test.go` to
|
||||
implement your API calls, helper functions and tests. The file `auth.go`
|
||||
is only generated the first time, and will not be overwritten if it exists.
|
||||
*/
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// HTTP handlers are a superset of internal APIs
|
||||
type AuthHandlers struct {
|
||||
Auth AuthAPI
|
||||
}
|
||||
|
||||
// Internal API interface
|
||||
type AuthAPI interface {
|
||||
Login(context.Context, *AuthLoginRequest) (interface{}, error)
|
||||
|
||||
// Authenticate API requests
|
||||
Authenticator() func(http.Handler) http.Handler
|
||||
}
|
||||
|
||||
// HTTP API interface
|
||||
type AuthHandlersAPI interface {
|
||||
Login(http.ResponseWriter, *http.Request)
|
||||
}
|
||||
27
sam/rest/server/auth_handlers.go
Normal file
27
sam/rest/server/auth_handlers.go
Normal file
@@ -0,0 +1,27 @@
|
||||
package server
|
||||
|
||||
/*
|
||||
Hello! This file is auto-generated from `docs/src/spec.json`.
|
||||
|
||||
For development:
|
||||
In order to update the generated files, edit this file under the location,
|
||||
add your struct fields, imports, API definitions and whatever you want, and:
|
||||
|
||||
1. run [spec](https://github.com/titpetric/spec) in the same folder,
|
||||
2. run `./_gen.php` in this folder.
|
||||
|
||||
You may edit `auth.go`, `auth.util.go` or `auth_test.go` to
|
||||
implement your API calls, helper functions and tests. The file `auth.go`
|
||||
is only generated the first time, and will not be overwritten if it exists.
|
||||
*/
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/titpetric/factory/resputil"
|
||||
)
|
||||
|
||||
func (ah *AuthHandlers) Login(w http.ResponseWriter, r *http.Request) {
|
||||
params := AuthLoginRequest{}.new()
|
||||
resputil.JSON(w, params.Fill(r), func() (interface{}, error) { return ah.Auth.Login(r.Context(), params) })
|
||||
}
|
||||
54
sam/rest/server/auth_requests.go
Normal file
54
sam/rest/server/auth_requests.go
Normal file
@@ -0,0 +1,54 @@
|
||||
package server
|
||||
|
||||
/*
|
||||
Hello! This file is auto-generated from `docs/src/spec.json`.
|
||||
|
||||
For development:
|
||||
In order to update the generated files, edit this file under the location,
|
||||
add your struct fields, imports, API definitions and whatever you want, and:
|
||||
|
||||
1. run [spec](https://github.com/titpetric/spec) in the same folder,
|
||||
2. run `./_gen.php` in this folder.
|
||||
|
||||
You may edit `auth.go`, `auth.util.go` or `auth_test.go` to
|
||||
implement your API calls, helper functions and tests. The file `auth.go`
|
||||
is only generated the first time, and will not be overwritten if it exists.
|
||||
*/
|
||||
|
||||
import (
|
||||
"github.com/go-chi/chi"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
var _ = chi.URLParam
|
||||
|
||||
// Auth login request parameters
|
||||
type AuthLoginRequest struct {
|
||||
Username string
|
||||
Password string
|
||||
}
|
||||
|
||||
func (AuthLoginRequest) new() *AuthLoginRequest {
|
||||
return &AuthLoginRequest{}
|
||||
}
|
||||
|
||||
func (a *AuthLoginRequest) Fill(r *http.Request) error {
|
||||
r.ParseForm()
|
||||
get := map[string]string{}
|
||||
post := map[string]string{}
|
||||
urlQuery := r.URL.Query()
|
||||
for name, param := range urlQuery {
|
||||
get[name] = string(param[0])
|
||||
}
|
||||
postVars := r.Form
|
||||
for name, param := range postVars {
|
||||
post[name] = string(param[0])
|
||||
}
|
||||
|
||||
a.Username = post["username"]
|
||||
|
||||
a.Password = post["password"]
|
||||
return nil
|
||||
}
|
||||
|
||||
var _ RequestFiller = AuthLoginRequest{}.new()
|
||||
@@ -83,7 +83,7 @@ var _ RequestFiller = ChannelCreateRequest{}.new()
|
||||
|
||||
// Channel edit request parameters
|
||||
type ChannelEditRequest struct {
|
||||
ID uint64
|
||||
ChannelId uint64
|
||||
Name string
|
||||
Topic string
|
||||
Archive bool
|
||||
@@ -107,7 +107,7 @@ func (c *ChannelEditRequest) Fill(r *http.Request) error {
|
||||
post[name] = string(param[0])
|
||||
}
|
||||
|
||||
c.ID = parseUInt64(post["id"])
|
||||
c.ChannelId = parseUInt64(chi.URLParam(r, "channelId"))
|
||||
|
||||
c.Name = post["name"]
|
||||
|
||||
@@ -123,7 +123,7 @@ var _ RequestFiller = ChannelEditRequest{}.new()
|
||||
|
||||
// Channel read request parameters
|
||||
type ChannelReadRequest struct {
|
||||
ID uint64
|
||||
ChannelId uint64
|
||||
}
|
||||
|
||||
func (ChannelReadRequest) new() *ChannelReadRequest {
|
||||
@@ -143,7 +143,7 @@ func (c *ChannelReadRequest) Fill(r *http.Request) error {
|
||||
post[name] = string(param[0])
|
||||
}
|
||||
|
||||
c.ID = parseUInt64(get["id"])
|
||||
c.ChannelId = parseUInt64(chi.URLParam(r, "channelId"))
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -151,7 +151,7 @@ var _ RequestFiller = ChannelReadRequest{}.new()
|
||||
|
||||
// Channel delete request parameters
|
||||
type ChannelDeleteRequest struct {
|
||||
ID uint64
|
||||
ChannelId uint64
|
||||
}
|
||||
|
||||
func (ChannelDeleteRequest) new() *ChannelDeleteRequest {
|
||||
@@ -171,7 +171,7 @@ func (c *ChannelDeleteRequest) Fill(r *http.Request) error {
|
||||
post[name] = string(param[0])
|
||||
}
|
||||
|
||||
c.ID = parseUInt64(get["id"])
|
||||
c.ChannelId = parseUInt64(chi.URLParam(r, "channelId"))
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -24,8 +24,7 @@ var _ = chi.URLParam
|
||||
|
||||
// Message create request parameters
|
||||
type MessageCreateRequest struct {
|
||||
ChannelId uint64
|
||||
Contents string
|
||||
Contents string
|
||||
}
|
||||
|
||||
func (MessageCreateRequest) new() *MessageCreateRequest {
|
||||
@@ -45,8 +44,6 @@ func (m *MessageCreateRequest) Fill(r *http.Request) error {
|
||||
post[name] = string(param[0])
|
||||
}
|
||||
|
||||
m.ChannelId = parseUInt64(chi.URLParam(r, "channelId"))
|
||||
|
||||
m.Contents = post["contents"]
|
||||
return nil
|
||||
}
|
||||
@@ -114,7 +111,6 @@ var _ RequestFiller = MessageDeleteRequest{}.new()
|
||||
|
||||
// Message attach request parameters
|
||||
type MessageAttachRequest struct {
|
||||
ChannelId uint64
|
||||
}
|
||||
|
||||
func (MessageAttachRequest) new() *MessageAttachRequest {
|
||||
@@ -133,8 +129,6 @@ func (m *MessageAttachRequest) Fill(r *http.Request) error {
|
||||
for name, param := range postVars {
|
||||
post[name] = string(param[0])
|
||||
}
|
||||
|
||||
m.ChannelId = parseUInt64(chi.URLParam(r, "channelId"))
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -142,7 +136,6 @@ var _ RequestFiller = MessageAttachRequest{}.new()
|
||||
|
||||
// Message search request parameters
|
||||
type MessageSearchRequest struct {
|
||||
ChannelId uint64
|
||||
Query string
|
||||
Message_type string
|
||||
}
|
||||
@@ -164,8 +157,6 @@ func (m *MessageSearchRequest) Fill(r *http.Request) error {
|
||||
post[name] = string(param[0])
|
||||
}
|
||||
|
||||
m.ChannelId = parseUInt64(chi.URLParam(r, "channelId"))
|
||||
|
||||
m.Query = get["query"]
|
||||
|
||||
m.Message_type = get["message_type"]
|
||||
|
||||
@@ -81,7 +81,7 @@ var _ RequestFiller = TeamCreateRequest{}.new()
|
||||
|
||||
// Team edit request parameters
|
||||
type TeamEditRequest struct {
|
||||
ID uint64
|
||||
TeamId uint64
|
||||
Name string
|
||||
Members []uint64
|
||||
}
|
||||
@@ -103,7 +103,7 @@ func (t *TeamEditRequest) Fill(r *http.Request) error {
|
||||
post[name] = string(param[0])
|
||||
}
|
||||
|
||||
t.ID = parseUInt64(chi.URLParam(r, "id"))
|
||||
t.TeamId = parseUInt64(chi.URLParam(r, "teamId"))
|
||||
|
||||
t.Name = post["name"]
|
||||
return nil
|
||||
@@ -113,7 +113,7 @@ var _ RequestFiller = TeamEditRequest{}.new()
|
||||
|
||||
// Team read request parameters
|
||||
type TeamReadRequest struct {
|
||||
ID uint64
|
||||
TeamId uint64
|
||||
}
|
||||
|
||||
func (TeamReadRequest) new() *TeamReadRequest {
|
||||
@@ -133,7 +133,7 @@ func (t *TeamReadRequest) Fill(r *http.Request) error {
|
||||
post[name] = string(param[0])
|
||||
}
|
||||
|
||||
t.ID = parseUInt64(chi.URLParam(r, "id"))
|
||||
t.TeamId = parseUInt64(chi.URLParam(r, "teamId"))
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -141,7 +141,7 @@ var _ RequestFiller = TeamReadRequest{}.new()
|
||||
|
||||
// Team remove request parameters
|
||||
type TeamRemoveRequest struct {
|
||||
ID uint64
|
||||
TeamId uint64
|
||||
}
|
||||
|
||||
func (TeamRemoveRequest) new() *TeamRemoveRequest {
|
||||
@@ -161,7 +161,7 @@ func (t *TeamRemoveRequest) Fill(r *http.Request) error {
|
||||
post[name] = string(param[0])
|
||||
}
|
||||
|
||||
t.ID = parseUInt64(chi.URLParam(r, "id"))
|
||||
t.TeamId = parseUInt64(chi.URLParam(r, "teamId"))
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -169,7 +169,7 @@ var _ RequestFiller = TeamRemoveRequest{}.new()
|
||||
|
||||
// Team archive request parameters
|
||||
type TeamArchiveRequest struct {
|
||||
ID uint64
|
||||
TeamId uint64
|
||||
}
|
||||
|
||||
func (TeamArchiveRequest) new() *TeamArchiveRequest {
|
||||
@@ -189,7 +189,7 @@ func (t *TeamArchiveRequest) Fill(r *http.Request) error {
|
||||
post[name] = string(param[0])
|
||||
}
|
||||
|
||||
t.ID = parseUInt64(chi.URLParam(r, "id"))
|
||||
t.TeamId = parseUInt64(chi.URLParam(r, "teamId"))
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -197,7 +197,7 @@ var _ RequestFiller = TeamArchiveRequest{}.new()
|
||||
|
||||
// Team move request parameters
|
||||
type TeamMoveRequest struct {
|
||||
ID uint64
|
||||
TeamId uint64
|
||||
Organisation_id uint64
|
||||
}
|
||||
|
||||
@@ -218,7 +218,7 @@ func (t *TeamMoveRequest) Fill(r *http.Request) error {
|
||||
post[name] = string(param[0])
|
||||
}
|
||||
|
||||
t.ID = parseUInt64(chi.URLParam(r, "id"))
|
||||
t.TeamId = parseUInt64(chi.URLParam(r, "teamId"))
|
||||
|
||||
t.Organisation_id = parseUInt64(post["organisation_id"])
|
||||
return nil
|
||||
@@ -228,7 +228,7 @@ var _ RequestFiller = TeamMoveRequest{}.new()
|
||||
|
||||
// Team merge request parameters
|
||||
type TeamMergeRequest struct {
|
||||
ID uint64
|
||||
TeamId uint64
|
||||
Destination uint64
|
||||
}
|
||||
|
||||
@@ -249,7 +249,7 @@ func (t *TeamMergeRequest) Fill(r *http.Request) error {
|
||||
post[name] = string(param[0])
|
||||
}
|
||||
|
||||
t.ID = parseUInt64(chi.URLParam(r, "id"))
|
||||
t.TeamId = parseUInt64(chi.URLParam(r, "teamId"))
|
||||
|
||||
t.Destination = parseUInt64(post["destination"])
|
||||
return nil
|
||||
|
||||
@@ -27,7 +27,6 @@ type UserHandlers struct {
|
||||
|
||||
// Internal API interface
|
||||
type UserAPI interface {
|
||||
Login(context.Context, *UserLoginRequest) (interface{}, error)
|
||||
Search(context.Context, *UserSearchRequest) (interface{}, error)
|
||||
|
||||
// Authenticate API requests
|
||||
@@ -36,6 +35,5 @@ type UserAPI interface {
|
||||
|
||||
// HTTP API interface
|
||||
type UserHandlersAPI interface {
|
||||
Login(http.ResponseWriter, *http.Request)
|
||||
Search(http.ResponseWriter, *http.Request)
|
||||
}
|
||||
|
||||
@@ -21,10 +21,6 @@ import (
|
||||
"github.com/titpetric/factory/resputil"
|
||||
)
|
||||
|
||||
func (uh *UserHandlers) Login(w http.ResponseWriter, r *http.Request) {
|
||||
params := UserLoginRequest{}.new()
|
||||
resputil.JSON(w, params.Fill(r), func() (interface{}, error) { return uh.User.Login(r.Context(), params) })
|
||||
}
|
||||
func (uh *UserHandlers) Search(w http.ResponseWriter, r *http.Request) {
|
||||
params := UserSearchRequest{}.new()
|
||||
resputil.JSON(w, params.Fill(r), func() (interface{}, error) { return uh.User.Search(r.Context(), params) })
|
||||
|
||||
@@ -22,37 +22,6 @@ import (
|
||||
|
||||
var _ = chi.URLParam
|
||||
|
||||
// User login request parameters
|
||||
type UserLoginRequest struct {
|
||||
Username string
|
||||
Password string
|
||||
}
|
||||
|
||||
func (UserLoginRequest) new() *UserLoginRequest {
|
||||
return &UserLoginRequest{}
|
||||
}
|
||||
|
||||
func (u *UserLoginRequest) Fill(r *http.Request) error {
|
||||
r.ParseForm()
|
||||
get := map[string]string{}
|
||||
post := map[string]string{}
|
||||
urlQuery := r.URL.Query()
|
||||
for name, param := range urlQuery {
|
||||
get[name] = string(param[0])
|
||||
}
|
||||
postVars := r.Form
|
||||
for name, param := range postVars {
|
||||
post[name] = string(param[0])
|
||||
}
|
||||
|
||||
u.Username = post["username"]
|
||||
|
||||
u.Password = post["password"]
|
||||
return nil
|
||||
}
|
||||
|
||||
var _ RequestFiller = UserLoginRequest{}.new()
|
||||
|
||||
// User search request parameters
|
||||
type UserSearchRequest struct {
|
||||
Query string
|
||||
|
||||
@@ -33,7 +33,7 @@ func (Team) New() *Team {
|
||||
}
|
||||
|
||||
func (ctrl *Team) Read(ctx context.Context, r *server.TeamReadRequest) (interface{}, error) {
|
||||
return ctrl.service.FindById(ctx, r.ID)
|
||||
return ctrl.service.FindById(ctx, r.TeamId)
|
||||
}
|
||||
|
||||
func (ctrl *Team) List(ctx context.Context, r *server.TeamListRequest) (interface{}, error) {
|
||||
@@ -51,24 +51,24 @@ func (ctrl *Team) Create(ctx context.Context, r *server.TeamCreateRequest) (inte
|
||||
func (ctrl *Team) Edit(ctx context.Context, r *server.TeamEditRequest) (interface{}, error) {
|
||||
org := types.Team{}.
|
||||
New().
|
||||
SetID(r.ID).
|
||||
SetID(r.TeamId).
|
||||
SetName(r.Name)
|
||||
|
||||
return ctrl.service.Update(ctx, org)
|
||||
}
|
||||
|
||||
func (ctrl *Team) Remove(ctx context.Context, r *server.TeamRemoveRequest) (interface{}, error) {
|
||||
return nil, ctrl.service.Delete(ctx, r.ID)
|
||||
return nil, ctrl.service.Delete(ctx, r.TeamId)
|
||||
}
|
||||
|
||||
func (ctrl *Team) Archive(ctx context.Context, r *server.TeamArchiveRequest) (interface{}, error) {
|
||||
return nil, ctrl.service.Archive(ctx, r.ID)
|
||||
return nil, ctrl.service.Archive(ctx, r.TeamId)
|
||||
}
|
||||
|
||||
func (ctrl *Team) Merge(ctx context.Context, r *server.TeamMergeRequest) (interface{}, error) {
|
||||
return nil, ctrl.service.Merge(ctx, &types.Team{ID: r.ID})
|
||||
return nil, ctrl.service.Merge(ctx, &types.Team{ID: r.TeamId})
|
||||
}
|
||||
|
||||
func (ctrl *Team) Move(ctx context.Context, r *server.TeamMoveRequest) (interface{}, error) {
|
||||
return nil, ctrl.service.Move(ctx, &types.Team{ID: r.ID})
|
||||
return nil, ctrl.service.Move(ctx, &types.Team{ID: r.TeamId})
|
||||
}
|
||||
|
||||
@@ -17,16 +17,7 @@ type (
|
||||
}
|
||||
|
||||
userService interface {
|
||||
ValidateCredentials(context.Context, string, string) (*types.User, error)
|
||||
|
||||
FindById(context.Context, uint64) (*types.User, error)
|
||||
Find(context.Context, *types.UserFilter) ([]*types.User, error)
|
||||
|
||||
Create(context.Context, *types.User) (*types.User, error)
|
||||
Update(context.Context, *types.User) (*types.User, error)
|
||||
|
||||
deleter
|
||||
suspender
|
||||
}
|
||||
)
|
||||
|
||||
@@ -34,12 +25,7 @@ func (User) New() *User {
|
||||
return &User{service: service.User()}
|
||||
}
|
||||
|
||||
// User lookup & login
|
||||
func (self *User) Login(ctx context.Context, r *server.UserLoginRequest) (interface{}, error) {
|
||||
return self.service.ValidateCredentials(ctx, r.Username, r.Password)
|
||||
}
|
||||
|
||||
// Searches the users table in the database to find users by matching (by-prefix) their.Username
|
||||
func (self *User) Search(ctx context.Context, r *server.UserSearchRequest) (interface{}, error) {
|
||||
return self.service.Find(ctx, &types.UserFilter{Query: r.Query})
|
||||
func (ctrl *User) Search(ctx context.Context, r *server.UserSearchRequest) (interface{}, error) {
|
||||
return ctrl.service.Find(ctx, &types.UserFilter{Query: r.Query})
|
||||
}
|
||||
|
||||
18
sam/types/auth.go
Normal file
18
sam/types/auth.go
Normal file
@@ -0,0 +1,18 @@
|
||||
package types
|
||||
|
||||
/*
|
||||
Hello! This file is auto-generated from `docs/src/spec.json`.
|
||||
|
||||
For development:
|
||||
In order to update the generated files, edit this file under the location,
|
||||
add your struct fields, imports, API definitions and whatever you want, and:
|
||||
|
||||
1. run [spec](https://github.com/titpetric/spec) in the same folder,
|
||||
2. run `./_gen.php` in this folder.
|
||||
|
||||
You may edit `auth.go`, `auth.util.go` or `auth_test.go` to
|
||||
implement your API calls, helper functions and tests. The file `auth.go`
|
||||
is only generated the first time, and will not be overwritten if it exists.
|
||||
*/
|
||||
|
||||
type ()
|
||||
Reference in New Issue
Block a user