This is the backend API repository for TurLink. TurLink is a link shortener app for the Turing community.
Frontend Repository
AI Microservice
bundle install
rails db:{drop,create,migrate,seed}
bundle exec rspec
rails s
and use http://localhost:3000
as your base urlensure you have docker installed on your local machine
run chmod +x docker_start.sh
to make script executable
run ./docker_start.sh
application should now be live at http://localhost:3001
to stop the application run docker-compose down
Rails container: docker-compose exec web bash
Rails console: docker-compose run web rails c
/api/v1/users
{
"email": "user@example.com",
"password": "password123",
"password_confirmation": "password123"
}
{
"data": {
"id": "1",
"type": "user",
"attributes": {
"email": "user@example.com",
"links": []
}
}
}
{
"errors": [
{
"status": "422",
"message": "Email has already been taken"
}
]
}
/api/v1/sessions
{
"email": "user@example.com",
"password": "password123"
}
{
"data": {
"id": "1",
"type": "user",
"attributes": {
"email": "user@example.com",
"links": [
{
"id": 1,
"original": "testlink.com",
"short": "tur.link/4a7c204baeacaf2c",
"user_id": 1,
"created_at": "2024-08-23T15:51:38.866Z",
"updated_at": "2024-08-23T15:51:38.866Z"
},
{
"id": 2,
"original": "testlink.com",
"short": "tur.link/67c758fc",
"user_id": 1,
"created_at": "2024-08-23T15:53:08.573Z",
"updated_at": "2024-08-23T15:53:08.573Z"
},
]
}
}
}
{
"errors": [
{
"message": "Invalid email or password"
}
]
}
/api/v1/users/:id/links?link={original link}
https://turlink-be-53ba7254a7c1.herokuapp.com/api/v1/users/1/links?link=testlink.com
{
"data": {
"id": "1",
"type": "link",
"attributes": {
"original": "testlink.com",
"short": "tur.link/4a7c204baeacaf2c",
"user_id": 1
}
}
}
{
"errors": [
{
"status": "unprocessable_entity",
"message": "Original can't be blank"
}
]
}
{
"errors": [
{
"status": "unprocessable_entity",
"message": "User must exist"
}
]
}
/api/v1/users/:id/links
https://turlink-be-53ba7254a7c1.herokuapp.com/api/v1/users/1/links
{
"data": {
"id": "1",
"type": "user",
"attributes": {
"email": "user@example.com",
"links": [
{
"id": 1,
"original": "testlink.com",
"short": "tur.link/4a7c204baeacaf2c",
"user_id": 1,
"created_at": "2024-08-23T15:51:38.866Z",
"updated_at": "2024-08-23T15:51:38.866Z"
},
{
"id": 2,
"original": "testlink.com",
"short": "tur.link/67c758fc",
"user_id": 1,
"created_at": "2024-08-23T15:53:08.573Z",
"updated_at": "2024-08-23T15:53:08.573Z"
},
]
}
}
}
{
"errors": [
{
"message": "Record not found"
}
]
}
/api/v1/links?short={shortened link}
https://turlink-be-53ba7254a7c1.herokuapp.com/api/v1/links?short=tur.link/4a7c204baeacaf2c
{
"data": {
"id": "1",
"type": "link",
"attributes": {
"original": "testlink.com",
"short": "tur.link/4a7c204baeacaf2c",
"user_id": 1,
"click_count": 1,
"last_click": "2024-08-28T12:34:56.789Z",
"private": false
}
}
}
{
"errors": [
{
"message": "Record not found"
}
]
}
/api/v1/links?short={shortened link}
endpoint:click_count
for that link is automatically incremented.last_click
timestamp is updated to the current time./api/v1/tags
https://turlink-be-53ba7254a7c1.herokuapp.com/api/v1/tags
{
"data": [
{
"id": "1",
"type": "tag",
"attributes": {
"name": "javascript"
}
},
{
"id": "2",
"type": "tag",
"attributes": {
"name": "react"
}
},
{
"id": "3",
"type": "tag",
"attributes": {
"name": "ruby"
}
}, ...
]
}
/api/v1/tags?link={link_id}&tag={tag_id}
OR /api/v1/tags?link={link_id}&newTag={user created tag}
https://turlink-be-53ba7254a7c1.herokuapp.com/api/v1/tags?link=1&tag=1
{
"data": {
"id": "1",
"type": "link",
"attributes": {
"original": "testlink.com",
"short": "tur.link/4a7c204baeacaf2c",
"user_id": 1,
"tags": [
{
"id": 1,
"name": "javascript",
"created_at": "2024-08-27T01:19:47.421Z",
"updated_at": "2024-08-27T01:19:47.421Z"
}
]
}
}
}
https://turlink-be-53ba7254a7c1.herokuapp.com/api/v1/tags?link=1&newTag=miscellaneous
{
"data": {
"id": "1",
"type": "link",
"attributes": {
"original": "testlink.com",
"short": "tur.link/4a7c204baeacaf2c",
"user_id": 1,
"tags": [
{
"id": 173,
"name": "miscellaneous",
"created_at": "2024-08-27T01:19:47.421Z",
"updated_at": "2024-08-27T01:19:47.421Z"
}
]
}
}
}
{
"errors": [
{
"message": "Link or Tag not found"
}
]
}
/api/v1/tags/{tag_id}?link={link_id}
https://turlink-be-53ba7254a7c1.herokuapp.com/api/v1/tags/1?link=1
{
"data": {
"id": "1",
"type": "link",
"attributes": {
"original": "testlink.com",
"short": "tur.link/4a7c204baeacaf2c",
"user_id": 1,
"tags": []
}
}
}
{
"errors": [
{
"message": "Link or Tag not found"
}
]
}
/api/v1/tags?link={link_id}
https://turlink-be-53ba7254a7c1.herokuapp.com/api/v1/tags?link=1
{
"data": {
"id": "1",
"type": "link",
"attributes": {
"original": "testlink.com",
"short": "tur.link/4a7c204baeacaf2c",
"user_id": 1,
"tags": [
{
"id": 1,
"name": "javascript",
"created_at": "2024-08-27T01:19:47.421Z",
"updated_at": "2024-08-27T01:19:47.421Z"
}
]
}
}
}
{
"errors": [
{
"message": "Link or Tag not found"
}
]
}
/api/v1/top_links
tag
to filter by a specific tag.https://turlink-be-53ba7254a7c1.herokuapp.com/api/v1/top_links
https://turlink-be-53ba7254a7c1.herokuapp.com/api/v1/top_links?tag=javascript
https://turlink-be-53ba7254a7c1.herokuapp.com/api/v1/top_links?tag=javascript,ruby
{
"data": [
{
"id": "1",
"type": "link",
"attributes": {
"original": "https://example1.com",
"short": "tur.link/abc123",
"user_id": 1,
"click_count": 100,
"last_click": "2024-08-28T12:34:56.789Z",
"tags": [
{
"id": 1,
"name": "javascript"
}
],
"private": false,
"summary": "Summary not available"
}
},
{
"id": "2",
"type": "link",
"attributes": {
"original": "https://example2.com",
"short": "tur.link/def456",
"user_id": 2,
"click_count": 75,
"last_click": "2024-08-27T10:11:12.345Z",
"tags": [
{
"id": 2,
"name": "ruby"
}
],
"private": false,
"summary": "Summary not available"
}
},
// ... (3 more link objects)
]
}
/api/v1/summary?link={short link}
https://turlink-be-53ba7254a7c1.herokuapp.com/api/v1/summary?link=tur.link/96559226
{
"data": {
"id": "6",
"type": "link",
"attributes": {
"original": "https://mod4.turing.edu/lessons/cs/arrays_stacks_queues.html",
"short": "tur.link/96559226",
"user_id": 1,
"tags": [],
"click_count": 0,
"last_click": null,
"private": false,
"summary": "1. The document outlines the curriculum for Module 4 at the Turing School of Software and Design, focusing on data structures such as Arrays, Stacks, and Queues. It includes learning goals and key topics of discussion.\n\n2. It provides detailed explanations of each data structure: Arrays, Stacks (Last-In-First-Out), and Queues (First-In-First-Out), including their background, memory usage, implementation, usage, and their pros and cons.\n\n3. Students are encouraged to practice their knowledge of these data structures through various examples and a workshop challenge, reinforcing their understanding of how these data structures operate within programming languages."
}
}
}
PATCH /api/v1/users/:user_id/links/:id/update_privacy
user_id
: The ID of the user who owns the linkid
: The ID of the link to update{
"private": "true" // or "false" to make the link public
}
https://turlink-be-53ba7254a7c1.herokuapp.com/api/v1/users/1/links/1/update_privacy
{
"message": "Privacy setting updated successfully"
}
{
"error": "Unauthorized to update this link"
}
{
"error": "User or Link not found"
}
{
"error": "Failed to update privacy setting"
}
Notes: