-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #173 from ChubachiPT2024/feature/home-api
インポートページでの再開する用のAPI
- Loading branch information
Showing
13 changed files
with
187 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
src/application/reportCourse/reportCourseApplicationService.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { describe, expect, test } from 'vitest' | ||
import { InMemoryCourseRepository } from 'src/infrastructure/inMemory/courses/inMemoryCourseRepository' | ||
import { InMemoryReportRepository } from 'src/infrastructure/inMemory/reports/inMemoryReportRepository' | ||
import { ReportCourseApplicationService } from './reportCourseApplicationService' | ||
import { Course } from 'src/domain/models/courses/course' | ||
import { Report } from 'src/domain/models/reports/report' | ||
|
||
describe('get', () => { | ||
test('Can get report course', async () => { | ||
const courseRepository = new InMemoryCourseRepository() | ||
const reportRepository = new InMemoryReportRepository() | ||
const service = new ReportCourseApplicationService( | ||
courseRepository, | ||
reportRepository | ||
) | ||
const course = new Course(27048, 'コミュニケーション技術特論2') | ||
await courseRepository.saveAsync(course) | ||
const report = new Report( | ||
course.id, | ||
35677, | ||
'個人レポート課題', | ||
'folderAbsolutePath' | ||
) | ||
await reportRepository.saveAsync(report) | ||
|
||
const getResult = await service.getReportCourseAsync() | ||
|
||
const data = getResult.reportCourseDataList | ||
expect(data.length).toBe(1) | ||
expect(data[0].courseId).toBe(27048) | ||
expect(data[0].courseName).toBe('コミュニケーション技術特論2') | ||
expect(data[0].reportId).toBe(35677) | ||
expect(data[0].reportTitle).toBe('個人レポート課題') | ||
}) | ||
}) |
40 changes: 40 additions & 0 deletions
40
src/application/reportCourse/reportCourseApplicationService.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { ReportRepository } from 'src/domain/models/reports/reportRepository' | ||
import { CourseRepository } from 'src/domain/models/courses/courseRepository' | ||
import { ReportCourseData } from './reportCourseData' | ||
import { ReportCourseGetResult } from './reportCourseGetResult' | ||
|
||
/** | ||
* レポートコースアプリケーションサービス | ||
*/ | ||
export class ReportCourseApplicationService { | ||
/** | ||
* コンストラクタ | ||
* | ||
* @param courseRepository コースリポジトリ | ||
* @param reportRepository レポートリポジトリ | ||
*/ | ||
public constructor( | ||
private readonly courseRepository: CourseRepository, | ||
private readonly reportRepository: ReportRepository | ||
) {} | ||
|
||
/** | ||
* レポートとコースのデータを取得する | ||
* | ||
* @returns レポートとコースのデータ | ||
*/ | ||
public async getReportCourseAsync(): Promise<ReportCourseGetResult> { | ||
const reports = await this.reportRepository.findAllAsync() | ||
const courses = await this.courseRepository.findAllAsync() | ||
|
||
const reportCourseDataList: ReportCourseData[] = [] | ||
for (const report of reports) { | ||
const course = courses.find((course) => course.id === report.courseId) | ||
reportCourseDataList.push( | ||
new ReportCourseData(course.id, course.name, report.id, report.title) | ||
) | ||
} | ||
|
||
return new ReportCourseGetResult(reportCourseDataList) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/** | ||
* レポートとコースのデータ | ||
*/ | ||
export class ReportCourseData { | ||
/** | ||
* コンストラクタ | ||
* | ||
* @param courseId コース ID | ||
* @param courseName コース名 | ||
* @param reportId レポート ID | ||
* @param reportTitle レポートタイトル | ||
*/ | ||
public constructor( | ||
public readonly courseId: number, | ||
public readonly courseName: string, | ||
public readonly reportId: number, | ||
public readonly reportTitle: string | ||
) {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { ReportCourseData } from './reportCourseData' | ||
|
||
/** | ||
* レポートとコース取得結果 | ||
*/ | ||
export class ReportCourseGetResult { | ||
/** | ||
* コンストラクタ | ||
* | ||
* @param reportListData レポートコースデータ | ||
*/ | ||
public constructor( | ||
public readonly reportCourseDataList: ReportCourseData[] | ||
) {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters