-
Notifications
You must be signed in to change notification settings - Fork 0
feat!: SharedKernel StudentIdの実装 #87
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| export * from "./base"; | ||
| export * from "./exceptions"; | ||
| export * from "./aggregates"; | ||
| export * from "./shared"; |
This file contains hidden or 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 { ValueObject } from "#domain/base/ValueObject"; | ||
| import { InvalidStudentIdException } from "#domain/exceptions"; | ||
|
|
||
| /** | ||
| * 学籍番号 | ||
| * | ||
| * 2つのフォーマットに対応する: | ||
| * - 数字8桁(例: 70312031) | ||
| * - 数字3桁 + アルファベット1文字 + 数字4桁(例: 725A1061) | ||
| * | ||
| * 2025年度入学者から英字を含む形式に変更された。 | ||
| * アルファベットは大文字に正規化して保持する。 | ||
| */ | ||
| export class StudentId extends ValueObject<string> { | ||
| private static readonly NUMERIC_ONLY = /^[0-9]{8}$/; | ||
| private static readonly ALPHANUMERIC = /^[0-9]{3}[A-Z][0-9]{4}$/; | ||
|
|
||
| private constructor(value: string) { | ||
| super(value); | ||
| } | ||
|
|
||
| static fromString(value: string): StudentId { | ||
| return new StudentId(value.trim().toUpperCase()); | ||
| } | ||
|
KinjiKawaguchi marked this conversation as resolved.
|
||
|
|
||
| protected validate(): void { | ||
| const isValid = | ||
| StudentId.NUMERIC_ONLY.test(this.value) || | ||
| StudentId.ALPHANUMERIC.test(this.value); | ||
| if (!isValid) { | ||
| throw new InvalidStudentIdException(this.value); | ||
| } | ||
| } | ||
|
KinjiKawaguchi marked this conversation as resolved.
|
||
| } | ||
This file contains hidden or 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 @@ | ||
| export * from "./StudentId"; |
|
KinjiKawaguchi marked this conversation as resolved.
|
This file contains hidden or 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 hidden or 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,77 @@ | ||
| import { describe, expect, it } from "vitest"; | ||
| import { InvalidStudentIdException } from "#domain/exceptions"; | ||
| import { StudentId } from "#domain/shared/StudentId"; | ||
|
|
||
| describe("StudentId", () => { | ||
| describe("fromString", () => { | ||
| it("旧形式(8桁数字)の学籍番号を生成できる", () => { | ||
| const id = StudentId.fromString("70312031"); | ||
| expect(id.getValue()).toBe("70312031"); | ||
| }); | ||
|
|
||
| it("新形式(3桁数字+英字+4桁数字)の学籍番号を生成できる", () => { | ||
| const id = StudentId.fromString("725A1061"); | ||
| expect(id.getValue()).toBe("725A1061"); | ||
| }); | ||
|
|
||
| it("小文字の英字を大文字に正規化する", () => { | ||
| const id = StudentId.fromString("725a1061"); | ||
| expect(id.getValue()).toBe("725A1061"); | ||
| }); | ||
|
|
||
| it("前後の空白をトリムする", () => { | ||
| const id = StudentId.fromString(" 70312031 "); | ||
| expect(id.getValue()).toBe("70312031"); | ||
| }); | ||
| }); | ||
|
|
||
| describe("バリデーション", () => { | ||
| it("7桁の数字は無効", () => { | ||
| expect(() => StudentId.fromString("7031203")).toThrow( | ||
| InvalidStudentIdException, | ||
| ); | ||
| }); | ||
|
|
||
| it("9桁の数字は無効", () => { | ||
| expect(() => StudentId.fromString("703120310")).toThrow( | ||
| InvalidStudentIdException, | ||
| ); | ||
| }); | ||
|
|
||
| it("空文字は無効", () => { | ||
| expect(() => StudentId.fromString("")).toThrow(InvalidStudentIdException); | ||
| }); | ||
|
|
||
| it("英字のみは無効", () => { | ||
| expect(() => StudentId.fromString("ABCDEFGH")).toThrow( | ||
| InvalidStudentIdException, | ||
| ); | ||
| }); | ||
|
|
||
| it("新形式で英字が2文字あると無効", () => { | ||
| expect(() => StudentId.fromString("72AB1061")).toThrow( | ||
| InvalidStudentIdException, | ||
| ); | ||
| }); | ||
|
|
||
| it("新形式で英字の位置が異なると無効", () => { | ||
| expect(() => StudentId.fromString("7A251061")).toThrow( | ||
| InvalidStudentIdException, | ||
| ); | ||
| }); | ||
| }); | ||
|
|
||
| describe("equals", () => { | ||
| it("同じ学籍番号は等しい", () => { | ||
| const a = StudentId.fromString("725A1061"); | ||
| const b = StudentId.fromString("725a1061"); | ||
| expect(a.equals(b)).toBe(true); | ||
| }); | ||
|
|
||
| it("異なる学籍番号は等しくない", () => { | ||
| const a = StudentId.fromString("725A1061"); | ||
| const b = StudentId.fromString("70312031"); | ||
| expect(a.equals(b)).toBe(false); | ||
| }); | ||
| }); | ||
| }); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.