diff options
| author | Danijel Andjelkovic <adanijel99@gmail.com> | 2022-03-02 23:44:50 +0100 | 
|---|---|---|
| committer | Danijel Andjelkovic <adanijel99@gmail.com> | 2022-03-02 23:44:50 +0100 | 
| commit | 311c84b1bf0fa3a9680b16ba1ec3309a0a1dca1f (patch) | |
| tree | 987a2b00e211e56298f257834bef29bb268a6274 /sandbox/testAppSonja/MiniApkSonja | |
| parent | e3999e37a0a0018be4704ed58b7d984781f429c8 (diff) | |
| parent | ee11a13a99d5635eb27850bcd909b73e6f50fced (diff) | |
Merge branch 'dev' of http://gitlab.pmf.kg.ac.rs/igrannonica/neuronstellar
Diffstat (limited to 'sandbox/testAppSonja/MiniApkSonja')
15 files changed, 444 insertions, 0 deletions
| diff --git a/sandbox/testAppSonja/MiniApkSonja/.vs/MiniApkSonja/DesignTimeBuild/.dtbcache.v2 b/sandbox/testAppSonja/MiniApkSonja/.vs/MiniApkSonja/DesignTimeBuild/.dtbcache.v2Binary files differ new file mode 100644 index 00000000..1b7e3546 --- /dev/null +++ b/sandbox/testAppSonja/MiniApkSonja/.vs/MiniApkSonja/DesignTimeBuild/.dtbcache.v2 diff --git a/sandbox/testAppSonja/MiniApkSonja/.vs/MiniApkSonja/v16/.suo b/sandbox/testAppSonja/MiniApkSonja/.vs/MiniApkSonja/v16/.suoBinary files differ new file mode 100644 index 00000000..1099064a --- /dev/null +++ b/sandbox/testAppSonja/MiniApkSonja/.vs/MiniApkSonja/v16/.suo 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/<StudentsController> +        [HttpGet] +        public List<Student> Get() +        { +            return db.getAllStudents(); +        } + +        // GET api/<StudentsController>/5 +        [HttpGet("{id}")] +        public Student Get(int id) +        { +            return db.getStudentById(id); +        } + +        // POST api/<StudentsController> +        [HttpPost] +        public void Post([FromBody] Student student) +        { +            db.addStudent(student); +        } + +        // PUT api/<StudentsController>/5 +        [HttpPut("{id}")] +        public void Put(int id, [FromBody] Student student) +        { +            //Console.WriteLine(student); +            db.updateStudentInfo(student); +        } + +        // DELETE api/<StudentsController>/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 @@ +<Project Sdk="Microsoft.NET.Sdk.Web"> + +  <PropertyGroup> +    <TargetFramework>net5.0</TargetFramework> +  </PropertyGroup> + +  <ItemGroup> +    <PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="3.1.22" /> +    <PackageReference Include="Newtonsoft.Json" Version="13.0.1" /> +    <PackageReference Include="Swashbuckle.AspNetCore" Version="5.6.3" /> +    <PackageReference Include="System.Data.SQLite" Version="1.0.115.5" /> +  </ItemGroup> + +</Project> 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 @@ +<?xml version="1.0" encoding="utf-8"?> +<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> +  <PropertyGroup> +    <Controller_SelectedScaffolderID>ApiControllerWithActionsScaffolder</Controller_SelectedScaffolderID> +    <Controller_SelectedScaffolderCategoryPath>root/Common/Api</Controller_SelectedScaffolderCategoryPath> +    <ActiveDebugProfile>MiniApkSonja</ActiveDebugProfile> +  </PropertyGroup> +  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'"> +    <DebuggerFlavor>ProjectDebugger</DebuggerFlavor> +  </PropertyGroup> +</Project>
\ 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<Startup>(); +                }); +    } +} 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<ForwardedHeadersOptions>(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<Student> getAllStudents() +        { +            List<Student> students = new List<Student>(); + +            _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.dbBinary files differ new file mode 100644 index 00000000..5e7f5af1 --- /dev/null +++ b/sandbox/testAppSonja/MiniApkSonja/MiniApkSonja/probnaBaza.db | 
