From dce4e644d5e5d9c97ff5ac337448b52f2a2a64fd Mon Sep 17 00:00:00 2001 From: TAMARA JERINIC Date: Wed, 2 Mar 2022 23:38:27 +0100 Subject: Merge branch 'dev' of http://gitlab.pmf.kg.ac.rs/igrannonica/neuronstellar into Tamara # Conflicts: # .gitignore --- .../.vs/MiniApkSonja/DesignTimeBuild/.dtbcache.v2 | Bin 0 -> 122246 bytes .../MiniApkSonja/.vs/MiniApkSonja/v16/.suo | Bin 0 -> 57856 bytes sandbox/testAppSonja/MiniApkSonja/MiniApkSonja.sln | 25 ++++ .../MiniApkSonja/Controllers/StudentsController.cs | 55 +++++++++ .../MiniApkSonja/DatabaseConnection.cs | 23 ++++ .../MiniApkSonja/MiniApkSonja/MiniApkSonja.csproj | 14 +++ .../MiniApkSonja/MiniApkSonja.csproj.user | 11 ++ .../MiniApkSonja/MiniApkSonja/Models/Student.cs | 33 ++++++ .../MiniApkSonja/MiniApkSonja/Program.cs | 26 +++++ .../MiniApkSonja/Properties/launchSettings.json | 31 +++++ .../MiniApkSonja/MiniApkSonja/Startup.cs | 77 ++++++++++++ .../MiniApkSonja/MiniApkSonja/StudentsDb.cs | 130 +++++++++++++++++++++ .../MiniApkSonja/appsettings.Development.json | 9 ++ .../MiniApkSonja/MiniApkSonja/appsettings.json | 10 ++ .../MiniApkSonja/MiniApkSonja/probnaBaza.db | Bin 0 -> 12288 bytes 15 files changed, 444 insertions(+) create mode 100644 sandbox/testAppSonja/MiniApkSonja/.vs/MiniApkSonja/DesignTimeBuild/.dtbcache.v2 create mode 100644 sandbox/testAppSonja/MiniApkSonja/.vs/MiniApkSonja/v16/.suo create mode 100644 sandbox/testAppSonja/MiniApkSonja/MiniApkSonja.sln create mode 100644 sandbox/testAppSonja/MiniApkSonja/MiniApkSonja/Controllers/StudentsController.cs create mode 100644 sandbox/testAppSonja/MiniApkSonja/MiniApkSonja/DatabaseConnection.cs create mode 100644 sandbox/testAppSonja/MiniApkSonja/MiniApkSonja/MiniApkSonja.csproj create mode 100644 sandbox/testAppSonja/MiniApkSonja/MiniApkSonja/MiniApkSonja.csproj.user create mode 100644 sandbox/testAppSonja/MiniApkSonja/MiniApkSonja/Models/Student.cs create mode 100644 sandbox/testAppSonja/MiniApkSonja/MiniApkSonja/Program.cs create mode 100644 sandbox/testAppSonja/MiniApkSonja/MiniApkSonja/Properties/launchSettings.json create mode 100644 sandbox/testAppSonja/MiniApkSonja/MiniApkSonja/Startup.cs create mode 100644 sandbox/testAppSonja/MiniApkSonja/MiniApkSonja/StudentsDb.cs create mode 100644 sandbox/testAppSonja/MiniApkSonja/MiniApkSonja/appsettings.Development.json create mode 100644 sandbox/testAppSonja/MiniApkSonja/MiniApkSonja/appsettings.json create mode 100644 sandbox/testAppSonja/MiniApkSonja/MiniApkSonja/probnaBaza.db (limited to 'sandbox/testAppSonja/MiniApkSonja') diff --git a/sandbox/testAppSonja/MiniApkSonja/.vs/MiniApkSonja/DesignTimeBuild/.dtbcache.v2 b/sandbox/testAppSonja/MiniApkSonja/.vs/MiniApkSonja/DesignTimeBuild/.dtbcache.v2 new file mode 100644 index 00000000..1b7e3546 Binary files /dev/null and b/sandbox/testAppSonja/MiniApkSonja/.vs/MiniApkSonja/DesignTimeBuild/.dtbcache.v2 differ diff --git a/sandbox/testAppSonja/MiniApkSonja/.vs/MiniApkSonja/v16/.suo b/sandbox/testAppSonja/MiniApkSonja/.vs/MiniApkSonja/v16/.suo new file mode 100644 index 00000000..1099064a Binary files /dev/null and b/sandbox/testAppSonja/MiniApkSonja/.vs/MiniApkSonja/v16/.suo differ diff --git a/sandbox/testAppSonja/MiniApkSonja/MiniApkSonja.sln b/sandbox/testAppSonja/MiniApkSonja/MiniApkSonja.sln new file mode 100644 index 00000000..bc772a57 --- /dev/null +++ b/sandbox/testAppSonja/MiniApkSonja/MiniApkSonja.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.32126.315 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MiniApkSonja", "MiniApkSonja\MiniApkSonja.csproj", "{1E83711A-DEDA-4901-BD93-6D9E880CB9AA}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {1E83711A-DEDA-4901-BD93-6D9E880CB9AA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {1E83711A-DEDA-4901-BD93-6D9E880CB9AA}.Debug|Any CPU.Build.0 = Debug|Any CPU + {1E83711A-DEDA-4901-BD93-6D9E880CB9AA}.Release|Any CPU.ActiveCfg = Release|Any CPU + {1E83711A-DEDA-4901-BD93-6D9E880CB9AA}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {247FC99F-65DB-4842-8837-6514DE7832C8} + EndGlobalSection +EndGlobal diff --git a/sandbox/testAppSonja/MiniApkSonja/MiniApkSonja/Controllers/StudentsController.cs b/sandbox/testAppSonja/MiniApkSonja/MiniApkSonja/Controllers/StudentsController.cs new file mode 100644 index 00000000..3b53f636 --- /dev/null +++ b/sandbox/testAppSonja/MiniApkSonja/MiniApkSonja/Controllers/StudentsController.cs @@ -0,0 +1,55 @@ +using Microsoft.AspNetCore.Mvc; +using MiniApkSonja.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using System.Data.SQLite; +using Newtonsoft.Json; + +// For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860 + +namespace MiniApkSonja.Controllers +{ + [Route("api/[controller]")] + [ApiController] + public class StudentsController : ControllerBase + { + private StudentsDb db = new StudentsDb(); + // GET: api/ + [HttpGet] + public List Get() + { + return db.getAllStudents(); + } + + // GET api//5 + [HttpGet("{id}")] + public Student Get(int id) + { + return db.getStudentById(id); + } + + // POST api/ + [HttpPost] + public void Post([FromBody] Student student) + { + db.addStudent(student); + } + + // PUT api//5 + [HttpPut("{id}")] + public void Put(int id, [FromBody] Student student) + { + //Console.WriteLine(student); + db.updateStudentInfo(student); + } + + // DELETE api//5 + [HttpDelete("{id}")] + public void Delete(int id) + { + db.deleteStudentById(id); + } + } +} diff --git a/sandbox/testAppSonja/MiniApkSonja/MiniApkSonja/DatabaseConnection.cs b/sandbox/testAppSonja/MiniApkSonja/MiniApkSonja/DatabaseConnection.cs new file mode 100644 index 00000000..26f94c6a --- /dev/null +++ b/sandbox/testAppSonja/MiniApkSonja/MiniApkSonja/DatabaseConnection.cs @@ -0,0 +1,23 @@ +using System; +using System.Collections.Generic; +using System.Data.SQLite; +using System.Linq; +using System.Threading.Tasks; + +namespace MiniApkSonja +{ + public class DatabaseConnection + { + private static SQLiteConnection _connection = null; + + public static SQLiteConnection Connection + { + get + { + if (_connection == null) + _connection = new SQLiteConnection("Data Source=probnaBaza.db"); + return _connection; + } + } + } +} diff --git a/sandbox/testAppSonja/MiniApkSonja/MiniApkSonja/MiniApkSonja.csproj b/sandbox/testAppSonja/MiniApkSonja/MiniApkSonja/MiniApkSonja.csproj new file mode 100644 index 00000000..531e1672 --- /dev/null +++ b/sandbox/testAppSonja/MiniApkSonja/MiniApkSonja/MiniApkSonja.csproj @@ -0,0 +1,14 @@ + + + + net5.0 + + + + + + + + + + diff --git a/sandbox/testAppSonja/MiniApkSonja/MiniApkSonja/MiniApkSonja.csproj.user b/sandbox/testAppSonja/MiniApkSonja/MiniApkSonja/MiniApkSonja.csproj.user new file mode 100644 index 00000000..397c9961 --- /dev/null +++ b/sandbox/testAppSonja/MiniApkSonja/MiniApkSonja/MiniApkSonja.csproj.user @@ -0,0 +1,11 @@ + + + + ApiControllerWithActionsScaffolder + root/Common/Api + MiniApkSonja + + + ProjectDebugger + + \ No newline at end of file diff --git a/sandbox/testAppSonja/MiniApkSonja/MiniApkSonja/Models/Student.cs b/sandbox/testAppSonja/MiniApkSonja/MiniApkSonja/Models/Student.cs new file mode 100644 index 00000000..eb09af9a --- /dev/null +++ b/sandbox/testAppSonja/MiniApkSonja/MiniApkSonja/Models/Student.cs @@ -0,0 +1,33 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace MiniApkSonja.Models +{ + public class Student + { + public int id; + public string firstName; + public string lastName; + public string regNum; + public string address; + public string phoneNum; + public double gpa; + + public Student(int id, string firstName, string lastName, string regNum, string address, string phoneNum, double gpa) + { + this.id = id; + this.firstName = firstName; + this.lastName = lastName; + this.regNum = regNum; + this.address = address; + this.phoneNum = phoneNum; + this.gpa = gpa; + } + public override string ToString() + { + return id + " " + firstName + " " + lastName + " " + regNum + " " + address + " " + phoneNum + " " + gpa; + } + } +} diff --git a/sandbox/testAppSonja/MiniApkSonja/MiniApkSonja/Program.cs b/sandbox/testAppSonja/MiniApkSonja/MiniApkSonja/Program.cs new file mode 100644 index 00000000..b27489b8 --- /dev/null +++ b/sandbox/testAppSonja/MiniApkSonja/MiniApkSonja/Program.cs @@ -0,0 +1,26 @@ +using Microsoft.AspNetCore.Hosting; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.Hosting; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace MiniApkSonja +{ + public class Program + { + public static void Main(string[] args) + { + CreateHostBuilder(args).Build().Run(); + } + + public static IHostBuilder CreateHostBuilder(string[] args) => + Host.CreateDefaultBuilder(args) + .ConfigureWebHostDefaults(webBuilder => + { + webBuilder.UseStartup(); + }); + } +} diff --git a/sandbox/testAppSonja/MiniApkSonja/MiniApkSonja/Properties/launchSettings.json b/sandbox/testAppSonja/MiniApkSonja/MiniApkSonja/Properties/launchSettings.json new file mode 100644 index 00000000..7f2c7f55 --- /dev/null +++ b/sandbox/testAppSonja/MiniApkSonja/MiniApkSonja/Properties/launchSettings.json @@ -0,0 +1,31 @@ +{ + "$schema": "http://json.schemastore.org/launchsettings.json", + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:38320", + "sslPort": 0 + } + }, + "profiles": { + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "launchUrl": "swagger", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "MiniApkSonja": { + "commandName": "Project", + "dotnetRunMessages": "true", + "launchBrowser": true, + "launchUrl": "swagger", + "applicationUrl": "http://localhost:5000", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + } + } +} diff --git a/sandbox/testAppSonja/MiniApkSonja/MiniApkSonja/Startup.cs b/sandbox/testAppSonja/MiniApkSonja/MiniApkSonja/Startup.cs new file mode 100644 index 00000000..e920a364 --- /dev/null +++ b/sandbox/testAppSonja/MiniApkSonja/MiniApkSonja/Startup.cs @@ -0,0 +1,77 @@ +using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting; +using Microsoft.Extensions.Logging; +using Microsoft.OpenApi.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Newtonsoft.Json.Serialization; +using Microsoft.AspNetCore.HttpOverrides; + +namespace MiniApkSonja +{ + public class Startup + { + public Startup(IConfiguration configuration) + { + Configuration = configuration; + } + + public IConfiguration Configuration { get; } + + // This method gets called by the runtime. Use this method to add services to the container. + public void ConfigureServices(IServiceCollection services) + { + + services.AddSwaggerGen(c => + { + c.SwaggerDoc("v1", new OpenApiInfo { Title = "MiniApkSonja", Version = "v1" }); + }); + + services.AddControllersWithViews() + .AddNewtonsoftJson(options => + options.SerializerSettings.ReferenceLoopHandling = Newtonsoft + .Json.ReferenceLoopHandling.Ignore) + .AddNewtonsoftJson(options => options.SerializerSettings.ContractResolver = new DefaultContractResolver()); + + services.AddCors(options => options.AddDefaultPolicy(builder => builder.WithOrigins("http://localhost:4200").AllowAnyHeader().AllowAnyMethod())); + + services.AddControllers(); + + services.Configure(options => + { + options.ForwardedHeaders = + ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto; + }); + } + + // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. + public void Configure(IApplicationBuilder app, IWebHostEnvironment env) + { + if (env.IsDevelopment()) + { + app.UseDeveloperExceptionPage(); + app.UseSwagger(); + app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "MiniApkSonja v1")); + } + + app.UseForwardedHeaders(); + app.UseStaticFiles(); + + app.UseRouting(); + app.UseCors(); + + app.UseAuthorization(); + + app.UseEndpoints(endpoints => + { + endpoints.MapControllers(); + }); + } + } +} diff --git a/sandbox/testAppSonja/MiniApkSonja/MiniApkSonja/StudentsDb.cs b/sandbox/testAppSonja/MiniApkSonja/MiniApkSonja/StudentsDb.cs new file mode 100644 index 00000000..fe5ad221 --- /dev/null +++ b/sandbox/testAppSonja/MiniApkSonja/MiniApkSonja/StudentsDb.cs @@ -0,0 +1,130 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using System.Data.SQLite; +using MiniApkSonja.Models; + +namespace MiniApkSonja +{ + public class StudentsDb + { + SQLiteConnection _connection = DatabaseConnection.Connection; + + internal List getAllStudents() + { + List students = new List(); + + _connection.Open(); + + SQLiteCommand cmd = new SQLiteCommand(); + cmd.Connection = _connection; + cmd.CommandText = @"select * from studenti"; + + SQLiteDataReader reader = cmd.ExecuteReader(); + while (reader.Read()) + { + students.Add(new Student( + int.Parse(reader["id"].ToString()), + reader["firstName"].ToString(), + reader["lastName"].ToString(), + reader["regNum"].ToString(), + reader["address"].ToString(), + reader["phoneNum"].ToString(), + double.Parse(reader["gpa"].ToString()) + )); + } + reader.Close(); + + _connection.Close(); + + return students; + } + + internal void addStudent(Student student) + { + _connection.Open(); + + SQLiteCommand cmd = new SQLiteCommand(); + cmd.Connection = _connection; + cmd.CommandText = @"insert into studenti(firstName,lastName,regNum,address,phoneNum,gpa) values(@firstName, @lastName, @regNum, @address, @phoneNum, @gpa)"; + cmd.Parameters.AddWithValue("@id", student.id); + cmd.Parameters.AddWithValue("@firstName", student.firstName); + cmd.Parameters.AddWithValue("@lastName", student.lastName); + cmd.Parameters.AddWithValue("@regNum", student.regNum); + cmd.Parameters.AddWithValue("@address", student.address); + cmd.Parameters.AddWithValue("@phoneNum", student.phoneNum); + cmd.Parameters.AddWithValue("@gpa", student.gpa); + + cmd.ExecuteNonQuery(); + + _connection.Close(); + } + + internal Student getStudentById(int id) + { + Student student = null; + + _connection.Open(); + + SQLiteCommand cmd = new SQLiteCommand(); + cmd.Connection = _connection; + cmd.CommandText = @"select * from studenti where id=@id"; + cmd.Parameters.AddWithValue("@id", id); + + SQLiteDataReader reader = cmd.ExecuteReader(); + while (reader.Read()) + { + student = new Student( + int.Parse(reader["id"].ToString()), + reader["firstName"].ToString(), + reader["lastName"].ToString(), + reader["regNum"].ToString(), + reader["address"].ToString(), + reader["phoneNum"].ToString(), + double.Parse(reader["gpa"].ToString()) + ); + } + reader.Close(); + + _connection.Close(); + + return student; + } + + internal void updateStudentInfo(Student student) + { + _connection.Open(); + + SQLiteCommand cmd = new SQLiteCommand(); + cmd.Connection = _connection; + cmd.CommandText = @"update studenti set firstName=@firstName, lastName=@lastName, regNum=@regNum, address=@address, phoneNum=@phoneNum, gpa=@gpa where id=@id"; + cmd.Parameters.AddWithValue("@id", student.id); + cmd.Parameters.AddWithValue("@firstName", student.firstName); + cmd.Parameters.AddWithValue("@lastName", student.lastName); + cmd.Parameters.AddWithValue("@regNum", student.regNum); + cmd.Parameters.AddWithValue("@address", student.address); + cmd.Parameters.AddWithValue("@phoneNum", student.phoneNum); + cmd.Parameters.AddWithValue("@gpa", student.gpa); + + cmd.ExecuteNonQuery(); + + _connection.Close(); + } + + internal void deleteStudentById(int id) + { + _connection.Open(); + + SQLiteCommand cmd = new SQLiteCommand(); + cmd.Connection = _connection; + cmd.CommandText = @"delete from studenti where id=@id"; + cmd.Parameters.AddWithValue("@id", id); + + cmd.ExecuteNonQuery(); + + _connection.Close(); + } + + } +} diff --git a/sandbox/testAppSonja/MiniApkSonja/MiniApkSonja/appsettings.Development.json b/sandbox/testAppSonja/MiniApkSonja/MiniApkSonja/appsettings.Development.json new file mode 100644 index 00000000..8983e0fc --- /dev/null +++ b/sandbox/testAppSonja/MiniApkSonja/MiniApkSonja/appsettings.Development.json @@ -0,0 +1,9 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft": "Warning", + "Microsoft.Hosting.Lifetime": "Information" + } + } +} diff --git a/sandbox/testAppSonja/MiniApkSonja/MiniApkSonja/appsettings.json b/sandbox/testAppSonja/MiniApkSonja/MiniApkSonja/appsettings.json new file mode 100644 index 00000000..d9d9a9bf --- /dev/null +++ b/sandbox/testAppSonja/MiniApkSonja/MiniApkSonja/appsettings.json @@ -0,0 +1,10 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft": "Warning", + "Microsoft.Hosting.Lifetime": "Information" + } + }, + "AllowedHosts": "*" +} diff --git a/sandbox/testAppSonja/MiniApkSonja/MiniApkSonja/probnaBaza.db b/sandbox/testAppSonja/MiniApkSonja/MiniApkSonja/probnaBaza.db new file mode 100644 index 00000000..5e7f5af1 Binary files /dev/null and b/sandbox/testAppSonja/MiniApkSonja/MiniApkSonja/probnaBaza.db differ -- cgit v1.2.3