Skip to content

Commit

Permalink
show how many users are active
Browse files Browse the repository at this point in the history
  • Loading branch information
lbernhard95 committed Oct 31, 2024
1 parent 61fddf1 commit d37ab30
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 19 deletions.
17 changes: 9 additions & 8 deletions schafkopf/api/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from fastapi import FastAPI

from schafkopf.api.models import SubscribeRequest, SubscribeResponse, PollResponse
from schafkopf.api.models import SubscribeRequest, SubscribeResponse, PollResponse, SubscribeCountResponse
from schafkopf.core.dynamodb import email_table, poll_table

app = FastAPI(
Expand All @@ -12,13 +12,6 @@
)


@app.get(
"/"
)
def hello() -> str:
return "Hello World"


@app.post("/subscribe")
def subscribe_to_schafkopf_rounds(req: SubscribeRequest) ->SubscribeResponse:
import boto3
Expand All @@ -27,6 +20,14 @@ def subscribe_to_schafkopf_rounds(req: SubscribeRequest) ->SubscribeResponse:
return SubscribeResponse(email=req.email)


@app.get("/subscribers/count")
def get_subscriber_count() -> SubscribeCountResponse:
import boto3
dynamodb = boto3.resource("dynamodb")
return SubscribeCountResponse(
count=email_table.count(dynamodb)
)

@app.get("/poll")
def get_poll() -> PollResponse:
import boto3
Expand Down
2 changes: 2 additions & 0 deletions schafkopf/api/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ def to_email_item(self) -> EmailItem:
class SubscribeResponse(BaseModel):
email: str

class SubscribeCountResponse(BaseModel):
count: int

class PollResponse(BaseModel):
bitpoll_link: str
Expand Down
4 changes: 4 additions & 0 deletions schafkopf/core/dynamodb/email_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ def load_all_mails(dynamodb) -> List[str]:
registered = [i.email for i in load_all(dynamodb)]
return list(set(registered + [env.get_gmail_sender_address()]))

def count(dynamodb) -> int:
table = dynamodb.Table("schafkopf_emails")
item_count = table.item_count
return item_count

def load_all(dynamodb) -> List[EmailItem]:
try:
Expand Down
32 changes: 22 additions & 10 deletions web/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import {Stack, Paper, Typography, Divider } from '@mui/material';
import { OpenAPI } from './client';
import React, {useEffect, useState } from 'react';
import {Stack, Paper, Typography } from '@mui/material';
import { OpenAPI, SubscribeCountResponse, getSubscriberCountSubscribersCountGet } from './client';
import EmailSubscribe from './pages/EmailSubscribe';
import { createTheme, ThemeProvider } from '@mui/material/styles';
import { CssBaseline } from '@mui/material';
Expand All @@ -23,22 +23,34 @@ const theme = createTheme({
OpenAPI.BASE = process.env.REACT_APP_API_URL!;

const App: React.FC = () => {

const [memberCount, setMemberCount] = useState<SubscribeCountResponse | undefined>()
useEffect(() => {
getSubscriberCountSubscribersCountGet()
.then(d => setMemberCount(d))
.catch(e => console.log(e))
}, []);
return (
<ThemeProvider theme={theme}>
<Paper elevation={3} sx={{ maxWidth: 1000, height: '80vh', margin: 'auto', marginTop: "15px", padding: '20px' }}>
<Stack spacing={2}
alignItems="center"
justifyContent="center"
sx={{ height: '100%' }} >
<Typography variant="h4" component="h1" gutterBottom>
alignItems="center"
justifyContent="center" >
<CssBaseline/>
<Typography variant="h4" component="h1" gutterBottom={false}>
[at] Schafkopf Group
</Typography>
<CssBaseline/>
<Typography style={{ minHeight: '1em' }}>
{memberCount !== undefined ? `Already ${memberCount.count} members subscribed` : "\u00A0"}
</Typography>
<EmailSubscribe/>
<Divider></Divider>
</Stack>
<div style={{ marginTop: 50}}>
<Stack spacing={2}
alignItems="center"
justifyContent="center">
<SchedulingState/>
</Stack>
</div>
</Paper>
</ThemeProvider>
);
Expand Down
12 changes: 12 additions & 0 deletions web/src/client/schemas.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,18 @@ export const $PollResponse = {
title: 'PollResponse'
} as const;

export const $SubscribeCountResponse = {
properties: {
count: {
type: 'integer',
title: 'Count'
}
},
type: 'object',
required: ['count'],
title: 'SubscribeCountResponse'
} as const;

export const $SubscribeRequest = {
properties: {
email: {
Expand Down
12 changes: 11 additions & 1 deletion web/src/client/services.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import type { CancelablePromise } from './core/CancelablePromise';
import { OpenAPI } from './core/OpenAPI';
import { request as __request } from './core/request';
import type { HelloGetResponse, SubscribeToSchafkopfRoundsSubscribePostData, SubscribeToSchafkopfRoundsSubscribePostResponse, GetPollPollGetResponse } from './types.gen';
import type { HelloGetResponse, SubscribeToSchafkopfRoundsSubscribePostData, SubscribeToSchafkopfRoundsSubscribePostResponse, GetSubscriberCountSubscribersCountGetResponse, GetPollPollGetResponse } from './types.gen';

/**
* Hello
Expand Down Expand Up @@ -32,6 +32,16 @@ export const subscribeToSchafkopfRoundsSubscribePost = (data: SubscribeToSchafko
}
}); };

/**
* Get Subscriber Count
* @returns SubscribeCountResponse Successful Response
* @throws ApiError
*/
export const getSubscriberCountSubscribersCountGet = (): CancelablePromise<GetSubscriberCountSubscribersCountGetResponse> => { return __request(OpenAPI, {
method: 'GET',
url: '/subscribers/count'
}); };

/**
* Get Poll
* @returns PollResponse Successful Response
Expand Down
16 changes: 16 additions & 0 deletions web/src/client/types.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ export type PollResponse = {
current_poll_started: string;
};

export type SubscribeCountResponse = {
count: number;
};

export type SubscribeRequest = {
email: string;
};
Expand All @@ -33,6 +37,8 @@ export type SubscribeToSchafkopfRoundsSubscribePostData = {

export type SubscribeToSchafkopfRoundsSubscribePostResponse = SubscribeResponse;

export type GetSubscriberCountSubscribersCountGetResponse = SubscribeCountResponse;

export type GetPollPollGetResponse = PollResponse;

export type $OpenApiTs = {
Expand Down Expand Up @@ -61,6 +67,16 @@ export type $OpenApiTs = {
};
};
};
'/subscribers/count': {
get: {
res: {
/**
* Successful Response
*/
200: SubscribeCountResponse;
};
};
};
'/poll': {
get: {
res: {
Expand Down

0 comments on commit d37ab30

Please sign in to comment.