diff --git a/.editorconfig b/.editorconfig index 9896049..19e562e 100644 --- a/.editorconfig +++ b/.editorconfig @@ -1,64 +1,59 @@ root = true -# All files +# ============================================================ +# ALL FILES +# ============================================================ [*] indent_style = space -# Xml files +# ============================================================ +# XML FILES +# ============================================================ [*.xml] indent_size = 2 -# Xml project files [*.{csproj,fsproj,vbproj,proj,slnx}] indent_size = 2 -# Xml config files [*.{props,targets,config,nuspec}] indent_size = 2 +# ============================================================ +# JSON FILES +# ============================================================ [*.json] indent_size = 2 -# C# files -[*.cs] - -#### Core EditorConfig Options #### - -# Indentation and spacing -indent_size = 4 -tab_width = 4 - -# New line preferences -insert_final_newline = false - -#### .NET Coding Conventions #### +# ============================================================ +# C# AND VB FILES — SHARED .NET CONVENTIONS +# ============================================================ [*.{cs,vb}] -# Organize usings +#### Organize Usings #### dotnet_separate_import_directive_groups = true dotnet_sort_system_directives_first = true file_header_template = unset -# this. and Me. preferences +#### this. and Me. Preferences #### dotnet_style_qualification_for_event = false:silent dotnet_style_qualification_for_field = false:silent dotnet_style_qualification_for_method = false:silent dotnet_style_qualification_for_property = false:silent -# Language keywords vs BCL types preferences +#### Language Keywords vs BCL Types #### dotnet_style_predefined_type_for_locals_parameters_members = true:silent dotnet_style_predefined_type_for_member_access = true:silent -# Parentheses preferences +#### Parentheses Preferences #### dotnet_style_parentheses_in_arithmetic_binary_operators = always_for_clarity:silent dotnet_style_parentheses_in_other_binary_operators = always_for_clarity:silent dotnet_style_parentheses_in_other_operators = never_if_unnecessary:silent dotnet_style_parentheses_in_relational_binary_operators = always_for_clarity:silent -# Modifier preferences +#### Modifier Preferences #### dotnet_style_require_accessibility_modifiers = for_non_interface_members:silent -# Expression-level preferences +#### Expression-Level Preferences #### dotnet_style_coalesce_expression = true:suggestion dotnet_style_collection_initializer = true:suggestion dotnet_style_explicit_tuple_names = true:suggestion @@ -78,129 +73,30 @@ dotnet_style_prefer_is_null_check_over_reference_equality_method = true:suggesti dotnet_style_prefer_simplified_boolean_expressions = true:suggestion dotnet_style_prefer_simplified_interpolation = true:suggestion -# Field preferences +#### Field Preferences #### dotnet_style_readonly_field = true:warning -# Parameter preferences +#### Parameter Preferences #### dotnet_code_quality_unused_parameters = all:suggestion -# Suppression preferences +#### Suppression Preferences #### dotnet_remove_unnecessary_suppression_exclusions = none -#### C# Coding Conventions #### -[*.cs] +#### Diagnostics #### +dotnet_diagnostic.IDE0005.severity = warning # Remove unused usings +dotnet_diagnostic.IDE0073.severity = none # File header not required +dotnet_diagnostic.SA1600.severity = warning # Elements should be documented +dotnet_diagnostic.SA1623.severity = none # Property summary text +dotnet_diagnostic.SA1624.severity = none # Property summary text +dotnet_diagnostic.SA1633.severity = none # File header not required +dotnet_diagnostic.SA1642.severity = suggestion # Constructor summary text -# var preferences -csharp_style_var_elsewhere = false:silent -csharp_style_var_for_built_in_types = false:silent -csharp_style_var_when_type_is_apparent = false:silent - -# Expression-bodied members -csharp_style_expression_bodied_accessors = true:silent -csharp_style_expression_bodied_constructors = false:silent -csharp_style_expression_bodied_indexers = true:silent -csharp_style_expression_bodied_lambdas = true:suggestion -csharp_style_expression_bodied_local_functions = false:silent -csharp_style_expression_bodied_methods = false:silent -csharp_style_expression_bodied_operators = false:silent -csharp_style_expression_bodied_properties = true:silent - -# Pattern matching preferences -csharp_style_pattern_matching_over_as_with_null_check = true:suggestion -csharp_style_pattern_matching_over_is_with_cast_check = true:suggestion -csharp_style_prefer_extended_property_pattern = true:suggestion -csharp_style_prefer_not_pattern = true:suggestion -csharp_style_prefer_pattern_matching = true:silent -csharp_style_prefer_switch_expression = true:suggestion - -# Null-checking preferences -csharp_style_conditional_delegate_call = true:suggestion - -# Modifier preferences -csharp_prefer_static_anonymous_function = true:suggestion -csharp_prefer_static_local_function = true:warning -csharp_preferred_modifier_order = public,private,protected,internal,file,const,static,extern,new,virtual,abstract,sealed,override,readonly,unsafe,required,volatile,async:suggestion -csharp_style_prefer_readonly_struct = true:suggestion -csharp_style_prefer_readonly_struct_member = true:suggestion - -# Code-block preferences -csharp_prefer_braces = true:silent -csharp_prefer_simple_using_statement = true:suggestion -csharp_style_namespace_declarations = file_scoped:suggestion -csharp_style_prefer_method_group_conversion = true:silent -csharp_style_prefer_primary_constructors = true:suggestion -csharp_style_prefer_top_level_statements = true:silent - -# Expression-level preferences -csharp_prefer_simple_default_expression = true:suggestion -csharp_style_deconstructed_variable_declaration = true:suggestion -csharp_style_implicit_object_creation_when_type_is_apparent = true:suggestion -csharp_style_inlined_variable_declaration = true:suggestion -csharp_style_prefer_index_operator = true:suggestion -csharp_style_prefer_local_over_anonymous_function = true:suggestion -csharp_style_prefer_null_check_over_type_check = true:suggestion -csharp_style_prefer_range_operator = true:suggestion -csharp_style_prefer_tuple_swap = true:suggestion -csharp_style_prefer_utf8_string_literals = true:suggestion -csharp_style_throw_expression = true:suggestion -csharp_style_unused_value_assignment_preference = discard_variable:suggestion -csharp_style_unused_value_expression_statement_preference = discard_variable:silent - -# 'using' directive preferences -csharp_using_directive_placement = outside_namespace:silent - -#### C# Formatting Rules #### - -# New line preferences -csharp_new_line_before_catch = true -csharp_new_line_before_else = true -csharp_new_line_before_finally = true -csharp_new_line_before_members_in_anonymous_types = true -csharp_new_line_before_members_in_object_initializers = true -csharp_new_line_before_open_brace = all -csharp_new_line_between_query_expression_clauses = true - -# Indentation preferences -csharp_indent_block_contents = true -csharp_indent_braces = false -csharp_indent_case_contents = true -csharp_indent_case_contents_when_block = true -csharp_indent_labels = one_less_than_current -csharp_indent_switch_labels = true - -# Space preferences -csharp_space_after_cast = false -csharp_space_after_colon_in_inheritance_clause = true -csharp_space_after_comma = true -csharp_space_after_dot = false -csharp_space_after_keywords_in_control_flow_statements = true -csharp_space_after_semicolon_in_for_statement = true -csharp_space_around_binary_operators = before_and_after -csharp_space_around_declaration_statements = false -csharp_space_before_colon_in_inheritance_clause = true -csharp_space_before_comma = false -csharp_space_before_dot = false -csharp_space_before_open_square_brackets = false -csharp_space_before_semicolon_in_for_statement = false -csharp_space_between_empty_square_brackets = false -csharp_space_between_method_call_empty_parameter_list_parentheses = false -csharp_space_between_method_call_name_and_opening_parenthesis = false -csharp_space_between_method_call_parameter_list_parentheses = false -csharp_space_between_method_declaration_empty_parameter_list_parentheses = false -csharp_space_between_method_declaration_name_and_open_parenthesis = false -csharp_space_between_method_declaration_parameter_list_parentheses = false -csharp_space_between_parentheses = false -csharp_space_between_square_brackets = false - -# Wrapping preferences -csharp_preserve_single_line_blocks = true -csharp_preserve_single_line_statements = true - -#### Naming styles #### +# ============================================================ +# NAMING RULES +# ============================================================ [*.{cs,vb}] -# Naming rules - +## Rules ## dotnet_naming_rule.types_and_namespaces_should_be_pascalcase.severity = suggestion dotnet_naming_rule.types_and_namespaces_should_be_pascalcase.symbols = types_and_namespaces dotnet_naming_rule.types_and_namespaces_should_be_pascalcase.style = pascalcase @@ -225,6 +121,38 @@ dotnet_naming_rule.events_should_be_pascalcase.severity = suggestion dotnet_naming_rule.events_should_be_pascalcase.symbols = events dotnet_naming_rule.events_should_be_pascalcase.style = pascalcase +dotnet_naming_rule.public_fields_should_be_pascalcase.severity = suggestion +dotnet_naming_rule.public_fields_should_be_pascalcase.symbols = public_fields +dotnet_naming_rule.public_fields_should_be_pascalcase.style = pascalcase + +dotnet_naming_rule.public_constant_fields_should_be_pascalcase.severity = suggestion +dotnet_naming_rule.public_constant_fields_should_be_pascalcase.symbols = public_constant_fields +dotnet_naming_rule.public_constant_fields_should_be_pascalcase.style = pascalcase + +dotnet_naming_rule.public_static_readonly_fields_should_be_pascalcase.severity = suggestion +dotnet_naming_rule.public_static_readonly_fields_should_be_pascalcase.symbols = public_static_readonly_fields +dotnet_naming_rule.public_static_readonly_fields_should_be_pascalcase.style = pascalcase + +dotnet_naming_rule.private_fields_should_be__camelcase.severity = suggestion +dotnet_naming_rule.private_fields_should_be__camelcase.symbols = private_fields +dotnet_naming_rule.private_fields_should_be__camelcase.style = _camelcase + +dotnet_naming_rule.private_static_fields_should_be_s_camelcase.severity = suggestion +dotnet_naming_rule.private_static_fields_should_be_s_camelcase.symbols = private_static_fields +dotnet_naming_rule.private_static_fields_should_be_s_camelcase.style = s_camelcase + +dotnet_naming_rule.private_constant_fields_should_be_pascalcase.severity = suggestion +dotnet_naming_rule.private_constant_fields_should_be_pascalcase.symbols = private_constant_fields +dotnet_naming_rule.private_constant_fields_should_be_pascalcase.style = pascalcase + +dotnet_naming_rule.private_static_readonly_fields_should_be_pascalcase.severity = suggestion +dotnet_naming_rule.private_static_readonly_fields_should_be_pascalcase.symbols = private_static_readonly_fields +dotnet_naming_rule.private_static_readonly_fields_should_be_pascalcase.style = pascalcase + +dotnet_naming_rule.enums_should_be_pascalcase.severity = suggestion +dotnet_naming_rule.enums_should_be_pascalcase.symbols = enums +dotnet_naming_rule.enums_should_be_pascalcase.style = pascalcase + dotnet_naming_rule.local_variables_should_be_camelcase.severity = suggestion dotnet_naming_rule.local_variables_should_be_camelcase.symbols = local_variables dotnet_naming_rule.local_variables_should_be_camelcase.style = camelcase @@ -237,38 +165,6 @@ dotnet_naming_rule.parameters_should_be_camelcase.severity = suggestion dotnet_naming_rule.parameters_should_be_camelcase.symbols = parameters dotnet_naming_rule.parameters_should_be_camelcase.style = camelcase -dotnet_naming_rule.public_fields_should_be_pascalcase.severity = suggestion -dotnet_naming_rule.public_fields_should_be_pascalcase.symbols = public_fields -dotnet_naming_rule.public_fields_should_be_pascalcase.style = pascalcase - -dotnet_naming_rule.private_fields_should_be__camelcase.severity = suggestion -dotnet_naming_rule.private_fields_should_be__camelcase.symbols = private_fields -dotnet_naming_rule.private_fields_should_be__camelcase.style = _camelcase - -dotnet_naming_rule.private_static_fields_should_be_s_camelcase.severity = suggestion -dotnet_naming_rule.private_static_fields_should_be_s_camelcase.symbols = private_static_fields -dotnet_naming_rule.private_static_fields_should_be_s_camelcase.style = s_camelcase - -dotnet_naming_rule.public_constant_fields_should_be_pascalcase.severity = suggestion -dotnet_naming_rule.public_constant_fields_should_be_pascalcase.symbols = public_constant_fields -dotnet_naming_rule.public_constant_fields_should_be_pascalcase.style = pascalcase - -dotnet_naming_rule.private_constant_fields_should_be_pascalcase.severity = suggestion -dotnet_naming_rule.private_constant_fields_should_be_pascalcase.symbols = private_constant_fields -dotnet_naming_rule.private_constant_fields_should_be_pascalcase.style = pascalcase - -dotnet_naming_rule.public_static_readonly_fields_should_be_pascalcase.severity = suggestion -dotnet_naming_rule.public_static_readonly_fields_should_be_pascalcase.symbols = public_static_readonly_fields -dotnet_naming_rule.public_static_readonly_fields_should_be_pascalcase.style = pascalcase - -dotnet_naming_rule.private_static_readonly_fields_should_be_pascalcase.severity = suggestion -dotnet_naming_rule.private_static_readonly_fields_should_be_pascalcase.symbols = private_static_readonly_fields -dotnet_naming_rule.private_static_readonly_fields_should_be_pascalcase.style = pascalcase - -dotnet_naming_rule.enums_should_be_pascalcase.severity = suggestion -dotnet_naming_rule.enums_should_be_pascalcase.symbols = enums -dotnet_naming_rule.enums_should_be_pascalcase.style = pascalcase - dotnet_naming_rule.local_functions_should_be_pascalcase.severity = suggestion dotnet_naming_rule.local_functions_should_be_pascalcase.symbols = local_functions dotnet_naming_rule.local_functions_should_be_pascalcase.style = pascalcase @@ -277,67 +173,35 @@ dotnet_naming_rule.non_field_members_should_be_pascalcase.severity = suggestion dotnet_naming_rule.non_field_members_should_be_pascalcase.symbols = non_field_members dotnet_naming_rule.non_field_members_should_be_pascalcase.style = pascalcase -# Symbol specifications +## Symbol Specifications ## +dotnet_naming_symbols.types_and_namespaces.applicable_kinds = namespace, class, struct, interface, enum +dotnet_naming_symbols.types_and_namespaces.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected +dotnet_naming_symbols.types_and_namespaces.required_modifiers = dotnet_naming_symbols.interfaces.applicable_kinds = interface dotnet_naming_symbols.interfaces.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected -dotnet_naming_symbols.interfaces.required_modifiers = +dotnet_naming_symbols.interfaces.required_modifiers = -dotnet_naming_symbols.enums.applicable_kinds = enum -dotnet_naming_symbols.enums.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected -dotnet_naming_symbols.enums.required_modifiers = - -dotnet_naming_symbols.events.applicable_kinds = event -dotnet_naming_symbols.events.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected -dotnet_naming_symbols.events.required_modifiers = +# NOTE: was previously misconfigured as 'namespace' kind — corrected to 'type_parameter' +dotnet_naming_symbols.type_parameters.applicable_kinds = type_parameter +dotnet_naming_symbols.type_parameters.applicable_accessibilities = * +dotnet_naming_symbols.type_parameters.required_modifiers = dotnet_naming_symbols.methods.applicable_kinds = method dotnet_naming_symbols.methods.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected -dotnet_naming_symbols.methods.required_modifiers = +dotnet_naming_symbols.methods.required_modifiers = dotnet_naming_symbols.properties.applicable_kinds = property dotnet_naming_symbols.properties.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected -dotnet_naming_symbols.properties.required_modifiers = +dotnet_naming_symbols.properties.required_modifiers = + +dotnet_naming_symbols.events.applicable_kinds = event +dotnet_naming_symbols.events.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected +dotnet_naming_symbols.events.required_modifiers = dotnet_naming_symbols.public_fields.applicable_kinds = field dotnet_naming_symbols.public_fields.applicable_accessibilities = public, internal -dotnet_naming_symbols.public_fields.required_modifiers = - -dotnet_naming_symbols.private_fields.applicable_kinds = field -dotnet_naming_symbols.private_fields.applicable_accessibilities = private, protected, protected_internal, private_protected -dotnet_naming_symbols.private_fields.required_modifiers = - -dotnet_naming_symbols.private_static_fields.applicable_kinds = field -dotnet_naming_symbols.private_static_fields.applicable_accessibilities = private, protected, protected_internal, private_protected -dotnet_naming_symbols.private_static_fields.required_modifiers = static - -dotnet_naming_symbols.types_and_namespaces.applicable_kinds = namespace, class, struct, interface, enum -dotnet_naming_symbols.types_and_namespaces.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected -dotnet_naming_symbols.types_and_namespaces.required_modifiers = - -dotnet_naming_symbols.non_field_members.applicable_kinds = property, event, method -dotnet_naming_symbols.non_field_members.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected -dotnet_naming_symbols.non_field_members.required_modifiers = - -dotnet_naming_symbols.type_parameters.applicable_kinds = namespace -dotnet_naming_symbols.type_parameters.applicable_accessibilities = * -dotnet_naming_symbols.type_parameters.required_modifiers = - -dotnet_naming_symbols.private_constant_fields.applicable_kinds = field -dotnet_naming_symbols.private_constant_fields.applicable_accessibilities = private, protected, protected_internal, private_protected -dotnet_naming_symbols.private_constant_fields.required_modifiers = const - -dotnet_naming_symbols.local_variables.applicable_kinds = local -dotnet_naming_symbols.local_variables.applicable_accessibilities = local -dotnet_naming_symbols.local_variables.required_modifiers = - -dotnet_naming_symbols.local_constants.applicable_kinds = local -dotnet_naming_symbols.local_constants.applicable_accessibilities = local -dotnet_naming_symbols.local_constants.required_modifiers = const - -dotnet_naming_symbols.parameters.applicable_kinds = parameter -dotnet_naming_symbols.parameters.applicable_accessibilities = * -dotnet_naming_symbols.parameters.required_modifiers = +dotnet_naming_symbols.public_fields.required_modifiers = dotnet_naming_symbols.public_constant_fields.applicable_kinds = field dotnet_naming_symbols.public_constant_fields.applicable_accessibilities = public, internal @@ -347,57 +211,193 @@ dotnet_naming_symbols.public_static_readonly_fields.applicable_kinds = field dotnet_naming_symbols.public_static_readonly_fields.applicable_accessibilities = public, internal dotnet_naming_symbols.public_static_readonly_fields.required_modifiers = readonly, static +dotnet_naming_symbols.private_fields.applicable_kinds = field +dotnet_naming_symbols.private_fields.applicable_accessibilities = private, protected, protected_internal, private_protected +dotnet_naming_symbols.private_fields.required_modifiers = + +dotnet_naming_symbols.private_static_fields.applicable_kinds = field +dotnet_naming_symbols.private_static_fields.applicable_accessibilities = private, protected, protected_internal, private_protected +dotnet_naming_symbols.private_static_fields.required_modifiers = static + +dotnet_naming_symbols.private_constant_fields.applicable_kinds = field +dotnet_naming_symbols.private_constant_fields.applicable_accessibilities = private, protected, protected_internal, private_protected +dotnet_naming_symbols.private_constant_fields.required_modifiers = const + dotnet_naming_symbols.private_static_readonly_fields.applicable_kinds = field dotnet_naming_symbols.private_static_readonly_fields.applicable_accessibilities = private, protected, protected_internal, private_protected dotnet_naming_symbols.private_static_readonly_fields.required_modifiers = readonly, static +dotnet_naming_symbols.enums.applicable_kinds = enum +dotnet_naming_symbols.enums.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected +dotnet_naming_symbols.enums.required_modifiers = + +dotnet_naming_symbols.local_variables.applicable_kinds = local +dotnet_naming_symbols.local_variables.applicable_accessibilities = local +dotnet_naming_symbols.local_variables.required_modifiers = + +dotnet_naming_symbols.local_constants.applicable_kinds = local +dotnet_naming_symbols.local_constants.applicable_accessibilities = local +dotnet_naming_symbols.local_constants.required_modifiers = const + +dotnet_naming_symbols.parameters.applicable_kinds = parameter +dotnet_naming_symbols.parameters.applicable_accessibilities = * +dotnet_naming_symbols.parameters.required_modifiers = + dotnet_naming_symbols.local_functions.applicable_kinds = local_function dotnet_naming_symbols.local_functions.applicable_accessibilities = * -dotnet_naming_symbols.local_functions.required_modifiers = +dotnet_naming_symbols.local_functions.required_modifiers = -# Naming styles +dotnet_naming_symbols.non_field_members.applicable_kinds = property, event, method +dotnet_naming_symbols.non_field_members.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected +dotnet_naming_symbols.non_field_members.required_modifiers = -dotnet_naming_style.pascalcase.required_prefix = -dotnet_naming_style.pascalcase.required_suffix = -dotnet_naming_style.pascalcase.word_separator = +## Naming Styles ## dotnet_naming_style.pascalcase.capitalization = pascal_case +dotnet_naming_style.pascalcase.required_prefix = +dotnet_naming_style.pascalcase.required_suffix = +dotnet_naming_style.pascalcase.word_separator = -dotnet_naming_style.ipascalcase.required_prefix = I -dotnet_naming_style.ipascalcase.required_suffix = -dotnet_naming_style.ipascalcase.word_separator = dotnet_naming_style.ipascalcase.capitalization = pascal_case +dotnet_naming_style.ipascalcase.required_prefix = I +dotnet_naming_style.ipascalcase.required_suffix = +dotnet_naming_style.ipascalcase.word_separator = -dotnet_naming_style.tpascalcase.required_prefix = T -dotnet_naming_style.tpascalcase.required_suffix = -dotnet_naming_style.tpascalcase.word_separator = dotnet_naming_style.tpascalcase.capitalization = pascal_case +dotnet_naming_style.tpascalcase.required_prefix = T +dotnet_naming_style.tpascalcase.required_suffix = +dotnet_naming_style.tpascalcase.word_separator = -dotnet_naming_style._camelcase.required_prefix = _ -dotnet_naming_style._camelcase.required_suffix = -dotnet_naming_style._camelcase.word_separator = -dotnet_naming_style._camelcase.capitalization = camel_case - -dotnet_naming_style.camelcase.required_prefix = -dotnet_naming_style.camelcase.required_suffix = -dotnet_naming_style.camelcase.word_separator = dotnet_naming_style.camelcase.capitalization = camel_case +dotnet_naming_style.camelcase.required_prefix = +dotnet_naming_style.camelcase.required_suffix = +dotnet_naming_style.camelcase.word_separator = + +dotnet_naming_style._camelcase.capitalization = camel_case +dotnet_naming_style._camelcase.required_prefix = _ +dotnet_naming_style._camelcase.required_suffix = +dotnet_naming_style._camelcase.word_separator = -dotnet_naming_style.s_camelcase.required_prefix = s_ -dotnet_naming_style.s_camelcase.required_suffix = -dotnet_naming_style.s_camelcase.word_separator = dotnet_naming_style.s_camelcase.capitalization = camel_case +dotnet_naming_style.s_camelcase.required_prefix = s_ +dotnet_naming_style.s_camelcase.required_suffix = +dotnet_naming_style.s_camelcase.word_separator = -dotnet_diagnostic.SA1623.severity = none -dotnet_diagnostic.SA1624.severity = none - -dotnet_diagnostic.SA1600.severity = suggestion - +# ============================================================ +# C# FILES ONLY +# ============================================================ [*.cs] -# 1. Tell the .NET Formatter to stop injecting a header -file_header_template = unset -# 2. Tell StyleCop to stop requiring a file header (SA1633) -dotnet_diagnostic.SA1633.severity = none +#### Core EditorConfig Options #### +indent_size = 4 +tab_width = 4 +insert_final_newline = false -# 3. Tell the IDE to stop requiring a file header (IDE0073) -dotnet_diagnostic.IDE0073.severity = none \ No newline at end of file +#### var Preferences #### +csharp_style_var_elsewhere = false:silent +csharp_style_var_for_built_in_types = false:silent +csharp_style_var_when_type_is_apparent = false:silent + +#### Expression-Bodied Members #### +csharp_style_expression_bodied_accessors = true:silent +csharp_style_expression_bodied_constructors = false:silent +csharp_style_expression_bodied_indexers = true:silent +csharp_style_expression_bodied_lambdas = true:suggestion +csharp_style_expression_bodied_local_functions = false:silent +csharp_style_expression_bodied_methods = false:silent +csharp_style_expression_bodied_operators = false:silent +csharp_style_expression_bodied_properties = true:silent + +#### Pattern Matching Preferences #### +csharp_style_pattern_matching_over_as_with_null_check = true:suggestion +csharp_style_pattern_matching_over_is_with_cast_check = true:suggestion +csharp_style_prefer_extended_property_pattern = true:suggestion +csharp_style_prefer_not_pattern = true:suggestion +csharp_style_prefer_pattern_matching = true:silent +csharp_style_prefer_switch_expression = true:suggestion + +#### Null-Checking Preferences #### +csharp_style_conditional_delegate_call = true:suggestion + +#### Modifier Preferences #### +csharp_prefer_static_anonymous_function = true:suggestion +csharp_prefer_static_local_function = true:warning +csharp_preferred_modifier_order = public,private,protected,internal,file,const,static,extern,new,virtual,abstract,sealed,override,readonly,unsafe,required,volatile,async:suggestion +csharp_style_prefer_readonly_struct = true:suggestion +csharp_style_prefer_readonly_struct_member = true:suggestion + +#### Code-Block Preferences #### +csharp_prefer_braces = true:silent +csharp_prefer_simple_using_statement = true:suggestion +csharp_style_namespace_declarations = file_scoped:suggestion +csharp_style_prefer_method_group_conversion = true:silent +csharp_style_prefer_primary_constructors = true:suggestion +csharp_style_prefer_top_level_statements = true:silent + +#### Expression-Level Preferences #### +csharp_prefer_simple_default_expression = true:suggestion +csharp_style_deconstructed_variable_declaration = true:suggestion +csharp_style_implicit_object_creation_when_type_is_apparent = true:suggestion +csharp_style_inlined_variable_declaration = true:suggestion +csharp_style_prefer_index_operator = true:suggestion +csharp_style_prefer_local_over_anonymous_function = true:suggestion +csharp_style_prefer_null_check_over_type_check = true:suggestion +csharp_style_prefer_range_operator = true:suggestion +csharp_style_prefer_tuple_swap = true:suggestion +csharp_style_prefer_utf8_string_literals = true:suggestion +csharp_style_throw_expression = true:suggestion +csharp_style_unused_value_assignment_preference = discard_variable:suggestion +csharp_style_unused_value_expression_statement_preference = discard_variable:silent + +#### Using Directive Preferences #### +csharp_using_directive_placement = inside_namespace:warning + +#### Formatting — New Line Preferences #### +csharp_new_line_before_catch = true +csharp_new_line_before_else = true +csharp_new_line_before_finally = true +csharp_new_line_before_members_in_anonymous_types = true +csharp_new_line_before_members_in_object_initializers = true +csharp_new_line_before_open_brace = all +csharp_new_line_between_query_expression_clauses = true + +#### Formatting — Indentation Preferences #### +csharp_indent_block_contents = true +csharp_indent_braces = false +csharp_indent_case_contents = true +csharp_indent_case_contents_when_block = true +csharp_indent_labels = one_less_than_current +csharp_indent_switch_labels = true + +#### Formatting — Space Preferences #### +csharp_space_after_cast = false +csharp_space_after_colon_in_inheritance_clause = true +csharp_space_after_comma = true +csharp_space_after_dot = false +csharp_space_after_keywords_in_control_flow_statements = true +csharp_space_after_semicolon_in_for_statement = true +csharp_space_around_binary_operators = before_and_after +csharp_space_around_declaration_statements = false +csharp_space_before_colon_in_inheritance_clause = true +csharp_space_before_comma = false +csharp_space_before_dot = false +csharp_space_before_open_square_brackets = false +csharp_space_before_semicolon_in_for_statement = false +csharp_space_between_empty_square_brackets = false +csharp_space_between_method_call_empty_parameter_list_parentheses = false +csharp_space_between_method_call_name_and_opening_parenthesis = false +csharp_space_between_method_call_parameter_list_parentheses = false +csharp_space_between_method_declaration_empty_parameter_list_parentheses = false +csharp_space_between_method_declaration_name_and_open_parenthesis = false +csharp_space_between_method_declaration_parameter_list_parentheses = false +csharp_space_between_parentheses = false +csharp_space_between_square_brackets = false + +#### Formatting — Wrapping Preferences #### +csharp_preserve_single_line_blocks = true +csharp_preserve_single_line_statements = true + +# ============================================================ +# TEST PROJECTS — RELAXED RULES +# ============================================================ +[*.Tests/**/*.cs] +dotnet_diagnostic.SA1600.severity = none \ No newline at end of file diff --git a/.gitea/workflows/deploy-prod.yaml b/.gitea/workflows/deploy-prod.yaml new file mode 100644 index 0000000..b2a359a --- /dev/null +++ b/.gitea/workflows/deploy-prod.yaml @@ -0,0 +1,26 @@ +name: Deploiement API Prod Docker + +on: + push: + branches: + - main + +jobs: + deploy: + name: Build et Déploiement + runs-on: ubuntu-latest + + steps: + - name: 📥 Récupération du code source + uses: actions/checkout@v4 + + - name: 🔐 Injection des variables d'environnement + run: | + echo "PGSQL_CONNECTION=${{ secrets.PGSQL_CONNECTION }}" > .env + + - name: 🐳 Redémarrage Docker + run: | + echo "🚀 Démarrage du déploiement Docker sur api-prod..." + docker compose down + docker compose up -d --build + echo "✅ Déploiement terminé !" \ No newline at end of file diff --git a/.gitea/workflows/pr-endpoint-check.yml b/.gitea/workflows/pr-endpoint-check.yml index 427f687..9cd7435 100644 --- a/.gitea/workflows/pr-endpoint-check.yml +++ b/.gitea/workflows/pr-endpoint-check.yml @@ -13,19 +13,29 @@ jobs: - name: Configure appsettings for CI run: | - # Find the appsettings.json file APPSETTINGS_PATH="Webzine.WebApplication/appsettings.json" - - # Backup original file cp $APPSETTINGS_PATH $APPSETTINGS_PATH.bak - - # Use jq to modify the JSON jq '.UseDatabase = true | .IsSQLite = true' $APPSETTINGS_PATH > $APPSETTINGS_PATH.tmp mv $APPSETTINGS_PATH.tmp $APPSETTINGS_PATH - echo "Updated appsettings.json:" cat $APPSETTINGS_PATH + - name: Cache .NET SDK + uses: actions/cache@v3 + with: + path: | + ~/.dotnet + /usr/share/dotnet + key: ${{ runner.os }}-dotnet-10.0.x + + - name: Cache NuGet packages + uses: actions/cache@v3 + with: + path: ~/.nuget/packages + key: ${{ runner.os }}-nuget-${{ hashFiles('**/*.csproj', '**/*.sln') }} + restore-keys: | + ${{ runner.os }}-nuget- + - name: Setup .NET 10 uses: actions/setup-dotnet@v4 with: @@ -64,25 +74,22 @@ jobs: run: | chmod +x scripts/test-endpoints.sh bash scripts/test-endpoints.sh http://localhost:5038 1000 2>&1 | tee /tmp/webzine_endpoint_output.txt - EXIT_CODE=${PIPESTATUS[0]} - - # Count failures + FAIL_COUNT=$(grep -cE "^\[ÉCHEC\]" /tmp/webzine_endpoint_output.txt 2>/dev/null || echo 0) SLOW_COUNT=$(grep -cE "^\[LENT\]" /tmp/webzine_endpoint_output.txt 2>/dev/null || echo 0) - + echo "failed=$FAIL_COUNT" >> "$GITHUB_OUTPUT" echo "slow=$SLOW_COUNT" >> "$GITHUB_OUTPUT" - - # Échoue s’il y a DES problèmes (échecs OU lents) + if [ $FAIL_COUNT -gt 0 ] || [ $SLOW_COUNT -gt 0 ]; then echo "❌ Performance check failed: $FAIL_COUNT endpoint(s) failed, $SLOW_COUNT endpoint(s) exceeded threshold (1000ms)" exit 1 fi - + echo "✅ All endpoints passed performance check (< 1000ms)" - name: Post performance report as PR comment - if: always() # Always post comment, even on failure + if: always() env: GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }} GITEA_SERVER_URL: ${{ gitea.server_url }} @@ -92,20 +99,15 @@ jobs: RAW_REPORT=$(cat /tmp/webzine_endpoint_output.txt 2>/dev/null || echo "Aucune sortie capturée.") FAILED_COUNT="${{ steps.perf_test.outputs.failed }}" SLOW_COUNT="${{ steps.perf_test.outputs.slow }}" - - # Determine if the check passed or failed + if [ "$FAILED_COUNT" -gt 0 ] || [ "$SLOW_COUNT" -gt 0 ]; then STATUS_HEADER="❌ **PERFORMANCE CHECK FAILED**" - STATUS_ICON="❌" else STATUS_HEADER="✅ **PERFORMANCE CHECK PASSED**" - STATUS_ICON="✅" fi - - # Convert report to Markdown with colors + CLEAN_REPORT=$(echo "$RAW_REPORT" | sed 's/\x1b\[[0-9;]*m//g') - - # Generate formatted report + FORMATTED_REPORT=$(echo "$CLEAN_REPORT" | sed \ -e 's/^\[OK\] /✅ /' \ -e 's/^\[LENT\] /⚠️ /' \ @@ -120,31 +122,18 @@ jobs: -e 's/^\(⚠️ ENDPOINTS LENTS.*\)$/\n### \1/' \ -e 's/^\(❌ ENDPOINTS EN ÉCHEC.*\)$/\n### \1/' \ -e 's/^\(La PR doit.*\)$/\n**❌ \1**/') - + BODY=$(cat </dev/null || echo 0) - - ⚠️ Endpoints lents (>1000ms): $SLOW_COUNT - - ❌ Endpoints en échec: $FAILED_COUNT - + **Vérifié par**: Workflow PR Endpoint Performance EOF ) - + curl -s -X POST \ -H "Authorization: token $GITEA_TOKEN" \ -H "Content-Type: application/json" \ -d "$(jq -n --arg body "$BODY" '{body: $body}')" \ - "$GITEA_SERVER_URL/api/v1/repos/$REPO/issues/$PR_NUMBER/comments" - - - name: Fail job if performance issues detected - if: steps.perf_test.outputs.failed > 0 || steps.perf_test.outputs.slow > 0 - run: | - echo "❌ Job failed due to performance issues" - exit 1 \ No newline at end of file + "$GITEA_SERVER_URL/api/v1/repos/$REPO/issues/$PR_NUMBER/comments" \ No newline at end of file diff --git a/Webzine.WebApplication/Dockerfile b/Dockerfile similarity index 88% rename from Webzine.WebApplication/Dockerfile rename to Dockerfile index 3211249..bd375cc 100644 --- a/Webzine.WebApplication/Dockerfile +++ b/Dockerfile @@ -7,7 +7,7 @@ EXPOSE 8081 FROM mcr.microsoft.com/dotnet/sdk:10.0 AS build ARG BUILD_CONFIGURATION=Release WORKDIR /src -COPY ["Webzine.WebApplication/Webzine.WebApplication.csproj", "Webzine.WebApplication/"] +COPY ["./Webzine.WebApplication/Webzine.WebApplication.csproj", "Webzine.WebApplication/"] RUN dotnet restore "Webzine.WebApplication/Webzine.WebApplication.csproj" COPY . . WORKDIR "/src/Webzine.WebApplication" diff --git a/Webzine.WebApplication/Areas/Administration/ViewModels/DashboardViewModel.cs b/Webzine.Business.Contracts/Dto/DashboardDTO.cs similarity index 90% rename from Webzine.WebApplication/Areas/Administration/ViewModels/DashboardViewModel.cs rename to Webzine.Business.Contracts/Dto/DashboardDTO.cs index 106779d..9509c6c 100644 --- a/Webzine.WebApplication/Areas/Administration/ViewModels/DashboardViewModel.cs +++ b/Webzine.Business.Contracts/Dto/DashboardDTO.cs @@ -1,9 +1,9 @@ -namespace Webzine.WebApplication.Areas.Administration.ViewModels; +namespace Webzine.Business.Contracts.Dto; /// -/// ViewModel pour le tableau de bord de l'administration du webzine. +/// DTO pour le tableau de bord de l'administration du webzine. /// -public class DashboardViewModel +public class DashboardDTO { /// /// Définit le nombre total d'artistes chroniqués dans le webzine. diff --git a/Webzine.Business.Contracts/Dto/TitreAdminDTO.cs b/Webzine.Business.Contracts/Dto/TitreAdminDTO.cs new file mode 100644 index 0000000..2c2454b --- /dev/null +++ b/Webzine.Business.Contracts/Dto/TitreAdminDTO.cs @@ -0,0 +1,57 @@ +namespace Webzine.Business.Contracts.Dto; + +/// +/// Dto transportant les données métier d'un titre saisi en administration. +/// +public class TitreAdminDTO +{ + /// + /// Identifiant du titre (0 lors d'une création). + /// + public int Id { get; set; } + + /// + /// Identifiant de l'artiste sélectionné. + /// + public int IdArtiste { get; set; } + + /// + /// Libellé du titre. + /// + public string Libelle { get; set; } = string.Empty; + + /// + /// Nom de l'album. + /// + public string Album { get; set; } = string.Empty; + + /// + /// Texte de la chronique. + /// + public string Chronique { get; set; } = string.Empty; + + /// + /// Date de sortie du titre. + /// + public DateTime DateSortie { get; set; } + + /// + /// Durée en secondes. + /// + public int Duree { get; set; } + + /// + /// URL de la jaquette. + /// + public string UrlJaquette { get; set; } = string.Empty; + + /// + /// URL d'écoute. + /// + public string? UrlEcoute { get; set; } + + /// + /// Identifiants des styles sélectionnés. + /// + public List Styles { get; set; } = new (); +} \ No newline at end of file diff --git a/Webzine.Business.Contracts/IDashboardService.cs b/Webzine.Business.Contracts/IDashboardService.cs new file mode 100644 index 0000000..423880f --- /dev/null +++ b/Webzine.Business.Contracts/IDashboardService.cs @@ -0,0 +1,16 @@ +namespace Webzine.Business.Contracts; + +using Webzine.Business.Contracts.Dto; + +/// +/// Service responsable du calcul des statistiques affichées sur le tableau de bord d'administration. +/// Agrège les données provenant de plusieurs repositories pour produire un résumé cohérent. +/// +public interface IDashboardService +{ + /// + /// Calcule et retourne toutes les statistiques du tableau de bord en une seule passe. + /// + /// Un contenant les agrégats calculés. + DashboardDTO GetDashboardData(); +} \ No newline at end of file diff --git a/Webzine.Business.Contracts/ITitreAdminService.cs b/Webzine.Business.Contracts/ITitreAdminService.cs new file mode 100644 index 0000000..e14a7a7 --- /dev/null +++ b/Webzine.Business.Contracts/ITitreAdminService.cs @@ -0,0 +1,22 @@ +namespace Webzine.Business.Contracts; + +using Webzine.Business.Contracts.Dto; + +/// +/// Service responsable des opérations d'administration sur les titres. +/// Orchestre la résolution des dépendances (artiste, styles) et la persistance. +/// +public interface ITitreAdminService +{ + /// + /// Crée un nouveau titre à partir des données du formulaire d'administration. + /// + /// Les données saisies dans le formulaire de création. + void CreerTitre(TitreAdminDTO commande); + + /// + /// Met à jour un titre existant à partir des données du formulaire d'administration. + /// + /// Les données saisies dans le formulaire de modification. + void ModifierTitre(TitreAdminDTO commande); +} \ No newline at end of file diff --git a/Webzine.Business/DTOs/Spotify/SpotifyAlbumDto.cs b/Webzine.Business/DTOs/Spotify/SpotifyAlbumDto.cs new file mode 100644 index 0000000..6a0ca27 --- /dev/null +++ b/Webzine.Business/DTOs/Spotify/SpotifyAlbumDto.cs @@ -0,0 +1,34 @@ +namespace Webzine.Business.DTOs.Spotify +{ + using System.Text.Json.Serialization; + + /// + /// Objet album de spotify. + /// + public class SpotifyAlbumDto + { + /// + /// Id de l'album. + /// + [JsonPropertyName("id")] + public string Id { get; set; } = string.Empty; + + /// + /// Nom de l'album. + /// + [JsonPropertyName("name")] + public string Name { get; set; } = string.Empty; + + /// + /// Date de sortie. + /// + [JsonPropertyName("release_date")] + public string? ReleaseDate { get; set; } + + /// + /// Urls de la jaquette. + /// + [JsonPropertyName("images")] + public List Images { get; set; } = new (); + } +} \ No newline at end of file diff --git a/Webzine.Business/DTOs/Spotify/SpotifyAlbumsResponseDto.cs b/Webzine.Business/DTOs/Spotify/SpotifyAlbumsResponseDto.cs new file mode 100644 index 0000000..75e1f61 --- /dev/null +++ b/Webzine.Business/DTOs/Spotify/SpotifyAlbumsResponseDto.cs @@ -0,0 +1,16 @@ +namespace Webzine.Business.DTOs.Spotify +{ + using System.Text.Json.Serialization; + + /// + /// Objet Spotify qui contient une liste d'album. + /// + public class SpotifyAlbumsResponseDto + { + /// + /// Container de plusieurs albums spotify. + /// + [JsonPropertyName("items")] + public List Items { get; set; } = new (); + } +} \ No newline at end of file diff --git a/Webzine.Business/DTOs/Spotify/SpotifyArtistDto.cs b/Webzine.Business/DTOs/Spotify/SpotifyArtistDto.cs new file mode 100644 index 0000000..68be855 --- /dev/null +++ b/Webzine.Business/DTOs/Spotify/SpotifyArtistDto.cs @@ -0,0 +1,28 @@ +namespace Webzine.Business.DTOs.Spotify +{ + using System.Text.Json.Serialization; + + /// + /// Objet artiste retourne depuis spotify. + /// + public class SpotifyArtistDto + { + /// + /// Id de l'artiste. + /// + [JsonPropertyName("id")] + public string Id { get; set; } = string.Empty; + + /// + /// Nom de l'artiste. + /// + [JsonPropertyName("name")] + public string Name { get; set; } = string.Empty; + + /// + /// Genre musical de l'artiste. + /// + [JsonPropertyName("genres")] + public List Genres { get; set; } = new (); + } +} \ No newline at end of file diff --git a/Webzine.Business/DTOs/Spotify/SpotifyArtistsContainerDto.cs b/Webzine.Business/DTOs/Spotify/SpotifyArtistsContainerDto.cs new file mode 100644 index 0000000..a737493 --- /dev/null +++ b/Webzine.Business/DTOs/Spotify/SpotifyArtistsContainerDto.cs @@ -0,0 +1,16 @@ +namespace Webzine.Business.DTOs.Spotify +{ + using System.Text.Json.Serialization; + + /// + /// Container d'artistes spotify. + /// + public class SpotifyArtistsContainerDto + { + /// + /// Liste d'artiste spotify. + /// + [JsonPropertyName("items")] + public List Items { get; set; } = new (); + } +} \ No newline at end of file diff --git a/Webzine.Business/DTOs/Spotify/SpotifyExternalUrlsDto.cs b/Webzine.Business/DTOs/Spotify/SpotifyExternalUrlsDto.cs new file mode 100644 index 0000000..436dda8 --- /dev/null +++ b/Webzine.Business/DTOs/Spotify/SpotifyExternalUrlsDto.cs @@ -0,0 +1,9 @@ +namespace Webzine.Business.DTOs.Spotify; + +using System.Text.Json.Serialization; + +public class SpotifyExternalUrlsDto +{ + [JsonPropertyName("spotify")] + public string? Spotify { get; set; } +} \ No newline at end of file diff --git a/Webzine.Business/DTOs/Spotify/SpotifyImageDto.cs b/Webzine.Business/DTOs/Spotify/SpotifyImageDto.cs new file mode 100644 index 0000000..1e73ba1 --- /dev/null +++ b/Webzine.Business/DTOs/Spotify/SpotifyImageDto.cs @@ -0,0 +1,9 @@ +namespace Webzine.Business.DTOs.Spotify; + +using System.Text.Json.Serialization; + +public class SpotifyImageDto +{ + [JsonPropertyName("url")] + public string? Url { get; set; } +} \ No newline at end of file diff --git a/Webzine.Business/DTOs/Spotify/SpotifySearchArtistsResponseDto.cs b/Webzine.Business/DTOs/Spotify/SpotifySearchArtistsResponseDto.cs new file mode 100644 index 0000000..3e89fc5 --- /dev/null +++ b/Webzine.Business/DTOs/Spotify/SpotifySearchArtistsResponseDto.cs @@ -0,0 +1,16 @@ +namespace Webzine.Business.DTOs.Spotify +{ + using System.Text.Json.Serialization; + + /// + /// Resultat d'une recherche spotify avec un objet artist. + /// + public class SpotifySearchArtistsResponseDto + { + /// + /// Liste d'artistes. + /// + [JsonPropertyName("artists")] + public SpotifyArtistsContainerDto? Artists { get; set; } + } +} \ No newline at end of file diff --git a/Webzine.Business/DTOs/Spotify/SpotifyTokenResponseDto.cs b/Webzine.Business/DTOs/Spotify/SpotifyTokenResponseDto.cs new file mode 100644 index 0000000..238b693 --- /dev/null +++ b/Webzine.Business/DTOs/Spotify/SpotifyTokenResponseDto.cs @@ -0,0 +1,16 @@ +namespace Webzine.Business.DTOs.Spotify +{ + using System.Text.Json.Serialization; + + /// + /// Recuperation Token Bearer de spotify. + /// + public class SpotifyTokenResponseDto + { + /// + /// Jeton d'acces. + /// + [JsonPropertyName("access_token")] + public string? AccessToken { get; set; } + } +} \ No newline at end of file diff --git a/Webzine.Business/DTOs/Spotify/SpotifyTrackDto.cs b/Webzine.Business/DTOs/Spotify/SpotifyTrackDto.cs new file mode 100644 index 0000000..5f11220 --- /dev/null +++ b/Webzine.Business/DTOs/Spotify/SpotifyTrackDto.cs @@ -0,0 +1,34 @@ +namespace Webzine.Business.DTOs.Spotify +{ + using System.Text.Json.Serialization; + + /// + /// Objet track de spotify. + /// + public class SpotifyTrackDto + { + /// + /// Id de la track. + /// + [JsonPropertyName("id")] + public string Id { get; set; } = string.Empty; + + /// + /// Nom de la musique. + /// + [JsonPropertyName("name")] + public string Name { get; set; } = string.Empty; + + /// + /// Duree de la musique en millieseconde. + /// + [JsonPropertyName("duration_ms")] + public int DurationMs { get; set; } + + /// + /// urls spotify. + /// + [JsonPropertyName("external_urls")] + public SpotifyExternalUrlsDto? ExternalUrls { get; set; } + } +} \ No newline at end of file diff --git a/Webzine.Business/DTOs/Spotify/SpotifyTracksResponseDto.cs b/Webzine.Business/DTOs/Spotify/SpotifyTracksResponseDto.cs new file mode 100644 index 0000000..2de1d7a --- /dev/null +++ b/Webzine.Business/DTOs/Spotify/SpotifyTracksResponseDto.cs @@ -0,0 +1,16 @@ +namespace Webzine.Business.DTOs.Spotify +{ + using System.Text.Json.Serialization; + + /// + /// Reponse spotify qui contient une liste de tracks. + /// + public class SpotifyTracksResponseDto + { + /// + /// Container qui contient plusieurs tracks. + /// + [JsonPropertyName("items")] + public List Items { get; set; } = new (); + } +} \ No newline at end of file diff --git a/Webzine.Business/DashboardService.cs b/Webzine.Business/DashboardService.cs new file mode 100644 index 0000000..f68d1d5 --- /dev/null +++ b/Webzine.Business/DashboardService.cs @@ -0,0 +1,54 @@ +namespace Webzine.Business; + +using Webzine.Business.Contracts; +using Webzine.Business.Contracts.Dto; +using Webzine.Repository.Contracts; + +/// +/// Implémentation de . +/// Orchestre plusieurs appels aux repositories pour produire les statistiques du tableau de bord. +/// +public class DashboardService : IDashboardService +{ + private readonly IArtisteRepository artisteRepository; + private readonly ITitreRepository titreRepository; + private readonly IStyleRepository styleRepository; + + /// + /// Initializes a new instance of the class. + /// + /// Repository des artistes. + /// Repository des titres. + /// Repository des styles. + public DashboardService( + IArtisteRepository artisteRepository, + ITitreRepository titreRepository, + IStyleRepository styleRepository) + { + this.artisteRepository = artisteRepository; + this.titreRepository = titreRepository; + this.styleRepository = styleRepository; + } + + /// + public DashboardDTO GetDashboardData() + { + string artisteLePlusChronique = this.titreRepository.FindMostReviewedArtistName() ?? string.Empty; + string albumLePlusChronique = this.titreRepository.FindArtistNameWithMostReviewedAlbums() ?? string.Empty; + var musiqueLaPlusJouee = this.titreRepository.FindMostPlayedTitle(); + + return new DashboardDTO + { + NombreArtistes = this.artisteRepository.Count(), + ArtisteLePlusChronique = artisteLePlusChronique, + AlbumLePlusChronique = albumLePlusChronique, + NombreBiographies = this.artisteRepository.CountWithBiography(), + IdMusiqueLaPlusJouee = musiqueLaPlusJouee?.IdTitre ?? 0, + MusiqueLaPlusJouee = musiqueLaPlusJouee?.Libelle ?? string.Empty, + NombreTitres = this.titreRepository.Count(), + NombreGenres = this.styleRepository.Count(), + NombreLectures = this.titreRepository.CountLecture(), + NombreLikes = this.titreRepository.CountLike(), + }; + } +} \ No newline at end of file diff --git a/Webzine.Business/Mappers/Spotify/SpotifyMapper.cs b/Webzine.Business/Mappers/Spotify/SpotifyMapper.cs new file mode 100644 index 0000000..55aca46 --- /dev/null +++ b/Webzine.Business/Mappers/Spotify/SpotifyMapper.cs @@ -0,0 +1,128 @@ +namespace Webzine.Business.Mappers.Spotify +{ + using System.Globalization; + + using Webzine.Business.DTOs.Spotify; + using Webzine.Entity; + + /// + /// Mapper pour transformer les objets de Spotify (DTOs) en Entity. + /// + public static class SpotifyMapper + { + /// + /// Permet d'ajouter ou de creer un style. + /// + /// Dictionnaire string, Style. + /// Genre. + /// Id du style. + /// Le style. + public static Style GetOrCreateStyle(Dictionary styles, string genre, ref int nextStyleId) + { + // On verifie si le genre est présent dans la liste de styles. + if (!styles.TryGetValue(genre, out var style)) + { + // Creation d'un nouveau style. + style = new Style + { + IdStyle = nextStyleId++, + Libelle = genre, + Titres = new List(), + }; + + // Ajout dans la liste. + styles.Add(style.Libelle, style); + } + + return style; + } + + /// + /// Creation d'un nouvel artiste a l'aide des infos Spotify. + /// + /// Artiste spotify. + /// Style spotify. + /// Id de l'artiste. + /// Artiste. + public static Artiste ToArtiste(SpotifyArtistDto artisteSpotify, List