Skip to content
Merged
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
12 changes: 12 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
name: lint
on: [push, pull request]
jobs:
dotnet-format:
runs-on: ubuntu-latest
steps:
-uses: actions/checkout@v4
-uses: actions/settup-dotnet@v4
with:
dotnet-version: '9.x';
-run: dotnet format --verify-no-changes

11 changes: 7 additions & 4 deletions Podcast/AppDbContext.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
using Microsoft.EntityFrameworkCore;
using Podcast.Models;

namespace Podcast
{
public class AppDbContext : DbContext
{
public AppDbContext(DbContextOptions<AppDbContext> options) : base(options) { }
public AppDbContext(DbContextOptions<AppDbContext> options) : base(options)
{
}

public DbSet<UserC> Usuarios { get; set; }
public DbSet<PodcastModel> Podcasts { get; set; }
public DbSet<PodcastModel> Podcasts { get; set; }
public DbSet<Episode> Episodios { get; set; }
public DbSet<Reproduction> Reproducciones { get; set; }
public DbSet<Category> Categorías { get; set; }
Expand Down Expand Up @@ -58,6 +62,5 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
modelBuilder.Entity<Reproduction>().Property(r => r.ReproductionTime).HasColumnName("fecha_reproduccion");
modelBuilder.Entity<Reproduction>().Property(r => r.TimeHeard).HasColumnName("segundos_escuchados");
}

}
}
}
14 changes: 7 additions & 7 deletions Podcast/Controllers/CategoryController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,31 +12,31 @@ public class CategoryController : ControllerBase
private readonly string _connectionString;
public CategoryController(IConfiguration configuration)
{
_connectionString = configuration.GetConnectionString("DefaultConnection")!;
this._connectionString = configuration.GetConnectionString("DefaultConnection")!;
}
[HttpGet]
public async Task<IActionResult> GetAll()
{
using var conn = new SqlConnection(_connectionString);
var categories = await conn.QueryAsync<Category>(
using SqlConnection conn = new SqlConnection(this._connectionString);
IEnumerable<Category> categories = await conn.QueryAsync<Category>(
@"SELECT id_categoria AS IdCategory,
nombre AS Name,
descripcion AS Description
FROM CATEGORIA"
);
return Ok(categories);
return this.Ok(categories);
}
[HttpPost]
public async Task<IActionResult> Insert(Category category)
{
using var conn = new SqlConnection(_connectionString);
var id = await conn.ExecuteScalarAsync<int>(
using SqlConnection conn = new SqlConnection(this._connectionString);
int id = await conn.ExecuteScalarAsync<int>(
@"INSERT INTO CATEGORIA (nombre, descripcion)
VALUES (@nombre, @descripcion);
SELECT SCOPE_IDENTITY();",
new { nombre = category.Name, descripcion = category.Description }
);
return Ok(new { id_category_new = id });
return this.Ok(new { id_category_new = id });
}
}
}
24 changes: 12 additions & 12 deletions Podcast/Controllers/EpisodeController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,40 +11,40 @@ public class EpisodeController : ControllerBase
private readonly EpisodeRepository _repo;
public EpisodeController(EpisodeRepository repo)
{
_repo = repo;
this._repo = repo;
}
[HttpGet("podcast/{idPodcast}")]
public async Task<IActionResult> GetByPodcast(int idPodcast)
{
var episodes = await _repo.GetByPodcastAsync(idPodcast);
return Ok(episodes);
IEnumerable<Episode> episodes = await this._repo.GetByPodcastAsync(idPodcast);
return this.Ok(episodes);
}
[HttpGet("audio/{idEpisode}")]
public async Task<IActionResult> GetAudio(int idEpisode)
{
var episode = await _repo.GetAudioAsync(idEpisode);
if (episode == null) return NotFound();
return File(episode.AudioData!, "audio/mpeg");
Episode? episode = await this._repo.GetAudioAsync(idEpisode);
if (episode == null) return this.NotFound();
return this.File(episode.AudioData!, "audio/mpeg");
}
[HttpGet("search")]
public async Task<IActionResult> Search(
[FromQuery] string? keyword,
[FromQuery] string? category)
{
var results = await _repo.SearchAsync(keyword, category);
return Ok(results);
IEnumerable<Episode> results = await this._repo.SearchAsync(keyword, category);
return this.Ok(results);
}
[HttpPost]
public async Task<IActionResult> Insert([FromForm] Episode episode, IFormFile? audioFile)
{
if (audioFile != null)
{
using var ms = new MemoryStream();
using MemoryStream ms = new MemoryStream();
await audioFile.CopyToAsync(ms);
episode.AudioData = ms.ToArray();
}
var id = await _repo.InsertAsync(episode);
return Ok(new { id_episode_new = id });
int id = await this._repo.InsertAsync(episode);
return this.Ok(new { id_episode_new = id });
}
}
}
}
16 changes: 8 additions & 8 deletions Podcast/Controllers/PodcastController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,25 @@ public class PodcastController : ControllerBase
private readonly PodcastRepository _repo;
public PodcastController(PodcastRepository repo)
{
_repo = repo;
this._repo = repo;
}
[HttpGet]
public async Task<IActionResult> GetAll()
{
var podcasts = await _repo.GetAllAsync();
return Ok(podcasts);
IEnumerable<PodcastModel> podcasts = await this._repo.GetAllAsync();
return this.Ok(podcasts);
}
[HttpGet("user/{idUser}")]
public async Task<IActionResult> GetByUser(int idUser)
{
var podcasts = await _repo.GetByUserAsync(idUser);
return Ok(podcasts);
IEnumerable<PodcastModel> podcasts = await this._repo.GetByUserAsync(idUser);
return this.Ok(podcasts);
}
[HttpPost]
public async Task<IActionResult> Insert(PodcastModel podcast)
{
var id = await _repo.InsertAsync(podcast);
return Ok(new { id_podcast_new = id });
int id = await this._repo.InsertAsync(podcast);
return this.Ok(new { id_podcast_new = id });
}
}
}
}
12 changes: 6 additions & 6 deletions Podcast/Controllers/ReproductionController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,19 @@ public class ReproductionController : ControllerBase
private readonly ReproductionRepository _repo;
public ReproductionController(ReproductionRepository repo)
{
_repo = repo;
this._repo = repo;
}
[HttpGet("user/{idUser}")]
public async Task<IActionResult> GetByUser(int idUser)
{
var reproductions = await _repo.GetByUserAsync(idUser);
return Ok(reproductions);
IEnumerable<Reproduction> reproductions = await this._repo.GetByUserAsync(idUser);
return this.Ok(reproductions);
}
[HttpPost]
public async Task<IActionResult> Insert(Reproduction reproduction)
{
var id = await _repo.InsertAsync(reproduction);
return Ok(new { id_reproduction_new = id });
int id = await this._repo.InsertAsync(reproduction);
return this.Ok(new { id_reproduction_new = id });
}
}
}
}
33 changes: 20 additions & 13 deletions Podcast/Controllers/UserController.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Podcast.Models;
using Podcast.Repositories;

Expand All @@ -9,35 +11,40 @@ namespace Podcast.Controllers
public class UserController : ControllerBase
{
private readonly UserRepository _repo;

public UserController(UserRepository repo)
{
_repo = repo;
this._repo = repo;
}

[HttpGet]
public async Task<IActionResult> GetAll()
{
var users = await _repo.GetAllAsync();
return Ok(users);
IEnumerable<UserC> users = await this._repo.GetAllAsync();
return this.Ok(users);
}

[HttpGet("{id}")]
public async Task<IActionResult> GetById(int id)
{
var user = await _repo.GetByIdAsync(id);
if (user == null) return NotFound();
return Ok(user);
UserC? user = await this._repo.GetByIdAsync(id);
if (user == null) return this.NotFound();
return this.Ok(user);
}

[HttpPost]
public async Task<IActionResult> Insert(UserC user)
{
var id = await _repo.InsertAsync(user);
return Ok(new { id_user_new = id });
int id = await this._repo.InsertAsync(user);
return this.Ok(new { id_user_new = id });
}

[HttpPost("login")]
public async Task<IActionResult> Login(UserC user)
{
var result = await _repo.LoginAsync(user.User, user.Password);
if (result == null) return Unauthorized();
return Ok(result);
UserC? result = await this._repo.LoginAsync(user.User, user.Password);
if (result == null) return this.Unauthorized();
return this.Ok(result);
}
}
}
}
3 changes: 1 addition & 2 deletions Podcast/Models/UserC.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,5 @@ public class UserC
public string User { get; set; } = string.Empty;
public string Password { get; set; } = string.Empty;
public DateTime Register { get; set; }

}
}
}
2 changes: 2 additions & 0 deletions Podcast/Podcast.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
<TargetFramework>net9.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
</PropertyGroup>

<ItemGroup>
Expand Down
4 changes: 2 additions & 2 deletions Podcast/Program.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using Microsoft.EntityFrameworkCore;
using Podcast;
using Podcast.Repositories;
var builder = WebApplication.CreateBuilder(args);
WebApplicationBuilder builder = WebApplication.CreateBuilder(args);

builder.Services.AddControllers();
builder.Services.AddEndpointsApiExplorer();
Expand All @@ -15,7 +15,7 @@
builder.Services.AddScoped<EpisodeRepository>();
builder.Services.AddScoped<ReproductionRepository>();

var app = builder.Build();
WebApplication app = builder.Build();

