Skip to content

Commit e230a05

Browse files
authored
Patch up oversights (#46)
* fix: add missing id to response of /users endpoint * docs: more concise and better documented readme
1 parent 1633697 commit e230a05

File tree

4 files changed

+121
-127
lines changed

4 files changed

+121
-127
lines changed

readme.md

Lines changed: 117 additions & 125 deletions
Original file line numberDiff line numberDiff line change
@@ -1,201 +1,193 @@
1-
> Warning: You should probably not use this in production or with any data that is sensitive as the authentication
2-
> system
3-
> is made very amateurish.
1+
# Cira - A Minimalistic Ticket System Backend
42

5-
# Cira - a minimalistic ticket system backend
3+
Cira is a minimalistic backend for managing tickets in small projects. It provides essential APIs to handle ticket creation, updates, deletion, labeling, assignment, and filtering.
64

7-
Cira is a minimalistic ticket system backend for small and simple projects.
8-
You could even use it as an overcomplicated todo app.
5+
## Overview
6+
Cira offers foundational API functionalities for managing tickets including:
7+
- Creation and deletion of tickets
8+
- Updating existing tickets
9+
- Grouping tickets by labels
10+
- Assigning tickets to users
11+
- Filtering tickets by various criteria
12+
- User authentication via bearer tokens
913

10-
The only thing it does is to provide an api.
11-
The rest is up to you.
12-
Create a native desktop or smartphone app, or keep in the web as most ticket boards to.
13-
You decide, the possibilities are endless.
14+
## Setup & Usage
1415

15-
## Features
16+
### Prerequisites
17+
Ensure you have installed the following tools:
18+
- [Rust](https://rust-lang.org)
19+
- [Git](https://git-scm.com/)
20+
- [Diesel](https://diesel.rs)
21+
- [SQLite](https://www.sqlite.org/)
1622

17-
Cira gives you the foundation to:
23+
### Running Locally
1824

19-
- create and delete tickets
20-
- update tickets after creation
21-
- group tickets by labels
22-
- assign tickets to users
23-
- filter tickets by labels, assignee, status and labels
24-
- authentication with bearer tokens
25+
1. **Clone the repository**:
26+
```bash
27+
git clone https://github.com/CodeF0x/cira.git
28+
cd cira
29+
```
30+
2. **Install Diesel CLI for SQLite** and set up database:
31+
```bash
32+
cargo install diesel_cli --no-default-features --features "sqlite"
33+
diesel setup
34+
```
35+
3. **Build and run**:
36+
```bash
37+
cargo build --release
38+
./target/release/cira
39+
```
2540

26-
## Run Locally
41+
**Note**: Make sure to update both `HASH_SECRET` and `JWT_SECRET` in the `.env` file with cryptographically secure values!
2742

28-
Simply clone the repository, set up the database and compile the application locally.
29-
Then start it.
30-
You are required to have installed: [the rust programming language](https://rust-lang.org),
31-
[git](https://git-scm.com/), [diesel](https://diesel.rs), [sqlite](https://www.sqlite.org/)
43+
### Troubleshooting
3244

33-
```bash
34-
git clone https://github.com/CodeF0x/cira.git
35-
cd cira
36-
cargo install diesel_cli --no-default-features --features "sqlite"
37-
diesel setup
38-
cargo build --release
39-
./target/release/cira
40-
```
41-
42-
If you're on Debian and get `error: linking with 'cc' failed: exit status: 1`, make sure to have `build-essential`
43-
installed. Same goes for other distros (build-essential might be called different / have an equivalent).
44-
45-
If this error accours while installing `diesel_cli`, try `sudo apt install -y libsqlite3-dev libpq-dev libmysqlclient-dev`.
46-
47-
There are some default values set in the .env file, you can adjust them as you wish.
48-
Keep in mind to change the code as well.
49-
> ⚠️ Be sure to update both `HASH_SECRET` and `JWT_SECRET` to something cryptographically safe!
50-
51-
If everything went well and there is no output after running the last command, cira is listening on port `8080`.
52-
53-
You can also launch it in a screen or in a container, so it runs without an active shell session.
45+
If you encounter errors during installation or setup:
46+
- On Debian, if you get a `linking with 'cc' failed: exit status: 1` error, ensure `build-essential` is installed.
47+
- For issues while installing Diesel CLI, try running: `sudo apt install -y libsqlite3-dev libpq-dev libmysqlclient-dev`.
5448

55-
## Running Tests
49+
---
5650

57-
To run tests, set up a fake database that is independent of the actual production database.
58-
You need to have installed [diesel](https://diesel.rs), [sqlite](https://www.sqlite.org/) and [rust](https://rust-lang.org).
51+
## API Documentation
5952

60-
```bash
61-
diesel migration run --database-url test-backend.sqlite
62-
cargo test
63-
```
53+
### General Information
54+
- **Authorization**: Every endpoint requires a Bearer Token for authentication except the endpoints related to user login and signup (`/api/login` and `/api/signup`).
6455

65-
## API Reference
56+
### Ticket Management
6657

67-
#### Create a new ticket
58+
#### Create a New Ticket
6859

6960
```http
70-
POST /api/tickets
61+
POST /api/tickets
7162
```
7263

73-
Your payload must be valid JSON and contain the following properties:
64+
**Payload**:
7465

7566
| Property | Type | Description |
7667
|:----------------|:----------------|:------------------------------------------------------------------------------|
77-
| `title` | `string` | **Required**. The title of your ticket |
78-
| `body` | `string` | **Required**. The body of your ticket |
79-
| `labels` | `Array<string>` | **Required**. Labels of your ticket |
80-
| `status` | `string` | **Required**. The status of your ticket (set it to "Open") |
81-
| `assigned_user` | `id \| null` | **Optional**. A user the ticket should be assigned to. Can be omitted or null |
68+
| `title` | `string` | **Required**. Title of the ticket |
69+
| `body` | `string` | **Required**. Body content of the ticket |
70+
| `labels` | `Array<string>` | **Required**. Labels for categorizing the ticket |
71+
| `status` | `string` | **Required**. Status (e.g., 'Open') |
72+
| `assigned_user` | `id \| null` | **Optional**. ID of user assigned to this ticket or `null`. |
73+
74+
**Status Options**:
75+
76+
- Open
77+
- Closed
8278

83-
Possible Status options:
79+
**Label Options**:
8480

85-
- `Open`
86-
- `Closed`
81+
- Feature
82+
- Bug
83+
- WontFix
84+
- Done
85+
- InProgress
8786

88-
Possible Label options:
87+
#### Get All Tickets
8988

90-
- `Feature`
91-
- `Bug`
92-
- `WontFix`
93-
- `Done`
94-
- `InProgress`
89+
```http
90+
GET /api/tickets
91+
```
9592

96-
Creates a new ticket and returns it.
93+
Retrieves all tickets.
9794

98-
#### Get tickets
95+
#### Delete a Ticket
9996

10097
```http
101-
GET /api/tickets
98+
DELETE /api/tickets/{id}
10299
```
103100

104-
Get all tickets.
101+
**Path Parameters**:
102+
103+
| Parameter | Type | Description |
104+
|:----------|:-------|:-----------------------------------|
105+
| `id` | number | **Required**. ID of the ticket |
105106

106-
#### Delete ticket
107+
#### Edit a Ticket
107108

108109
```http
109-
DELETE /api/tickets/{id}
110+
PUT /api/tickets/{id}
110111
```
111112

112-
URL parameters:
113+
**Path Parameters**: (Same as Delete Ticket)
113114

114-
| Property | Type | Description |
115-
|:---------|:---------|:-----------------------------------|
116-
| `id` | `number` | **Required**. The id of the ticket |
115+
**Payload**: (Same structure as Create a New Ticket)
117116

118-
Deletes a ticket and returns it.
117+
### User Authentication
119118

120-
#### Edit a ticket
119+
#### Sign Up
121120

122121
```http
123-
PUT /api/tickets/{id}
122+
POST /api/signup
124123
```
125124

126-
URL parameters:
125+
**Payload**:
127126

128-
| Property | Type | Description |
129-
|:---------|:---------|:-----------------------------------|
130-
| `id` | `number` | **Required**. The id of the ticket |
127+
| Property | Type | Description |
128+
|:---------------|:-------|:---------------------------------------|
129+
| `display_name` | string | **Required**. Display name |
130+
| `email` | string | **Required**. Email address |
131+
| `password` | string | **Required**. Password |
131132

132-
Your payload must be valid JSON and contain the following properties:
133+
#### Login
133134

134-
| Property | Type | Description |
135-
|:----------------|:----------------|:------------------------------------------------------------------------------|
136-
| `title` | `string` | **Required**. The title of your ticket |
137-
| `body` | `string` | **Required**. The body of your ticket |
138-
| `labels` | `Array<string>` | **Required**. Labels of your ticket |
139-
| `status` | `string` | **Required**. The status of your ticket (set it to "Open") |
140-
| `assigned_user` | `id \| null` | **Optional**. A user the ticket should be assigned to. Can be omitted or null |
135+
```http
136+
POST /api/login
137+
```
141138

142-
Possible Status options:
139+
**Payload**:
143140

144-
- `Open`
145-
- `Closed`
141+
| Property | Type | Description |
142+
|:----------|:-------|:---------------------------------------|
143+
| `email` | string | **Required**. Email address |
144+
| `password` | string | **Required**. Password |
146145

147-
Possible Label options:
146+
Returns a bearer token upon successful login.
148147

149-
- `Feature`
150-
- `Bug`
151-
- `WontFix`
152-
- `Done`
153-
- `InProgress`
148+
#### Logout
154149

155-
Updates a ticket and returns it.
150+
```http
151+
POST /api/logout
152+
```
156153

157-
#### Sign up
154+
Logs out the user by invalidating their current token.
158155

159-
```
160-
POST /api/signup
161-
```
156+
### User Management
162157

163-
Your payload must be valid JSON and contain the following properties:
158+
#### Get All Users
164159

165-
| Property | Type | Description |
166-
|:---------------|:---------|:---------------------------------------|
167-
| `display_name` | `string` | **Required**. The user's display name |
168-
| `email` | `string` | **Required**. The user's email address |
169-
| `password` | `string` | **Required**. The user's password |
160+
```http
161+
GET /api/users
162+
```
170163

171-
Create a new user and return it.
164+
Retrieves all users in a simplified format (`id`, `email`, `display_name`).
172165

173-
#### Filter tickets
166+
### Filter Tickets
174167

175168
```http
176-
POST /api/filter
169+
POST /api/filter
177170
```
178171

179-
Your payload must be valid JSON and contain the following properties:
172+
**Payload**:
180173

181174
| Property | Type | Description |
182175
|:----------------|:------------------------|:----------------------------------------------------------------|
183176
| `title` | `string \| null` | **Optional**. Title to search for. Can be omitted or null |
184177
| `labels` | `Array<string> \| null` | **Optional**. Labels to search for. Can be omitted or null |
185178
| `status` | `string \| null` | **Optional**. Status to search for. Can be omitted or null |
186-
| `assigned_user` | `id \| null` | **Optional**. Assignee id to search for. Can be omitted or null |
179+
| `assigned_user` | `id \| null` | **Optional**. Assignee ID to search for. Can be omitted or null |
180+
181+
Returns filtered results.
187182

188-
Lets you filter for tickets and return results.
183+
---
189184

190185
## Contributing
191186

192-
Contributions are always welcome!
187+
Contributions in any form (issues, PRs, feedback) are welcome!
193188

194-
Either by submitting issues, pull requests or just general constructive feedback in the form of issues,
195-
emails or direct messages on Telegram.
189+
---
196190

197191
## License
198192

199193
[MIT](https://choosealicense.com/licenses/mit/)
200-
201-
MIT or "I do not care what you do with this as long as you don't claim it to be your own"-license.

src/database.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use crate::schema::sessions::token;
1111
use crate::schema::tickets::dsl::tickets;
1212
use crate::schema::tickets::{body, id, labels, last_modified, status, title};
1313
use crate::schema::users::dsl::users;
14-
use crate::schema::users::{display_name, email};
14+
use crate::schema::users::{display_name, email, id as user_id};
1515
use actix_web::web::Json;
1616
use argonautica::Hasher;
1717
use diesel::{Connection, ExpressionMethods, QueryDsl, QueryResult, RunQueryDsl, SqliteConnection};
@@ -145,7 +145,7 @@ pub fn get_user_by_email(
145145

146146
pub fn get_all_users(connection: &mut SqliteConnection) -> QueryResult<Vec<DisplayUser>> {
147147
users
148-
.select((email, display_name))
148+
.select((user_id, email, display_name))
149149
.load::<DisplayUser>(connection)
150150
}
151151

src/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -786,6 +786,7 @@ mod tests {
786786

787787
assert_eq!(response[0].email, "[email protected]");
788788
assert_eq!(response[0].display_name, "user");
789+
assert_eq!(response[0].id, 1);
789790
}
790791
}
791792

src/models.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ pub struct DataBaseUser {
103103

104104
#[derive(Serialize, Deserialize, Debug, Queryable)]
105105
pub struct DisplayUser {
106+
pub id: i32,
106107
pub email: String,
107108
pub display_name: String,
108109
}

0 commit comments

Comments
 (0)