Skip to content

Commit 0b72084

Browse files
Merge pull request #10 from thetechnicker/9-networking-for-client
9 networking for client
2 parents 0f22052 + c977ac7 commit 0b72084

File tree

35 files changed

+2996
-3057
lines changed

35 files changed

+2996
-3057
lines changed

.github/workflows/ci.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717
fmt:
1818
defaults:
1919
run:
20-
working-directory: console-chat-event
20+
working-directory: console-chat
2121
name: fmt
2222
runs-on: ubuntu-latest
2323
steps:
@@ -34,7 +34,7 @@ jobs:
3434
clippy:
3535
defaults:
3636
run:
37-
working-directory: console-chat-event
37+
working-directory: console-chat
3838
name: clippy
3939
runs-on: ubuntu-latest
4040
permissions:
@@ -56,7 +56,7 @@ jobs:
5656
doc:
5757
defaults:
5858
run:
59-
working-directory: console-chat-event
59+
working-directory: console-chat
6060
# run docs generation on nightly rather than stable. This enables features like
6161
# https://doc.rust-lang.org/beta/unstable-book/language-features/doc-cfg.html which allows an
6262
# API be documented as only available in some specific platforms.
@@ -73,7 +73,7 @@ jobs:
7373
test:
7474
defaults:
7575
run:
76-
working-directory: console-chat-event
76+
working-directory: console-chat
7777
runs-on: ${{ matrix.os }}
7878
name: test ${{ matrix.os }}
7979
strategy:

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,7 @@
22

33
This is a simple chat service for the terminal where.
44

5-
> [!IMPORTANT]
6-
> This project is still in an early dev phase.
5+
## Overview
6+
7+
- `backend`: This folder contains the backend for this chat application.
8+
- `console-chat`: This is the current TUI chat application.

backend/app/main.py

Lines changed: 30 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,15 @@ async def login(
172172
# raise HTTPException(
173173
# status_code=status.HTTP_501_NOT_IMPLEMENTED, detail=f"{db_user}"
174174
# )
175-
elif password or username:
175+
elif username:
176+
public = PublicUser(display_name=username)
177+
user = BetterUser(
178+
username=str(uuid4()),
179+
password_hash=None,
180+
private=True,
181+
public_data=public,
182+
)
183+
elif password: # or username:
176184
raise HTTPException(
177185
status_code=status.HTTP_401_UNAUTHORIZED,
178186
detail="Incomplete login parameters",
@@ -250,6 +258,25 @@ async def register(
250258
return {"status": "sugsesfully registered"}
251259

252260

261+
@app.post("/room/{room}")
262+
async def send(
263+
room: str,
264+
message: ClientMessage, # Use the new Message model
265+
user: BetterUser = Depends(get_current_user),
266+
context: Context = Depends(get_context),
267+
):
268+
msg = ServerMessage(
269+
user=user.public_data,
270+
text=message.text,
271+
# timestamp=datetime.now(timezone.utc),
272+
type=MessageType.TEXT,
273+
)
274+
await context.v.publish(
275+
room, msg.model_dump_json()
276+
) # Use model_dump_json for serialization
277+
return {"message": f"send successful by user {user.public_data.display_name}"}
278+
279+
253280
@app.get("/room/{room}", response_model=ServerMessage)
254281
async def get(
255282
room: str,
@@ -267,27 +294,9 @@ async def get(
267294
).model_dump_json(),
268295
)
269296
return StreamingResponse(
270-
get_message(room, timeout=listen_seconds), media_type="application/json"
271-
)
272-
273-
274-
@app.post("/room/{room}")
275-
async def send(
276-
room: str,
277-
message: ClientMessage, # Use the new Message model
278-
user: BetterUser = Depends(get_current_user),
279-
context: Context = Depends(get_context),
280-
):
281-
msg = ServerMessage(
282-
user=user.public_data,
283-
text=message.text,
284-
# timestamp=datetime.now(timezone.utc),
285-
type=MessageType.TEXT,
297+
get_message(room, timeout=listen_seconds, context=context),
298+
media_type="application/json",
286299
)
287-
await context.v.publish(
288-
room, msg.model_dump_json()
289-
) # Use model_dump_json for serialization
290-
return {"message": f"send successful by user {user.public_data.display_name}"}
291300

292301

293302
async def get_message(

console-chat-event/.gitignore

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)