Skip to content

Commit becc691

Browse files
authored
fix member typing (#336)
* fix member typing * adjust the test so it can pass
1 parent da33baa commit becc691

File tree

9 files changed

+174
-8
lines changed

9 files changed

+174
-8
lines changed

backend/app/models/groups.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,21 @@
11
from datetime import datetime
2-
from typing import Optional
2+
from typing import Optional, List
33

4-
from mongoengine import DynamicDocument
54
from pydantic import Field, BaseModel
6-
from pydantic import Field
75

86
from app.models.mongomodel import OID, MongoModel
97
from app.models.users import UserOut
108

119

12-
class Member:
10+
class Member(BaseModel):
1311
user: UserOut
1412
isOwner: bool = False
1513

1614

1715
class GroupBase(BaseModel):
1816
name: str = "N/A"
1917
description: str = "N/A"
20-
userList = [Member()]
18+
userList: List[Member] = []
2119

2220

2321
class GroupIn(GroupBase):

backend/app/routers/groups.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@
77
from pymongo.mongo_client import MongoClient
88

99
from app import keycloak_auth, dependencies
10-
from app.keycloak_auth import get_current_user
11-
from app.models.groups import GroupOut, GroupIn, GroupDB, Member, GroupBase
10+
from app.models.groups import GroupOut, GroupIn, GroupDB, GroupBase
1211
from app.models.users import UserOut
1312
from app.routers.users import get_user
1413

backend/app/tests/test_groups.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,9 @@ def test_add_and_remove_member(client: TestClient, headers: dict):
7777

7878
# removing member
7979
new_group = response.json()
80-
new_group["userList"].remove(member2)
80+
new_group["userList"].pop()
81+
82+
# TODO add a put endpoint for this
8183
response = client.post(
8284
f"{settings.API_V2_STR}/groups", headers=headers, json=new_group
8385
)

frontend/src/openapi/v2/index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,12 @@ export type { FileOut } from './models/FileOut';
2828
export type { FileVersion } from './models/FileVersion';
2929
export type { FolderIn } from './models/FolderIn';
3030
export type { FolderOut } from './models/FolderOut';
31+
export type { GroupBase } from './models/GroupBase';
32+
export type { GroupIn } from './models/GroupIn';
33+
export type { GroupOut } from './models/GroupOut';
3134
export type { HTTPValidationError } from './models/HTTPValidationError';
3235
export type { LegacyEventListenerIn } from './models/LegacyEventListenerIn';
36+
export type { Member } from './models/Member';
3337
export type { MetadataAgent } from './models/MetadataAgent';
3438
export type { MetadataConfig } from './models/MetadataConfig';
3539
export type { MetadataDefinitionIn } from './models/MetadataDefinitionIn';
@@ -58,6 +62,7 @@ export { ExtractorsService } from './services/ExtractorsService';
5862
export { FeedsService } from './services/FeedsService';
5963
export { FilesService } from './services/FilesService';
6064
export { FoldersService } from './services/FoldersService';
65+
export { GroupsService } from './services/GroupsService';
6166
export { JobsService } from './services/JobsService';
6267
export { ListenersService } from './services/ListenersService';
6368
export { LoginService } from './services/LoginService';
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/* istanbul ignore file */
2+
/* tslint:disable */
3+
/* eslint-disable */
4+
5+
import type { Member } from './Member';
6+
7+
export type GroupBase = {
8+
name?: string;
9+
description?: string;
10+
userList?: Array<Member>;
11+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/* istanbul ignore file */
2+
/* tslint:disable */
3+
/* eslint-disable */
4+
5+
import type { Member } from './Member';
6+
7+
export type GroupIn = {
8+
name?: string;
9+
description?: string;
10+
userList?: Array<Member>;
11+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/* istanbul ignore file */
2+
/* tslint:disable */
3+
/* eslint-disable */
4+
5+
import type { Member } from './Member';
6+
import type { UserOut } from './UserOut';
7+
8+
export type GroupOut = {
9+
name?: string;
10+
description?: string;
11+
userList?: Array<Member>;
12+
id?: string;
13+
author: UserOut;
14+
created?: string;
15+
modified?: string;
16+
views?: number;
17+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/* istanbul ignore file */
2+
/* tslint:disable */
3+
/* eslint-disable */
4+
5+
import type { UserOut } from './UserOut';
6+
7+
export type Member = {
8+
user: UserOut;
9+
isOwner?: boolean;
10+
}
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
/* istanbul ignore file */
2+
/* tslint:disable */
3+
/* eslint-disable */
4+
import type { GroupBase } from '../models/GroupBase';
5+
import type { GroupIn } from '../models/GroupIn';
6+
import type { GroupOut } from '../models/GroupOut';
7+
import type { CancelablePromise } from '../core/CancelablePromise';
8+
import { request as __request } from '../core/request';
9+
10+
export class GroupsService {
11+
12+
/**
13+
* Save Group
14+
* @param requestBody
15+
* @returns GroupOut Successful Response
16+
* @throws ApiError
17+
*/
18+
public static saveGroupApiV2GroupsPost(
19+
requestBody: GroupIn,
20+
): CancelablePromise<GroupOut> {
21+
return __request({
22+
method: 'POST',
23+
path: `/api/v2/groups`,
24+
body: requestBody,
25+
mediaType: 'application/json',
26+
errors: {
27+
422: `Validation Error`,
28+
},
29+
});
30+
}
31+
32+
/**
33+
* Get Group
34+
* @param groupId
35+
* @returns GroupOut Successful Response
36+
* @throws ApiError
37+
*/
38+
public static getGroupApiV2GroupsGroupIdGet(
39+
groupId: string,
40+
): CancelablePromise<GroupOut> {
41+
return __request({
42+
method: 'GET',
43+
path: `/api/v2/groups/${groupId}`,
44+
errors: {
45+
422: `Validation Error`,
46+
},
47+
});
48+
}
49+
50+
/**
51+
* Edit Group
52+
* @param groupId
53+
* @param userId
54+
* @param requestBody
55+
* @returns GroupOut Successful Response
56+
* @throws ApiError
57+
*/
58+
public static editGroupApiV2GroupsGroupIdPost(
59+
groupId: string,
60+
userId: string,
61+
requestBody: GroupBase,
62+
): CancelablePromise<GroupOut> {
63+
return __request({
64+
method: 'POST',
65+
path: `/api/v2/groups/${groupId}`,
66+
query: {
67+
'user_id': userId,
68+
},
69+
body: requestBody,
70+
mediaType: 'application/json',
71+
errors: {
72+
422: `Validation Error`,
73+
},
74+
});
75+
}
76+
77+
/**
78+
* Delete Group
79+
* @param groupId
80+
* @returns any Successful Response
81+
* @throws ApiError
82+
*/
83+
public static deleteGroupApiV2GroupsGroupIdDelete(
84+
groupId: string,
85+
): CancelablePromise<any> {
86+
return __request({
87+
method: 'DELETE',
88+
path: `/api/v2/groups/${groupId}`,
89+
errors: {
90+
422: `Validation Error`,
91+
},
92+
});
93+
}
94+
95+
/**
96+
* Search Group
97+
* @param searchTerm
98+
* @returns any Successful Response
99+
* @throws ApiError
100+
*/
101+
public static searchGroupApiV2GroupsSearchSearchTermGet(
102+
searchTerm: string,
103+
): CancelablePromise<any> {
104+
return __request({
105+
method: 'GET',
106+
path: `/api/v2/groups/search/${searchTerm}`,
107+
errors: {
108+
422: `Validation Error`,
109+
},
110+
});
111+
}
112+
113+
}

0 commit comments

Comments
 (0)