fase(3): crawling module domain and application
This commit is contained in:
27
src/modules/crawling/domain/value-objects/Url.ts
Normal file
27
src/modules/crawling/domain/value-objects/Url.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
import { ValueObject } from '../../../../shared/domain/ValueObject';
|
||||
import { Result, Ok, Err } from '../../../../shared/domain/Result';
|
||||
|
||||
interface UrlProps {
|
||||
value: string;
|
||||
}
|
||||
|
||||
export class Url extends ValueObject<UrlProps> {
|
||||
private constructor(props: UrlProps) {
|
||||
super(props);
|
||||
}
|
||||
|
||||
static create(raw: string): Result<Url, string> {
|
||||
if (!raw || raw.trim().length === 0) {
|
||||
return Err('URL must not be empty');
|
||||
}
|
||||
const trimmed = raw.trim();
|
||||
if (!trimmed.startsWith('http://') && !trimmed.startsWith('https://')) {
|
||||
return Err('URL must start with http:// or https://');
|
||||
}
|
||||
return Ok(new Url({ value: trimmed }));
|
||||
}
|
||||
|
||||
toString(): string {
|
||||
return this.props.value;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user