Skip to content

Commit 29c2a3a

Browse files
authored
Merge branch 'amfoss:master' into dev
2 parents a0bd10d + 3f7c4c2 commit 29c2a3a

File tree

8 files changed

+897
-1
lines changed

8 files changed

+897
-1
lines changed

LICENSE

Lines changed: 674 additions & 0 deletions
Large diffs are not rendered by default.

README.md

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<div align="center">
2+
<h1>Root</h1>
3+
<p>a backend to manage all club information</p>
4+
</div>
5+
6+
### Overview
7+
**Root** is a backend for managing all club related info; most other projects will be getting or publishing their data to root.
8+
9+
### Setup Instructions
10+
11+
#### Prerequisites
12+
1. Ensure you have Rust installed. Use `rustup` for easy installation.
13+
```bash
14+
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
15+
source $HOME/.cargo/env
16+
```
17+
2. Install the Shuttle CLI.
18+
```bash
19+
cargo install shuttle-cli
20+
```
21+
22+
3. Install Docker. Check [this](https://docs.docker.com/desktop/setup/install/linux/) out for instructions.
23+
24+
#### Clone the Repository
25+
```bash
26+
git clone https://github.com/amfoss/root.git
27+
cd root
28+
```
29+
30+
#### Set up Secrets
31+
Create a `Secrets.toml` file in the root directory with the secret key
32+
```
33+
ROOT_SECRET='secret_key'
34+
```
35+
36+
#### Run Locally
37+
```bash
38+
cargo shuttle run
39+
```
40+
41+
---
42+
43+
### Documentation
44+
45+
Explore the [API documentation](/docs/docs.md) for detailed information and usage guidelines.
46+
47+
---
48+
49+
### How to Contribute
50+
51+
1. Fork the repository and clone it to your local machine.
52+
2. Set up the project by following the installation instructions above.
53+
3. Identify an issue or feature you'd like to work on, and create an issue to track it.
54+
4. Develop the patch or feature, ensuring it is thoroughly tested.
55+
5. Submit a pull request, referencing the relevant issue number.
56+
57+
### License
58+
This project is licensed under GNU General Public License V3. You are welcome to adapt it, make it yours. Just make sure that you credit us too.

docs/docs.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# API Documentation
2+
3+
## Contents
4+
- [GraphQL Queries](/docs/queries.md)
5+
- [GraphQL Mutations](/docs/mutations.md)

docs/mutations.md

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
## GraphQL Mutations
2+
3+
## Contents
4+
- [addMember](#addmember)
5+
- [markAttendance](#markattendance)
6+
- [addAttendance](#addattendance)
7+
8+
---
9+
10+
### addMember
11+
Add a new member to the database.
12+
13+
#### GraphQL Mutation
14+
```graphql
15+
mutation {
16+
addMember(name: "name", email: "email", year: 2) {
17+
id
18+
name
19+
year
20+
}
21+
}
22+
```
23+
24+
#### Arguments (all required)
25+
```graphql
26+
rollno: String!
27+
name: String!
28+
hostel: String!
29+
email: String!
30+
sex: String!
31+
year: Int!
32+
macaddress: String!
33+
discordId: String
34+
```
35+
36+
**Note:** The `year` field represents the members's current college year
37+
- `1` for first-year
38+
- `2` for second-year
39+
- `3` for third-year
40+
- `4` for fourth-year
41+
42+
---
43+
44+
### markAttendance
45+
Record attendance for a member.
46+
47+
#### GraphQL Mutation
48+
```graphql
49+
mutation {
50+
markAttendance(id: 0, date: "YYYY-MM-DD", isPresent: true, hmacSignature: "hmac_signature") {
51+
id
52+
date
53+
isPresent
54+
hmacSignature
55+
}
56+
}
57+
```
58+
59+
#### Arguments (all required)
60+
```graphql
61+
id: Int!
62+
date: NaiveDate!
63+
isPresent: Boolean!
64+
hmacSignature: String!
65+
```
66+
67+
---
68+
69+
### addAttendance
70+
Initiate attendance records for the day (*used internally*).
71+
72+
#### GraphQL Mutation
73+
```graphql
74+
mutation {
75+
addAttendance(id: 0, date: "YYYY-MM-DD", timein: "%H:%M:%S%.f", timeout: "%H:%M:%S%.f", isPresent:true) {
76+
id
77+
date
78+
isPresent
79+
hmacSignature
80+
}
81+
}
82+
```
83+
84+
#### Arguments (all required)
85+
```graphql
86+
id: Int!
87+
date: NaiveDate!
88+
timein: NaiveTime!
89+
timeout: NaiveTime!
90+
isPresent: Boolean!
91+
```

docs/queries.md

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
## GraphQL Queries
2+
3+
## Contents
4+
- [getMember](#getmember)
5+
- [getAttendance](#getattendance)
6+
7+
---
8+
9+
### getMember
10+
Retrieve all the members from the database.
11+
12+
#### GraphQL Query
13+
```graphql
14+
query {
15+
getMember {
16+
id
17+
name
18+
email
19+
}
20+
}
21+
```
22+
23+
#### Fields
24+
```graphql
25+
id: Int!
26+
rollno: String!
27+
name: String!
28+
hostel: String!
29+
email: String!
30+
sex: String!
31+
year: Int!
32+
macaddress: String!
33+
discordId: String!
34+
```
35+
36+
---
37+
38+
### getAttendance
39+
Retrieve attendance records for a specific date.
40+
41+
#### GraphQL Query
42+
```graphql
43+
query {
44+
getAttendance(date: "YYYY-MM-DD") {
45+
id
46+
date
47+
timein
48+
timeout
49+
isPresent
50+
}
51+
}
52+
```
53+
54+
#### Arguments
55+
- `date` (required): A date in the format `YYYY-MM-DD`.
56+
57+
#### Fields
58+
```graphql
59+
id: Int!
60+
date: NaiveDate!
61+
timein: NaiveTime!
62+
timeout: NaiveTime!
63+
isPresent: Boolean!
64+
```
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ALTER TABLE Member ADD COLUMN discord_id TEXT;

src/db/member.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,5 @@ pub struct Member {
1414
pub sex: String,
1515
pub year: i32,
1616
pub macaddress: String,
17+
pub discord_id: Option<String>,
1718
}

src/graphql/mutations.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,15 @@ impl MutationRoot {
2929
sex: String,
3030
year: i32,
3131
macaddress: String,
32+
discord_id: String,
3233

3334
) -> Result<Member, sqlx::Error> {
3435
let pool = ctx.data::<Arc<PgPool>>().expect("Pool not found in context");
3536

3637

3738

3839
let member = sqlx::query_as::<_, Member>(
39-
"INSERT INTO Member (rollno, name, hostel, email, sex, year, macaddress) VALUES ($1, $2, $3, $4, $5, $6, $7) RETURNING *"
40+
"INSERT INTO Member (rollno, name, hostel, email, sex, year, macaddress, discord_id) VALUES ($1, $2, $3, $4, $5, $6, $7, $8) RETURNING *"
4041
)
4142
.bind(rollno)
4243
.bind(name)
@@ -45,6 +46,7 @@ impl MutationRoot {
4546
.bind(sex)
4647
.bind(year)
4748
.bind(macaddress)
49+
.bind(discord_id)
4850
.fetch_one(pool.as_ref())
4951
.await?;
5052

0 commit comments

Comments
 (0)