Skip to content

Commit

Permalink
Merge pull request #173 from ChubachiPT2024/feature/home-api
Browse files Browse the repository at this point in the history
インポートページでの再開する用のAPI
  • Loading branch information
shunya9811 authored Jul 17, 2024
2 parents ace19b6 + d572692 commit 75764e7
Show file tree
Hide file tree
Showing 13 changed files with 187 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/@types/interface.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ export interface IElectronAPI {
reportListExportCommand: ReportListExportCommand
) => Promise<ReportListExportResult>

getReportCourseAsync: () => Promise<ReportCourseGetResult>

getReportListAsync: (
reportListGetCommand: ReportListGetCommand
) => Promise<ReportListGetResult>
Expand Down
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 src/application/reportCourse/reportCourseApplicationService.ts
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)
}
}
19 changes: 19 additions & 0 deletions src/application/reportCourse/reportCourseData.ts
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
) {}
}
15 changes: 15 additions & 0 deletions src/application/reportCourse/reportCourseGetResult.ts
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[]
) {}
}
6 changes: 6 additions & 0 deletions src/domain/models/courses/courseRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,10 @@ export interface CourseRepository {
* @param id ID
*/
findAsync(id: number): Promise<Course>

/**
* コースを全件取得する
*
*/
findAllAsync(): Promise<Course[]>
}
6 changes: 6 additions & 0 deletions src/domain/models/reports/reportRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,10 @@ export interface ReportRepository {
* @param id ID
*/
findAsync(id: number): Promise<Report>

/**
* レポートを全件取得する
*
*/
findAllAsync(): Promise<Report[]>
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,16 @@ describe('save', () => {
expect(actual.id).toBe(expected.id)
expect(actual.name).toBe(expected.name)
})

test('should return all courses', async () => {
const repository = new InMemoryCourseRepository()
const expected1 = new Course(1, 'name')
const expected2 = new Course(2, 'name')

await repository.saveAsync(expected1)
await repository.saveAsync(expected2)

const actual = await repository.findAllAsync()
expect(actual.length).toBe(2)
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,13 @@ export class InMemoryCourseRepository implements CourseRepository {
}
return course
}

/**
* コースを全件取得する
*
* @returns コース
*/
public async findAllAsync(): Promise<Course[]> {
return Array.from(this.courses.values())
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,26 @@ describe('save', () => {
expected.reportListFolderAbsolutePath
)
})

test('should return all reports', async () => {
const repository = new InMemoryReportRepository()
const expected1 = new Report(
1,
1,
'title1',
'reportListFolderAbsolutePath1'
)
const expected2 = new Report(
2,
2,
'title2',
'reportListFolderAbsolutePath2'
)

await repository.saveAsync(expected1)
await repository.saveAsync(expected2)

const actual = await repository.findAllAsync()
expect(actual.length).toBe(2)
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,13 @@ export class InMemoryReportRepository implements ReportRepository {
}
return report
}

/**
* レポートを全件取得する
*
* @returns レポート
*/
public async findAllAsync(): Promise<Report[]> {
return Array.from(this.reports.values())
}
}
10 changes: 10 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { SubmissionSummariesGetCommand } from './application/submissionSummaries
import { SubmissionFileApplicationService } from './application/submissionFiles/submissionFileApplicationService'
import { SubmissionFileGetCommand } from './application/submissionFiles/submissionFileGetCommand'
import { ReportListExportCommand } from './application/reportLists/reportListExportCommand'
import { ReportCourseApplicationService } from './application/reportCourse/reportCourseApplicationService'

// Handle creating/removing shortcuts on Windows when installing/uninstalling.
if (require('electron-squirrel-startup')) {
Expand Down Expand Up @@ -75,6 +76,10 @@ const submissionFileApplicationService = new SubmissionFileApplicationService(
reportRepository,
submissionRepository
)
const reportCourseApplicationService = new ReportCourseApplicationService(
courseRepository,
reportRepository
)

// This method will be called when Electron has finished
// initialization and is ready to create browser windows.
Expand All @@ -92,6 +97,11 @@ app.whenReady().then(() => {
await reportListApplicationService.exportAsync(reportListExportCommand)
)

ipcMain.handle(
'getReportCourseAsync',
async () => await reportCourseApplicationService.getReportCourseAsync()
)

ipcMain.handle(
'getReportListAsync',
async (_, reportListGetCommand: ReportListGetCommand) =>
Expand Down
2 changes: 2 additions & 0 deletions src/preload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ contextBridge.exposeInMainWorld('electronAPI', {
exportReportListAsync: (reportListExportCommand: ReportListExportCommand) =>
ipcRenderer.invoke('exportReportListAsync', reportListExportCommand),

getReportCourseAsync: () => ipcRenderer.invoke('getReportCourseAsync'),

getReportListAsync: (reportListGetCommand: ReportListGetCommand) =>
ipcRenderer.invoke('getReportListAsync', reportListGetCommand),

Expand Down

0 comments on commit 75764e7

Please sign in to comment.