Browse Source

Update urls

pull/1370/head
Hironsan 3 years ago
parent
commit
51fa5036e5
6 changed files with 29 additions and 27 deletions
  1. 16
      backend/api/urls.py
  2. 2
      backend/api/views/annotation.py
  3. 4
      backend/api/views/comment.py
  4. 2
      backend/api/views/example.py
  5. 18
      frontend/repositories/comment/apiCommentRepository.ts
  6. 14
      frontend/repositories/example/apiDocumentRepository.ts

16
backend/api/urls.py

@ -43,15 +43,16 @@ urlpatterns_project = [
name='label_detail'
),
path(
route='data',
route='examples',
view=views.ExampleList.as_view(),
name='data_list'
name='example_list'
),
path(
route='data/<int:data_id>',
route='examples/<int:example_id>',
view=views.ExampleDetail.as_view(),
name='data_detail'
name='example_detail'
),
# Todo: remove.
path(
route='docs',
view=views.DocumentList.as_view(),
@ -63,10 +64,11 @@ urlpatterns_project = [
name='doc_detail'
),
path(
route='approval/<int:data_id>',
route='approval/<int:example_id>',
view=views.ApprovalAPI.as_view(),
name='approve_labels'
),
# Todo: change.
path(
route='docs/<int:doc_id>/annotations',
view=views.AnnotationList.as_view(),
@ -88,7 +90,7 @@ urlpatterns_project = [
name='tag_detail'
),
path(
route='docs/<int:doc_id>/comments',
route='examples/<int:example_id>/comments',
view=views.CommentListDoc.as_view(),
name='comment_list_doc'
),
@ -98,7 +100,7 @@ urlpatterns_project = [
name='comment_list_project'
),
path(
route='docs/<int:doc_id>/comments/<int:comment_id>',
route='examples/<int:example_id>/comments/<int:comment_id>',
view=views.CommentDetail.as_view(),
name='comment_detail'
),

2
backend/api/views/annotation.py

@ -75,7 +75,7 @@ class ApprovalAPI(APIView):
def post(self, request, *args, **kwargs):
approved = self.request.data.get('approved', True)
example = get_object_or_404(Example, pk=self.kwargs['data_id'])
example = get_object_or_404(Example, pk=self.kwargs['example_id'])
example.annotations_approved_by = self.request.user if approved else None
example.save()
return Response(ApproverSerializer(example).data)

4
backend/api/views/comment.py

@ -17,12 +17,12 @@ class CommentListDoc(generics.ListCreateAPIView):
def get_queryset(self):
queryset = self.model.objects.filter(
example__project_id=self.kwargs['project_id'],
example=self.kwargs['doc_id']
example=self.kwargs['example_id']
)
return queryset
def perform_create(self, serializer):
serializer.save(example_id=self.kwargs['doc_id'], user=self.request.user)
serializer.save(example_id=self.kwargs['example_id'], user=self.request.user)
class CommentListProject(generics.ListAPIView):

2
backend/api/views/example.py

@ -52,7 +52,7 @@ class ExampleList(generics.ListCreateAPIView):
class ExampleDetail(generics.RetrieveUpdateDestroyAPIView):
queryset = Example.objects.all()
serializer_class = ExampleSerializer
lookup_url_kwarg = 'data_id'
lookup_url_kwarg = 'example_id'
permission_classes = [IsAuthenticated & IsInProjectReadOnlyOrAdmin]

18
frontend/repositories/comment/apiCommentRepository.ts

@ -14,29 +14,29 @@ export class APICommentRepository implements CommentRepository {
return items.map(item => CommentItem.valueOf(item))
}
async list(projectId: string, docId: number): Promise<CommentItem[]> {
const url = `/projects/${projectId}/docs/${docId}/comments`
async list(projectId: string, exampleId: number): Promise<CommentItem[]> {
const url = `/projects/${projectId}/examples/${exampleId}/comments`
const response = await this.request.get(url)
const items: CommentItemResponse[] = response.data
return items.map(item => CommentItem.valueOf(item))
}
async create(projectId: string, docId: number, text: string): Promise<CommentItem> {
const url = `/projects/${projectId}/docs/${docId}/comments`
const response = await this.request.post(url, { projectId, docId, text })
async create(projectId: string, exampleId: number, text: string): Promise<CommentItem> {
const url = `/projects/${projectId}/examples/${exampleId}/comments`
const response = await this.request.post(url, { projectId, exampleId, text })
const responseItem: CommentItemResponse = response.data
return CommentItem.valueOf(responseItem)
}
async update(projectId: string, docId: number, item: CommentItem): Promise<CommentItem> {
const url = `/projects/${projectId}/docs/${docId}/comments/${item.id}`
async update(projectId: string, exampleId: number, item: CommentItem): Promise<CommentItem> {
const url = `/projects/${projectId}/examples/${exampleId}/comments/${item.id}`
const response = await this.request.put(url, item.toObject())
const responseItem: CommentItemResponse = response.data
return CommentItem.valueOf(responseItem)
}
async delete(projectId: string, docId: number, commentId: number): Promise<void> {
const url = `/projects/${projectId}/docs/${docId}/comments/${commentId}`
async delete(projectId: string, exampleId: number, commentId: number): Promise<void> {
const url = `/projects/${projectId}/examples/${exampleId}/comments/${commentId}`
const response = await this.request.delete(url)
}

14
frontend/repositories/example/apiDocumentRepository.ts

@ -9,35 +9,35 @@ export class APIExampleRepository implements ExampleRepository {
) {}
async list(projectId: string, { limit = '10', offset = '0', q = '', isChecked = '', filterName = '' }: SearchOption): Promise<ExampleItemList> {
const url = `/projects/${projectId}/data?limit=${limit}&offset=${offset}&q=${q}&${filterName}=${isChecked}`
const url = `/projects/${projectId}/examples?limit=${limit}&offset=${offset}&q=${q}&${filterName}=${isChecked}`
const response = await this.request.get(url)
return ExampleItemList.valueOf(response.data)
}
async create(projectId: string, item: ExampleItem): Promise<ExampleItem> {
const url = `/projects/${projectId}/data`
const url = `/projects/${projectId}/examples`
const response = await this.request.post(url, item.toObject())
return ExampleItem.valueOf(response.data)
}
async update(projectId: string, item: ExampleItem): Promise<ExampleItem> {
const url = `/projects/${projectId}/data/${item.id}`
const url = `/projects/${projectId}/examples/${item.id}`
const response = await this.request.patch(url, item.toObject())
return ExampleItem.valueOf(response.data)
}
async bulkDelete(projectId: string, ids: number[]): Promise<void> {
const url = `/projects/${projectId}/data`
const url = `/projects/${projectId}/examples`
await this.request.delete(url, { ids })
}
async deleteAll(projectId: string): Promise<void> {
const url = `/projects/${projectId}/data`
const url = `/projects/${projectId}/examples`
await this.request.delete(url)
}
async approve(projectId: string, docId: number, approved: boolean): Promise<void> {
const url = `/projects/${projectId}/approval/${docId}`
async approve(projectId: string, exampleId: number, approved: boolean): Promise<void> {
const url = `/projects/${projectId}/approval/${exampleId}`
await this.request.post(url, { approved })
}
}
Loading…
Cancel
Save