Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 0 additions & 13 deletions AskFm/.idea/.idea.AskFm/.idea/.gitignore

This file was deleted.

4 changes: 0 additions & 4 deletions AskFm/.idea/.idea.AskFm/.idea/encodings.xml

This file was deleted.

10 changes: 0 additions & 10 deletions AskFm/.idea/.idea.AskFm/.idea/indexLayout.xml

This file was deleted.

7 changes: 0 additions & 7 deletions AskFm/.idea/.idea.AskFm/.idea/vcs.xml

This file was deleted.

1 change: 1 addition & 0 deletions AskFm/AskFm.API/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CONNECTION_STRING="Put you connection string here then rename file to .env"
17 changes: 11 additions & 6 deletions AskFm/AskFm.API/AskFm.API.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,20 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="9.0.7"/>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="9.0.7"/>
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="9.0.7"/>
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="9.0.7"/>
<PackageReference Include="DotNetEnv" Version="3.1.1" />
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="9.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="9.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="9.0.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="9.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="9.0.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\AskFm.BLL\AskFm.BLL.csproj"/>
<ProjectReference Include="..\Shared\Shared.csproj"/>
<ProjectReference Include="..\AskFm.BLL\AskFm.BLL.csproj" />
<ProjectReference Include="..\Shared\Shared.csproj" />
</ItemGroup>

</Project>
10 changes: 8 additions & 2 deletions AskFm/AskFm.API/Program.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Microsoft.EntityFrameworkCore;
using AskFm.DAL;

using DotNetEnv;
namespace AskFm.API;

public class Program
Expand All @@ -15,8 +15,14 @@ public static void Main(string[] args)
// Learn more about configuring OpenAPI at https://aka.ms/aspnet/openapi
builder.Services.AddOpenApi();

Env.Load();
string ConnectionString = Environment.GetEnvironmentVariable("CONNECTION_STRING");
Comment on lines +18 to +19

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue

Add null checking and error handling for environment variable.

The code doesn't handle the case where the CONNECTION_STRING environment variable is missing or null, which will cause a runtime exception when trying to configure the database context.

Apply this diff to add proper error handling:

 Env.Load();
-string ConnectionString = Environment.GetEnvironmentVariable("CONNECTION_STRING");
+string? connectionString = Environment.GetEnvironmentVariable("CONNECTION_STRING");
+if (string.IsNullOrEmpty(connectionString))
+{
+    throw new InvalidOperationException("CONNECTION_STRING environment variable is required but not set.");
+}

Also update the variable usage:

 builder.Services.AddDbContext<AppDbContext>(options =>
-    options.UseSqlServer(ConnectionString));
+    options.UseSqlServer(connectionString));
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
Env.Load();
string ConnectionString = Environment.GetEnvironmentVariable("CONNECTION_STRING");
Env.Load();
string? connectionString = Environment.GetEnvironmentVariable("CONNECTION_STRING");
if (string.IsNullOrEmpty(connectionString))
{
throw new InvalidOperationException("CONNECTION_STRING environment variable is required but not set.");
}
builder.Services.AddDbContext<AppDbContext>(options =>
options.UseSqlServer(connectionString));
🤖 Prompt for AI Agents
In AskFm/AskFm.API/Program.cs around lines 18 to 19, the code retrieves the
CONNECTION_STRING environment variable without checking if it is null, which can
cause runtime exceptions. Add a null check after retrieving the environment
variable, and if it is null or empty, log an appropriate error message and
terminate the application or throw a clear exception. Update all usages of the
ConnectionString variable to ensure it is only used if valid.

if (ConnectionString is null)
{
throw new Exception("Connection string is null");
}
builder.Services.AddDbContext<AppDbContext>(options =>
options.UseSqlServer(builder.Configuration.GetConnectionString("DefaultConnection")));
options.UseSqlServer(ConnectionString));