if (app.Environment.IsDevelopment())
{
Expand Down
10 changes: 5 additions & 5 deletions Podcast/Repositories/EpisodeRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ public class EpisodeRepository

public EpisodeRepository(IConfiguration configuration)
{
_connectionString = configuration.GetConnectionString("DefaultConnection")!;
this._connectionString = configuration.GetConnectionString("DefaultConnection")!;
}
public async Task<int> InsertAsync(Episode episode)
{
using var conn = new SqlConnection(_connectionString);
using SqlConnection conn = new SqlConnection(this._connectionString);
return await conn.ExecuteScalarAsync<int>(
"SP_INSERT_EPISODIO",
new
Expand All @@ -31,7 +31,7 @@ public async Task<int> InsertAsync(Episode episode)
}
public async Task<IEnumerable<Episode>> GetByPodcastAsync(int idPodcast)
{
using var conn = new SqlConnection(_connectionString);
using SqlConnection conn = new SqlConnection(this._connectionString);
return await conn.QueryAsync<Episode>(
"SP_GET_EPISODIOS_BY_PODCAST",
new { id_podcast = idPodcast },
Expand All @@ -40,7 +40,7 @@ public async Task<IEnumerable<Episode>> GetByPodcastAsync(int idPodcast)
}
public async Task<Episode?> GetAudioAsync(int idEpisode)
{
using var conn = new SqlConnection(_connectionString);
using SqlConnection conn = new SqlConnection(this._connectionString);
return await conn.QueryFirstOrDefaultAsync<Episode>(
"SP_GET_AUDIO",
new { id_episodio = idEpisode },
Expand All @@ -49,7 +49,7 @@ public async Task<IEnumerable<Episode>> GetByPodcastAsync(int idPodcast)
}
public async Task<IEnumerable<Episode>> SearchAsync(string? keyword, string? category)
{
using var conn = new SqlConnection(_connectionString);
using SqlConnection conn = new SqlConnection(this._connectionString);
return await conn.QueryAsync<Episode>(
"SP_SEARCH_EPISODIOS",
new { keyword, categoria = category },
Expand Down
8 changes: 4 additions & 4 deletions Podcast/Repositories/PodcastRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ public class PodcastRepository

public PodcastRepository(IConfiguration configuration)
{
_connectionString = configuration.GetConnectionString("DefaultConnection")!;
this._connectionString = configuration.GetConnectionString("DefaultConnection")!;
}

public async Task<int> InsertAsync(PodcastModel podcast)
{
using var conn = new SqlConnection(_connectionString);
using SqlConnection conn = new SqlConnection(this._connectionString);
return await conn.ExecuteScalarAsync<int>(
"SP_INSERT_PODCAST",
new
Expand All @@ -31,7 +31,7 @@ public async Task<int> InsertAsync(PodcastModel podcast)

public async Task<IEnumerable<PodcastModel>> GetAllAsync()
{
using var conn = new SqlConnection(_connectionString);
using SqlConnection conn = new SqlConnection(this._connectionString);
return await conn.QueryAsync<PodcastModel>(
@"SELECT id_podcast AS IdPodcast, id_usuario AS IdUser,
titulo AS Title, descripcion AS Description,
Expand All @@ -42,7 +42,7 @@ FROM PODCAST"

public async Task<IEnumerable<PodcastModel>> GetByUserAsync(int idUser)
{
using var conn = new SqlConnection(_connectionString);
using SqlConnection conn = new SqlConnection(this._connectionString);
return await conn.QueryAsync<PodcastModel>(
@"SELECT id_podcast AS IdPodcast, id_usuario AS IdUser,
titulo AS Title, descripcion AS Description,
Expand Down
6 changes: 3 additions & 3 deletions Podcast/Repositories/ReproductionRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ public class ReproductionRepository

public ReproductionRepository(IConfiguration configuration)
{
_connectionString = configuration.GetConnectionString("DefaultConnection")!;
this._connectionString = configuration.GetConnectionString("DefaultConnection")!;
}
public async Task<int> InsertAsync(Reproduction reproduction)
{
using var conn = new SqlConnection(_connectionString);
using SqlConnection conn = new SqlConnection(this._connectionString);
return await conn.ExecuteScalarAsync<int>(
"SP_INSERT_REPRODUCCION",
new
Expand All @@ -28,7 +28,7 @@ public async Task<int> InsertAsync(Reproduction reproduction)
}
public async Task<IEnumerable<Reproduction>> GetByUserAsync(int idUser)
{
using var conn = new SqlConnection(_connectionString);
using SqlConnection conn = new SqlConnection(this._connectionString);
return await conn.QueryAsync<Reproduction>(
@"SELECT id_reproduccion AS IdReproduction, id_episodio AS IdEpisode,
id_usuario AS IdUser, fecha_reproduccion AS ReproductionTime,
Expand Down
Loading