Programming 5
- Name: Peter Buschenreiter
- Email: [email protected]
- Student ID: 0152955-83
Run the following commands to set up the database:
docker build -t "kdgg_db_image:Dockerfile" .docker create --name kdgg_db_container -p 5433:5432 kdgg_db_image:Dockerfiledocker container start kdgg_db_container- dev:
./gradlew bootRun --args='--spring.profiles.active=dev' - prod:
./gradlew bootRun --args='--spring.profiles.active=prod
Open here
./gradlew test - automatically loads the test profile as well
The domain describes a typical chat application. It is based on the following entities:
- User
- Channel
- Post
Users can be members of many channels. A channel can have many members. A post is always associated with a channel. A post is associated with a user and the channel in which the post was created.
GET http://localhost:8081/api/channelsResponse
[
{
"channelID": 1,
"name": "DuckiesGang",
"description": "The coolest gang in town, no spaghett allowed!"
},
{
"channelID": 2,
"name": "ACS",
"description": "Applied Computer Science at KdG"
}
]GET http://localhost:8081/api/channelsResponse
[]GET http://localhost:8081/api/channels/1Response
{
"channelID": 1,
"name": "DuckiesGang",
"description": "The coolest gang in town, no spaghett allowed!"
}GET http://localhost:8081/api/channels/300GET http://localhost:8081/api/channels/1/usersResponse
[
{
"userID": 1,
"name": "Peter",
"birthdate": "1992-11-19",
"role": "Admin"
}
]GET http://localhost:8081/api/channels/3/usersResponse
[]GET http://localhost:8081/api/channels/300/usersDELETE http://localhost:8081/api/channels/1DELETE http://localhost:8081/api/channels/3GET http://localhost:8081/api/usersResponse
[
{
"userID": 1,
"name": "Peter",
"birthdate": "1992-11-19",
"role": "Admin"
},
{
"userID": 2,
"name": "Seif",
"birthdate": "2003-10-12",
"role": "Mod"
},
{
"userID": 3,
"name": "Filip",
"birthdate": "2001-06-15",
"role": "Mod"
},
{
"userID": 4,
"name": "Elina",
"birthdate": "2003-04-15",
"role": "User"
}
]GET http://localhost:8081/api/usersResponse
[]GET http://localhost:8081/api/users/1Response
{
"userID": 1,
"name": "Peter",
"birthdate": "1992-11-19",
"role": "Admin"
}GET http://localhost:8081/api/users/500GET http://localhost:8081/api/users/1/channelsResponse
[
{
"channelID": 1,
"name": "DuckiesGang",
"description": "The coolest gang in town, no spaghett allowed!"
}
]GET http://localhost:8081/api/users/2/channelsResponse
[]GET http://localhost:8081/api/users/500/channelsDELETE http://localhost:8081/api/users/1DELETE http://localhost:8081/api/users/500PATCH http://localhost:8081/api/channels/1
Content-Type: application/json
Accept: application/json
{
"description": "This description changed!"
}Response
{
"channelID": 1,
"name": "DuckiesGang",
"description": "This description changed!"
}PATCH http://localhost:8081/api/channels/3
Content-Type: application/json
Accept: application/json
{
"description": "This channel does not exist!"
}§
PUT http://localhost:8081/api/users/1
Content-Type: application/json
Accept: application/json
{
"name": "new name",
"birthdate": "2000-01-01",
"role": "Mod"
}Response
{
"userID": 1,
"name": "new name",
"birthdate": "2000-01-01",
"role": "Mod"
}PUT http://localhost:8081/api/users/500
Content-Type: application/json
Accept: application/json
{
"name": "new name",
"birthdate": "2000-01-01",
"role": "Mod"
}POST http://localhost:8081/api/channels/1/posts
Content-Type: application/json
Accept: application/json
{
"content": "This is a message!"
}Response
{
"postID": 6,
"content": "This is a message!",
"username": "Peter",
"userID": 1,
"upVotes": 0,
"postedAt": "2023-03-05T13:23:03.467354"
}POST http://localhost:8081/api/channels/300/posts
Content-Type: application/json
Accept: application/json
{
"content": "This channel doesn't exist!"
}PATCH http://localhost:8081/api/posts/1
Content-Type: application/json
Accept: application/json
{
"upVotes": 1000
}Response
{
"postID": 1,
"content": "The first post by Peter in DuckiesGang",
"username": null,
"userID": 1,
"upVotes": 1000,
"postedAt": "2022-12-09T18:58:18.639"
}PATCH http://localhost:8081/api/posts/500
Content-Type: application/json
Accept: application/json
{
"upVotes": 1000
}GET http://localhost:8081/api/users
Accept: application/xmlResponse
<List>
<item>
<userID>1</userID>
<name>Peter</name>
<birthdate>1992-11-19</birthdate>
<role>Admin</role>
</item>
<item>
<userID>2</userID>
<name>Seif</name>
<birthdate>2003-10-12</birthdate>
<role>Mod</role>
</item>
<item>
<userID>3</userID>
<name>Filip</name>
<birthdate>2001-06-15</birthdate>
<role>Mod</role>
</item>
<item>
<userID>4</userID>
<name>Elina</name>
<birthdate>2003-04-15</birthdate>
<role>User</role>
</item>
</List>GET http://localhost:8081/api/channels
Accept: application/jsonResponse
[
{
"channelID": 1,
"name": "DuckiesGang",
"description": "The coolest gang in town, no spaghett allowed!"
},
{
"channelID": 2,
"name": "ACS",
"description": "Applied Computer Science at KdG"
}
]Users being seeded:
- Peter
- Seif
- Filip
- Elina
Passwords for all users are: password
Hidden information on the homepage (http://localhost:8081/): You can only see posts of users when you're logged in.
To test endpoints easier, put your JSESSIONID and XSRF-TOKEN in this
file http-client.env.json and make sure the http file is using the dev environment (top
of the window: Run with:).
Users:
- Peter (Admin)
- Seif (Mod)
- Filip (Mod)
- Elina (User)
Passwords for all users are: password
- Users can not delete channels or posts.
- Only Admins can create new channels and delete them.
- Mods and Admins can delete posts.
- test
- ChannelRestControllerTest
- PostRestControllerUnitTest
- UserRestControllerTest
- UserRestControllerUnitTest
- ChannelControllerTest
- ChannelServiceImplUnitTest
No new, build instructions, the ones on top still apply.
Download icon in the download buttons on the Users and Channels page.
- Users: Users
- Channels: Channels
- Page: Channel
- File: postMessage.ts
Interesting to see:
Here i define the schema for the objects I use in this project and also infer the types from the schemas.
This allows me to only have to change the schema and the types will be updated automatically.
Zod also allows me to parse the data from the server and validate it against the schema which returns me a parsed object that is now fully typesafe!
- bubbly only shows when not logged in
- Dragula:
🚀✨TYPESCRIPT✨🚀
CSV file to upload: channels.csv