-
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 #107 from ChubachiPT2024/feature/classify-api
#96 分類用 API の実装
- Loading branch information
Showing
13 changed files
with
207 additions
and
7 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
32 changes: 32 additions & 0 deletions
32
src/application/assessments/assessmentApplicationService.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,32 @@ | ||
import { Assessment } from 'src/domain/models/assessments/assessment' | ||
import { InMemoryAssessmentRepository } from 'src/infrastructure/inMemory/assessments/inMemoryAssessmentRepository' | ||
import { describe, expect, test } from 'vitest' | ||
import { AssessmentApplicationService } from './assessmentApplicationService' | ||
import { AssessmentClassifyCommand } from './assessmentClassifyCommand' | ||
|
||
describe('classify', () => { | ||
test('The grade and rank are set after classification.', async () => { | ||
// Arrange | ||
const repository = new InMemoryAssessmentRepository() | ||
const assessment = new Assessment(0, 0) | ||
await repository.saveAsync(assessment) | ||
const service = new AssessmentApplicationService(repository) | ||
const command = new AssessmentClassifyCommand( | ||
assessment.reportId, | ||
assessment.studentNumId, | ||
1, | ||
2 | ||
) | ||
|
||
// Act | ||
await service.classifyAsync(command) | ||
|
||
// Assert | ||
const classified = await repository.findAsync( | ||
assessment.reportId, | ||
assessment.studentNumId | ||
) | ||
expect(classified.grade).toBe(1) | ||
expect(classified.rank).toBe(2) | ||
}) | ||
}) |
34 changes: 34 additions & 0 deletions
34
src/application/assessments/assessmentApplicationService.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,34 @@ | ||
import { AssessmentRepository } from 'src/domain/models/assessments/assessmentRepository' | ||
import { AssessmentClassifyCommand } from './assessmentClassifyCommand' | ||
|
||
/** | ||
* 個別評価アプリケーションサービス | ||
*/ | ||
export class AssessmentApplicationService { | ||
/** | ||
* コンストラクタ | ||
* | ||
* @param assessmentRepository 個別評価リポジトリ | ||
*/ | ||
public constructor( | ||
private readonly assessmentRepository: AssessmentRepository | ||
) {} | ||
|
||
/** | ||
* 個別評価を分類する | ||
* | ||
* @param command 個別評価分類コマンド | ||
*/ | ||
public async classifyAsync( | ||
command: AssessmentClassifyCommand | ||
): Promise<void> { | ||
const assessment = await this.assessmentRepository.findAsync( | ||
command.reportId, | ||
command.studentNumId | ||
) | ||
|
||
const classified = assessment.classify(command.grade, command.rank) | ||
|
||
await this.assessmentRepository.saveAsync(classified) | ||
} | ||
} |
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 AssessmentClassifyCommand { | ||
/** | ||
* コンストラクタ | ||
* | ||
* @param reportId レポート ID | ||
* @param studentNumId 学籍番号 | ||
* @param grade 評点 | ||
* @param rank 評点内の位置 | ||
*/ | ||
public constructor( | ||
public readonly reportId: number, | ||
public readonly studentNumId: number, | ||
public readonly grade: number, | ||
public readonly rank: number | ||
) {} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { describe, expect, test } from 'vitest' | ||
import { Assessment } from './assessment' | ||
|
||
describe('classify', () => { | ||
test('The grade and rank are set after classification', async () => { | ||
// Arrange | ||
const assessment = new Assessment(0, 0) | ||
|
||
// Act | ||
const classified = assessment.classify(1, 2) | ||
|
||
// Assert | ||
expect(classified.grade).toBe(1) | ||
expect(classified.rank).toBe(2) | ||
}) | ||
}) |
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