mirror of
https://github.com/m1k1o/neko-rooms.git
synced 2026-11-02 22:51:34 -06:00
add get entry by name.
This commit is contained in:
+23
@@ -111,6 +111,29 @@ paths:
|
||||
description: OK
|
||||
'500':
|
||||
description: Internal server error
|
||||
/api/rooms/{roomName}/by-name:
|
||||
get:
|
||||
tags:
|
||||
- rooms
|
||||
summary: Get room entry by name
|
||||
operationId: roomGetByName
|
||||
parameters:
|
||||
- in: path
|
||||
name: roomName
|
||||
required: true
|
||||
schema:
|
||||
type: string
|
||||
responses:
|
||||
'200':
|
||||
description: OK
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/RoomEntry'
|
||||
'400':
|
||||
description: Bad request
|
||||
'500':
|
||||
description: Internal server error
|
||||
/api/rooms/{roomId}/settings:
|
||||
get:
|
||||
tags:
|
||||
|
||||
+89
-15
@@ -1021,12 +1021,47 @@ export const RoomsApiAxiosParamCreator = function (configuration?: Configuration
|
||||
},
|
||||
/**
|
||||
*
|
||||
* @summary Recreate room
|
||||
* @param {string} roomId
|
||||
* @summary Get room entry by name
|
||||
* @param {string} roomName
|
||||
* @param {*} [options] Override http request option.
|
||||
* @throws {RequiredError}
|
||||
*/
|
||||
roomRecreate: async (roomId: string, options: AxiosRequestConfig = {}): Promise<RequestArgs> => {
|
||||
roomGetByName: async (roomName: string, options: AxiosRequestConfig = {}): Promise<RequestArgs> => {
|
||||
// verify required parameter 'roomName' is not null or undefined
|
||||
assertParamExists('roomGetByName', 'roomName', roomName)
|
||||
const localVarPath = `/api/rooms/{roomName}/by-name`
|
||||
.replace(`{${"roomName"}}`, encodeURIComponent(String(roomName)));
|
||||
// use dummy base URL string because the URL constructor only accepts absolute URLs.
|
||||
const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL);
|
||||
let baseOptions;
|
||||
if (configuration) {
|
||||
baseOptions = configuration.baseOptions;
|
||||
}
|
||||
|
||||
const localVarRequestOptions = { method: 'GET', ...baseOptions, ...options};
|
||||
const localVarHeaderParameter = {} as any;
|
||||
const localVarQueryParameter = {} as any;
|
||||
|
||||
|
||||
|
||||
setSearchParams(localVarUrlObj, localVarQueryParameter);
|
||||
let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {};
|
||||
localVarRequestOptions.headers = {...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers};
|
||||
|
||||
return {
|
||||
url: toPathString(localVarUrlObj),
|
||||
options: localVarRequestOptions,
|
||||
};
|
||||
},
|
||||
/**
|
||||
*
|
||||
* @summary Recreate room
|
||||
* @param {string} roomId
|
||||
* @param {RoomSettings} [roomSettings]
|
||||
* @param {*} [options] Override http request option.
|
||||
* @throws {RequiredError}
|
||||
*/
|
||||
roomRecreate: async (roomId: string, roomSettings?: RoomSettings, options: AxiosRequestConfig = {}): Promise<RequestArgs> => {
|
||||
// verify required parameter 'roomId' is not null or undefined
|
||||
assertParamExists('roomRecreate', 'roomId', roomId)
|
||||
const localVarPath = `/api/rooms/{roomId}/recreate`
|
||||
@@ -1044,9 +1079,12 @@ export const RoomsApiAxiosParamCreator = function (configuration?: Configuration
|
||||
|
||||
|
||||
|
||||
localVarHeaderParameter['Content-Type'] = 'application/json';
|
||||
|
||||
setSearchParams(localVarUrlObj, localVarQueryParameter);
|
||||
let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {};
|
||||
localVarRequestOptions.headers = {...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers};
|
||||
localVarRequestOptions.data = serializeDataIfNeeded(roomSettings, localVarRequestOptions, configuration)
|
||||
|
||||
return {
|
||||
url: toPathString(localVarUrlObj),
|
||||
@@ -1328,13 +1366,25 @@ export const RoomsApiFp = function(configuration?: Configuration) {
|
||||
},
|
||||
/**
|
||||
*
|
||||
* @summary Recreate room
|
||||
* @param {string} roomId
|
||||
* @summary Get room entry by name
|
||||
* @param {string} roomName
|
||||
* @param {*} [options] Override http request option.
|
||||
* @throws {RequiredError}
|
||||
*/
|
||||
async roomRecreate(roomId: string, options?: AxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise<RoomEntry>> {
|
||||
const localVarAxiosArgs = await localVarAxiosParamCreator.roomRecreate(roomId, options);
|
||||
async roomGetByName(roomName: string, options?: AxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise<RoomEntry>> {
|
||||
const localVarAxiosArgs = await localVarAxiosParamCreator.roomGetByName(roomName, options);
|
||||
return createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration);
|
||||
},
|
||||
/**
|
||||
*
|
||||
* @summary Recreate room
|
||||
* @param {string} roomId
|
||||
* @param {RoomSettings} [roomSettings]
|
||||
* @param {*} [options] Override http request option.
|
||||
* @throws {RequiredError}
|
||||
*/
|
||||
async roomRecreate(roomId: string, roomSettings?: RoomSettings, options?: AxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise<RoomEntry>> {
|
||||
const localVarAxiosArgs = await localVarAxiosParamCreator.roomRecreate(roomId, roomSettings, options);
|
||||
return createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration);
|
||||
},
|
||||
/**
|
||||
@@ -1446,13 +1496,24 @@ export const RoomsApiFactory = function (configuration?: Configuration, basePath
|
||||
},
|
||||
/**
|
||||
*
|
||||
* @summary Recreate room
|
||||
* @param {string} roomId
|
||||
* @summary Get room entry by name
|
||||
* @param {string} roomName
|
||||
* @param {*} [options] Override http request option.
|
||||
* @throws {RequiredError}
|
||||
*/
|
||||
roomRecreate(roomId: string, options?: any): AxiosPromise<RoomEntry> {
|
||||
return localVarFp.roomRecreate(roomId, options).then((request) => request(axios, basePath));
|
||||
roomGetByName(roomName: string, options?: any): AxiosPromise<RoomEntry> {
|
||||
return localVarFp.roomGetByName(roomName, options).then((request) => request(axios, basePath));
|
||||
},
|
||||
/**
|
||||
*
|
||||
* @summary Recreate room
|
||||
* @param {string} roomId
|
||||
* @param {RoomSettings} [roomSettings]
|
||||
* @param {*} [options] Override http request option.
|
||||
* @throws {RequiredError}
|
||||
*/
|
||||
roomRecreate(roomId: string, roomSettings?: RoomSettings, options?: any): AxiosPromise<RoomEntry> {
|
||||
return localVarFp.roomRecreate(roomId, roomSettings, options).then((request) => request(axios, basePath));
|
||||
},
|
||||
/**
|
||||
*
|
||||
@@ -1560,14 +1621,27 @@ export class RoomsApi extends BaseAPI {
|
||||
|
||||
/**
|
||||
*
|
||||
* @summary Recreate room
|
||||
* @param {string} roomId
|
||||
* @summary Get room entry by name
|
||||
* @param {string} roomName
|
||||
* @param {*} [options] Override http request option.
|
||||
* @throws {RequiredError}
|
||||
* @memberof RoomsApi
|
||||
*/
|
||||
public roomRecreate(roomId: string, options?: AxiosRequestConfig) {
|
||||
return RoomsApiFp(this.configuration).roomRecreate(roomId, options).then((request) => request(this.axios, this.basePath));
|
||||
public roomGetByName(roomName: string, options?: AxiosRequestConfig) {
|
||||
return RoomsApiFp(this.configuration).roomGetByName(roomName, options).then((request) => request(this.axios, this.basePath));
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @summary Recreate room
|
||||
* @param {string} roomId
|
||||
* @param {RoomSettings} [roomSettings]
|
||||
* @param {*} [options] Override http request option.
|
||||
* @throws {RequiredError}
|
||||
* @memberof RoomsApi
|
||||
*/
|
||||
public roomRecreate(roomId: string, roomSettings?: RoomSettings, options?: AxiosRequestConfig) {
|
||||
return RoomsApiFp(this.configuration).roomRecreate(roomId, roomSettings, options).then((request) => request(this.axios, this.basePath));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+2
-1
@@ -48,11 +48,12 @@ func (manager *ApiManagerCtx) Mount(r chi.Router) {
|
||||
|
||||
r.Route("/rooms/{roomId}", func(r chi.Router) {
|
||||
r.Get("/", manager.roomGetEntry)
|
||||
r.Delete("/", manager.roomGenericAction(manager.rooms.Remove))
|
||||
r.Get("/by-name", manager.roomGetEntryByName)
|
||||
|
||||
r.Get("/settings", manager.roomGetSettings)
|
||||
r.Get("/stats", manager.roomGetStats)
|
||||
|
||||
r.Delete("/", manager.roomGenericAction(manager.rooms.Remove))
|
||||
r.Post("/start", manager.roomGenericAction(manager.rooms.Start))
|
||||
r.Post("/stop", manager.roomGenericAction(manager.rooms.Stop))
|
||||
r.Post("/restart", manager.roomGenericAction(manager.rooms.Restart))
|
||||
|
||||
@@ -133,6 +133,20 @@ func (manager *ApiManagerCtx) roomGetEntry(w http.ResponseWriter, r *http.Reques
|
||||
json.NewEncoder(w).Encode(response)
|
||||
}
|
||||
|
||||
func (manager *ApiManagerCtx) roomGetEntryByName(w http.ResponseWriter, r *http.Request) {
|
||||
// roomId is actually room name here
|
||||
roomName := chi.URLParam(r, "roomId")
|
||||
|
||||
response, err := manager.rooms.GetEntryByName(roomName)
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), 500)
|
||||
return
|
||||
}
|
||||
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
json.NewEncoder(w).Encode(response)
|
||||
}
|
||||
|
||||
func (manager *ApiManagerCtx) roomGetSettings(w http.ResponseWriter, r *http.Request) {
|
||||
roomId := chi.URLParam(r, "roomId")
|
||||
|
||||
|
||||
@@ -82,15 +82,6 @@ func (manager *RoomManagerCtx) List(labels map[string]string) ([]types.RoomEntry
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func (manager *RoomManagerCtx) FindByName(name string) (*types.RoomEntry, error) {
|
||||
container, err := manager.containerByName(name)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return manager.containerToEntry(*container)
|
||||
}
|
||||
|
||||
func (manager *RoomManagerCtx) Create(settings types.RoomSettings) (string, error) {
|
||||
if settings.Name != "" && !dockerNames.RestrictedNamePattern.MatchString(settings.Name) {
|
||||
return "", fmt.Errorf("invalid container name, must match %s", dockerNames.RestrictedNameChars)
|
||||
@@ -504,6 +495,15 @@ func (manager *RoomManagerCtx) GetEntry(id string) (*types.RoomEntry, error) {
|
||||
return manager.containerToEntry(*container)
|
||||
}
|
||||
|
||||
func (manager *RoomManagerCtx) GetEntryByName(name string) (*types.RoomEntry, error) {
|
||||
container, err := manager.containerByName(name)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return manager.containerToEntry(*container)
|
||||
}
|
||||
|
||||
func (manager *RoomManagerCtx) Remove(id string) error {
|
||||
_, err := manager.inspectContainer(id)
|
||||
if err != nil {
|
||||
|
||||
@@ -283,10 +283,10 @@ type RoomMember struct {
|
||||
type RoomManager interface {
|
||||
Config() RoomsConfig
|
||||
List(labels map[string]string) ([]RoomEntry, error)
|
||||
FindByName(name string) (*RoomEntry, error)
|
||||
|
||||
Create(settings RoomSettings) (string, error)
|
||||
GetEntry(id string) (*RoomEntry, error)
|
||||
GetEntryByName(name string) (*RoomEntry, error)
|
||||
GetSettings(id string) (*RoomSettings, error)
|
||||
GetStats(id string) (*RoomStats, error)
|
||||
Remove(id string) error
|
||||
|
||||
Reference in New Issue
Block a user