Skip to content

Commit 88641df

Browse files
committed
Support for some types of some accounts
1 parent 47d945c commit 88641df

File tree

7 files changed

+137
-7
lines changed

7 files changed

+137
-7
lines changed

backend/src/html.rs

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use axum::Form;
88
use once_cell::sync::Lazy;
99
use serde::Deserialize;
1010
use time::{format_description, Date, Month};
11-
use tracing::{debug, info};
11+
use tracing::{debug, info, span, Level};
1212
use url;
1313
use url::Url;
1414

@@ -115,6 +115,53 @@ pub async fn delete_some_account(
115115
Ok(Redirect::to("/me"))
116116
}
117117

118+
#[derive(Deserialize, Debug)]
119+
pub(crate) struct AddSomeAccountForm {
120+
bluesky: String,
121+
button_bluesky: Option<String>,
122+
123+
linkedin: String,
124+
button_linkedin: Option<String>,
125+
126+
x: String,
127+
button_x: Option<String>,
128+
}
129+
130+
pub async fn add_some_account(
131+
State(app): State<ServerImpl>,
132+
user: SessionUser,
133+
Form(input): Form<AddSomeAccountForm>,
134+
) -> Result<Redirect, AppError> {
135+
let _span = span!(Level::INFO, "add_some_account");
136+
137+
info!("input" = ?input, "Adding some account");
138+
139+
let mut network: Option<String> = None;
140+
let mut nick: Option<String> = None;
141+
let mut url: Option<String> = None;
142+
143+
if input.button_bluesky.is_some() {
144+
network = Some("bluesky".to_string());
145+
nick = Some(input.bluesky.clone());
146+
url = Some(format!("https://bsky.app/profile/{}", input.bluesky.clone()).to_string());
147+
} else if input.button_linkedin.is_some() {
148+
network = Some("linkedin".to_string());
149+
url = Some(input.linkedin);
150+
} else if input.button_x.is_some() && input.x.trim().len() > 0 {
151+
network = Some("x".to_string());
152+
nick = Some(input.x.clone());
153+
url = Some(format!("https://x.com/{}", input.x.clone()).to_string());
154+
}
155+
156+
if let Some(network) = network {
157+
app.employee_dao
158+
.add_some_account(user.employee, network.to_string(), nick, url)
159+
.await?;
160+
}
161+
162+
Ok(Redirect::to("/me"))
163+
}
164+
118165
#[derive(Template)]
119166
#[template(path = "employee.html")]
120167
struct EmployeeTemplate {

backend/src/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,8 +190,8 @@ impl ServerImpl {
190190
skjera_api::models::SomeAccount {
191191
id: s.id.into(),
192192
network: s.network.to_string(),
193-
nick: s.nick.to_string(),
194-
url: s.url.to_string(),
193+
nick: s.nick.clone().unwrap_or_default(),
194+
url: s.url.clone().unwrap_or_default(),
195195
}
196196
}
197197
}

backend/src/model/employee.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,29 @@ pub struct EmployeeDao {
1818
pool: Pool<Postgres>,
1919
}
2020

21+
impl EmployeeDao {
22+
pub(crate) async fn add_some_account(
23+
&self,
24+
employee: EmployeeId,
25+
network: String,
26+
nick: Option<String>,
27+
url: Option<String>,
28+
) -> Result<SomeAccount, Error> {
29+
sqlx::query_as!(
30+
SomeAccount,
31+
"INSERT INTO skjera.some_account(employee, network, nick, url)
32+
VALUES ($1, $2, $3, $4)
33+
RETURNING *",
34+
employee.0,
35+
network,
36+
nick,
37+
url
38+
)
39+
.fetch_one(&self.pool)
40+
.await
41+
}
42+
}
43+
2144
impl EmployeeDao {
2245
pub(crate) fn new(pool: Pool<Postgres>) -> EmployeeDao {
2346
EmployeeDao { pool }

backend/src/model/some_account.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ pub struct SomeAccount {
88
pub id: SomeAccountId,
99
pub employee: EmployeeId,
1010
pub network: String,
11-
pub nick: String,
12-
pub url: String,
11+
pub nick: Option<String>,
12+
pub url: Option<String>,
1313
}

backend/src/web.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ pub(crate) fn create_router(app: ServerImpl) -> Router {
1515
.route("/", get(html::hello_world))
1616
.route("/me", get(html::get_me))
1717
.route("/me", post(html::post_me))
18+
.route(
19+
"/me/some_account/add",
20+
post(html::add_some_account),
21+
)
1822
.route(
1923
"/me/some_account/:some_account_id/delete",
2024
post(html::delete_some_account),

backend/templates/me.html

Lines changed: 55 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@
33
<head>
44
<link rel="icon" href="data:;base64,," />
55
<link rel="stylesheet" href="/assets/reset-zone.regular.css">
6+
<style>
7+
tr th {
8+
vertical-align: top;
9+
}
10+
</style>
611
</head>
712
<body>
813
<h1>Edit profile</h1>
@@ -58,9 +63,11 @@ <h2>SoMe Accounts</h2>
5863
{% for a in some_accounts %}
5964
<tr>
6065
<td>{{ a.network }}</td>
61-
<td>{{ a.nick }}</td>
66+
<td>{% if let Some(nick) = a.nick %}{{ nick }}{% endif %}</td>
6267
<td>
63-
<a href="{{ a.url }}" target="_blank">{{ a.url }}</a>
68+
{% if let Some(url) = a.url -%}
69+
<a href="{{ url }}" target="_blank">{{ url }}</a>
70+
{%- endif %}
6471
</td>
6572
<td>
6673
<form action="/me/some_account/{{ a.id }}/delete" method="POST">
@@ -72,5 +79,51 @@ <h2>SoMe Accounts</h2>
7279
{% endfor %}
7380
</tbody>
7481
</table>
82+
83+
<h3>Add SoMe Account</h3>
84+
<form action="/me/some_account/add" method="POST">
85+
<table>
86+
<tr>
87+
<th>
88+
<label for="bluesky">Bluesky @handle</label>
89+
</th>
90+
<td>
91+
<input type="text" name="bluesky" id="bluesky" placeholder="@bluesky">
92+
</td>
93+
<td>
94+
<input type="submit" name="button_bluesky" value="Add Bluesky account">
95+
</td>
96+
</tr>
97+
<tr>
98+
<th>
99+
<label for="linkedin">Linked-in profile URL</label>
100+
</th>
101+
<td>
102+
<input type="text" name="linkedin" id="linkedin" placeholder="https://www.linkedin.com/in/my-profile">
103+
</td>
104+
<td>
105+
<input type="submit" name="button_linkedin" value="Add Linked-in account">
106+
</td>
107+
</tr>
108+
<tr>
109+
<td></td>
110+
<td colspan="2">
111+
Click on your own name on the Linked-in home page to find your own URL.
112+
</td>
113+
</tr>
114+
<tr>
115+
<th>
116+
<label for="x">X @handle</label>
117+
</th>
118+
<td>
119+
<input type="text" name="x" id="x" placeholder="@handle">
120+
</td>
121+
<td>
122+
<input type="submit" name="button_x" value="Add X account">
123+
</td>
124+
</tr>
125+
</table>
126+
</form>
127+
75128
</body>
76129
</html>

migrations/20250103095402_some.sql

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
ALTER TABLE skjera.some_account
2+
ALTER COLUMN url DROP NOT NULL,
3+
ALTER COLUMN nick DROP NOT NULL;

0 commit comments

Comments
 (0)