Skip to content

Conversation

striped-zebra-dev
Copy link

No description provided.


// It's not real it's magic
pub fn get_tenant_id() -> Uuid {
Uuid::parse_str("2eda70a4-e7ef-4c1d-8e2c-d1f050f1cf9e").unwrap()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mmm, do we really need it?

instance: &str,
) -> ProblemResponse {
let problem = Problem::new(status, title, detail)
.with_type(format!("https://errors.example.com/{}", code))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shall we keep it?

use modkit::{Problem, ProblemResponse};

/// Helper to create a ProblemResponse with less boilerplate
pub fn from_parts(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can it be a library function with good human-readable (= LLM readable) function description ?

use crate::domain::error::DomainError;

/// Map domain error to RFC9457 ProblemResponse
pub fn map_domain_error(e: &DomainError, instance: &str) -> ProblemResponse {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we rename instance to something else? Or it's a standard term for this operation?

.await
{
Ok(settings) => Ok(Json(SettingsDTO {
user_id: settings.user_id,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it makes sense to have a 'mapper' function always, not to make it inline, because I can assume we'll end up with multiple similar cases like this in the future. For example what if get_setting, get_settings, update_setting, post_setting, etc. return the same SettingsDTO

.description("Retrieve user's settings")
.tag("settings")
.handler(handlers::get_settings)
.json_response_with_schema::<dto::SettingsDTO>(openapi, 200, "User's settings")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are there enums/constants for that? Just for easier source code grep in the future

impl Default for Settings {
fn default() -> Self {
Self {
user_id: auth::get_user_id(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same thing, I'd have a mapper function...

user_id: Uuid,
tenant_id: Uuid,
) -> Result<Settings, DomainError> {
debug!(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this debug() be a service method that would always automatically print tenant id, user id?
I see it would be a common problem/pattern for many services


/// Data for updating an existing user entity
pub struct UpdateSettingsEntity {
pub theme: Option<String>,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it mean we are going to copy and copy all the model fields in NewXXX, UpdateXXX, Model, DTO, and such?
Isn't it too verbose?


/// Convert a database entity to a contract model (owned version)
impl From<SettingsEntity> for Settings {
fn from(rhs: SettingsEntity) -> Self {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why rhs? just curious

pub async fn get_settings(
&self,
user_id: Uuid,
tenant_id: Uuid,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we have a context object (with user_id and tenant_id and request_id, etc), not separate values?


#[derive(Clone, Debug, PartialEq, DeriveEntityModel)]
#[sea_orm(table_name = "settings")]
pub struct Model {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we have a convention for the Model name here? Like, what if have several such 'models' in single file?

}

/// Update user's settings
pub async fn update<TX>(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what if we have a generic upsert (save) method that handles DB timeout/retries, and such

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants