feat: moved to C# thanks to deepseek
This commit is contained in:
1 parent
ab81a1c4be
commit
29ed46aa7f
34 files changed
+1583
-14
No files matched your search
+11
@@ -1,3 +1,4 @@
|
||||
# Deno
|
||||
node_modules/*
|
||||
lib/*
|
||||
css/*
|
||||
@@ -6,3 +7,13 @@ css/*
|
||||
/main-built.js
|
||||
/api
|
||||
result
|
||||
|
||||
# .NET
|
||||
bin/
|
||||
obj/
|
||||
*.user
|
||||
*.suo
|
||||
*.db
|
||||
publish/
|
||||
|
||||
.direnv/
|
||||
@@ -0,0 +1,45 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Phenix.Services;
|
||||
|
||||
namespace Phenix.Controllers;
|
||||
|
||||
[Route("/api")]
|
||||
public class ApiController : Controller
|
||||
{
|
||||
private readonly IGameService _games;
|
||||
|
||||
public ApiController(IGameService games)
|
||||
{
|
||||
_games = games;
|
||||
}
|
||||
|
||||
[HttpGet("results/{year}.json")]
|
||||
public async Task<IActionResult> ResultsJson(int year)
|
||||
{
|
||||
var games = await _games.GetAllGames();
|
||||
var results = games
|
||||
.Where(g => g.Year == year)
|
||||
.Select(g => new Dictionary<string, object?>
|
||||
{
|
||||
["id"] = g.Id,
|
||||
["date"] = g.Date,
|
||||
["time"] = g.Time,
|
||||
["home"] = g.Home,
|
||||
["away"] = g.Away,
|
||||
["year"] = g.Year,
|
||||
[g.Home] = g.HomeScore,
|
||||
[g.Away] = g.AwayScore,
|
||||
["practice"] = g.Practice,
|
||||
["rain"] = g.Rain,
|
||||
});
|
||||
return Json(results);
|
||||
}
|
||||
|
||||
[HttpGet("available-years.json")]
|
||||
public async Task<IActionResult> AvailableYearsJson()
|
||||
{
|
||||
var games = await _games.GetAllGames();
|
||||
var years = games.Select(g => g.Year).Distinct().OrderByDescending(y => y);
|
||||
return Json(years);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Phenix.Services;
|
||||
|
||||
namespace Phenix.Controllers;
|
||||
|
||||
public class HomeController : Controller
|
||||
{
|
||||
[HttpGet("/")]
|
||||
public IActionResult Index() => View();
|
||||
|
||||
[HttpGet("/calendrier")]
|
||||
public IActionResult Calendrier() => View();
|
||||
|
||||
[HttpGet("/nouvelles")]
|
||||
public IActionResult Nouvelles() => View();
|
||||
|
||||
[HttpGet("/contact")]
|
||||
public IActionResult Contact() => View();
|
||||
|
||||
[HttpGet("/reglement")]
|
||||
public IActionResult Reglement() => View();
|
||||
}
|
||||
@@ -0,0 +1,141 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Phenix.Services;
|
||||
|
||||
namespace Phenix.Controllers;
|
||||
|
||||
[Route("/membre")]
|
||||
public class MembreController : Controller
|
||||
{
|
||||
private readonly IGameService _games;
|
||||
private readonly LoginService _login;
|
||||
private const string SessionCookie = "phenix-session";
|
||||
private const string SessionSignCookie = "phenix-session-sign";
|
||||
|
||||
public MembreController(IGameService games, LoginService login)
|
||||
{
|
||||
_games = games;
|
||||
_login = login;
|
||||
}
|
||||
|
||||
[HttpGet("")]
|
||||
public IActionResult Index()
|
||||
{
|
||||
ViewBag.IsLoggedIn = IsLoggedIn();
|
||||
return View();
|
||||
}
|
||||
|
||||
[HttpGet("/login")]
|
||||
public IActionResult Login(string? username, string? password)
|
||||
{
|
||||
if (username is null || password is null || !_login.ValidateCredentials(username, password))
|
||||
return StatusCode(403);
|
||||
|
||||
var expiresAt = DateTimeOffset.UtcNow.AddDays(90).ToUnixTimeSeconds();
|
||||
Response.Cookies.Append(SessionCookie, expiresAt.ToString(), new CookieOptions
|
||||
{
|
||||
MaxAge = TimeSpan.FromDays(90),
|
||||
});
|
||||
Response.Cookies.Append(SessionSignCookie, _login.SignSession(expiresAt), new CookieOptions
|
||||
{
|
||||
MaxAge = TimeSpan.FromDays(90),
|
||||
});
|
||||
|
||||
return Redirect("/membre/games-editor/today");
|
||||
}
|
||||
|
||||
[HttpGet("games-editor/today")]
|
||||
public async Task<IActionResult> GamesEditorToday()
|
||||
{
|
||||
if (!IsLoggedIn()) return Redirect("/membre");
|
||||
var games = await _games.GetAllGames();
|
||||
var today = DateOnly.FromDateTime(TimeZoneInfo.ConvertTime(
|
||||
DateTime.UtcNow, TimeZoneInfo.FindSystemTimeZoneById("America/New_York")));
|
||||
|
||||
var lastGameDay = games
|
||||
.Where(g => DateOnly.Parse(g.Date) <= today)
|
||||
.Select(g => g.Date)
|
||||
.OrderByDescending(d => d)
|
||||
.FirstOrDefault();
|
||||
|
||||
ViewBag.SelectedYear = (int?)null;
|
||||
ViewBag.IsToday = true;
|
||||
ViewBag.Years = games.Select(g => g.Year).Distinct().OrderByDescending(y => y).ToList();
|
||||
ViewBag.Games = games.Where(g => g.Date == lastGameDay).ToList();
|
||||
return PartialView("GamesEditor");
|
||||
}
|
||||
|
||||
[HttpGet("games-editor/{year:int}")]
|
||||
public async Task<IActionResult> GamesEditorByYear(int year)
|
||||
{
|
||||
if (!IsLoggedIn()) return Redirect("/membre");
|
||||
var games = await _games.GetAllGames();
|
||||
ViewBag.SelectedYear = year;
|
||||
ViewBag.IsToday = false;
|
||||
ViewBag.Years = games.Select(g => g.Year).Distinct().OrderByDescending(y => y).ToList();
|
||||
ViewBag.Games = games.Where(g => g.Year == year).ToList();
|
||||
return PartialView("GamesEditor");
|
||||
}
|
||||
|
||||
[HttpGet("new-game-editor")]
|
||||
public IActionResult NewGameEditor()
|
||||
{
|
||||
if (!IsLoggedIn()) return Redirect("/membre");
|
||||
return PartialView();
|
||||
}
|
||||
|
||||
[HttpPost("new-game")]
|
||||
public async Task<IActionResult> NewGame(string gameDate, string gameTime, string homeTeam, string awayTeam)
|
||||
{
|
||||
if (!IsLoggedIn()) return Redirect("/membre");
|
||||
|
||||
var (game, error) = await _games.CreateNewGame(gameDate, gameTime, homeTeam, awayTeam);
|
||||
|
||||
if (error != "")
|
||||
{
|
||||
ViewBag.Error = error;
|
||||
return StatusCode(500, PartialView("NewGameError"));
|
||||
}
|
||||
|
||||
Response.Headers["game-id"] = game!.Id;
|
||||
return PartialView("SingleGameEditor", game);
|
||||
}
|
||||
|
||||
[HttpDelete("games/{gameId}")]
|
||||
public async Task<IActionResult> DeleteGame(string gameId)
|
||||
{
|
||||
if (!IsLoggedIn()) return Redirect("/membre");
|
||||
var ok = await _games.DeleteGameById(gameId);
|
||||
return Content(ok ? "true" : "false");
|
||||
}
|
||||
|
||||
[HttpPost("games/{gameId}")]
|
||||
public async Task<IActionResult> UpdateGame(string gameId, int? awayScore, int? homeScore, string? gameType)
|
||||
{
|
||||
if (!IsLoggedIn()) return Redirect("/membre");
|
||||
var success = await _games.UpdateGame(gameId, homeScore, awayScore,
|
||||
rain: gameType == "rain", practice: gameType == "practice");
|
||||
return Content(success
|
||||
? "<i class=\"fa fa-floppy-o\" aria-hidden=\"true\"></i>"
|
||||
: "<i class=\"fa fa-exclamation-triangle\" aria-hidden=\"true\"></i>");
|
||||
}
|
||||
|
||||
[HttpPost("games/{gameId}/switch")]
|
||||
public async Task<IActionResult> SwitchVisitors(string gameId)
|
||||
{
|
||||
if (!IsLoggedIn()) return Redirect("/membre");
|
||||
var success = await _games.SwitchVisitors(gameId);
|
||||
if (!success)
|
||||
return Content("<i class=\"fa fa-exclamation-triangle\" aria-hidden=\"true\"></i>");
|
||||
|
||||
var game = await _games.GetGameById(gameId);
|
||||
Response.Headers["game-id"] = gameId;
|
||||
return PartialView("SingleGameEditor", game);
|
||||
}
|
||||
|
||||
private bool IsLoggedIn()
|
||||
{
|
||||
Request.Cookies.TryGetValue(SessionCookie, out var expires);
|
||||
Request.Cookies.TryGetValue(SessionSignCookie, out var sig);
|
||||
return _login.VerifySession(expires, sig);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
namespace Phenix.Models;
|
||||
|
||||
public class Game
|
||||
{
|
||||
public string Id { get; set; } = "";
|
||||
public string Date { get; set; } = "";
|
||||
public string Time { get; set; } = "";
|
||||
public string Home { get; set; } = "";
|
||||
public string Away { get; set; } = "";
|
||||
public int Year { get; set; }
|
||||
public int? HomeScore { get; set; }
|
||||
public int? AwayScore { get; set; }
|
||||
public bool Practice { get; set; }
|
||||
public bool Rain { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
namespace Phenix.Models;
|
||||
|
||||
public class TeamSelectorModel
|
||||
{
|
||||
public string Name { get; set; } = "";
|
||||
public string SelectedTeam { get; set; } = "";
|
||||
public bool IsDisabled { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net9.0</TargetFramework>
|
||||
<RootNamespace>Phenix</RootNamespace>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Data.Sqlite" Version="9.0.0" />
|
||||
<PackageReference Include="Npgsql" Version="8.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
+47
@@ -0,0 +1,47 @@
|
||||
using Phenix.Services;
|
||||
|
||||
var builder = WebApplication.CreateBuilder(new WebApplicationOptions
|
||||
{
|
||||
Args = args,
|
||||
WebRootPath = "static",
|
||||
});
|
||||
|
||||
builder.Services
|
||||
.AddControllersWithViews()
|
||||
.AddRazorOptions(o =>
|
||||
{
|
||||
o.ViewLocationFormats.Clear();
|
||||
o.ViewLocationFormats.Add("/Views/{1}/{0}.cshtml");
|
||||
o.ViewLocationFormats.Add("/Views/Shared/{0}.cshtml");
|
||||
o.ViewLocationFormats.Add("/Views/{0}.cshtml");
|
||||
});
|
||||
|
||||
builder.Services.AddSingleton<IGameService>(sp =>
|
||||
{
|
||||
var config = sp.GetRequiredService<IConfiguration>();
|
||||
var connStr = config.GetConnectionString("Default")
|
||||
?? "Data Source=phenix.db";
|
||||
var provider = config["DatabaseProvider"] ?? "Sqlite";
|
||||
|
||||
IGameService svc = provider.ToLowerInvariant() switch
|
||||
{
|
||||
"postgres" or "postgresql" => new PostgresGameService(connStr),
|
||||
_ => new SqliteGameService(connStr),
|
||||
};
|
||||
svc.Init().GetAwaiter().GetResult();
|
||||
return svc;
|
||||
});
|
||||
|
||||
builder.Services.AddSingleton(sp =>
|
||||
{
|
||||
var key = sp.GetRequiredService<IConfiguration>()["SessionKey"] ?? "dev-only";
|
||||
return new LoginService(key);
|
||||
});
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
app.UseStaticFiles();
|
||||
|
||||
app.MapControllers();
|
||||
|
||||
app.Run();
|
||||
@@ -0,0 +1,14 @@
|
||||
using Phenix.Models;
|
||||
|
||||
namespace Phenix.Services;
|
||||
|
||||
public interface IGameService
|
||||
{
|
||||
Task Init();
|
||||
Task<List<Game>> GetAllGames();
|
||||
Task<Game?> GetGameById(string id);
|
||||
Task<(Game? Game, string Error)> CreateNewGame(string date, string time, string home, string away);
|
||||
Task<bool> UpdateGame(string id, int? homeScore, int? awayScore, bool? rain, bool? practice);
|
||||
Task<bool> DeleteGameById(string id);
|
||||
Task<bool> SwitchVisitors(string id);
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
|
||||
namespace Phenix.Services;
|
||||
|
||||
public class LoginService
|
||||
{
|
||||
private readonly Dictionary<string, string> _users;
|
||||
private readonly string _sessionKey;
|
||||
|
||||
private static readonly (string User, string Hash)[] OfficialUsers =
|
||||
[
|
||||
("marqueur", "34373780cc542a1eddb6a08488ec149323b94d66025421acd98ffc20eb5055a0:6f2fa05777d45a2da9db79b7fd11e3bc69eb1807642ccb53d41a0b9eb71a3311"),
|
||||
("comite", "8649feff48a50f53448e59ce480db97b5549eef1d92c886c49b5a14ee22648e5:a0017b879c8834d2f34938e7a4fa3f4c7be8f70545b9bb22a28cf56ab2eb26d9"),
|
||||
];
|
||||
|
||||
public LoginService(string sessionKey)
|
||||
{
|
||||
_users = OfficialUsers.ToDictionary(x => x.User, x => x.Hash);
|
||||
_sessionKey = sessionKey;
|
||||
}
|
||||
|
||||
public bool ValidateCredentials(string username, string password)
|
||||
{
|
||||
if (!_users.TryGetValue(username, out var hashWithSalt))
|
||||
return false;
|
||||
return VerifyPassword(password, hashWithSalt);
|
||||
}
|
||||
|
||||
public string SignSession(long expiresAt)
|
||||
{
|
||||
return ShittyHmac(expiresAt.ToString(), _sessionKey);
|
||||
}
|
||||
|
||||
public bool VerifySession(string? expiresAt, string? signature)
|
||||
{
|
||||
if (expiresAt is null || signature is null)
|
||||
return false;
|
||||
if (!long.TryParse(expiresAt, out var ts))
|
||||
return false;
|
||||
if (signature != ShittyHmac(ts.ToString(), _sessionKey))
|
||||
return false;
|
||||
return DateTimeOffset.UtcNow.ToUnixTimeSeconds() < ts;
|
||||
}
|
||||
|
||||
private static bool VerifyPassword(string password, string hashWithSalt)
|
||||
{
|
||||
var parts = hashWithSalt.Split(':');
|
||||
if (parts.Length != 2) return false;
|
||||
var salt = parts[0];
|
||||
var expected = parts[1];
|
||||
return ShittyHmac(password, salt) == expected;
|
||||
}
|
||||
|
||||
private static string HashMessage(string message)
|
||||
{
|
||||
var bytes = SHA256.HashData(Encoding.UTF8.GetBytes(message));
|
||||
return Convert.ToHexStringLower(bytes);
|
||||
}
|
||||
|
||||
private static string ShittyHmac(string message, string salt)
|
||||
{
|
||||
var h1 = HashMessage(message + salt);
|
||||
var h2 = HashMessage(salt + message);
|
||||
return HashMessage(h1 + h2);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,200 @@
|
||||
using System.Data.Common;
|
||||
using Npgsql;
|
||||
using Phenix.Models;
|
||||
|
||||
namespace Phenix.Services;
|
||||
|
||||
public class PostgresGameService : IGameService
|
||||
{
|
||||
private readonly string _connectionString;
|
||||
|
||||
public PostgresGameService(string connectionString)
|
||||
{
|
||||
_connectionString = connectionString;
|
||||
}
|
||||
|
||||
public async Task Init()
|
||||
{
|
||||
await using var conn = new NpgsqlConnection(_connectionString);
|
||||
await conn.OpenAsync();
|
||||
var cmd = conn.CreateCommand();
|
||||
cmd.CommandText = """
|
||||
CREATE TABLE IF NOT EXISTS games (
|
||||
id TEXT PRIMARY KEY,
|
||||
date TEXT NOT NULL,
|
||||
time TEXT NOT NULL,
|
||||
home TEXT NOT NULL,
|
||||
away TEXT NOT NULL,
|
||||
year INTEGER NOT NULL,
|
||||
home_score INTEGER,
|
||||
away_score INTEGER,
|
||||
practice BOOLEAN NOT NULL DEFAULT FALSE,
|
||||
rain BOOLEAN NOT NULL DEFAULT FALSE,
|
||||
UNIQUE(date, time)
|
||||
)
|
||||
""";
|
||||
await cmd.ExecuteNonQueryAsync();
|
||||
}
|
||||
|
||||
public async Task<List<Game>> GetAllGames()
|
||||
{
|
||||
var games = new List<Game>();
|
||||
await using var conn = new NpgsqlConnection(_connectionString);
|
||||
await conn.OpenAsync();
|
||||
var cmd = conn.CreateCommand();
|
||||
cmd.CommandText = "SELECT * FROM games ORDER BY date, time";
|
||||
await using var reader = await cmd.ExecuteReaderAsync();
|
||||
while (await reader.ReadAsync())
|
||||
games.Add(ReadGame(reader));
|
||||
return games;
|
||||
}
|
||||
|
||||
public async Task<Game?> GetGameById(string id)
|
||||
{
|
||||
await using var conn = new NpgsqlConnection(_connectionString);
|
||||
await conn.OpenAsync();
|
||||
var cmd = conn.CreateCommand();
|
||||
cmd.CommandText = "SELECT * FROM games WHERE id = @id";
|
||||
cmd.Parameters.AddWithValue("@id", id);
|
||||
await using var reader = await cmd.ExecuteReaderAsync();
|
||||
if (await reader.ReadAsync())
|
||||
return ReadGame(reader);
|
||||
return null;
|
||||
}
|
||||
|
||||
public async Task<(Game? Game, string Error)> CreateNewGame(string date, string time, string home, string away)
|
||||
{
|
||||
date = CleanDate(date);
|
||||
time = CleanTime(time);
|
||||
|
||||
if (!DateOnly.TryParse(date, out _))
|
||||
return (null, $"Invalide date format {date}");
|
||||
if (!TimeOnly.TryParse(time, out _))
|
||||
return (null, $"Invalide time format {time}");
|
||||
if (!ValidTeams.Contains(away))
|
||||
return (null, $"Invalide away format {away}");
|
||||
if (!ValidTeams.Contains(home))
|
||||
return (null, $"Invalide home format {home}");
|
||||
if (home == away)
|
||||
return (null, $"Home and away teams must be different (received {home} for both)");
|
||||
|
||||
var year = DateOnly.Parse(date).Year;
|
||||
var game = new Game
|
||||
{
|
||||
Id = Guid.NewGuid().ToString(),
|
||||
Date = date,
|
||||
Time = time,
|
||||
Home = home,
|
||||
Away = away,
|
||||
Year = year,
|
||||
};
|
||||
|
||||
try
|
||||
{
|
||||
await using var conn = new NpgsqlConnection(_connectionString);
|
||||
await conn.OpenAsync();
|
||||
var cmd = conn.CreateCommand();
|
||||
cmd.CommandText = """
|
||||
INSERT INTO games (id, date, time, home, away, year)
|
||||
VALUES (@id, @date, @time, @home, @away, @year)
|
||||
""";
|
||||
cmd.Parameters.AddWithValue("@id", game.Id);
|
||||
cmd.Parameters.AddWithValue("@date", game.Date);
|
||||
cmd.Parameters.AddWithValue("@time", game.Time);
|
||||
cmd.Parameters.AddWithValue("@home", game.Home);
|
||||
cmd.Parameters.AddWithValue("@away", game.Away);
|
||||
cmd.Parameters.AddWithValue("@year", game.Year);
|
||||
await cmd.ExecuteNonQueryAsync();
|
||||
}
|
||||
catch (PostgresException ex) when (ex.SqlState == "23505")
|
||||
{
|
||||
return (null, "game already exists at this date/time");
|
||||
}
|
||||
|
||||
return (game, "");
|
||||
}
|
||||
|
||||
public async Task<bool> UpdateGame(string id, int? homeScore, int? awayScore, bool? rain, bool? practice)
|
||||
{
|
||||
await using var conn = new NpgsqlConnection(_connectionString);
|
||||
await conn.OpenAsync();
|
||||
var cmd = conn.CreateCommand();
|
||||
cmd.CommandText = """
|
||||
UPDATE games SET
|
||||
home_score = COALESCE(@homeScore, home_score),
|
||||
away_score = COALESCE(@awayScore, away_score),
|
||||
rain = COALESCE(@rain, rain),
|
||||
practice = COALESCE(@practice, practice)
|
||||
WHERE id = @id
|
||||
""";
|
||||
cmd.Parameters.AddWithValue("@id", id);
|
||||
cmd.Parameters.AddWithValue("@homeScore", (object?)homeScore ?? DBNull.Value);
|
||||
cmd.Parameters.AddWithValue("@awayScore", (object?)awayScore ?? DBNull.Value);
|
||||
cmd.Parameters.AddWithValue("@rain", rain ?? (object?)DBNull.Value);
|
||||
cmd.Parameters.AddWithValue("@practice", practice ?? (object?)DBNull.Value);
|
||||
return await cmd.ExecuteNonQueryAsync() > 0;
|
||||
}
|
||||
|
||||
public async Task<bool> DeleteGameById(string id)
|
||||
{
|
||||
await using var conn = new NpgsqlConnection(_connectionString);
|
||||
await conn.OpenAsync();
|
||||
var cmd = conn.CreateCommand();
|
||||
cmd.CommandText = "DELETE FROM games WHERE id = @id";
|
||||
cmd.Parameters.AddWithValue("@id", id);
|
||||
return await cmd.ExecuteNonQueryAsync() > 0;
|
||||
}
|
||||
|
||||
public async Task<bool> SwitchVisitors(string id)
|
||||
{
|
||||
var game = await GetGameById(id);
|
||||
if (game is null) return false;
|
||||
|
||||
await using var conn = new NpgsqlConnection(_connectionString);
|
||||
await conn.OpenAsync();
|
||||
var cmd = conn.CreateCommand();
|
||||
cmd.CommandText = """
|
||||
UPDATE games SET home = @home, away = @away,
|
||||
home_score = @homeScore, away_score = @awayScore
|
||||
WHERE id = @id
|
||||
""";
|
||||
cmd.Parameters.AddWithValue("@id", id);
|
||||
cmd.Parameters.AddWithValue("@home", game.Away);
|
||||
cmd.Parameters.AddWithValue("@away", game.Home);
|
||||
cmd.Parameters.AddWithValue("@homeScore", (object?)game.AwayScore ?? DBNull.Value);
|
||||
cmd.Parameters.AddWithValue("@awayScore", (object?)game.HomeScore ?? DBNull.Value);
|
||||
return await cmd.ExecuteNonQueryAsync() > 0;
|
||||
}
|
||||
|
||||
private static Game ReadGame(DbDataReader r) => new()
|
||||
{
|
||||
Id = r.GetString(r.GetOrdinal("id")),
|
||||
Date = r.GetString(r.GetOrdinal("date")),
|
||||
Time = r.GetString(r.GetOrdinal("time")),
|
||||
Home = r.GetString(r.GetOrdinal("home")),
|
||||
Away = r.GetString(r.GetOrdinal("away")),
|
||||
Year = r.GetInt32(r.GetOrdinal("year")),
|
||||
HomeScore = r.IsDBNull(r.GetOrdinal("home_score")) ? null : r.GetInt32(r.GetOrdinal("home_score")),
|
||||
AwayScore = r.IsDBNull(r.GetOrdinal("away_score")) ? null : r.GetInt32(r.GetOrdinal("away_score")),
|
||||
Practice = r.GetBoolean(r.GetOrdinal("practice")),
|
||||
Rain = r.GetBoolean(r.GetOrdinal("rain")),
|
||||
};
|
||||
|
||||
private static readonly string[] ValidTeams =
|
||||
["jaune", "rouge", "bleu", "gris", "vert", "noir", "orange", "mauve"];
|
||||
|
||||
private static string CleanDate(string raw)
|
||||
{
|
||||
var parts = raw.Split('-');
|
||||
if (parts.Length != 3) return raw;
|
||||
return $"{parts[0]}-{parts[1].PadLeft(2, '0')}-{parts[2].PadLeft(2, '0')}";
|
||||
}
|
||||
|
||||
private static string CleanTime(string raw)
|
||||
{
|
||||
var sep = raw.Contains('h') ? 'h' : ':';
|
||||
var parts = raw.Split(sep);
|
||||
if (parts.Length != 2) return raw;
|
||||
return $"{parts[0].PadLeft(2, '0')}:{parts[1].PadLeft(2, '0')}";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,200 @@
|
||||
using System.Data.Common;
|
||||
using Microsoft.Data.Sqlite;
|
||||
using Phenix.Models;
|
||||
|
||||
namespace Phenix.Services;
|
||||
|
||||
public class SqliteGameService : IGameService
|
||||
{
|
||||
private readonly string _connectionString;
|
||||
|
||||
public SqliteGameService(string connectionString)
|
||||
{
|
||||
_connectionString = connectionString;
|
||||
}
|
||||
|
||||
public async Task Init()
|
||||
{
|
||||
await using var conn = new SqliteConnection(_connectionString);
|
||||
await conn.OpenAsync();
|
||||
var cmd = conn.CreateCommand();
|
||||
cmd.CommandText = """
|
||||
CREATE TABLE IF NOT EXISTS games (
|
||||
id TEXT PRIMARY KEY,
|
||||
date TEXT NOT NULL,
|
||||
time TEXT NOT NULL,
|
||||
home TEXT NOT NULL,
|
||||
away TEXT NOT NULL,
|
||||
year INTEGER NOT NULL,
|
||||
home_score INTEGER,
|
||||
away_score INTEGER,
|
||||
practice INTEGER NOT NULL DEFAULT 0,
|
||||
rain INTEGER NOT NULL DEFAULT 0,
|
||||
UNIQUE(date, time)
|
||||
)
|
||||
""";
|
||||
await cmd.ExecuteNonQueryAsync();
|
||||
}
|
||||
|
||||
public async Task<List<Game>> GetAllGames()
|
||||
{
|
||||
var games = new List<Game>();
|
||||
await using var conn = new SqliteConnection(_connectionString);
|
||||
await conn.OpenAsync();
|
||||
var cmd = conn.CreateCommand();
|
||||
cmd.CommandText = "SELECT * FROM games ORDER BY date, time";
|
||||
await using var reader = await cmd.ExecuteReaderAsync();
|
||||
while (await reader.ReadAsync())
|
||||
games.Add(ReadGame(reader));
|
||||
return games;
|
||||
}
|
||||
|
||||
public async Task<Game?> GetGameById(string id)
|
||||
{
|
||||
await using var conn = new SqliteConnection(_connectionString);
|
||||
await conn.OpenAsync();
|
||||
var cmd = conn.CreateCommand();
|
||||
cmd.CommandText = "SELECT * FROM games WHERE id = @id";
|
||||
cmd.Parameters.AddWithValue("@id", id);
|
||||
await using var reader = await cmd.ExecuteReaderAsync();
|
||||
if (await reader.ReadAsync())
|
||||
return ReadGame(reader);
|
||||
return null;
|
||||
}
|
||||
|
||||
public async Task<(Game? Game, string Error)> CreateNewGame(string date, string time, string home, string away)
|
||||
{
|
||||
date = CleanDate(date);
|
||||
time = CleanTime(time);
|
||||
|
||||
if (!DateOnly.TryParse(date, out _))
|
||||
return (null, $"Invalide date format {date}");
|
||||
if (!TimeOnly.TryParse(time, out _))
|
||||
return (null, $"Invalide time format {time}");
|
||||
if (!ValidTeams.Contains(away))
|
||||
return (null, $"Invalide away format {away}");
|
||||
if (!ValidTeams.Contains(home))
|
||||
return (null, $"Invalide home format {home}");
|
||||
if (home == away)
|
||||
return (null, $"Home and away teams must be different (received {home} for both)");
|
||||
|
||||
var year = DateOnly.Parse(date).Year;
|
||||
var game = new Game
|
||||
{
|
||||
Id = Guid.NewGuid().ToString(),
|
||||
Date = date,
|
||||
Time = time,
|
||||
Home = home,
|
||||
Away = away,
|
||||
Year = year,
|
||||
};
|
||||
|
||||
try
|
||||
{
|
||||
await using var conn = new SqliteConnection(_connectionString);
|
||||
await conn.OpenAsync();
|
||||
var cmd = conn.CreateCommand();
|
||||
cmd.CommandText = """
|
||||
INSERT INTO games (id, date, time, home, away, year)
|
||||
VALUES (@id, @date, @time, @home, @away, @year)
|
||||
""";
|
||||
cmd.Parameters.AddWithValue("@id", game.Id);
|
||||
cmd.Parameters.AddWithValue("@date", game.Date);
|
||||
cmd.Parameters.AddWithValue("@time", game.Time);
|
||||
cmd.Parameters.AddWithValue("@home", game.Home);
|
||||
cmd.Parameters.AddWithValue("@away", game.Away);
|
||||
cmd.Parameters.AddWithValue("@year", game.Year);
|
||||
await cmd.ExecuteNonQueryAsync();
|
||||
}
|
||||
catch (SqliteException ex) when (ex.SqliteErrorCode == 19)
|
||||
{
|
||||
return (null, "game already exists at this date/time");
|
||||
}
|
||||
|
||||
return (game, "");
|
||||
}
|
||||
|
||||
public async Task<bool> UpdateGame(string id, int? homeScore, int? awayScore, bool? rain, bool? practice)
|
||||
{
|
||||
await using var conn = new SqliteConnection(_connectionString);
|
||||
await conn.OpenAsync();
|
||||
var cmd = conn.CreateCommand();
|
||||
cmd.CommandText = """
|
||||
UPDATE games SET
|
||||
home_score = COALESCE(@homeScore, home_score),
|
||||
away_score = COALESCE(@awayScore, away_score),
|
||||
rain = COALESCE(@rain, rain),
|
||||
practice = COALESCE(@practice, practice)
|
||||
WHERE id = @id
|
||||
""";
|
||||
cmd.Parameters.AddWithValue("@id", id);
|
||||
cmd.Parameters.AddWithValue("@homeScore", (object?)homeScore ?? DBNull.Value);
|
||||
cmd.Parameters.AddWithValue("@awayScore", (object?)awayScore ?? DBNull.Value);
|
||||
cmd.Parameters.AddWithValue("@rain", rain ?? (object?)DBNull.Value);
|
||||
cmd.Parameters.AddWithValue("@practice", practice ?? (object?)DBNull.Value);
|
||||
return await cmd.ExecuteNonQueryAsync() > 0;
|
||||
}
|
||||
|
||||
public async Task<bool> DeleteGameById(string id)
|
||||
{
|
||||
await using var conn = new SqliteConnection(_connectionString);
|
||||
await conn.OpenAsync();
|
||||
var cmd = conn.CreateCommand();
|
||||
cmd.CommandText = "DELETE FROM games WHERE id = @id";
|
||||
cmd.Parameters.AddWithValue("@id", id);
|
||||
return await cmd.ExecuteNonQueryAsync() > 0;
|
||||
}
|
||||
|
||||
public async Task<bool> SwitchVisitors(string id)
|
||||
{
|
||||
var game = await GetGameById(id);
|
||||
if (game is null) return false;
|
||||
|
||||
await using var conn = new SqliteConnection(_connectionString);
|
||||
await conn.OpenAsync();
|
||||
var cmd = conn.CreateCommand();
|
||||
cmd.CommandText = """
|
||||
UPDATE games SET home = @home, away = @away,
|
||||
home_score = @homeScore, away_score = @awayScore
|
||||
WHERE id = @id
|
||||
""";
|
||||
cmd.Parameters.AddWithValue("@id", id);
|
||||
cmd.Parameters.AddWithValue("@home", game.Away);
|
||||
cmd.Parameters.AddWithValue("@away", game.Home);
|
||||
cmd.Parameters.AddWithValue("@homeScore", (object?)game.AwayScore ?? DBNull.Value);
|
||||
cmd.Parameters.AddWithValue("@awayScore", (object?)game.HomeScore ?? DBNull.Value);
|
||||
return await cmd.ExecuteNonQueryAsync() > 0;
|
||||
}
|
||||
|
||||
private static Game ReadGame(DbDataReader r) => new()
|
||||
{
|
||||
Id = r.GetString(r.GetOrdinal("id")),
|
||||
Date = r.GetString(r.GetOrdinal("date")),
|
||||
Time = r.GetString(r.GetOrdinal("time")),
|
||||
Home = r.GetString(r.GetOrdinal("home")),
|
||||
Away = r.GetString(r.GetOrdinal("away")),
|
||||
Year = r.GetInt32(r.GetOrdinal("year")),
|
||||
HomeScore = r.IsDBNull(r.GetOrdinal("home_score")) ? null : r.GetInt32(r.GetOrdinal("home_score")),
|
||||
AwayScore = r.IsDBNull(r.GetOrdinal("away_score")) ? null : r.GetInt32(r.GetOrdinal("away_score")),
|
||||
Practice = r.GetBoolean(r.GetOrdinal("practice")),
|
||||
Rain = r.GetBoolean(r.GetOrdinal("rain")),
|
||||
};
|
||||
|
||||
private static readonly string[] ValidTeams =
|
||||
["jaune", "rouge", "bleu", "gris", "vert", "noir", "orange", "mauve"];
|
||||
|
||||
private static string CleanDate(string raw)
|
||||
{
|
||||
var parts = raw.Split('-');
|
||||
if (parts.Length != 3) return raw;
|
||||
return $"{parts[0]}-{parts[1].PadLeft(2, '0')}-{parts[2].PadLeft(2, '0')}";
|
||||
}
|
||||
|
||||
private static string CleanTime(string raw)
|
||||
{
|
||||
var sep = raw.Contains('h') ? 'h' : ':';
|
||||
var parts = raw.Split(sep);
|
||||
if (parts.Length != 2) return raw;
|
||||
return $"{parts[0].PadLeft(2, '0')}:{parts[1].PadLeft(2, '0')}";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
@{
|
||||
Layout = "_Layout";
|
||||
ViewData["Tab"] = "calendrier";
|
||||
}
|
||||
|
||||
<div id="mithril-content"></div>
|
||||
<script type=module src="scripts/calendar.js"></script>
|
||||
@@ -0,0 +1,36 @@
|
||||
@{
|
||||
Layout = "_Layout";
|
||||
ViewData["Tab"] = "contact";
|
||||
}
|
||||
|
||||
<div class="uk-width-large-2-5 uk-width-medium-4-5 uk-width-small-1-1 uk-container-center">
|
||||
<div class="uk-grid uk-margin">
|
||||
<div class="uk-width-1-1">
|
||||
<div style="height: 300px; width: 300px; background-size: 300px; background-image: url(images/logosansfond.JPG);" class="uk-cover-background uk-container-center"></div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="div uk-panel uk-panel-box uk-panel-box-secondary uk-container-center uk-margin">
|
||||
<table class="uk-table">
|
||||
<tr>
|
||||
<td class="uk-text-right"><i class="fa fa-desktop"></i></td>
|
||||
<td><a href="mailto:sportsphenixmtl@gmail.com">sportsphenixmtl@gmail.com</a></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="uk-text-right"><i class="fa fa-phone"></i></td>
|
||||
<td> (514) 838-8950</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="uk-text-right"><i class="fa fa-envelope"></i></td>
|
||||
<td>
|
||||
<p> 10454 Sylvain-Garneau<br>Montréal, Québec H1C 0A2</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="uk-text-right"><i class="fa fa-gitlab"></i></td>
|
||||
<td>
|
||||
<p> Le site web est ouvert et accessible sur <a href="https://gitlab.com/ballephenix/website">gitlab.</a></p>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
@@ -0,0 +1,103 @@
|
||||
@{
|
||||
Layout = "_Layout";
|
||||
ViewData["Tab"] = "home";
|
||||
}
|
||||
|
||||
<script type="module" src="scripts/little-calendar.js"></script>
|
||||
|
||||
<div class="uk-grid">
|
||||
<div class="uk-large-1-3 uk-medium-2-3 uk-container-center">
|
||||
<div style="height:300px; width: 300px; background-size: 300px; background-image: url(images/logosansfond.JPG);" class="uk-cover-background uk-container-center uk-margin-left uk-margin-top"></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="uk-margin-top uk-margin-bottom uk-grid">
|
||||
<div class="uk-width-large-3-5 uk-width-medium-4-5 uk-width-small-1-1 uk-container-center">
|
||||
<div class="uk-grid uk-visible-large uk-grid-match">
|
||||
<div class="uk-width-large-1-3 uk-width-medium-1-3">
|
||||
<div class="uk-panel uk-panel-box">
|
||||
<div class="uk-panel-badge uk-badge">
|
||||
<i class="fa fa-newspaper-o" style="font-size: 1.7em;"></i>
|
||||
</div>
|
||||
<div>
|
||||
<partial name="HomeNews" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="uk-width-large-1-3 uk-width-medium-1-3">
|
||||
<div class="uk-panel uk-panel-box">
|
||||
<div class="uk-panel-badge uk-badge"><i class="fa fa-calendar" style="font-size: 1.7em;"></i></div>
|
||||
<h3 class="uk-panel-title"><a href="#/calendrier" class="uk-link-muted">Calendrier</a></h3>
|
||||
<div id="large-mithril-container"></div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="uk-width-large-1-3 uk-width-medium-1-3">
|
||||
<div class="uk-panel uk-panel-box">
|
||||
<div class="uk-panel-badge uk-badge"><i class="fa fa-map-o" style="font-size: 1.7em;"></i></div>
|
||||
<h3 class="uk-panel-title">Parc Walter-Stewart</h3>
|
||||
<partial name="WalterStewartMap" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="uk-visible-medium">
|
||||
<div class="uk-grid uk-grid-match">
|
||||
<div class="uk-width-medium-1-2">
|
||||
<div class="uk-panel uk-panel-box">
|
||||
<div class="uk-panel-badge uk-badge"><i class="fa fa-newspaper-o" style="font-size: 1.7em;"></i></div>
|
||||
<div>
|
||||
<partial name="HomeNews" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="uk-width-medium-1-2">
|
||||
<div class="uk-panel uk-panel-box">
|
||||
<div class="uk-panel-badge uk-badge"><i class="fa fa-calendar" style="font-size: 1.7em;"></i></div>
|
||||
<h3 class="uk-panel-title"><a href="#/calendrier" class="uk-link-muted">Calendrier</a></h3>
|
||||
<div id="medium-mithril-container"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="uk-grid">
|
||||
<div class="uk-width-medium-1-1">
|
||||
<div class="uk-panel uk-panel-box">
|
||||
<div class="uk-panel-badge uk-badge"><i class="fa fa-map-o" style="font-size: 1.7em;"></i></div>
|
||||
<h3 class="uk-panel-title">Parc Walter-Stewart</h3>
|
||||
<partial name="WalterStewartMap" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="uk-visible-small">
|
||||
<div class="uk-grid">
|
||||
<div class="uk-width-small-1-1">
|
||||
<div class="uk-panel uk-panel-box">
|
||||
<div class="uk-panel-badge uk-badge"><i class="fa fa-newspaper-o" style="font-size: 1.7em;"></i></div>
|
||||
<div>
|
||||
<partial name="HomeNews" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="uk-grid">
|
||||
<div class="uk-width-small-1-1">
|
||||
<div class="uk-panel uk-panel-box">
|
||||
<div class="uk-panel-badge uk-badge"><i class="fa fa-calendar" style="font-size: 1.7em;"></i></div>
|
||||
<h3 class="uk-panel-title"><a href="#/calendrier" class="uk-link-muted">Calendrier</a></h3>
|
||||
<div id="small-mithril-container"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="uk-grid">
|
||||
<div class="uk-width-small-1-1">
|
||||
<div class="uk-panel uk-panel-box">
|
||||
<div class="uk-panel-badge uk-badge"><i class="fa fa-map-o" style="font-size: 1.7em;"></i></div>
|
||||
<h3 class="uk-panel-title">Parc Walter-Stewart</h3>
|
||||
<partial name="WalterStewartMap" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -0,0 +1,45 @@
|
||||
@{
|
||||
Layout = "_Layout";
|
||||
ViewData["Tab"] = "nouvelles";
|
||||
}
|
||||
|
||||
<div class="uk-width-large-2-5 uk-width-medium-3-5 uk-width-small-1-1 uk-container-center">
|
||||
<div>
|
||||
<article class="uk-article uk-margin-">
|
||||
<h1 class="uk-article-title">
|
||||
<h2 id="saison-2025">Saison 2026</h2>
|
||||
</h1>
|
||||
<p class="uk-article-meta">
|
||||
<p>Lundi 9 Mars 2026</p>
|
||||
</p>
|
||||
<p>
|
||||
La saison de la balle annonce à grand pas et les inscriptions débuteront lundi prochain (16 mars 2026). Le coût de la saison sera le même que l'an passé: 155$ pour la saison + 20$ de dépôt remboursable pour le prêt du chandail.
|
||||
</p>
|
||||
<p>
|
||||
Comme à l'habitude, nous jouerons au parc walter-stewart les jeudis soir. La ligue comptera quatre équipes pour un grand total de 44 joueurs.
|
||||
</p>
|
||||
<p>
|
||||
Les inscriptions en présentiel auront lieu le vendredi 20 mars au bar fullum entre 18h00 et 21h00. Pour ceux qui veulle venir prendre une petite bière avec nous ou payer en argent compten.
|
||||
</p>
|
||||
<p>
|
||||
On vous tiens au courrant!
|
||||
</p>
|
||||
</article>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="uk-width-large-2-5 uk-width-medium-3-5 uk-width-small-1-1 uk-container-center">
|
||||
<div>
|
||||
<article class="uk-article uk-margin-">
|
||||
<h1 class="uk-article-title">
|
||||
<h2 id="saison-2025">Saison 2025</h2>
|
||||
</h1>
|
||||
<p class="uk-article-meta">
|
||||
<p>Vendredi 25 Avril 2025</p>
|
||||
</p>
|
||||
<p>Bonne saison à tous et toutes!</p>
|
||||
<p>N'oubliez pas de consulter la page facebook: <a href="https://www.facebook.com/SportsPhenixMtl/">https://www.facebook.com/SportsPhenixMtl/</a> pour toutes mises à jour, y compris les annulations due à la météo.</p>
|
||||
<p>Votre Comité 2023</p>
|
||||
</article>
|
||||
</div>
|
||||
</div>
|
||||
@@ -0,0 +1,43 @@
|
||||
@{
|
||||
Layout = "_Layout";
|
||||
ViewData["Tab"] = "reglement";
|
||||
}
|
||||
|
||||
<div class="uk-margin-top uk-margin-bottom uk-grid">
|
||||
<div class="uk-width-large-3-5 uk-width-medium-4-5 uk-width-large-1-1 uk-container-center">
|
||||
<div class="uk-grid">
|
||||
<div class="uk-width-large-1-3 uk-width-small-1-1">
|
||||
<div style="height: 250px; width: 250px; background-size: 250px; background-image: url(images/logosansfond.JPG);" class="uk-cover-background uk-container-center"></div>
|
||||
</div>
|
||||
<div class="uk-width-large-2-3 uk-width-small-1-1">
|
||||
<div class="uk-panel uk-panel-box uk-panel-box-secondary">
|
||||
<h2>Règlements 2021</h2>
|
||||
<ul>
|
||||
<li>
|
||||
<h3><a href="files/regle_de_jeux_2021.pdf">Règles de jeu</a></h3>
|
||||
</li>
|
||||
<li>
|
||||
<h3><a href="files/regles_et_procedures_2021.pdf">Règles et procédures</a></h3>
|
||||
</li>
|
||||
<li>
|
||||
<h3><a href="files/charte_organisationnelle_2021.pdf">Charte Organisationnelle</a></h3>
|
||||
</li>
|
||||
<li>
|
||||
<h3><a href="files/formulaire_inscription_2021.pdf">Formulaire d'inscription</a></h3>
|
||||
</li>
|
||||
<li>
|
||||
<h3><a href="files/code_ethique_2021.pdf">Code d'éthique</a></h3>
|
||||
</li>
|
||||
<li>
|
||||
<h3><a href="http://www.asbm.ca/">Association des Sports de Balle à Montréal (ASBN)</a></h3>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="uk-panel uk-panel-box uk-panel-box-secondary">
|
||||
<h2>Mission</h2>
|
||||
<p>La ligue de balle Les Phénix a été fondée en 2004 afin d'offrir aux membres de la communauté gaie et lesbienne et à leurs amis hétéros l'opportunité de s'amuser et de pratiquer un sport dans une ambiance amicale et décontractée. L'ouverture d'esprit, la camaraderie et le plaisir de pratiquer un sport à l'extérieur caractérisent cette ligue.</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -0,0 +1,36 @@
|
||||
@{
|
||||
var isToday = ViewBag.IsToday == true;
|
||||
var years = (List<int>)ViewBag.Years;
|
||||
var games = (List<Phenix.Models.Game>)ViewBag.Games;
|
||||
var selectedYear = (int?)ViewBag.SelectedYear;
|
||||
}
|
||||
|
||||
<div class="uk-width-large-2-3 uk-container-center uk-margin">
|
||||
<div class="uk-margin" style="margin-top: 1em">
|
||||
<ul class="uk-tab">
|
||||
<li class="@(isToday ? "uk-active" : "")">
|
||||
<a hx-get="/membre/games-editor/today" hx-target="#content">Aujourd'hui</a>
|
||||
</li>
|
||||
@foreach (var year in years)
|
||||
{
|
||||
<li class="@(year == selectedYear ? "uk-active" : "")">
|
||||
<a hx-get="/membre/games-editor/@year" hx-target="#content">Saison @year</a>
|
||||
</li>
|
||||
}
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
@foreach (var game in games)
|
||||
{
|
||||
<div class="uk-panel uk-panel-box uk-panel-box-secondary uk-margin">
|
||||
<partial name="GameEditor" model="game" />
|
||||
</div>
|
||||
}
|
||||
|
||||
<hr>
|
||||
<button class="uk-button"
|
||||
hx-get="/membre/new-game-editor"
|
||||
hx-target="#content">
|
||||
Nouvelle Partie
|
||||
</button>
|
||||
</div>
|
||||
@@ -0,0 +1,28 @@
|
||||
@{
|
||||
Layout = "_Layout";
|
||||
ViewData["Tab"] = "membre";
|
||||
}
|
||||
|
||||
<div id="content"
|
||||
@if (ViewBag.IsLoggedIn == true)
|
||||
{
|
||||
@:hx-get="/membre/games-editor/today"
|
||||
@:hx-trigger="load"
|
||||
@:hx-target="#content"
|
||||
}>
|
||||
<div class="uk-grid uk-margin">
|
||||
<div class="uk-width-1-1">
|
||||
<div style="height: 250px; width: 250px; background-size: 250px; background-image: url(images/logosansfond.JPG);" class="uk-cover-background uk-container-center"></div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="uk-panel uk-panel-box uk-panel-box-secondary uk-width-large-1-3 uk-container-center uk-margin">
|
||||
<form action=""
|
||||
class="uk-text-center"
|
||||
hx-get="/login"
|
||||
hx-target="#content">
|
||||
<div class="uk-form-row"><label>Nom d'utilisateur <input type="text" name="username" class="uk-form-width-small"></label></div>
|
||||
<div class="uk-form-row"><label>Mot de passe <input type="password" name="password" class="uk-form-width-small"></label></div>
|
||||
<div class="uk-form-row"><button class="uk-button"><i class="fa fa-mars-double"></i> Pénétrez</button></div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
@@ -0,0 +1,35 @@
|
||||
@{
|
||||
Layout = null;
|
||||
}
|
||||
|
||||
<div class="uk-width-large-2-3 uk-container-center uk-margin">
|
||||
<div class="uk-margin"></div>
|
||||
|
||||
<div class="uk-panel uk-panel-box uk-panel-box-secondary uk-margin">
|
||||
<form hx-post="/membre/new-game"
|
||||
hx-target="#created-game"
|
||||
hx-swap="afterbegin">
|
||||
<div class="uk-form-row" style="text-align: center; font-size: 2em;">
|
||||
<partial name="TeamSelector" model='new Phenix.Models.TeamSelectorModel { Name = "awayTeam" }' />
|
||||
<label>Vs.</label>
|
||||
<partial name="TeamSelector" model='new Phenix.Models.TeamSelectorModel { Name = "homeTeam" }' />
|
||||
</div>
|
||||
|
||||
<div class="uk-form-row">
|
||||
<label>Date: <input type=date name="gameDate" required></label>
|
||||
</div>
|
||||
|
||||
<div class="uk-form-row">
|
||||
<label>Heure: <input type="time" name="gameTime"></label>
|
||||
</div>
|
||||
|
||||
<br>
|
||||
|
||||
<div style="text-align: right;">
|
||||
<button class="uk-button">Creer</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<div id="created-game"></div>
|
||||
</div>
|
||||
@@ -0,0 +1,9 @@
|
||||
@{
|
||||
Layout = null;
|
||||
}
|
||||
|
||||
<div class="uk-width-large-2-3 uk-container-center uk-margin">
|
||||
<div class="uk-panel uk-panel-box uk-panel-box-secondary uk-margin">
|
||||
<pre>@ViewBag.Error</pre>
|
||||
</div>
|
||||
</div>
|
||||
@@ -0,0 +1,7 @@
|
||||
@model Phenix.Models.Game
|
||||
|
||||
<div class="uk-width-large-2-3 uk-container-center uk-margin">
|
||||
<div class="uk-panel uk-panel-box uk-panel-box-secondary uk-margin">
|
||||
<partial name="GameEditor" model="Model" />
|
||||
</div>
|
||||
</div>
|
||||
@@ -0,0 +1,53 @@
|
||||
@model Phenix.Models.Game
|
||||
@{
|
||||
var prettyDate = DateOnly.Parse(Model.Date).ToString("d MMMM yyyy", new System.Globalization.CultureInfo("fr-CA"));
|
||||
}
|
||||
|
||||
<div id="game-@Model.Id">
|
||||
<h3>@Model.Away vs @Model.Home | @prettyDate | @Model.Time</h3>
|
||||
<form style="font-size: 1.1em;"
|
||||
hx-trigger="input delay:250ms"
|
||||
hx-post="/membre/games/@Model.Id"
|
||||
hx-target="#saving-result">
|
||||
<div class="uk-form-row">
|
||||
<label>
|
||||
Points @Model.Away : <input type=number min=0 name="awayScore"
|
||||
value="@(Model.AwayScore ?? 0)"
|
||||
disabled="@(Model.Rain || Model.Practice ? true : null)">
|
||||
</label>
|
||||
</div>
|
||||
<div class="uk-form-row">
|
||||
<label>
|
||||
Points @Model.Home : <input type=number min=0 name="homeScore"
|
||||
value="@(Model.HomeScore ?? 0)"
|
||||
disabled="@(Model.Rain || Model.Practice ? true : null)">
|
||||
</label>
|
||||
</div>
|
||||
<div class="uk-form-row">
|
||||
<label>
|
||||
Partie reguliere <input type=radio name="gameType" value="regular-game"
|
||||
checked="@(!Model.Practice && !Model.Rain ? true : null)">
|
||||
</label>
|
||||
<label>
|
||||
Pluie <input type=radio name="gameType" value="rain"
|
||||
checked="@(Model.Rain ? true : null)">
|
||||
</label>
|
||||
<label>
|
||||
Pratique <input type=radio name="gameType" value="practice"
|
||||
checked="@(Model.Practice && !Model.Rain ? true : null)">
|
||||
</label>
|
||||
</div>
|
||||
<div id="saving-result"></div>
|
||||
</form>
|
||||
|
||||
<div style="text-align: right">
|
||||
<button class="uk-button"
|
||||
hx-post="/membre/games/@Model.Id/switch"
|
||||
hx-target="#game-@Model.Id">Inverser visiteur/receveur</button>
|
||||
<button class="uk-button-danger"
|
||||
hx-delete="/membre/games/@Model.Id"
|
||||
hx-confirm="Certain de voulez supprimer la partie?"
|
||||
hx-target="#game-@Model.Id"
|
||||
hx-swap="delete">Supprimer</button>
|
||||
</div>
|
||||
</div>
|
||||
@@ -0,0 +1,9 @@
|
||||
<h3 class="uk-panel-title">
|
||||
<a href="/nouvelles" class="uk-link-muted">
|
||||
<h2 id="saison-2026">Saison 2026</h2>
|
||||
</a>
|
||||
</h3>
|
||||
<p>
|
||||
La saison de la balle annonce à grand pas et les inscriptions débuteront lundi prochain (16 mars 2026). Le coût de la saison sera le même que l'an passé: 155$ pour la saison + 20$ de dépôt remboursable pour le prêt du chandail.
|
||||
</p>
|
||||
<p><strong><a href="/nouvelles">lire la suite ...</a></strong></p>
|
||||
@@ -0,0 +1,11 @@
|
||||
@model Phenix.Models.TeamSelectorModel
|
||||
@{
|
||||
var teams = new[] { "jaune", "rouge", "bleu", "gris", "vert", "noir", "orange", "mauve" };
|
||||
}
|
||||
|
||||
<select name="@Model.Name" class="uk-select" disabled="@(Model.IsDisabled)">
|
||||
@foreach (var team in teams)
|
||||
{
|
||||
<option value="@team" selected="@(Model.SelectedTeam == team)">@team</option>
|
||||
}
|
||||
</select>
|
||||
@@ -0,0 +1,14 @@
|
||||
<div>
|
||||
<iframe
|
||||
style="border: 1px solid black; min-height: 300px;"
|
||||
width="100%"
|
||||
frameborder="0"
|
||||
scrolling="no"
|
||||
marginheight="0"
|
||||
src="//www.openstreetmap.org/export/embed.html?bbox=-73.55936229228975%2C45.53102667048665%2C-73.55230271816255%2C45.53444249585723&layer=mapnik">
|
||||
</iframe>
|
||||
<br>
|
||||
<small>
|
||||
<a href="http://www.openstreetmap.org/#map=17/45.53216/-73.55692">Voir la carte</a>
|
||||
</small>
|
||||
</div>
|
||||
@@ -0,0 +1,86 @@
|
||||
@{
|
||||
Layout = null;
|
||||
}
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Balle Phenix</title>
|
||||
<link rel="shortcut icon" href="/images/favicon.ico">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<script src="/scripts/jquery-3.7.1.min.js"></script>
|
||||
<script src="/scripts/uikit.min.js"></script>
|
||||
<script src="https://unpkg.com/htmx.org@2.0.0"></script>
|
||||
<link rel="stylesheet" href="/css/style.css">
|
||||
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
|
||||
</head>
|
||||
<body>
|
||||
<nav class="uk-navbar uk-navbar-attached">
|
||||
<ul class="uk-navbar-nav uk-visible-large uk-navbar-content uk-navbar-center">
|
||||
<li class="uk-parent">
|
||||
<div class="uk-navbar-brand"><a href="https://www.facebook.com/SportsPhenixMtl"><i class="fa fa-facebook-square"></i></a></div>
|
||||
</li>
|
||||
<li class="@((ViewData["Tab"] as string) == "home" ? "uk-active" : "")">
|
||||
<a href="/"><div><i class="fa fa-home"></i> Accueil</div></a>
|
||||
</li>
|
||||
<li class="@((ViewData["Tab"] as string) == "nouvelles" ? "uk-active" : "")">
|
||||
<a href="/nouvelles"><div><i class="fa fa-newspaper-o"></i> Nouvelles</div></a>
|
||||
</li>
|
||||
<li class="@((ViewData["Tab"] as string) == "calendrier" ? "uk-active" : "")">
|
||||
<a href="/calendrier"><div><i class="fa fa-calendar"></i> Calendrier</div></a>
|
||||
</li>
|
||||
<li class="@((ViewData["Tab"] as string) == "reglement" ? "uk-active" : "")">
|
||||
<a href="/reglement"><div><i class="fa fa-legal"></i> Règlement</div></a>
|
||||
</li>
|
||||
<li class="@((ViewData["Tab"] as string) == "membre" ? "uk-active" : "")">
|
||||
<a href="/membre"><div><i class="fa fa-lock"></i> Membre</div></a>
|
||||
</li>
|
||||
<li class="@((ViewData["Tab"] as string) == "contact" ? "uk-active" : "")">
|
||||
<a href="/contact"><div><i class="fa fa-phone"></i> Nous Joindre</div></a>
|
||||
</li>
|
||||
</ul>
|
||||
<ul class="uk-navbar-nav uk-visible-medium">
|
||||
<li class="uk-parent">
|
||||
<div class="uk-navbar-brand"><a href="https://www.facebook.com/SportsPhenixMtl"><i class="fa fa-facebook-square"></i></a></div>
|
||||
</li>
|
||||
<li class="@((ViewData["Tab"] as string) == "home" ? "uk-active" : "")"><a href="/"><i class="fa fa-home"></i> Accueil </a></li>
|
||||
<li class="@((ViewData["Tab"] as string) == "nouvelles" ? "uk-active" : "")"><a href="/nouvelles"><i class="fa fa-newspaper-o"></i> Nouvelles</a></li>
|
||||
<li class="@((ViewData["Tab"] as string) == "calendrier" ? "uk-active" : "")"><a href="/calendrier"><i class="fa fa-calendar"></i> Calendrier</a></li>
|
||||
<li class="@((ViewData["Tab"] as string) == "reglement" ? "uk-active" : "")"><a href="/reglement"><i class="fa fa-legal"></i> Règlement</a></li>
|
||||
<li class="@((ViewData["Tab"] as string) == "membre" ? "uk-active" : "")"><a href="/membre"><i class="fa fa-lock"></i> Membre</a></li>
|
||||
<li class="@((ViewData["Tab"] as string) == "contact" ? "uk-active" : "")"><a href="/contact"><i class="fa fa-phone"></i> Nous Joindre</a></li>
|
||||
</ul>
|
||||
<ul class="uk-navbar-nav uk-visible-small">
|
||||
<li class="uk-parent">
|
||||
<div class="uk-navbar-brand"><a href="https://www.facebook.com/SportsPhenixMtl"><i class="fa fa-facebook-square"></i></a></div>
|
||||
</li>
|
||||
<li data-uk-dropdown="" aria-expanded="" class="uk-parent"><a><i class="fa fa-bars"></i> Menu</a>
|
||||
<div class="uk-dropdown">
|
||||
<ul class="uk-nav uk-nav-navbar uk-dropdown-navbar">
|
||||
<li class="uk-active"><a href="/"><i class="fa fa-home"></i> Accueil</a></li>
|
||||
<li class=""><a href="/nouvelles"><i class="fa fa-newspaper-o"></i> Nouvelles</a></li>
|
||||
<li class=""><a href="/calendrier"><i class="fa fa-calendar"></i> Calendrier</a></li>
|
||||
<li class=""><a href="/reglement"><i class="fa fa-legal"></i> Règlement</a></li>
|
||||
<li class=""><a href="/membre"><i class="fa fa-lock"></i> Membre</a></li>
|
||||
<li class=""><a href="/contact"><i class="fa fa-phone"></i> Nous Joindre</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
</li>
|
||||
</ul>
|
||||
</nav>
|
||||
|
||||
@RenderBody()
|
||||
|
||||
<footer class="uk-grid ph-footer" style="padding: 40px;">
|
||||
<div class="uk-container uk-container-center uk-text-center">
|
||||
<div class="uk-panel"><span class="uk-hidden-small">Ligue de balle les Phénix... pour le plaisir de jouer!</span>
|
||||
<h4 class="uk-visible-small">Ligue de balle les Phénix</h4>
|
||||
</div>
|
||||
<ul class="uk-subnav uk-subnav-line uk-flex-center">
|
||||
<li><a href="mailto:sportsphenixmtl@gmail.com">sportsphenixmtl@gmail.com</a></li>
|
||||
</ul>
|
||||
<h1><a href="https://www.facebook.com/SportsPhenixMtl"><i class="fa fa-facebook-square"></i></a></h1>
|
||||
</div>
|
||||
</footer>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1 @@
|
||||
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
|
||||
@@ -0,0 +1,3 @@
|
||||
@{
|
||||
Layout = "_Layout";
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"DatabaseProvider": "Sqlite",
|
||||
"ConnectionStrings": {
|
||||
"Default": "Data Source=phenix.db"
|
||||
},
|
||||
"SessionKey": "dev-only"
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
{ fetchNuGet }: [
|
||||
(fetchNuGet { pname = "Microsoft.Data.Sqlite"; version = "9.0.0"; sha256 = "0m58j9cdrkk8m0yl24z8jy3iafxfbwmf3v01cwhwnqs0cbq1ara8"; })
|
||||
(fetchNuGet { pname = "Microsoft.Data.Sqlite.Core"; version = "9.0.0"; sha256 = "11s3pf12x4ghi1xn2dv6dsj3ckxq062m82dcinn2l42z590ny5fg"; })
|
||||
(fetchNuGet { pname = "Microsoft.Extensions.DependencyInjection.Abstractions"; version = "8.0.0"; sha256 = "1zw0bpp5742jzx03wvqc8csnvsbgdqi0ls9jfc5i2vd3cl8b74pg"; })
|
||||
(fetchNuGet { pname = "Microsoft.Extensions.Logging.Abstractions"; version = "8.0.0"; sha256 = "1klcqhg3hk55hb6vmjiq2wgqidsl81aldw0li2z98lrwx26msrr6"; })
|
||||
(fetchNuGet { pname = "Npgsql"; version = "8.0.0"; sha256 = "1x3jlin44frkhd7d50q0vmy0gapxqhmd4jv1nvsnkndp3xjsaynd"; })
|
||||
(fetchNuGet { pname = "SQLitePCLRaw.bundle_e_sqlite3"; version = "2.1.10"; sha256 = "1irrg46sv2w12nh6jc810clbi06fgclnbky14b8kamfkgy61d4li"; })
|
||||
(fetchNuGet { pname = "SQLitePCLRaw.core"; version = "2.1.10"; sha256 = "03q02p1cajqzcbk9112mgw3qq733l4gd2vi21dq2am4911imr5l2"; })
|
||||
(fetchNuGet { pname = "SQLitePCLRaw.lib.e_sqlite3"; version = "2.1.10"; sha256 = "0xqa3l4p68vm3p5n4h3d2gs97vrpnvhwfv366i6fv5x80m2zcswv"; })
|
||||
(fetchNuGet { pname = "SQLitePCLRaw.provider.e_sqlite3"; version = "2.1.10"; sha256 = "0n7cdwix5h9k578a07g00sw9c03sv4liy91qzpj9wb8k4673gfrh"; })
|
||||
(fetchNuGet { pname = "System.Memory"; version = "4.5.3"; sha256 = "0naqahm3wljxb5a911d37mwjqjdxv9l0b49p5dmfyijvni2ppy8a"; })
|
||||
]
|
||||
Executable
+144
@@ -0,0 +1,144 @@
|
||||
#!/usr/bin/env python3
|
||||
import argparse
|
||||
import os
|
||||
import sqlite3
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
import requests
|
||||
|
||||
|
||||
def find_project_root():
|
||||
direnv_file = os.environ.get("DIRENV_FILE")
|
||||
if direnv_file:
|
||||
return Path(direnv_file).parent.resolve()
|
||||
|
||||
direnv_dir = os.environ.get("DIRENV_DIR")
|
||||
if direnv_dir:
|
||||
return Path(direnv_dir).resolve()
|
||||
|
||||
cwd = Path.cwd().resolve()
|
||||
for parent in [cwd] + list(cwd.parents):
|
||||
if (parent / "flake.nix").exists():
|
||||
return parent
|
||||
|
||||
raise RuntimeError(
|
||||
"Cannot find project root. Set DIRENV_FILE or DIRENV_DIR, "
|
||||
"or run from within the project tree."
|
||||
)
|
||||
|
||||
|
||||
def fetch_json(api_root, path):
|
||||
url = f"{api_root}{path}"
|
||||
resp = requests.get(url, timeout=30)
|
||||
resp.raise_for_status()
|
||||
return resp.json()
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(
|
||||
description="Populate a local SQLite DB from production data"
|
||||
)
|
||||
parser.add_argument(
|
||||
"--url",
|
||||
default=os.environ.get("PHENIX_URL", "https://ballephenix.com"),
|
||||
help="Source API root (default: https://ballephenix.com)",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--db",
|
||||
default=None,
|
||||
help="Path to SQLite DB (default: <project-root>/phenix.db)",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--force",
|
||||
action="store_true",
|
||||
help="Clear existing games before inserting",
|
||||
)
|
||||
args = parser.parse_args()
|
||||
|
||||
api_root = args.url.rstrip("/")
|
||||
|
||||
project_root = find_project_root()
|
||||
db_path = Path(args.db) if args.db else project_root / "phenix.db"
|
||||
|
||||
years = fetch_json(api_root, "/api/available-years.json")
|
||||
print(f"Years on source: {len(years)} ({min(years)}–{max(years)})")
|
||||
|
||||
all_games = []
|
||||
for year in years:
|
||||
games = fetch_json(api_root, f"/api/results/{year}.json")
|
||||
all_games.extend(games)
|
||||
print(f"Total games fetched: {len(all_games)}")
|
||||
|
||||
conn = sqlite3.connect(str(db_path))
|
||||
cursor = conn.cursor()
|
||||
|
||||
cursor.execute("""
|
||||
CREATE TABLE IF NOT EXISTS games (
|
||||
id TEXT PRIMARY KEY,
|
||||
date TEXT NOT NULL,
|
||||
time TEXT NOT NULL,
|
||||
home TEXT NOT NULL,
|
||||
away TEXT NOT NULL,
|
||||
year INTEGER NOT NULL,
|
||||
home_score INTEGER,
|
||||
away_score INTEGER,
|
||||
practice INTEGER NOT NULL DEFAULT 0,
|
||||
rain INTEGER NOT NULL DEFAULT 0,
|
||||
UNIQUE(date, time)
|
||||
)
|
||||
""")
|
||||
|
||||
if args.force:
|
||||
cursor.execute("DELETE FROM games")
|
||||
print("Cleared existing games")
|
||||
|
||||
inserted = 0
|
||||
skipped = 0
|
||||
errors = 0
|
||||
|
||||
for g in all_games:
|
||||
try:
|
||||
home_score = int(g["homeScore"]) if g.get("homeScore") is not None else None
|
||||
away_score = int(g["awayScore"]) if g.get("awayScore") is not None else None
|
||||
except (ValueError, TypeError):
|
||||
home_score = None
|
||||
away_score = None
|
||||
|
||||
try:
|
||||
cursor.execute(
|
||||
"""
|
||||
INSERT OR IGNORE INTO games
|
||||
(id, date, time, home, away, year, home_score, away_score, practice, rain)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||
""",
|
||||
(
|
||||
g.get("id", ""),
|
||||
g["date"],
|
||||
g.get("time", ""),
|
||||
g.get("home", ""),
|
||||
g.get("away", ""),
|
||||
g.get("year", 0),
|
||||
home_score,
|
||||
away_score,
|
||||
1 if g.get("practice") else 0,
|
||||
1 if g.get("rain") else 0,
|
||||
),
|
||||
)
|
||||
if cursor.rowcount > 0:
|
||||
inserted += 1
|
||||
else:
|
||||
skipped += 1
|
||||
except sqlite3.Error as e:
|
||||
print(f"DB error on {g.get('date')} {g.get('time')}: {e}", file=sys.stderr)
|
||||
errors += 1
|
||||
|
||||
conn.commit()
|
||||
conn.close()
|
||||
|
||||
print(f"Inserted: {inserted}, skipped: {skipped}, errors: {errors}")
|
||||
print(f"Database: {db_path}")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -1,32 +1,126 @@
|
||||
{
|
||||
description = "Phenix website";
|
||||
description = "Balle Phenix website — ASP.NET + SQLite";
|
||||
|
||||
inputs = {
|
||||
nixpkgs.url = "nixpkgs/nixos-unstable";
|
||||
flake-utils.url = "github:numtide/flake-utils";
|
||||
};
|
||||
|
||||
outputs = { self, nixpkgs, flake-utils }:
|
||||
|
||||
outputs = { self, nixpkgs, flake-utils, ... }:
|
||||
flake-utils.lib.eachDefaultSystem (system:
|
||||
let
|
||||
pkgs = nixpkgs.legacyPackages.${system};
|
||||
build-static-files = pkgs.stdenv.mkDerivation {
|
||||
name = "phenix-website-static-assets";
|
||||
src = ./static;
|
||||
buildPhase = ''
|
||||
find . -type f -exec ${pkgs.brotli}/bin/brotli -9 -f -k {} \;
|
||||
'';
|
||||
installPhase = ''
|
||||
cp -r . $out
|
||||
dotnet = pkgs.dotnetCorePackages.sdk_9_0;
|
||||
pythonEnv = pkgs.python3.withPackages (ps: [ ps.requests ]);
|
||||
|
||||
phenix-website = pkgs.buildDotnetModule {
|
||||
name = "phenix-website";
|
||||
src = ./.;
|
||||
projectFile = "Phenix.csproj";
|
||||
selfContainedBuild = true;
|
||||
dotnet-sdk = dotnet;
|
||||
dotnet-runtime = pkgs.dotnetCorePackages.runtime_9_0;
|
||||
runtimeIdentifiers = "linux-x64";
|
||||
nugetDeps = ./deps.nix;
|
||||
|
||||
postInstall = ''
|
||||
cp -r static $out/lib/static/
|
||||
cp appsettings.json $out/lib/
|
||||
'';
|
||||
meta.mainProgram = "Phenix";
|
||||
};
|
||||
in {
|
||||
packages = { static = build-static-files; };
|
||||
packages = {
|
||||
default = phenix-website;
|
||||
website = phenix-website;
|
||||
};
|
||||
|
||||
devShell = pkgs.mkShell {
|
||||
name = "Phenix-Website";
|
||||
buildInputs = with pkgs; [ deno ];
|
||||
buildInputs = [ dotnet pkgs.nuget-to-nix pythonEnv ];
|
||||
|
||||
shellHook = ''
|
||||
export PATH="$PWD/dev/populate-db:$PATH"
|
||||
'';
|
||||
};
|
||||
}) // {
|
||||
|
||||
nixosModules.default = { config, lib, pkgs, ... }:
|
||||
let
|
||||
cfg = config.services.phenix-website;
|
||||
phenix = self.packages.${pkgs.system}.website;
|
||||
pythonEnv = pkgs.python3.withPackages (ps: [ ps.requests ]);
|
||||
in {
|
||||
options.services.phenix-website = {
|
||||
enable = lib.mkEnableOption "Balle Phenix website";
|
||||
domain = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
default = "ballephenix.com";
|
||||
};
|
||||
port = lib.mkOption {
|
||||
type = lib.types.port;
|
||||
default = 8000;
|
||||
};
|
||||
dataDir = lib.mkOption {
|
||||
type = lib.types.path;
|
||||
default = "/var/lib/phenix";
|
||||
};
|
||||
sessionKey = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
default = "";
|
||||
};
|
||||
};
|
||||
|
||||
config = lib.mkIf cfg.enable {
|
||||
systemd.services.phenix-website = {
|
||||
description = "Balle Phenix website";
|
||||
wantedBy = [ "multi-user.target" ];
|
||||
after = [ "network.target" ];
|
||||
|
||||
serviceConfig = {
|
||||
Type = "simple";
|
||||
ExecStart = "${phenix}/lib/Phenix";
|
||||
WorkingDirectory = "${phenix}/lib/";
|
||||
Restart = "always";
|
||||
RestartSec = 5;
|
||||
User = "phenix";
|
||||
Group = "phenix";
|
||||
};
|
||||
|
||||
environment = {
|
||||
ASPNETCORE_URLS = "http://0.0.0.0:${toString cfg.port}";
|
||||
ASPNETCORE_ENVIRONMENT = "Production";
|
||||
ConnectionStrings__Default = "Data Source=${cfg.dataDir}/phenix.db";
|
||||
} // lib.optionalAttrs (cfg.sessionKey != "") {
|
||||
SessionKey = cfg.sessionKey;
|
||||
};
|
||||
|
||||
postStart = ''
|
||||
mkdir -p ${cfg.dataDir}
|
||||
'';
|
||||
};
|
||||
|
||||
users.users.phenix = {
|
||||
isSystemUser = true;
|
||||
group = "phenix";
|
||||
home = cfg.dataDir;
|
||||
createHome = true;
|
||||
};
|
||||
|
||||
users.groups.phenix = {};
|
||||
|
||||
services.nginx = lib.mkIf (cfg.domain != "") {
|
||||
enable = true;
|
||||
virtualHosts.${cfg.domain} = {
|
||||
forceSSL = true;
|
||||
enableACME = true;
|
||||
locations."/" = {
|
||||
proxyPass = "http://127.0.0.1:${toString cfg.port}";
|
||||
proxyWebsockets = false;
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
});
|
||||
}
|
||||
Reference in new issue
Block a user