Skip to content

Commit

Permalink
add get entry by name.
Browse files Browse the repository at this point in the history
  • Loading branch information
m1k1o committed Sep 30, 2023
1 parent 52dc6ea commit 06b5969
Show file tree
Hide file tree
Showing 6 changed files with 130 additions and 18 deletions.
23 changes: 23 additions & 0 deletions OpenApi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
88 changes: 81 additions & 7 deletions client/src/api/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1010,6 +1010,40 @@ export const RoomsApiAxiosParamCreator = function (configuration?: Configuration



setSearchParams(localVarUrlObj, localVarQueryParameter);
let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {};
localVarRequestOptions.headers = {...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers};

return {
url: toPathString(localVarUrlObj),
options: localVarRequestOptions,
};
},
/**
*
* @summary Get room entry by name
* @param {string} roomName
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
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};
Expand All @@ -1023,10 +1057,11 @@ export const RoomsApiAxiosParamCreator = function (configuration?: Configuration
*
* @summary Recreate room
* @param {string} roomId
* @param {RoomSettings} [roomSettings]
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
roomRecreate: async (roomId: string, options: AxiosRequestConfig = {}): Promise<RequestArgs> => {
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`
Expand All @@ -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),
Expand Down Expand Up @@ -1326,15 +1364,27 @@ export const RoomsApiFp = function(configuration?: Configuration) {
const localVarAxiosArgs = await localVarAxiosParamCreator.roomGet(roomId, options);
return createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration);
},
/**
*
* @summary Get room entry by name
* @param {string} roomName
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
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, options?: AxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise<RoomEntry>> {
const localVarAxiosArgs = await localVarAxiosParamCreator.roomRecreate(roomId, options);
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);
},
/**
Expand Down Expand Up @@ -1444,15 +1494,26 @@ export const RoomsApiFactory = function (configuration?: Configuration, basePath
roomGet(roomId: string, options?: any): AxiosPromise<RoomEntry> {
return localVarFp.roomGet(roomId, options).then((request) => request(axios, basePath));
},
/**
*
* @summary Get room entry by name
* @param {string} roomName
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
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, options?: any): AxiosPromise<RoomEntry> {
return localVarFp.roomRecreate(roomId, options).then((request) => request(axios, basePath));
roomRecreate(roomId: string, roomSettings?: RoomSettings, options?: any): AxiosPromise<RoomEntry> {
return localVarFp.roomRecreate(roomId, roomSettings, options).then((request) => request(axios, basePath));
},
/**
*
Expand Down Expand Up @@ -1558,16 +1619,29 @@ export class RoomsApi extends BaseAPI {
return RoomsApiFp(this.configuration).roomGet(roomId, options).then((request) => request(this.axios, this.basePath));
}

/**
*
* @summary Get room entry by name
* @param {string} roomName
* @param {*} [options] Override http request option.
* @throws {RequiredError}
* @memberof RoomsApi
*/
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, options?: AxiosRequestConfig) {
return RoomsApiFp(this.configuration).roomRecreate(roomId, options).then((request) => request(this.axios, this.basePath));
public roomRecreate(roomId: string, roomSettings?: RoomSettings, options?: AxiosRequestConfig) {
return RoomsApiFp(this.configuration).roomRecreate(roomId, roomSettings, options).then((request) => request(this.axios, this.basePath));
}

/**
Expand Down
3 changes: 2 additions & 1 deletion internal/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
14 changes: 14 additions & 0 deletions internal/api/rooms.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down
18 changes: 9 additions & 9 deletions internal/room/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion internal/types/room.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 06b5969

Please sign in to comment.