Skip to content
This repository was archived by the owner on Sep 9, 2025. It is now read-only.
Open
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: 13 additions & 0 deletions Atillo/.idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Atillo/.idea/indexLayout.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

53 changes: 53 additions & 0 deletions Atillo/StudentWebApi/Controllers/StudentController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
using Microsoft.AspNetCore.Mvc;
using Services.Interfaces;
using StudentWebApi.Models;

namespace StudentWebApi.Controllers
{
[ApiController]
[Route("api/[controller]")]
public class StudentController : ControllerBase
{
private readonly IStudentService _studentService;

public StudentController(IStudentService studentService)
{
_studentService = studentService;
}

[HttpGet]
public ActionResult<List<Student>> GetAllStudents()
{
return Ok(_studentService.GetAllStudents());
}

[HttpGet("{id}")]
public ActionResult<Student> GetStudentById(int id)
{
Student? student = _studentService.GetStudentById(id);

return student == null ? NotFound("Student not found") : Ok(student);
}

[HttpPost]
public IActionResult AddStudent([FromBody] Student student)
{
Student? studentToBeAdded = _studentService.AddStudent(student);
return studentToBeAdded != null? Ok(student): BadRequest("Id already taken.");
}

[HttpPut("{id}")]
public IActionResult UpdateStudent(int id, [FromBody] Student student)
{
Student? studentToUpdate = _studentService.UpdateStudent(id, student);

return studentToUpdate == null ? NotFound("Student not found") : Ok(studentToUpdate);
}

[HttpDelete("{id}")]
public ActionResult<bool> DeleteStudent(long id)
{
return _studentService.DeleteStudent(id)? Ok($"Removed {id} successfully") : NotFound($"Couldn't find id: {id}");
}
}
}
22 changes: 22 additions & 0 deletions Atillo/StudentWebApi/Models/Student.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
namespace StudentWebApi.Models
{
public class Student
{
private long _studentId;
private string _name;
private string _course;

public long StudentId { get; set; }
public string Name { get; set; }
public string Course { get; set; }

public Student() { }

public Student(long studentId, string name, string course)
{
StudentId = studentId;
Name = name;
Course = course;
}
}
}
24 changes: 24 additions & 0 deletions Atillo/StudentWebApi/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using Services.Interfaces;
using StudentWebApi.Services.Implementation;

var builder = WebApplication.CreateBuilder(args);

// Add services to the container.
// Learn more about configuring OpenAPI at https://aka.ms/aspnet/openapi
builder.Services.AddOpenApi();
builder.Services.AddSingleton<IStudentService, StudentService>();
builder.Services.AddControllers();

var app = builder.Build();

// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.MapOpenApi();
}

app.MapControllers();

app.UseHttpsRedirection();

app.Run();
23 changes: 23 additions & 0 deletions Atillo/StudentWebApi/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"$schema": "https://json.schemastore.org/launchsettings.json",
"profiles": {
"http": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": false,
"applicationUrl": "http://localhost:9090",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"https": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": false,
"applicationUrl": "https://localhost:7212;http://localhost:9090",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}
50 changes: 50 additions & 0 deletions Atillo/StudentWebApi/Services/Implementation/StudentService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
using StudentWebApi.Models;
using Services.Interfaces;

namespace StudentWebApi.Services.Implementation
{
public class StudentService : IStudentService
{
private Dictionary<long, Student> _students = new Dictionary<long, Student>();
private long _idCounter = 1L;

public Student AddStudent(Student student)
{
if (student.StudentId == 0)
{
student.StudentId = _idCounter++;
}

return _students.TryAdd(student.StudentId, student) ? student : null;
}

public List<Student> GetAllStudents()
{
return [.. _students.Values];
}

public Student? GetStudentById(long id)
{
return _students.GetValueOrDefault(id);
}

public Student UpdateStudent(long id, Student student)
{
if (!_students.TryGetValue(id, out var studentToUpdate))
{
return null!; // Student not found
}

if (!string.IsNullOrEmpty(student.Name)) studentToUpdate.Name = student.Name;

if(string.IsNullOrEmpty(student.Course)) studentToUpdate.Course = student.Course;

return studentToUpdate;
}

public bool DeleteStudent(long id)
{
return _students.Remove(id);
}
}
}
13 changes: 13 additions & 0 deletions Atillo/StudentWebApi/Services/Interfaces/IStudentService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using StudentWebApi.Models;

