mirror of https://github.com/doccano/doccano.git
Hiroki Nakayama
3 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
18 changed files with 326 additions and 11 deletions
Split View
Diff Options
-
10app/api/admin.py
-
22app/api/migrations/0009_tag.py
-
8app/api/models.py
-
15app/api/serializers.py
-
53app/api/tests/test_api.py
-
6app/api/urls.py
-
1app/api/views/__init__.py
-
24app/api/views/tag.py
-
40frontend/components/project/FormUpdate.vue
-
10frontend/components/project/ProjectList.vue
-
13frontend/domain/models/project/project.ts
-
46frontend/domain/models/tag/tag.ts
-
9frontend/domain/models/tag/tagRepository.ts
-
6frontend/plugins/services.ts
-
34frontend/repositories/tag/apiTagRepository.ts
-
4frontend/services/application/project/projectData.ts
-
23frontend/services/application/tag/tagApplicationService.ts
-
13frontend/services/application/tag/tagData.ts
@ -0,0 +1,22 @@ |
|||
# Generated by Django 3.2 on 2021-04-13 16:50 |
|||
|
|||
from django.db import migrations, models |
|||
import django.db.models.deletion |
|||
|
|||
|
|||
class Migration(migrations.Migration): |
|||
|
|||
dependencies = [ |
|||
('api', '0008_auto_20210302_1013'), |
|||
] |
|||
|
|||
operations = [ |
|||
migrations.CreateModel( |
|||
name='Tag', |
|||
fields=[ |
|||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), |
|||
('text', models.TextField()), |
|||
('project', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='tags', to='api.project')), |
|||
], |
|||
), |
|||
] |
@ -0,0 +1,24 @@ |
|||
from django.shortcuts import get_object_or_404 |
|||
from rest_framework import generics, status |
|||
from rest_framework.response import Response |
|||
|
|||
from ..models import Project, Tag |
|||
from ..serializers import TagSerializer |
|||
|
|||
|
|||
class TagList(generics.ListCreateAPIView): |
|||
serializer_class = TagSerializer |
|||
pagination_class = None |
|||
|
|||
def get_queryset(self): |
|||
project = get_object_or_404(Project, pk=self.kwargs['project_id']) |
|||
return project.tags |
|||
|
|||
def perform_create(self, serializer): |
|||
project = get_object_or_404(Project, pk=self.kwargs['project_id']) |
|||
serializer.save(project=project) |
|||
|
|||
def delete(self, request, *args, **kwargs): |
|||
delete_id = request.data['id'] |
|||
Tag.objects.get(id=delete_id).delete() |
|||
return Response(status=status.HTTP_204_NO_CONTENT) |
@ -0,0 +1,46 @@ |
|||
export class TagItemList { |
|||
constructor(public tagItems: TagItem[]) {} |
|||
|
|||
static valueOf(items: TagItem[]): TagItemList { |
|||
return new TagItemList(items) |
|||
} |
|||
|
|||
add(item: TagItem) { |
|||
this.tagItems.push(item) |
|||
} |
|||
|
|||
delete(item: TagItem) { |
|||
this.tagItems = this.tagItems.filter(tag => tag.id !== item.id) |
|||
} |
|||
|
|||
ids(): Number[]{ |
|||
return this.tagItems.map(item => item.id) |
|||
} |
|||
|
|||
toArray(): Object[] { |
|||
return this.tagItems.map(item => item.toObject()) |
|||
} |
|||
} |
|||
|
|||
export class TagItem { |
|||
constructor( |
|||
public id: number, |
|||
public text: string, |
|||
public project: string |
|||
) {} |
|||
|
|||
static valueOf( |
|||
{ id, text, project }: |
|||
{ id: number, text: string, project: string } |
|||
): TagItem { |
|||
return new TagItem(id, text, project) |
|||
} |
|||
|
|||
toObject(): Object { |
|||
return { |
|||
id: this.id, |
|||
text: this.text, |
|||
project: this.project |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,9 @@ |
|||
import { TagItem } from '~/domain/models/tag/tag' |
|||
|
|||
export interface TagRepository { |
|||
list(projectId: string): Promise<TagItem[]> |
|||
|
|||
create(projectId: string, item: string): Promise<TagItem> |
|||
|
|||
delete(projectId: string, tagId: number): Promise<void> |
|||
} |
@ -0,0 +1,34 @@ |
|||
import ApiService from '@/services/api.service' |
|||
import { TagRepository } from '~/domain/models/tag/tagRepository' |
|||
import { TagItem } from '~/domain/models/tag/tag' |
|||
|
|||
export interface TagItemResponse { |
|||
id: number, |
|||
text: string, |
|||
project: string |
|||
} |
|||
|
|||
export class APITagRepository implements TagRepository { |
|||
constructor( |
|||
private readonly request = ApiService |
|||
) {} |
|||
|
|||
async list(projectId: string): Promise<TagItem[]> { |
|||
const url = `/projects/${projectId}/tags` |
|||
const response = await this.request.get(url) |
|||
const responseItems: TagItemResponse[] = response.data |
|||
return responseItems.map(item => TagItem.valueOf(item)) |
|||
} |
|||
|
|||
async create(projectId: string, item: string): Promise<TagItem> { |
|||
const url = `/projects/${projectId}/tags` |
|||
const response = await this.request.post(url, { text: item }) |
|||
const responseItem: TagItemResponse = response.data |
|||
return TagItem.valueOf(responseItem) |
|||
} |
|||
|
|||
async delete(projectId: string, tagId: number): Promise<void> { |
|||
const url = `/projects/${projectId}/tags` |
|||
await this.request.delete(url, { id: tagId }) |
|||
} |
|||
} |
@ -0,0 +1,23 @@ |
|||
import { TagDTO } from './tagData' |
|||
import { TagRepository } from '~/domain/models/tag/tagRepository' |
|||
import { TagItem } from '~/domain/models/tag/tag' |
|||
|
|||
|
|||
export class TagApplicationService { |
|||
constructor( |
|||
private readonly repository: TagRepository |
|||
) {} |
|||
|
|||
public async list(id: string): Promise<TagDTO[]> { |
|||
const items = await this.repository.list(id) |
|||
return items.map(item => new TagDTO(item)) |
|||
} |
|||
|
|||
public create(projectId: string, text: string): void { |
|||
this.repository.create(projectId, text) |
|||
} |
|||
|
|||
public delete(projectId: string, id: number): Promise<void> { |
|||
return this.repository.delete(projectId, id) |
|||
} |
|||
} |
@ -0,0 +1,13 @@ |
|||
import { TagItem } from '~/domain/models/tag/tag' |
|||
|
|||
export class TagDTO { |
|||
id: number |
|||
text: string |
|||
project: string |
|||
|
|||
constructor(item: TagItem) { |
|||
this.id = item.id |
|||
this.text = item.text |
|||
this.project = item.project |
|||
} |
|||
} |
Write
Preview
Loading…
Cancel
Save