From c4c04a7231c14326a7ef0eb601ee316cff1d1f15 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tommy=20=C3=96man?= Date: Thu, 5 Feb 2026 14:24:53 +0100 Subject: [PATCH] =?UTF-8?q?p=C3=A5b=C3=B6rjat=20utv?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../VideoGameCharactersController.cs | 17 +++++++++ VideoGameCharacterApi/Models/Character.cs | 10 +++++ VideoGameCharacterApi/Program.cs | 6 +++ .../Services/IVideoGameCharacterService.cs | 12 ++++++ .../Services/VideoGameCharacterService.cs | 37 +++++++++++++++++++ .../VideoGameCharacterApi.csproj | 3 +- 6 files changed, 84 insertions(+), 1 deletion(-) create mode 100644 VideoGameCharacterApi/Controllers/VideoGameCharactersController.cs create mode 100644 VideoGameCharacterApi/Models/Character.cs create mode 100644 VideoGameCharacterApi/Services/IVideoGameCharacterService.cs create mode 100644 VideoGameCharacterApi/Services/VideoGameCharacterService.cs diff --git a/VideoGameCharacterApi/Controllers/VideoGameCharactersController.cs b/VideoGameCharacterApi/Controllers/VideoGameCharactersController.cs new file mode 100644 index 0000000..05f53e8 --- /dev/null +++ b/VideoGameCharacterApi/Controllers/VideoGameCharactersController.cs @@ -0,0 +1,17 @@ +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; +using VideoGameCharacterApi.Models; +using VideoGameCharacterApi.Services; + +namespace VideoGameCharacterApi.Controllers +{ + [Route("api/[controller]")] + [ApiController] + public class VideoGameCharactersController(IVideoGameCharacterService service ) : ControllerBase + { + + [HttpGet] + public async Task>> GetCharacters() + => Ok(await service.GetCharactersAsync()); + } +} diff --git a/VideoGameCharacterApi/Models/Character.cs b/VideoGameCharacterApi/Models/Character.cs new file mode 100644 index 0000000..d151d68 --- /dev/null +++ b/VideoGameCharacterApi/Models/Character.cs @@ -0,0 +1,10 @@ +namespace VideoGameCharacterApi.Models +{ + public class Character + { + public int Id { get; set; } + public string Name { get; set; } = string.Empty; + public string Game { get; set; } = string.Empty; + public string Role { get; set; } = string.Empty; + } +} diff --git a/VideoGameCharacterApi/Program.cs b/VideoGameCharacterApi/Program.cs index 666a9c5..c0035fc 100644 --- a/VideoGameCharacterApi/Program.cs +++ b/VideoGameCharacterApi/Program.cs @@ -1,3 +1,6 @@ +using Scalar.AspNetCore; +using VideoGameCharacterApi.Services; + var builder = WebApplication.CreateBuilder(args); // Add services to the container. @@ -6,12 +9,15 @@ builder.Services.AddControllers(); // Learn more about configuring OpenAPI at https://aka.ms/aspnet/openapi builder.Services.AddOpenApi(); +builder.Services.AddScoped(); + var app = builder.Build(); // Configure the HTTP request pipeline. if (app.Environment.IsDevelopment()) { app.MapOpenApi(); + app.MapScalarApiReference(); } app.UseHttpsRedirection(); diff --git a/VideoGameCharacterApi/Services/IVideoGameCharacterService.cs b/VideoGameCharacterApi/Services/IVideoGameCharacterService.cs new file mode 100644 index 0000000..6d4f592 --- /dev/null +++ b/VideoGameCharacterApi/Services/IVideoGameCharacterService.cs @@ -0,0 +1,12 @@ +using VideoGameCharacterApi.Models; + +namespace VideoGameCharacterApi.Services; + +public interface IVideoGameCharacterService +{ + Task> GetCharactersAsync(); + Task GetCharacterByIdAsync(int id); + Task AddCharacterAsync(Character character); + Task UpdateCharacterAsync(int id,Character character); + Task DeleteCharacterAsync(int id); +} diff --git a/VideoGameCharacterApi/Services/VideoGameCharacterService.cs b/VideoGameCharacterApi/Services/VideoGameCharacterService.cs new file mode 100644 index 0000000..ab5fa95 --- /dev/null +++ b/VideoGameCharacterApi/Services/VideoGameCharacterService.cs @@ -0,0 +1,37 @@ +using VideoGameCharacterApi.Models; + +namespace VideoGameCharacterApi.Services +{ + public class VideoGameCharacterService : IVideoGameCharacterService + { + static List characters = new List + { + new Character { Id = 1, Name = "Mario", Game = "Super Mario Bros.", Role = "hero" }, + new Character { Id = 2, Name = "Link", Game = "The Legend of Zelda", Role = "hero" }, + new Character { Id = 3, Name = "Bowser", Game = "Super Mario Bros.", Role = "villain" }, + new Character { Id = 3, Name = "Zelda", Game = "The Legend of Zelda", Role = "princess" }, + + }; + + public Task AddCharacterAsync(Character character) + { + throw new NotImplementedException(); + } + + public Task DeleteCharacterAsync(int id) + { + throw new NotImplementedException(); + } + + public async Task GetCharacterByIdAsync(int id) + => await Task.FromResult(characters.FirstOrDefault(c => c.Id == id)); + + public async Task> GetCharactersAsync() + => await Task.FromResult(characters); + + public Task UpdateCharacterAsync(int id, Character character) + { + throw new NotImplementedException(); + } + } +} diff --git a/VideoGameCharacterApi/VideoGameCharacterApi.csproj b/VideoGameCharacterApi/VideoGameCharacterApi.csproj index 530dd4e..fd42fea 100644 --- a/VideoGameCharacterApi/VideoGameCharacterApi.csproj +++ b/VideoGameCharacterApi/VideoGameCharacterApi.csproj @@ -1,4 +1,4 @@ - + net10.0 @@ -8,6 +8,7 @@ +