Skip to content

Commit

Permalink
Defined and added user service and user class.
Browse files Browse the repository at this point in the history
  • Loading branch information
miguelcanosantana committed Nov 25, 2023
1 parent c00ef2e commit 23e9c9c
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 0 deletions.
21 changes: 21 additions & 0 deletions Model/User.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
namespace CirsaHackaton.Model
{
public class User
{
private String id;
private String name;
private String email;
private String password;

public User(String name, String email, String password)
{
id = Guid.NewGuid().ToString();
this.name = name;
this.email = email;
this.password = password;
}

//Getters
public String GetId() { return id; }
}
}
2 changes: 2 additions & 0 deletions Program.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using CirsaHackaton;
using CirsaHackaton.Services;
using Microsoft.AspNetCore.Components.Web;
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
using Microsoft.Extensions.FileProviders;
Expand All @@ -8,5 +9,6 @@
builder.RootComponents.Add<HeadOutlet>("head::after");

builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) });
builder.Services.AddSingleton<UserService>();

await builder.Build().RunAsync();
19 changes: 19 additions & 0 deletions Services/UserService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using CirsaHackaton.Model;

namespace CirsaHackaton.Services
{
public class UserService
{
private List<User> dummyUsersDatabase = new List<User>();
private User? loggedUser;

Check warning on line 8 in Services/UserService.cs

View workflow job for this annotation

GitHub Actions / deploy-to-github-pages

Field 'UserService.loggedUser' is never assigned to, and will always have its default value null


//Getters
public List<User> GetUsers() { return dummyUsersDatabase; }
public User? GetLoggedUser() { return loggedUser; }
public User? GetUserById(String uid) { return dummyUsersDatabase.Find(user => user.GetId().Equals(uid)); }

//Data modifiers
public void AddUser(User user) { dummyUsersDatabase.Add(user); }
}
}

0 comments on commit 23e9c9c

Please sign in to comment.