Skip to content

Commit ddcd694

Browse files
committed
feat: integrate FullCalendar for class scheduling and enhance UI
- Added FullCalendar web component to manage class schedules. - Updated server to fetch classes from the API and handle errors gracefully. - Improved logging middleware for better debugging. - Enhanced the index.ejs view with a new layout, styles, and class details display. - Implemented responsive design and improved user experience with visual feedback.
1 parent 3ec49c2 commit ddcd694

File tree

14 files changed

+1143
-1010
lines changed

14 files changed

+1143
-1010
lines changed
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
using backend.Models;
2+
using backend.Service;
3+
using Microsoft.AspNetCore.Mvc;
4+
5+
namespace backend.Controllers;
6+
7+
[Route("api/[controller]")]
8+
[ApiController]
9+
public class ClassesController(ClassService classService) : ControllerBase
10+
{
11+
// GET: api/classes
12+
[HttpGet]
13+
public IEnumerable<Class> Get() => classService.Get();
14+
15+
// GET api/classes/{id}
16+
[HttpGet("{id:length(24)}", Name = "GetClass")]
17+
public ActionResult<Class> Get(string id)
18+
{
19+
var @class = classService.Get(id);
20+
21+
if (@class == null)
22+
{
23+
return NotFound();
24+
}
25+
26+
return @class;
27+
}
28+
29+
// POST api/classes
30+
[HttpPost]
31+
public ActionResult<Class> Create(Class @class)
32+
{
33+
classService.Create(@class);
34+
return CreatedAtRoute("GetClass", new { id = @class.Id }, @class);
35+
}
36+
37+
// PUT api/classes/{id}
38+
[HttpPut("{id:length(24)}")]
39+
public IActionResult Update(string id, Class classIn)
40+
{
41+
var @class = classService.Get(id);
42+
43+
if (@class == null)
44+
{
45+
return NotFound();
46+
}
47+
48+
classService.Update(id, classIn);
49+
50+
return NoContent();
51+
}
52+
53+
// DELETE api/classes/{id}
54+
[HttpDelete("{id:length(24)}")]
55+
public IActionResult Delete(string id)
56+
{
57+
var @class = classService.Get(id);
58+
59+
if (@class == null)
60+
{
61+
return NotFound();
62+
}
63+
64+
classService.Remove(id);
65+
66+
return NoContent();
67+
}
68+
}

01-contenedores/lemoncode-challenge/dotnet-stack/backend/Controllers/TopicsController.cs

Lines changed: 0 additions & 68 deletions
This file was deleted.
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
using MongoDB.Bson;
2+
using MongoDB.Bson.Serialization.Attributes;
3+
4+
namespace backend.Models;
5+
6+
public class Class
7+
{
8+
[BsonId]
9+
[BsonRepresentation(BsonType.ObjectId)]
10+
public string? Id { get; set; }
11+
12+
[BsonElement("Name")]
13+
public string Name { get; set; } = null!;
14+
15+
[BsonElement("Instructor")]
16+
public string Instructor { get; set; } = null!;
17+
18+
[BsonElement("StartDate")]
19+
public DateTime StartDate { get; set; }
20+
21+
[BsonElement("EndDate")]
22+
public DateTime EndDate { get; set; }
23+
24+
[BsonElement("Duration")]
25+
public int Duration { get; set; } // En horas
26+
27+
[BsonElement("Level")]
28+
public string Level { get; set; } = null!; // Beginner, Intermediate, Advanced
29+
}

01-contenedores/lemoncode-challenge/dotnet-stack/backend/Models/TopicstoreDatabaseSettings.cs renamed to 01-contenedores/lemoncode-challenge/dotnet-stack/backend/Models/ClassDatabaseSettings.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
namespace backend.Models;
22

3-
public interface ITopicstoreDatabaseSettings
3+
public interface IClassDatabaseSettings
44
{
5-
string TopicsCollectionName { get; set; }
5+
string ClassesCollectionName { get; set; }
66
string ConnectionString { get; set; }
77
string DatabaseName { get; set; }
88
}
99

10-
public class TopicstoreDatabaseSettings : ITopicstoreDatabaseSettings
10+
public class ClassDatabaseSettings : IClassDatabaseSettings
1111
{
12-
public string TopicsCollectionName { get; set; } = null!;
12+
public string ClassesCollectionName { get; set; } = null!;
1313
public string ConnectionString { get; set; } = null!;
1414
public string DatabaseName { get; set; } = null!;
1515
}
16+

01-contenedores/lemoncode-challenge/dotnet-stack/backend/Models/Topic.cs

Lines changed: 0 additions & 14 deletions
This file was deleted.
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
using backend.Models;
2+
using MongoDB.Driver;
3+
4+
namespace backend.Service;
5+
6+
public class ClassService(IClassDatabaseSettings settings)
7+
{
8+
private readonly IMongoCollection<Class> _classes = new MongoClient(settings.ConnectionString)
9+
.GetDatabase(settings.DatabaseName)
10+
.GetCollection<Class>(settings.ClassesCollectionName);
11+
12+
public List<Class> Get() => _classes.Find(_ => true).ToList();
13+
14+
public Class? Get(string id) => _classes.Find(@class => @class.Id == id).FirstOrDefault();
15+
16+
public Class Create(Class @class)
17+
{
18+
_classes.InsertOne(@class);
19+
return @class;
20+
}
21+
22+
public void Update(string id, Class classIn) =>
23+
_classes.ReplaceOne(@class => @class.Id == id, classIn);
24+
25+
public void Remove(string id) =>
26+
_classes.DeleteOne(@class => @class.Id == id);
27+
}

01-contenedores/lemoncode-challenge/dotnet-stack/backend/Service/TopicService.cs

Lines changed: 0 additions & 27 deletions
This file was deleted.

01-contenedores/lemoncode-challenge/dotnet-stack/backend/Startup.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ public Startup(IConfiguration configuration)
2222
public void ConfigureServices(IServiceCollection services)
2323
{
2424
//requires using Microsoft.Extensions.Options
25-
services.Configure<TopicstoreDatabaseSettings>(Configuration.GetSection(nameof(TopicstoreDatabaseSettings)));
26-
services.AddSingleton<ITopicstoreDatabaseSettings>(sp => sp.GetRequiredService<IOptions<TopicstoreDatabaseSettings>>().Value);
27-
services.AddSingleton<TopicService>();
25+
services.Configure<ClassDatabaseSettings>(Configuration.GetSection(nameof(ClassDatabaseSettings)));
26+
services.AddSingleton<IClassDatabaseSettings>(sp => sp.GetRequiredService<IOptions<ClassDatabaseSettings>>().Value);
27+
services.AddSingleton<ClassService>();
2828

2929
services.AddCors(o => o.AddPolicy("MyPolicy", builder =>
3030
{

01-contenedores/lemoncode-challenge/dotnet-stack/backend/appsettings.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
2-
"TopicstoreDatabaseSettings": {
2+
"ClassDatabaseSettings": {
33
"ConnectionString": "mongodb://admin:password@localhost:27017",
4-
"TopicsCollectionName": "Topics",
5-
"DatabaseName": "TopicstoreDb"
4+
"ClassesCollectionName": "Classes",
5+
"DatabaseName": "LemoncodeCourseDb"
66
},
77
"Logging": {
88
"LogLevel": {

0 commit comments

Comments
 (0)