namespace Services.Interfaces
{
public interface IStudentService
{
Student AddStudent(Student student);
List<Student> GetAllStudents();
Student? GetStudentById(long id);
Student UpdateStudent(long id, Student student);
bool DeleteStudent(long id);
}
}
13 changes: 13 additions & 0 deletions Atillo/StudentWebApi/StudentWebApi.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="9.0.1" />
</ItemGroup>

</Project>
6 changes: 6 additions & 0 deletions Atillo/StudentWebApi/StudentWebApi.http
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
@StudentWebApi_HostAddress = http://localhost:5157

GET {{StudentWebApi_HostAddress}}/weatherforecast/
Accept: application/json

###
8 changes: 8 additions & 0 deletions Atillo/StudentWebApi/appsettings.Development.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
}
}
9 changes: 9 additions & 0 deletions Atillo/StudentWebApi/appsettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*"
}
Binary file not shown.
Binary file not shown.
Binary file not shown.
59 changes: 59 additions & 0 deletions Atillo/StudentWebApi/bin/Debug/net9.0/StudentWebApi.deps.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
{
"runtimeTarget": {
"name": ".NETCoreApp,Version=v9.0",
"signature": ""
},
"compilationOptions": {},
"targets": {
".NETCoreApp,Version=v9.0": {
"StudentWebApi/1.0.0": {
"dependencies": {
"Microsoft.AspNetCore.OpenApi": "9.0.1"
},
"runtime": {
"StudentWebApi.dll": {}
}
},
"Microsoft.AspNetCore.OpenApi/9.0.1": {
"dependencies": {
"Microsoft.OpenApi": "1.6.17"
},
"runtime": {
"lib/net9.0/Microsoft.AspNetCore.OpenApi.dll": {
"assemblyVersion": "9.0.1.0",
"fileVersion": "9.0.124.61009"
}
}
},
"Microsoft.OpenApi/1.6.17": {
"runtime": {
"lib/netstandard2.0/Microsoft.OpenApi.dll": {
"assemblyVersion": "1.6.17.0",
"fileVersion": "1.6.17.0"
}
}
}
}
},
"libraries": {
"StudentWebApi/1.0.0": {
"type": "project",
"serviceable": false,
"sha512": ""
},
"Microsoft.AspNetCore.OpenApi/9.0.1": {
"type": "package",
"serviceable": true,
"sha512": "sha512-xRJe8UrLnOGs6hOBrT/4r74q97626H0mABb/DV0smlReIx6uQCENAe+TUqF6hD3NtT4sB+qrvWhAej6kxPxgew==",
"path": "microsoft.aspnetcore.openapi/9.0.1",
"hashPath": "microsoft.aspnetcore.openapi.9.0.1.nupkg.sha512"
},
"Microsoft.OpenApi/1.6.17": {
"type": "package",
"serviceable": true,
"sha512": "sha512-Le+kehlmrlQfuDFUt1zZ2dVwrhFQtKREdKBo+rexOwaCoYP0/qpgT9tLxCsZjsgR5Itk1UKPcbgO+FyaNid/bA==",
"path": "microsoft.openapi/1.6.17",
"hashPath": "microsoft.openapi.1.6.17.nupkg.sha512"
}
}
}
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"runtimeOptions": {
"tfm": "net9.0",
"frameworks": [
{
"name": "Microsoft.NETCore.App",
"version": "9.0.0"
},
{
"name": "Microsoft.AspNetCore.App",
"version": "9.0.0"
}
],
"configProperties": {
"System.GC.Server": true,
"System.Runtime.Serialization.EnableUnsafeBinaryFormatterSerialization": false
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"Version": 1,
"ManifestType": "Build",
"Endpoints": []
}
Loading