ACTIVITY DIAGRAM
- Create Short URL:
- User submits a long URL and specifies the number of days before deletion.
- The application generates a short URL and a security code.
- The application stores the long URL, short URL, security code, and expiry date in the database.
- The application returns the short URL and security code to the user.
- Edit Short URL:
- User submits the security code and the short URL they want to edit.
- The application verifies the security code and allows editing the long URL or the expiry date.
- Updates the database accordingly.
- Deactivate Short URL:
- User submits the security code and the short URL they want to deactivate.
- The application verifies the security code and marks the short URL as deactivated in the database.
- Redirect Short URL:
- When a short URL is accessed, the application checks if it is active.
- If active, it redirects to the long URL.
- If inactive, it returns an appropriate response.
- Entities:
URL
entity with attributes:id
,longUrl
,shortUrl
,expiredAt
,securityCode
,isActive
, andcreatedAt
.
- Relationships:
- User submits a
longUrl
to generate ashortUrl
. shortUrl
is associated with asecurityCode
for editing and deactivating the URL.
- User submits a
- Define a schema for the URL shortener:
Javascript
- Create Short URL:
- Accepts a long URL and number of days before deletion.
- Generates a short URL and security code.
- Returns the short URL and security code.
- POST
/shorten
: AcceptslongUrl
,expiredAt
, and possiblyuserId
. - Returns the generated
shortUrl
and asecurityCode
.
- Edit Short URL Details:
- Accepts a short URL, security code, and new long URL or expiry date.
- Updates the URL's details if the security code matches.
- PUT
/edit
: AcceptsshortUrl
,securityCode
, and the new details to update. - Returns a success or failure response.
- Deactivate Short URL:
- Accepts a short URL and security code.
- Marks the URL as deactivated if the security code matches.
- PUT
/deactivate
: AcceptsshortUrl
andsecurityCode
. - Sets
deactivated
to true and returns a success or failure response.
- Redirect Short URL:
- Redirects the user to the long URL if the short URL is active.
- Returns a message if the short URL is inactive.
- GET
/:shortUrl
: Checks if the URL is active and redirects to the long URL or returns an error.
- User Deactivation: Since only the user who created the short URL has the security code, they should be the only ones who can deactivate the URL.
- Deactivated URL Availability: If the short URL is deactivated, it should remain associated with the original user and not be available to other users. This ensures privacy and avoids potential conflicts.
LATER
- Optional user authentication
- Accessing and editing all created urls(active or inactive), by an active user by the active user.