Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

temp/SubjectCommentRepository を削除 #215

Open
wants to merge 1 commit into
base: issue/185-remodel
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion frontend/src/components/CommentModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import CommentSubmitForm, {
} from './CommentSubmitForm';
import { SubjectRepository } from 'temp/SubjectRepository';
import SubjectCommentList from './SubjectCommentList';
import { SubjectCommentRepository } from 'temp/SubjectCommentRepository';
import { SubjectCommentRepository } from 'repositories/SubjectCommentRepository';
import { TeacherCommentRepository } from 'temp/TeacherCommentRepository';
import { EditRequestRepository } from 'temp/EditRequestRepository';
import { UserRepository } from 'repositories/UserRepository';
Expand Down
6 changes: 2 additions & 4 deletions frontend/src/components/SubjectCommentList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,8 @@ import {

import { DeleteIcon } from '@chakra-ui/icons';

import {
SubjectComment,
SubjectCommentRepository,
} from 'temp/SubjectCommentRepository';
import { SubjectCommentRepository } from 'repositories/SubjectCommentRepository';
import { SubjectComment } from 'domains';

export type SubjectCommentListProps = {
subjectUuid: string;
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/domains/entities/SubjetComment.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { Subject, User } from '..';
import { ReductionUser, Subject } from '..';

export class SubjectComment {
constructor(
public uuid: string,
public subject: Subject,
public user: User,
public user: ReductionUser,
public comment: string,
) {}
}
11 changes: 8 additions & 3 deletions frontend/src/domains/factories/SubjectCommentFactory.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
import { SubjectFactory, SubjectResponse, UserFactory, UserResponse } from '..';
import {
ReductionUserFactory,
ReductionUserResponse,
SubjectFactory,
SubjectResponse,
} from '..';
import { SubjectComment } from '../entities/SubjetComment';

export interface SubjectCommentResponse {
uuid: string;
subject: SubjectResponse;
user: UserResponse;
user: ReductionUserResponse;
comment: string;
}

Expand All @@ -13,7 +18,7 @@ export class SubjectCommentFactory {
return new SubjectComment(
res.uuid,
SubjectFactory.createFromResponse(res.subject),
UserFactory.createFromResponse(res.user),
ReductionUserFactory.createFromResponse(res.user),
res.comment,
);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,42 +1,5 @@
import { authClient } from 'infras/RestClient';

export interface SubjectComment {
comment: string;
uuid: string;
subject: {
name: string;
credits: number;
syllabus_url: string;
category: string;
type: string;
target_grade: number;
uuid: string;
term: {
academic_year: number;
semester: string;
uuid: string;
};
teacher: {
name: string;
uuid: string;
};
school: {
name: string;
syllabus_url: string;
uuid: string;
};
department: {
name: string;
syllabus_url: string;
uuid: string;
};
};
user: {
username: string;
grade: number;
uuid: string;
};
}
import { SubjectCommentResponse, SubjectCommentFactory } from 'domains';

export interface CreateSubjectCommentRequest {
comment: string;
Expand All @@ -52,19 +15,19 @@ export class SubjectCommentRepository {
static async getsBySubject(subjectUuid: string) {
const authClientObject = authClient();
if (!authClientObject) return;
const res = await authClientObject.get<SubjectComment[]>(
const res = await authClientObject.get<SubjectCommentResponse[]>(
`/api/v1/subjects_comments?subject_uuid=${subjectUuid}`,
);
return res.data;
return res.data.map(SubjectCommentFactory.createFromResponse);
}
static async create(data: CreateSubjectCommentRequest) {
const authClientObject = authClient();
if (!authClientObject) return;
const res = await authClientObject.post<
CreateSubjectCommentRequest,
SubjectComment
SubjectCommentResponse
>(`/api/v1/subjects_comments`, data);
return res.data;
return SubjectCommentFactory.createFromResponse(res.data);
}

static async delete(uuid: string) {
Expand All @@ -73,6 +36,6 @@ export class SubjectCommentRepository {
const res = await authClientObject.delete(
`/api/v1/subjects_comments/${uuid}`,
);
return res.data;
return SubjectCommentFactory.createFromResponse(res.data);
}
}