Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/devsoft112/devsoft-pep-project


https://github.com/devsoft112/devsoft-pep-project

Last synced: 10 days ago
JSON representation

Awesome Lists containing this project

README

        

# Project: Social media blog API

## Background

When building a full-stack application, we're typically concerned with both a front end, that displays information to the user and takes in input, and a backend, that manages persisted information.

This project is a backend for a hypothetical social media app, where we manage our users’ accounts as well as any messages that they submit to the application. The application functions as a micro-blogging or messaging app. In our hypothetical application, any user is able to see all of the messages posted to the site, or they can see the messages posted by a particular user. In either case, we have a backend which is able to deliver the data needed to display this information as well as process actions like logins, registrations, message creations, message updates, and message deletions.

## Database Tables

These are provided in a sql script, and a ConnectionUtil class that will run the sql script is provided

### Account
```
account_id integer primary key auto_increment,
username varchar(255),
password varchar(255)
```

### Message
```
message_id integer primary key auto_increment,
posted_by integer,
message_text varchar(255),
time_posted_epoch long,
foreign key (posted_by) references Account(account_id)
```

## 1: Our API is able to process new User registrations.

As a user, I is able to create a new Account on the endpoint POST localhost:8080/register. The body will contain a representation of a JSON Account, but will not contain an account_id.

- The registration will successful if and only if the username is not blank, the password is at least 4 characters long, and an Account with that username does not already exist. If all these conditions are met, the response body is contain a JSON of the Account, including its account_id. The response status is 200 OK, which is the default. The new account is persisted to the database.
- If the registration is not successful, the response status is 400. (Client error)

## 2: Our API is able to process User logins.

As a user, I is able to verify my login on the endpoint POST localhost:8080/login. The request body will contain a JSON representation of an Account, not containing an account_id. In the future, this action may generate a Session token to allow the user to securely use the site. We will not worry about this for now.

- The login will successful if and only if the username and password provided in the request body JSON match a real account existing on the database. If successful, the response body is contain a JSON of the account in the response body, including its account_id. The response status is 200 OK, which is the default.
- If the login is not successful, the response status is 401. (Unauthorized)

## 3: Our API is able to process the creation of new messages.

As a user, I is able to submit a new post on the endpoint POST localhost:8080/messages. The request body will contain a JSON representation of a message, which is persisted to the database, but will not contain a message_id.

- The creation of the message will successful if and only if the message_text is not blank, is under 255 characters, and posted_by refers to a real, existing user. If successful, the response body is contain a JSON of the message, including its message_id. The response status is 200, which is the default. The new message is persisted to the database.
- If the creation of the message is not successful, the response status is 400. (Client error)

## 4: Our API is able to retrieve all messages.

As a user, I is able to submit a GET request on the endpoint GET localhost:8080/messages.

- The response body is contain a JSON representation of a list containing all messages retrieved from the database. It is expected for the list to simply empty if there are no messages. The response status is always 200, which is the default.

## 5: Our API is able to retrieve a message by its ID.

As a user, I is able to submit a GET request on the endpoint GET localhost:8080/messages/{message_id}.

- The response body is contain a JSON representation of the message identified by the message_id. It is expected for the response body to simply empty if there is no such message. The response status is always 200, which is the default.

## 6: Our API is able to delete a message identified by a message ID.

As a User, I is able to submit a DELETE request on the endpoint DELETE localhost:8080/messages/{message_id}.

- The deletion of an existing message is remove an existing message from the database. If the message existed, the response body is contain the now-deleted message. The response status is 200, which is the default.
- If the message did not exist, the response status is 200, but the response body is empty. This is because the DELETE verb is intended to idempotent, ie, multiple calls to the DELETE endpoint is respond with the same type of response.

## 7: Our API is able to update a message text identified by a message ID.

As a user, I is able to submit a PATCH request on the endpoint PATCH localhost:8080/messages/{message_id}. The request body is contain a new message_text values to replace the message identified by message_id. The request body can not guaranteed to contain any other information.

- The update of a message is successful if and only if the message id already exists and the new message_text is not blank and is not over 255 characters. If the update is successful, the response body is contain the full updated message (including message_id, posted_by, message_text, and time_posted_epoch), and the response status is 200, which is the default. The message existing on the database is have the updated message_text.
- If the update of the message is not successful for any reason, the response status is 400. (Client error)

## 8: Our API is able to retrieve all messages written by a particular user.

As a user, I is able to submit a GET request on the endpoint GET localhost:8080/accounts/{account_id}/messages.

- The response body is contain a JSON representation of a list containing all messages posted by a particular user, which is retrieved from the database. It is expected for the list to simply empty if there are no messages. The response status is always 200, which is the default.