var app = builder.Build();
Expand Down
2 changes: 1 addition & 1 deletion AskFm/AskFm.API/appsettings.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"ConnectionStrings": {
"DefaultConnection": "Server=.; Database = AskClone; Integrated Security = SSPI; TrustServerCertificate = True;"
"DefaultConnection": "CONNECTIONSTRING"
},
"Logging": {
"LogLevel": {
Expand Down
8 changes: 4 additions & 4 deletions AskFm/AskFm.DAL/AppDbContext.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using AskFm.DAL.Moodels;
using AskFm.DAL.Models;
using Microsoft.EntityFrameworkCore;
using Thread = AskFm.DAL.Moodels.Thread;
using Thread = AskFm.DAL.Models.Thread;

namespace AskFm.DAL;

Expand All @@ -14,10 +14,10 @@ public AppDbContext(DbContextOptions<AppDbContext> options) : base(options)
public DbSet<Thread> Threads { get; set; }
public DbSet<Comment> Comments { get; set; }
public DbSet<Follow> Follows { get; set; }
public DbSet<ThreadLike> QuestionLikes { get; set; }
public DbSet<ThreadLike> ThreadLikes { get; set; }
public DbSet<CommentLike> CommentLikes { get; set; }
public DbSet<Notification> Notifications { get; set; }

public DbSet<SavedThreads> SavedThreads { get; set; }

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
Expand Down
11 changes: 6 additions & 5 deletions AskFm/AskFm.DAL/AskFm.DAL.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,22 @@
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<RootNamespace>AskFm.DLL</RootNamespace>
<RootNamespace>AskFm.DAL</RootNamespace>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="9.0.7"/>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="9.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="9.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="9.0.7"/>
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="9.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="9.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="9.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.Extensions.Configuration" Version="10.0.0-preview.6.25358.103"/>
<PackageReference Include="Microsoft.Extensions.Configuration" Version="9.0.0" />
</ItemGroup>

<ItemGroup>
Expand All @@ -28,7 +29,7 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Shared\Shared.csproj"/>
<ProjectReference Include="..\Shared\Shared.csproj" />
</ItemGroup>

</Project>
12 changes: 6 additions & 6 deletions AskFm/AskFm.DAL/Enums/NotificationStatus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ namespace AskFm.DAL.Enums;

public enum NotificationStatus
{
ANSWER = 1,
QUESTION = 2,
FOLLOW = 3,
COMMENT_LIKE = 4,
QUESTION_LIKE = 5,
REPLAY = 6
ANSWER ,
QUESTION,
FOLLOW,
COMMENT_LIKE,
QUESTION_LIKE,
REPLAY
Comment on lines +5 to +10

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Verification agent

🧩 Analysis chain

Verify enum value changes and fix naming issues.

Similar to ThreadStatus, removing explicit integer assignments could break existing database records or API contracts. Additionally, there are naming inconsistencies and a potential typo.

Consider fixing naming consistency and the typo:

-    ANSWER ,
-    QUESTION,
-    FOLLOW,
-    COMMENT_LIKE,
-    QUESTION_LIKE,
-    REPLAY
+    Answer,
+    Question,
+    Follow,
+    CommentLike,
+    QuestionLike,
+    Reply

🏁 Script executed:

#!/bin/bash
# Check for existing NotificationStatus usage and values
rg -A 3 -B 3 "NotificationStatus" --type cs
ast-grep --pattern 'NotificationStatus.$_'

Length of output: 902


Rename enum members to PascalCase and correct typo

The NotificationStatus enum is currently unused elsewhere in the codebase, so you don’t need to worry about implicit value changes breaking existing data. However, its members should follow .NET’s PascalCase convention, and “REPLAY” appears to be a typo.

Files to update:

  • AskFm/AskFm.DAL/Enums/NotificationStatus.cs

Suggested diff:

 public enum NotificationStatus
 {
-    ANSWER ,
-    QUESTION,
-    FOLLOW,
-    COMMENT_LIKE,
-    QUESTION_LIKE,
-    REPLAY
+    Answer,
+    Question,
+    Follow,
+    CommentLike,
+    QuestionLike,
+    Reply
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
ANSWER ,
QUESTION,
FOLLOW,
COMMENT_LIKE,
QUESTION_LIKE,
REPLAY
public enum NotificationStatus
{
Answer,
Question,
Follow,
CommentLike,
QuestionLike,
Reply
}
🤖 Prompt for AI Agents
In AskFm/AskFm.DAL/Enums/NotificationStatus.cs between lines 5 and 10, rename
all enum members to PascalCase to follow .NET conventions and correct the typo
"REPLAY" to "REPLY". Update the enum members to Answer, Question, Follow,
CommentLike, QuestionLike, and Reply accordingly.

}
6 changes: 4 additions & 2 deletions AskFm/AskFm.DAL/Enums/ThreadStatus.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
namespace AskFm.DAL.Enums;
public enum ThreadStatus
{
PRIVATE = 1,
PUBLIC = 2
PRIVATE,
PUBLIC,
Closed,
PRIVATEQUESTION
}
Loading