Upload ruck

This commit is contained in:
Brandon Dyck 2024-05-16 22:30:18 -06:00
commit 50dd696a1b
24 changed files with 858 additions and 0 deletions

368
.gitignore vendored Normal file
View File

@ -0,0 +1,368 @@
## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.
##
## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
# User-specific files
*.rsuser
*.suo
*.user
*.userosscache
*.sln.docstates
# User-specific files (MonoDevelop/Xamarin Studio)
*.userprefs
# Mono auto generated files
mono_crash.*
# Build results
[Dd]ebug/
[Dd]ebugPublic/
[Rr]elease/
[Rr]eleases/
x64/
x86/
[Ww][Ii][Nn]32/
[Aa][Rr][Mm]/
[Aa][Rr][Mm]64/
bld/
[Bb]in/
[Oo]bj/
[Oo]ut/
[Ll]og/
[Ll]ogs/
# Visual Studio 2015/2017 cache/options directory
.vs/
# Uncomment if you have tasks that create the project's static files in wwwroot
#wwwroot/
# Visual Studio 2017 auto generated files
Generated\ Files/
# MSTest test Results
[Tt]est[Rr]esult*/
[Bb]uild[Ll]og.*
# NUnit
*.VisualState.xml
TestResult.xml
nunit-*.xml
# Build Results of an ATL Project
[Dd]ebugPS/
[Rr]eleasePS/
dlldata.c
# Benchmark Results
BenchmarkDotNet.Artifacts/
# .NET Core
project.lock.json
project.fragment.lock.json
artifacts/
# ASP.NET Scaffolding
ScaffoldingReadMe.txt
# StyleCop
StyleCopReport.xml
# Files built by Visual Studio
*_i.c
*_p.c
*_h.h
*.ilk
*.meta
*.obj
*.iobj
*.pch
*.pdb
*.ipdb
*.pgc
*.pgd
*.rsp
*.sbr
*.tlb
*.tli
*.tlh
*.tmp
*.tmp_proj
*_wpftmp.csproj
*.log
*.vspscc
*.vssscc
.builds
*.pidb
*.svclog
*.scc
# Chutzpah Test files
_Chutzpah*
# Visual C++ cache files
ipch/
*.aps
*.ncb
*.opendb
*.opensdf
*.sdf
*.cachefile
*.VC.db
*.VC.VC.opendb
# Visual Studio profiler
*.psess
*.vsp
*.vspx
*.sap
# Visual Studio Trace Files
*.e2e
# TFS 2012 Local Workspace
$tf/
# Guidance Automation Toolkit
*.gpState
# ReSharper is a .NET coding add-in
_ReSharper*/
*.[Rr]e[Ss]harper
*.DotSettings.user
# TeamCity is a build add-in
_TeamCity*
# DotCover is a Code Coverage Tool
*.dotCover
# AxoCover is a Code Coverage Tool
.axoCover/*
!.axoCover/settings.json
# Coverlet is a free, cross platform Code Coverage Tool
coverage*.json
coverage*.xml
coverage*.info
# Visual Studio code coverage results
*.coverage
*.coveragexml
# NCrunch
_NCrunch_*
.*crunch*.local.xml
nCrunchTemp_*
# MightyMoose
*.mm.*
AutoTest.Net/
# Web workbench (sass)
.sass-cache/
# Installshield output folder
[Ee]xpress/
# DocProject is a documentation generator add-in
DocProject/buildhelp/
DocProject/Help/*.HxT
DocProject/Help/*.HxC
DocProject/Help/*.hhc
DocProject/Help/*.hhk
DocProject/Help/*.hhp
DocProject/Help/Html2
DocProject/Help/html
# Click-Once directory
publish/
# Publish Web Output
*.[Pp]ublish.xml
*.azurePubxml
# Note: Comment the next line if you want to checkin your web deploy settings,
# but database connection strings (with potential passwords) will be unencrypted
*.pubxml
*.publishproj
# Microsoft Azure Web App publish settings. Comment the next line if you want to
# checkin your Azure Web App publish settings, but sensitive information contained
# in these scripts will be unencrypted
PublishScripts/
# NuGet Packages
*.nupkg
# NuGet Symbol Packages
*.snupkg
# The packages folder can be ignored because of Package Restore
**/[Pp]ackages/*
# except build/, which is used as an MSBuild target.
!**/[Pp]ackages/build/
# Uncomment if necessary however generally it will be regenerated when needed
#!**/[Pp]ackages/repositories.config
# NuGet v3's project.json files produces more ignorable files
*.nuget.props
*.nuget.targets
# Microsoft Azure Build Output
csx/
*.build.csdef
# Microsoft Azure Emulator
ecf/
rcf/
# Windows Store app package directories and files
AppPackages/
BundleArtifacts/
Package.StoreAssociation.xml
_pkginfo.txt
*.appx
*.appxbundle
*.appxupload
# Visual Studio cache files
# files ending in .cache can be ignored
*.[Cc]ache
# but keep track of directories ending in .cache
!?*.[Cc]ache/
# Others
ClientBin/
~$*
*~
*.dbmdl
*.dbproj.schemaview
*.jfm
*.pfx
*.publishsettings
orleans.codegen.cs
# Including strong name files can present a security risk
# (https://github.com/github/gitignore/pull/2483#issue-259490424)
#*.snk
# Since there are multiple workflows, uncomment next line to ignore bower_components
# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
#bower_components/
# RIA/Silverlight projects
Generated_Code/
# Backup & report files from converting an old project file
# to a newer Visual Studio version. Backup files are not needed,
# because we have git ;-)
_UpgradeReport_Files/
Backup*/
UpgradeLog*.XML
UpgradeLog*.htm
ServiceFabricBackup/
*.rptproj.bak
# SQL Server files
*.mdf
*.ldf
*.ndf
# Business Intelligence projects
*.rdl.data
*.bim.layout
*.bim_*.settings
*.rptproj.rsuser
*- [Bb]ackup.rdl
*- [Bb]ackup ([0-9]).rdl
*- [Bb]ackup ([0-9][0-9]).rdl
# Microsoft Fakes
FakesAssemblies/
# GhostDoc plugin setting file
*.GhostDoc.xml
# Node.js Tools for Visual Studio
.ntvs_analysis.dat
node_modules/
# Visual Studio 6 build log
*.plg
# Visual Studio 6 workspace options file
*.opt
# Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
*.vbw
# Visual Studio LightSwitch build output
**/*.HTMLClient/GeneratedArtifacts
**/*.DesktopClient/GeneratedArtifacts
**/*.DesktopClient/ModelManifest.xml
**/*.Server/GeneratedArtifacts
**/*.Server/ModelManifest.xml
_Pvt_Extensions
# Paket dependency manager
.paket/paket.exe
paket-files/
# FAKE - F# Make
.fake/
# CodeRush personal settings
.cr/personal
# Python Tools for Visual Studio (PTVS)
__pycache__/
*.pyc
# Cake - Uncomment if you are using it
# tools/**
# !tools/packages.config
# Tabs Studio
*.tss
# Telerik's JustMock configuration file
*.jmconfig
# BizTalk build output
*.btp.cs
*.btm.cs
*.odx.cs
*.xsd.cs
# OpenCover UI analysis results
OpenCover/
# Azure Stream Analytics local run output
ASALocalRun/
# MSBuild Binary and Structured Log
*.binlog
# NVidia Nsight GPU debugger configuration file
*.nvuser
# MFractors (Xamarin productivity tool) working folder
.mfractor/
# Local History for Visual Studio
.localhistory/
# BeatPulse healthcheck temp database
healthchecksdb
# Backup folder for Package Reference Convert tool in Visual Studio 2017
MigrationBackup/
# Ionide (cross platform F# VS Code tools) working folder
.ionide/
# Fody - auto-generated XML schema
FodyWeavers.xsd
# App database
*.db
*.db-shm
*.db-wal

25
RecordMyRuck.sln Normal file
View File

@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.9.34728.123
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RecordMyRuck", "RecordMyRuck\RecordMyRuck.csproj", "{B21703D9-9E6E-4335-BD79-81B8D059A0BC}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{B21703D9-9E6E-4335-BD79-81B8D059A0BC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B21703D9-9E6E-4335-BD79-81B8D059A0BC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B21703D9-9E6E-4335-BD79-81B8D059A0BC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B21703D9-9E6E-4335-BD79-81B8D059A0BC}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {E2B251E8-17E6-438D-B7A3-3D91847CF586}
EndGlobalSection
EndGlobal

View File

@ -0,0 +1,12 @@
using Microsoft.AspNetCore.Mvc;
namespace RecordMyRuck.Controllers
{
public class HomeController : Controller
{
public IActionResult Index()
{
return View();
}
}
}

View File

@ -0,0 +1,67 @@
using Microsoft.AspNetCore.Mvc;
using RecordMyRuck.Models;
namespace RecordMyRuck.Controllers
{
public class RuckController : Controller
{
private const string DateTimeFormat = "u";
private readonly IRuckRepository _ruckRepository;
public RuckController(IRuckRepository ruckRepository)
{
_ruckRepository = ruckRepository;
}
public IActionResult Index()
{
return View();
}
public IActionResult New()
{
return View();
}
[HttpPost]
public IActionResult New(RuckUpload ruckUpload)
{
if (!ModelState.IsValid)
{
return View(ruckUpload);
}
var gpxStream = ruckUpload.Route.OpenReadStream();
var reader = new StreamReader(gpxStream);
var gpxData = reader.ReadToEnd();
_ruckRepository.CreateRuck(new Ruck
{
DateTime = ruckUpload.DateTime,
Route = gpxData,
WeightPounds = ruckUpload.WeightPounds,
Notes = ruckUpload.Notes ?? "",
});
return RedirectToAction("Edit", new { dateTimeString = ruckUpload.DateTime.ToString(DateTimeFormat) });
}
public IActionResult Edit(string dateTimeString)
{
DateTime dateTime;
try
{
dateTime = DateTime.ParseExact(dateTimeString, DateTimeFormat, null);
}
catch
{
return NotFound();
}
var ruck = _ruckRepository.Get(dateTime);
if (ruck == null)
{
return NotFound();
}
return View(ruck);
}
}
}

View File

@ -0,0 +1,46 @@
// <auto-generated />
using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using RecordMyRuck.Models;
#nullable disable
namespace RecordMyRuck.Migrations
{
[DbContext(typeof(RecordMyRuckDbContext))]
[Migration("20240517025819_CreateRuck")]
partial class CreateRuck
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder.HasAnnotation("ProductVersion", "8.0.4");
modelBuilder.Entity("RecordMyRuck.Models.Ruck", b =>
{
b.Property<DateTime>("DateTime")
.HasColumnType("TEXT");
b.Property<string>("Notes")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("Route")
.IsRequired()
.HasColumnType("TEXT");
b.Property<float>("WeightPounds")
.HasColumnType("REAL");
b.HasKey("DateTime");
b.ToTable("Rucks");
});
#pragma warning restore 612, 618
}
}
}

View File

@ -0,0 +1,36 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace RecordMyRuck.Migrations
{
/// <inheritdoc />
public partial class CreateRuck : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "Rucks",
columns: table => new
{
DateTime = table.Column<DateTime>(type: "TEXT", nullable: false),
Route = table.Column<string>(type: "TEXT", nullable: false),
WeightPounds = table.Column<float>(type: "REAL", nullable: false),
Notes = table.Column<string>(type: "TEXT", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Rucks", x => x.DateTime);
});
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "Rucks");
}
}
}

View File

@ -0,0 +1,43 @@
// <auto-generated />
using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using RecordMyRuck.Models;
#nullable disable
namespace RecordMyRuck.Migrations
{
[DbContext(typeof(RecordMyRuckDbContext))]
partial class RecordMyRuckDbContextModelSnapshot : ModelSnapshot
{
protected override void BuildModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder.HasAnnotation("ProductVersion", "8.0.4");
modelBuilder.Entity("RecordMyRuck.Models.Ruck", b =>
{
b.Property<DateTime>("DateTime")
.HasColumnType("TEXT");
b.Property<string>("Notes")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("Route")
.IsRequired()
.HasColumnType("TEXT");
b.Property<float>("WeightPounds")
.HasColumnType("REAL");
b.HasKey("DateTime");
b.ToTable("Rucks");
});
#pragma warning restore 612, 618
}
}
}

View File

@ -0,0 +1,9 @@
namespace RecordMyRuck.Models
{
public interface IRuckRepository
{
Ruck? Get(DateTime dateTime);
IEnumerable<Ruck> GetAll();
void CreateRuck(Ruck ruck);
}
}

View File

@ -0,0 +1,11 @@
using Microsoft.EntityFrameworkCore;
namespace RecordMyRuck.Models
{
public class RecordMyRuckDbContext : Microsoft.EntityFrameworkCore.DbContext
{
public RecordMyRuckDbContext(DbContextOptions<RecordMyRuckDbContext> options) : base(options) { }
public DbSet<Ruck> Rucks { get; set; }
}
}

View File

@ -0,0 +1,25 @@
using Microsoft.EntityFrameworkCore;
using System.ComponentModel.DataAnnotations;
namespace RecordMyRuck.Models
{
[PrimaryKey(nameof(DateTime))]
public class Ruck
{
[Required]
[Display(Name = "Date/Time")]
[DataType(DataType.DateTime)]
public DateTime DateTime { get; set; }
[Required]
public string Route { get; set; }
[Required]
[Display(Name = "Weigh (lb)")]
public float WeightPounds { get; set; }
[DataType(DataType.MultilineText)]
public string Notes { get; set; } = "";
}
}

View File

@ -0,0 +1,28 @@
namespace RecordMyRuck.Models
{
public class RuckRepository : IRuckRepository
{
RecordMyRuckDbContext _dbContext;
public RuckRepository(RecordMyRuckDbContext dbContext)
{
_dbContext = dbContext;
}
public void CreateRuck(Ruck ruck)
{
_dbContext.Rucks.Add(ruck);
_dbContext.SaveChanges();
}
public Ruck? Get(DateTime dateTime)
{
return _dbContext.Rucks.FirstOrDefault(r => r.DateTime == dateTime);
}
public IEnumerable<Ruck> GetAll()
{
return _dbContext.Rucks;
}
}
}

View File

@ -0,0 +1,22 @@
using System.ComponentModel.DataAnnotations;
namespace RecordMyRuck.Models
{
public class RuckUpload
{
[Required]
[Display(Name = "Date/Time")]
[DataType(DataType.DateTime)]
public DateTime DateTime { get; set; }
[Required]
public IFormFile Route { get; set; }
[Required]
[Display(Name = "Weigh (lb)")]
public float WeightPounds { get; set; }
[DataType(DataType.MultilineText)]
public string Notes { get; set; } = "";
}
}

22
RecordMyRuck/Program.cs Normal file
View File

@ -0,0 +1,22 @@
using Microsoft.EntityFrameworkCore;
using RecordMyRuck.Models;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddControllersWithViews();
builder.Services.AddDbContext<RecordMyRuck.Models.RecordMyRuckDbContext>(options =>
{
options.UseSqlite(builder.Configuration["ConnectionStrings:AppDb"]);
});
builder.Services.AddScoped<IRuckRepository, RuckRepository>();
var app = builder.Build();
if (app.Environment.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.MapDefaultControllerRoute();
app.Run();

View File

@ -0,0 +1,38 @@
{
"$schema": "http://json.schemastore.org/launchsettings.json",
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:46321",
"sslPort": 44397
}
},
"profiles": {
"http": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"applicationUrl": "http://localhost:5201",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"https": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"applicationUrl": "https://localhost:7197;http://localhost:5201",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}

View File

@ -0,0 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="8.0.4" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite.NetTopologySuite" Version="8.0.4" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.4">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
</Project>

View File

@ -0,0 +1 @@
<p>Hello world!</p>

View File

@ -0,0 +1,13 @@
@model Ruck
<h2>Date/Time</h2>
@Model.DateTime
<h2>Weight</h2>
@Model.WeightPounds lb
<h2>Notes</h2>
<p>@Model.Notes</p>
<h2>GPX data</h2>
<pre>@Model.Route</pre>

View File

@ -0,0 +1,5 @@
@*
For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
*@
@{
}

View File

@ -0,0 +1,21 @@
@model RuckUpload
<h2>Record new ruck</h2>
<div asp-validation-summary="All"></div>
<form method="post" enctype="multipart/form-data">
<div>
<label asp-for="DateTime"></label><input asp-for="DateTime" type="datetime-local" />
</div>
<div>
<label asp-for="Route"></label><input asp-for="Route" type="file" />
</div>
<div>
<label asp-for="WeightPounds"></label><input asp-for="WeightPounds" type="number" />
</div>
<div>
<label asp-for="Notes"></label><textarea asp-for="Notes" placeholder="Type notes here…"></textarea>
</div>
<input type="submit" value="Create" />
</form>

View File

@ -0,0 +1,22 @@
<!DOCTYPE html>
<html>
<head>
<title>Record My Ruck</title>
</head>
<body>
<header>
<h1>Record My Ruck</h1>
<nav>
<ul>
<li><a asp-controller="Home" asp-action="Index">Home</a></li>
<li><a asp-controller="Ruck" asp-action="New">Record ruck</a></li>
</ul>
</nav>
</header>
<hr />
<content>
@RenderBody()
</content>
</body>
</html>

View File

@ -0,0 +1,3 @@
@using RecordMyRuck.Models
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers

View File

@ -0,0 +1,3 @@
@{
Layout = "_Layout";
}

View File

@ -0,0 +1,8 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
}
}

View File

@ -0,0 +1,12 @@
{
"ConnectionStrings": {
"AppDb": "Data Source=RecordMyRuck.db"
},
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*"
}