diff --git a/.gitignore b/.gitignore index cf6762f..88d1371 100644 --- a/.gitignore +++ b/.gitignore @@ -57,6 +57,7 @@ coverage .vscode/* !.vscode/extensions.json .idea +.vscode *.suo *.ntvs* *.njsproj diff --git a/ToDoList-WebApi.Server/.env b/ToDoList-WebApi.Server/.env new file mode 100644 index 0000000..f6f8373 --- /dev/null +++ b/ToDoList-WebApi.Server/.env @@ -0,0 +1 @@ +CONNECTION_STRING=Data Source=./db/db.sqlite \ No newline at end of file diff --git a/ToDoList-WebApi.Server/.gitignore b/ToDoList-WebApi.Server/.gitignore new file mode 100644 index 0000000..88d1371 --- /dev/null +++ b/ToDoList-WebApi.Server/.gitignore @@ -0,0 +1,67 @@ +# Common IntelliJ Platform excludes + +# User specific +**/.idea/**/workspace.xml +**/.idea/**/tasks.xml +**/.idea/shelf/* +**/.idea/dictionaries +**/.idea/httpRequests/ + +# Sensitive or high-churn files +**/.idea/**/dataSources/ +**/.idea/**/dataSources.ids +**/.idea/**/dataSources.xml +**/.idea/**/dataSources.local.xml +**/.idea/**/sqlDataSources.xml +**/.idea/**/dynamic.xml + +# Rider +# Rider auto-generates .iml files, and contentModel.xml +**/.idea/**/*.iml +**/.idea/**/contentModel.xml +**/.idea/**/modules.xml + +*.suo +*.user +.vs/ +[Bb]in/ +[Oo]bj/ +_UpgradeReport_Files/ +[Pp]ackages/ +.idea + +Thumbs.db +Desktop.ini +.DS_Store + +# Logs +logs +*.log +npm-debug.log* +yarn-debug.log* +yarn-error.log* +pnpm-debug.log* +lerna-debug.log* + +node_modules +.DS_Store +dist +dist-ssr +coverage +*.local + +/cypress/videos/ +/cypress/screenshots/ + +# Editor directories and files +.vscode/* +!.vscode/extensions.json +.idea +.vscode +*.suo +*.ntvs* +*.njsproj +*.sln +*.sw? + +*.tsbuildinfo diff --git a/ToDoList-WebApi.Server/Program.cs b/ToDoList-WebApi.Server/Program.cs index ef78545..9031e2d 100644 --- a/ToDoList-WebApi.Server/Program.cs +++ b/ToDoList-WebApi.Server/Program.cs @@ -13,17 +13,15 @@ .AllowAnyMethod() .AllowAnyHeader()); -ApplicationContextUser dbUser = new ApplicationContextUser(); -ApplicationContextNote dbNote = new ApplicationContextNote(); -dbUser.Database.EnsureCreated(); -dbNote.Database.EnsureCreated(); +ApplicationContext db = new ApplicationContext(); +db.Database.EnsureCreated(); app.MapPost("/register", async context => { context.Response.ContentType = "application/json"; var userCredentials = await context.Request.ReadFromJsonAsync(); User user = new User(userCredentials!.Username, userCredentials.Password); - User isCreated = dbUser.FindUserByName(userCredentials.Username); + User isCreated = db.FindUserByName(userCredentials.Username); if (isCreated != null) { @@ -31,8 +29,8 @@ return; } - dbUser.Users.Add(user); - dbUser.SaveChanges(); + db.Users.Add(user); + db.SaveChanges(); Console.WriteLine($"/register | Username: {userCredentials.Username} Pass: {userCredentials.Password}"); @@ -43,7 +41,7 @@ context.Response.ContentType = "application/json"; var userCredentials = await context.Request.ReadFromJsonAsync(); - User isCreated = dbUser.FindUserByNameAndPassword(userCredentials!.Username, userCredentials.Password); + User isCreated = db.FindUserByNameAndPassword(userCredentials!.Username, userCredentials.Password); if (isCreated == null) { @@ -60,7 +58,7 @@ var noteCredentials = await context.Request.ReadFromJsonAsync(); Console.WriteLine("/notes"); - await context.Response.WriteAsJsonAsync(new { notes = dbNote.FindNotesByUsername(noteCredentials.Username)}); + await context.Response.WriteAsJsonAsync(new { notes = db.FindNotesByUsername(noteCredentials.Username)}); }); app.MapPost("/notes/add", async context => { @@ -69,8 +67,8 @@ Note note = new Note(noteCredentials!.Username, noteCredentials!.Title, noteCredentials!.Description); - dbNote.Notes.Add(note); - dbNote.SaveChanges(); + db.Notes.Add(note); + db.SaveChanges(); Console.WriteLine($"/notes/add | Title: {noteCredentials!.Title} Description: {noteCredentials.Description}"); await context.Response.WriteAsJsonAsync(new { data = "2"}); @@ -80,10 +78,10 @@ context.Response.ContentType = "application/json"; var noteCredentials = await context.Request.ReadFromJsonAsync(); - Note note = dbNote.FindNote(noteCredentials!.Username, noteCredentials!.Title, noteCredentials!.Description); + Note note = db.FindNote(noteCredentials!.Username, noteCredentials!.Title, noteCredentials!.Description); - dbNote.Notes.Remove(note); - dbNote.SaveChanges(); + db.Notes.Remove(note); + db.SaveChanges(); Console.WriteLine($"/notes/delete | Title: {noteCredentials!.Title} Description: {noteCredentials.Description}"); await context.Response.WriteAsJsonAsync(new { data = "3"}); @@ -93,12 +91,12 @@ context.Response.ContentType = "application/json"; var editNoteCredentials = await context.Request.ReadFromJsonAsync(); - Note note = dbNote.FindNote(editNoteCredentials!.Username, editNoteCredentials!.Title, editNoteCredentials!.Description); + Note note = db.FindNote(editNoteCredentials!.Username, editNoteCredentials!.Title, editNoteCredentials!.Description); note.Title = editNoteCredentials.NewTitle; note.Description = editNoteCredentials.NewDescription; - dbNote.Notes.Update(note); - dbNote.SaveChanges(); + db.Notes.Update(note); + db.SaveChanges(); Console.WriteLine($"/notes/edit | Title: {editNoteCredentials!.NewTitle} Description: {editNoteCredentials.NewDescription}"); await context.Response.WriteAsJsonAsync(new { data = "3"}); diff --git a/ToDoList-WebApi.Server/ToDoList-WebApi.Server.csproj b/ToDoList-WebApi.Server/ToDoList-WebApi.Server.csproj index 741f9a2..cbbb92f 100644 --- a/ToDoList-WebApi.Server/ToDoList-WebApi.Server.csproj +++ b/ToDoList-WebApi.Server/ToDoList-WebApi.Server.csproj @@ -12,6 +12,7 @@ + 8.*-* diff --git a/ToDoList-WebApi.Server/db/DbContext.cs b/ToDoList-WebApi.Server/db/DbContext.cs new file mode 100644 index 0000000..6be6573 --- /dev/null +++ b/ToDoList-WebApi.Server/db/DbContext.cs @@ -0,0 +1,38 @@ +using Microsoft.EntityFrameworkCore; +using DotNetEnv; + +namespace SQLite +{ + public class ApplicationContext : DbContext + { + public DbSet Users { get; set; } = null!; + public DbSet Notes { get; set; } = null!; + + protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) + { + Env.Load(); + var connectionString = Environment.GetEnvironmentVariable("CONNECTION_STRING"); + optionsBuilder.UseSqlite(connectionString); + } + + public User FindUserByName(string name) + { + return Users.FirstOrDefault(u => u.Name == name); + } + + public User FindUserByNameAndPassword(string name, string password) + { + return Users.FirstOrDefault(u => u.Name == name && u.Password == password); + } + + public List FindNotesByUsername(string name) + { + return Notes.Where(u => u.Username == name).ToList(); + } + + public Note FindNote(string name, string title, string description) + { + return Notes.FirstOrDefault(u => u.Username == name && u.Title == title && u.Description == description); + } + } +} \ No newline at end of file diff --git a/ToDoList-WebApi.Server/db/DbContextNote.cs b/ToDoList-WebApi.Server/db/DbContextNote.cs deleted file mode 100644 index 1feb199..0000000 --- a/ToDoList-WebApi.Server/db/DbContextNote.cs +++ /dev/null @@ -1,25 +0,0 @@ -using Microsoft.EntityFrameworkCore; - -namespace SQLite -{ - public class ApplicationContextNote : DbContext - { - public DbSet Notes {get; set; } = null!; - - protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) - { - optionsBuilder.UseSqlite("Data Source=./db/notes.db"); - } - - public List FindNotesByUsername(string name) - { - List notes = Notes.Where(u => u.Username == name).ToList(); - return notes; - } - - public Note FindNote(string name, string title, string description) - { - return Notes.FirstOrDefault(u => u.Username == name && u.Title == title && u.Description == description); - } - } -} \ No newline at end of file diff --git a/ToDoList-WebApi.Server/db/DbContextUser.cs b/ToDoList-WebApi.Server/db/DbContextUser.cs deleted file mode 100644 index 4f3b383..0000000 --- a/ToDoList-WebApi.Server/db/DbContextUser.cs +++ /dev/null @@ -1,21 +0,0 @@ -using Microsoft.EntityFrameworkCore; - -namespace SQLite -{ - public class ApplicationContextUser : DbContext - { - public DbSet Users {get;set; } = null!; - protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) - { - optionsBuilder.UseSqlite("Data Source=./db/users.sqlite"); - } - public User FindUserByName(string name) - { - return Users.FirstOrDefault(u => u.Name == name); - } - public User FindUserByNameAndPassword(string name, string password) - { - return Users.FirstOrDefault(u => u.Name == name && u.Password == password); - } - } -} \ No newline at end of file diff --git a/ToDoList-WebApi.Server/db/users.sqlite b/ToDoList-WebApi.Server/db/db.sqlite similarity index 72% rename from ToDoList-WebApi.Server/db/users.sqlite rename to ToDoList-WebApi.Server/db/db.sqlite index cbe4fa4..9f72ab1 100644 Binary files a/ToDoList-WebApi.Server/db/users.sqlite and b/ToDoList-WebApi.Server/db/db.sqlite differ diff --git a/ToDoList-WebApi.Server/db/notes.db b/ToDoList-WebApi.Server/db/notes.db deleted file mode 100644 index 3d83e66..0000000 Binary files a/ToDoList-WebApi.Server/db/notes.db and /dev/null differ diff --git a/ToDoList-WebApi.sln.DotSettings.user b/ToDoList-WebApi.sln.DotSettings.user new file mode 100644 index 0000000..ebf25e5 --- /dev/null +++ b/ToDoList-WebApi.sln.DotSettings.user @@ -0,0 +1,4 @@ + + <AssemblyExplorer> + <Assembly Path="C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.7.2\mscorlib.dll" /> +</AssemblyExplorer> \ No newline at end of file diff --git a/todolist-webapi.client/.gitignore b/todolist-webapi.client/.gitignore new file mode 100644 index 0000000..88d1371 --- /dev/null +++ b/todolist-webapi.client/.gitignore @@ -0,0 +1,67 @@ +# Common IntelliJ Platform excludes + +# User specific +**/.idea/**/workspace.xml +**/.idea/**/tasks.xml +**/.idea/shelf/* +**/.idea/dictionaries +**/.idea/httpRequests/ + +# Sensitive or high-churn files +**/.idea/**/dataSources/ +**/.idea/**/dataSources.ids +**/.idea/**/dataSources.xml +**/.idea/**/dataSources.local.xml +**/.idea/**/sqlDataSources.xml +**/.idea/**/dynamic.xml + +# Rider +# Rider auto-generates .iml files, and contentModel.xml +**/.idea/**/*.iml +**/.idea/**/contentModel.xml +**/.idea/**/modules.xml + +*.suo +*.user +.vs/ +[Bb]in/ +[Oo]bj/ +_UpgradeReport_Files/ +[Pp]ackages/ +.idea + +Thumbs.db +Desktop.ini +.DS_Store + +# Logs +logs +*.log +npm-debug.log* +yarn-debug.log* +yarn-error.log* +pnpm-debug.log* +lerna-debug.log* + +node_modules +.DS_Store +dist +dist-ssr +coverage +*.local + +/cypress/videos/ +/cypress/screenshots/ + +# Editor directories and files +.vscode/* +!.vscode/extensions.json +.idea +.vscode +*.suo +*.ntvs* +*.njsproj +*.sln +*.sw? + +*.tsbuildinfo diff --git a/todolist-webapi.client/src/App.vue b/todolist-webapi.client/src/App.vue index 7b68ea4..78233ef 100644 --- a/todolist-webapi.client/src/App.vue +++ b/todolist-webapi.client/src/App.vue @@ -43,7 +43,6 @@ export default { display: flex; justify-content: space-evenly; align-items: center; - //background-image: linear-gradient(43deg, #4158D0 0%, #C850C0 46%, #FFCC70 100%); background: linear-gradient(45deg,#9e9eff, #8000ff, #fecb70); background-size: 300% 100%; animation: gradient 12s linear infinite; diff --git a/users.db b/users.db deleted file mode 100644 index e69de29..0000000