Updating
This commit is contained in:
12
teams/.config/dotnet-tools.json
Normal file
12
teams/.config/dotnet-tools.json
Normal file
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"version": 1,
|
||||
"isRoot": true,
|
||||
"tools": {
|
||||
"dotnet-ef": {
|
||||
"version": "6.0.12",
|
||||
"commands": [
|
||||
"dotnet-ef"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
25
teams/.dockerignore
Normal file
25
teams/.dockerignore
Normal file
@@ -0,0 +1,25 @@
|
||||
**/.classpath
|
||||
**/.dockerignore
|
||||
**/.env
|
||||
**/.git
|
||||
**/.gitignore
|
||||
**/.project
|
||||
**/.settings
|
||||
**/.toolstarget
|
||||
**/.vs
|
||||
**/.vscode
|
||||
**/*.*proj.user
|
||||
**/*.dbmdl
|
||||
**/*.jfm
|
||||
**/azds.yaml
|
||||
**/bin
|
||||
**/charts
|
||||
**/docker-compose*
|
||||
**/Dockerfile*
|
||||
**/node_modules
|
||||
**/npm-debug.log
|
||||
**/obj
|
||||
**/secrets.dev.yaml
|
||||
**/values.dev.yaml
|
||||
LICENSE
|
||||
README.md
|
||||
405
teams/.gitignore
vendored
Normal file
405
teams/.gitignore
vendored
Normal file
@@ -0,0 +1,405 @@
|
||||
# globs
|
||||
Makefile.in
|
||||
*.userprefs
|
||||
*.usertasks
|
||||
config.make
|
||||
config.status
|
||||
aclocal.m4
|
||||
install-sh
|
||||
autom4te.cache/
|
||||
*.tar.gz
|
||||
tarballs/
|
||||
test-results/
|
||||
|
||||
# Mac bundle stuff
|
||||
*.dmg
|
||||
*.app
|
||||
|
||||
# content below from: https://github.com/github/gitignore/blob/main/Global/macOS.gitignore
|
||||
# General
|
||||
.DS_Store
|
||||
.AppleDouble
|
||||
.LSOverride
|
||||
|
||||
# Icon must end with two \r
|
||||
Icon
|
||||
|
||||
|
||||
# Thumbnails
|
||||
._*
|
||||
|
||||
# Files that might appear in the root of a volume
|
||||
.DocumentRevisions-V100
|
||||
.fseventsd
|
||||
.Spotlight-V100
|
||||
.TemporaryItems
|
||||
.Trashes
|
||||
.VolumeIcon.icns
|
||||
.com.apple.timemachine.donotpresent
|
||||
|
||||
# Directories potentially created on remote AFP share
|
||||
.AppleDB
|
||||
.AppleDesktop
|
||||
Network Trash Folder
|
||||
Temporary Items
|
||||
.apdisk
|
||||
|
||||
# content below from: https://github.com/github/gitignore/blob/main/Global/Windows.gitignore
|
||||
# Windows thumbnail cache files
|
||||
Thumbs.db
|
||||
ehthumbs.db
|
||||
ehthumbs_vista.db
|
||||
|
||||
# Dump file
|
||||
*.stackdump
|
||||
|
||||
# Folder config file
|
||||
[Dd]esktop.ini
|
||||
|
||||
# Recycle Bin used on file shares
|
||||
$RECYCLE.BIN/
|
||||
|
||||
# Windows Installer files
|
||||
*.cab
|
||||
*.msi
|
||||
*.msix
|
||||
*.msm
|
||||
*.msp
|
||||
|
||||
# Windows shortcuts
|
||||
*.lnk
|
||||
|
||||
# content below from: https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
|
||||
## 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
|
||||
*.suo
|
||||
*.user
|
||||
*.userosscache
|
||||
*.sln.docstates
|
||||
|
||||
# User-specific files (MonoDevelop/Xamarin Studio)
|
||||
*.userprefs
|
||||
|
||||
# Build results
|
||||
[Dd]ebug/
|
||||
[Dd]ebugPublic/
|
||||
[Rr]elease/
|
||||
[Rr]eleases/
|
||||
x64/
|
||||
x86/
|
||||
bld/
|
||||
[Bb]in/
|
||||
[Oo]bj/
|
||||
[Ll]og/
|
||||
|
||||
# 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
|
||||
|
||||
# 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/
|
||||
|
||||
# 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
|
||||
|
||||
# JustCode is a .NET coding add-in
|
||||
.JustCode
|
||||
|
||||
# TeamCity is a build add-in
|
||||
_TeamCity*
|
||||
|
||||
# DotCover is a Code Coverage Tool
|
||||
*.dotCover
|
||||
|
||||
# AxoCover is a Code Coverage Tool
|
||||
.axoCover/*
|
||||
!.axoCover/settings.json
|
||||
|
||||
# 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
|
||||
# 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
|
||||
|
||||
# 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
|
||||
|
||||
# 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/
|
||||
|
||||
# JetBrains Rider
|
||||
.idea/
|
||||
*.sln.iml
|
||||
|
||||
# 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/
|
||||
50
teams/Controllers/TeamsController.cs
Normal file
50
teams/Controllers/TeamsController.cs
Normal file
@@ -0,0 +1,50 @@
|
||||
using AutoMapper;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Teams.Filter;
|
||||
using Teams.Models;
|
||||
using Teams.Services;
|
||||
using Teams.Wrappers;
|
||||
|
||||
namespace Teams.Controllers;
|
||||
|
||||
[ApiController]
|
||||
[Route("api/teams")]
|
||||
public class TeamsController : ControllerBase
|
||||
{
|
||||
private readonly ITeamsRepository _teamsRepository;
|
||||
private readonly IMapper _mapper;
|
||||
const int maxTeamsPerPage = 50;
|
||||
|
||||
public TeamsController(ITeamsRepository teamsRepository, IMapper mapper)
|
||||
{
|
||||
_teamsRepository = teamsRepository ?? throw new ArgumentNullException(nameof(teamsRepository));
|
||||
_mapper = mapper ?? throw new ArgumentNullException(nameof(mapper));
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public async Task<ActionResult<IEnumerable<TeamDto>>> GetTeams([FromQuery] PaginationFilter filter)
|
||||
{
|
||||
if (filter.PageSize > maxTeamsPerPage)
|
||||
{
|
||||
filter.PageSize = maxTeamsPerPage;
|
||||
}
|
||||
|
||||
var (teamsEntities, pageinationMetadata) = await _teamsRepository.GetTeamsAsync(filter.PageNumber, filter.PageSize);
|
||||
|
||||
return Ok(new PagedResponse<IEnumerable<TeamDto>>(_mapper.Map<IEnumerable<TeamDto>>(teamsEntities), pageinationMetadata));
|
||||
}
|
||||
|
||||
[HttpGet("{id}")]
|
||||
public async Task<ActionResult<TeamDto>> GetTeam(int id)
|
||||
{
|
||||
var team = await _teamsRepository.GetTeamAsync(id);
|
||||
|
||||
if (team == null)
|
||||
{
|
||||
return NotFound();
|
||||
}
|
||||
|
||||
return Ok(new Response<TeamDto>(_mapper.Map<TeamDto>(team)));
|
||||
}
|
||||
}
|
||||
|
||||
91
teams/DbContexts/MlbGameDayContext.cs
Normal file
91
teams/DbContexts/MlbGameDayContext.cs
Normal file
@@ -0,0 +1,91 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata;
|
||||
using Teams.Entities;
|
||||
|
||||
namespace Teams.DbContexts
|
||||
{
|
||||
public partial class MlbGameDayContext : DbContext
|
||||
{
|
||||
public MlbGameDayContext()
|
||||
{
|
||||
}
|
||||
|
||||
public MlbGameDayContext(DbContextOptions<MlbGameDayContext> options)
|
||||
: base(options)
|
||||
{
|
||||
}
|
||||
|
||||
public virtual DbSet<Team> Teams { get; set; } = null!;
|
||||
|
||||
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
||||
{
|
||||
if (!optionsBuilder.IsConfigured)
|
||||
{
|
||||
#warning To protect potentially sensitive information in your connection string, you should move it out of source code. You can avoid scaffolding the connection string by using the Name= syntax to read it from configuration - see https://go.microsoft.com/fwlink/?linkid=2131148. For more guidance on storing connection strings, see http://go.microsoft.com/fwlink/?LinkId=723263.
|
||||
optionsBuilder.UseNpgsql("Host=localhost;Database=mlb-game-day;Username=postgres;Password=postgres");
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||
{
|
||||
modelBuilder.Entity<Team>(entity =>
|
||||
{
|
||||
entity.HasNoKey();
|
||||
|
||||
entity.ToTable("team");
|
||||
|
||||
entity.Property(e => e.Abbreviation).HasColumnName("abbreviation");
|
||||
|
||||
entity.Property(e => e.Active).HasColumnName("active");
|
||||
|
||||
entity.Property(e => e.AllStarStatus).HasColumnName("allStarStatus");
|
||||
|
||||
entity.Property(e => e.ClubName).HasColumnName("clubName");
|
||||
|
||||
entity.Property(e => e.DivisionId).HasColumnName("divisionId");
|
||||
|
||||
entity.Property(e => e.FileCode).HasColumnName("fileCode");
|
||||
|
||||
entity.Property(e => e.FirstYearOfPlay).HasColumnName("firstYearOfPlay");
|
||||
|
||||
entity.Property(e => e.FranchiseName).HasColumnName("franchiseName");
|
||||
|
||||
entity.Property(e => e.Id).HasColumnName("id");
|
||||
|
||||
entity.Property(e => e.LeagueId).HasColumnName("leagueId");
|
||||
|
||||
entity.Property(e => e.Link).HasColumnName("link");
|
||||
|
||||
entity.Property(e => e.LocationName).HasColumnName("locationName");
|
||||
|
||||
entity.Property(e => e.Name).HasColumnName("name");
|
||||
|
||||
entity.Property(e => e.Season).HasColumnName("season");
|
||||
|
||||
entity.Property(e => e.ShortName).HasColumnName("shortName");
|
||||
|
||||
entity.Property(e => e.SportId).HasColumnName("sportId");
|
||||
|
||||
entity.Property(e => e.SpringLeagueId).HasColumnName("springLeagueId");
|
||||
|
||||
entity.Property(e => e.SpringVenue).HasColumnName("springVenue");
|
||||
|
||||
entity.Property(e => e.SpringVenueId).HasColumnName("springVenueId");
|
||||
|
||||
entity.Property(e => e.TeamCode).HasColumnName("teamCode");
|
||||
|
||||
entity.Property(e => e.TeamName).HasColumnName("teamName");
|
||||
|
||||
entity.Property(e => e.Venue).HasColumnName("venue");
|
||||
|
||||
entity.Property(e => e.VenueId).HasColumnName("venueId");
|
||||
});
|
||||
|
||||
OnModelCreatingPartial(modelBuilder);
|
||||
}
|
||||
|
||||
partial void OnModelCreatingPartial(ModelBuilder modelBuilder);
|
||||
}
|
||||
}
|
||||
22
teams/Dockerfile
Normal file
22
teams/Dockerfile
Normal file
@@ -0,0 +1,22 @@
|
||||
#See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging.
|
||||
|
||||
FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS base
|
||||
WORKDIR /app
|
||||
EXPOSE 80
|
||||
EXPOSE 443
|
||||
|
||||
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
|
||||
WORKDIR /src
|
||||
COPY ["Teams.csproj", "."]
|
||||
RUN dotnet restore "./Teams.csproj"
|
||||
COPY . .
|
||||
WORKDIR "/src/."
|
||||
RUN dotnet build "Teams.csproj" -c Release -o /app/build
|
||||
|
||||
FROM build AS publish
|
||||
RUN dotnet publish "Teams.csproj" -c Release -o /app/publish /p:UseAppHost=false
|
||||
|
||||
FROM base AS final
|
||||
WORKDIR /app
|
||||
COPY --from=publish /app/publish .
|
||||
ENTRYPOINT ["dotnet", "Teams.dll"]
|
||||
32
teams/Entities/Team.cs
Normal file
32
teams/Entities/Team.cs
Normal file
@@ -0,0 +1,32 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Teams.Entities
|
||||
{
|
||||
public partial class Team
|
||||
{
|
||||
public int? SpringLeagueId { get; set; }
|
||||
public string? AllStarStatus { get; set; }
|
||||
public int? Id { get; set; }
|
||||
public string? Name { get; set; }
|
||||
public string? Link { get; set; }
|
||||
public int? Season { get; set; }
|
||||
public int? VenueId { get; set; }
|
||||
public int? SpringVenueId { get; set; }
|
||||
public string? TeamCode { get; set; }
|
||||
public string? FileCode { get; set; }
|
||||
public string? Abbreviation { get; set; }
|
||||
public string? TeamName { get; set; }
|
||||
public string? LocationName { get; set; }
|
||||
public int? FirstYearOfPlay { get; set; }
|
||||
public int? LeagueId { get; set; }
|
||||
public int? DivisionId { get; set; }
|
||||
public int? SportId { get; set; }
|
||||
public string? ShortName { get; set; }
|
||||
public string? FranchiseName { get; set; }
|
||||
public string? ClubName { get; set; }
|
||||
public string? Active { get; set; }
|
||||
public int? Venue { get; set; }
|
||||
public int? SpringVenue { get; set; }
|
||||
}
|
||||
}
|
||||
22
teams/Filter/PaginationFilter.cs
Normal file
22
teams/Filter/PaginationFilter.cs
Normal file
@@ -0,0 +1,22 @@
|
||||
using System;
|
||||
namespace Teams.Filter
|
||||
{
|
||||
public class PaginationFilter
|
||||
{
|
||||
public int PageNumber { get; set; }
|
||||
public int PageSize { get; set; }
|
||||
|
||||
public PaginationFilter()
|
||||
{
|
||||
this.PageNumber = 1;
|
||||
this.PageSize = 10;
|
||||
}
|
||||
|
||||
public PaginationFilter(int pageNumber, int pageSize)
|
||||
{
|
||||
this.PageNumber = pageNumber < 1 ? 1 : pageNumber;
|
||||
this.PageSize = pageSize > 10 ? 10 : pageSize;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
29
teams/Models/TeamDto.cs
Normal file
29
teams/Models/TeamDto.cs
Normal file
@@ -0,0 +1,29 @@
|
||||
using System;
|
||||
namespace Teams.Models
|
||||
{
|
||||
public class TeamDto
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string? Name { get; set; }
|
||||
public string? Abbreviation { get; set; }
|
||||
public string? Active { get; set; }
|
||||
public string? AllStarStatus { get; set; }
|
||||
public string? ClubName { get; set; }
|
||||
public int? DivisionId { get; set; }
|
||||
public string? FileCode { get; set; }
|
||||
public int? FirstYearOfPlay { get; set; }
|
||||
public string? FranchiseName { get; set; }
|
||||
public int? LeagueId { get; set; }
|
||||
public string? Link { get; set; }
|
||||
public string? LocationName { get; set; }
|
||||
public string? Season { get; set; }
|
||||
public string? ShortName { get; set; }
|
||||
public int? SpringLeagueId { get; set; }
|
||||
public int? SpringVenueId { get; set; }
|
||||
public int? SportId { get; set; }
|
||||
public string? TeamCode { get; set; }
|
||||
public string? TeamName { get; set; }
|
||||
public int? VenueId { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
14
teams/Profiles/TeamProfile.cs
Normal file
14
teams/Profiles/TeamProfile.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
using System;
|
||||
using AutoMapper;
|
||||
|
||||
namespace Teams.Profiles
|
||||
{
|
||||
public class TeamProfile : Profile
|
||||
{
|
||||
public TeamProfile()
|
||||
{
|
||||
CreateMap<Entities.Team, Models.TeamDto>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
56
teams/Program.cs
Normal file
56
teams/Program.cs
Normal file
@@ -0,0 +1,56 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Serilog;
|
||||
using Teams;
|
||||
using Teams.DbContexts;
|
||||
using Teams.Services;
|
||||
|
||||
Log.Logger = new LoggerConfiguration()
|
||||
.MinimumLevel.Debug()
|
||||
.WriteTo.Console()
|
||||
.WriteTo.File("logs/teams.txt", rollingInterval: RollingInterval.Day)
|
||||
.CreateLogger();
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
builder.Host.UseSerilog();
|
||||
|
||||
// Add services to the container.
|
||||
|
||||
builder.Services.AddControllers(options =>
|
||||
{
|
||||
options.ReturnHttpNotAcceptable = true;
|
||||
}).AddXmlDataContractSerializerFormatters();
|
||||
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
|
||||
builder.Services.AddEndpointsApiExplorer();
|
||||
builder.Services.AddSwaggerGen();
|
||||
|
||||
builder.Services.AddDbContext<MlbGameDayContext>(dbContextOptions =>
|
||||
dbContextOptions.UseNpgsql(builder.Configuration["ConnectionStrings:DBConnectionString"])
|
||||
);
|
||||
|
||||
builder.Services.AddScoped<ITeamsRepository, TeamsRepository>();
|
||||
|
||||
builder.Services.AddAutoMapper(AppDomain.CurrentDomain.GetAssemblies());
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
// Configure the HTTP request pipeline.
|
||||
if (app.Environment.IsDevelopment())
|
||||
{
|
||||
app.UseSwagger();
|
||||
app.UseSwaggerUI();
|
||||
}
|
||||
|
||||
app.UseHttpsRedirection();
|
||||
|
||||
app.UseRouting();
|
||||
|
||||
app.UseAuthorization();
|
||||
|
||||
app.UseEndpoints(endpoints =>
|
||||
{
|
||||
endpoints.MapControllers();
|
||||
});
|
||||
|
||||
app.Run();
|
||||
|
||||
30
teams/Properties/launchSettings.json
Normal file
30
teams/Properties/launchSettings.json
Normal file
@@ -0,0 +1,30 @@
|
||||
{
|
||||
"$schema": "https://json.schemastore.org/launchsettings.json",
|
||||
"iisSettings": {
|
||||
"windowsAuthentication": false,
|
||||
"anonymousAuthentication": true,
|
||||
"iisExpress": {
|
||||
"applicationUrl": "http://localhost:39374",
|
||||
"sslPort": 44327
|
||||
}
|
||||
},
|
||||
"profiles": {
|
||||
"Teams": {
|
||||
"commandName": "Project",
|
||||
"launchBrowser": true,
|
||||
"launchUrl": "swagger",
|
||||
"applicationUrl": "https://localhost:7520;http://localhost:5520",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
},
|
||||
"IIS Express": {
|
||||
"commandName": "IISExpress",
|
||||
"launchBrowser": true,
|
||||
"launchUrl": "swagger",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
12
teams/Services/ITeamsRepository.cs
Normal file
12
teams/Services/ITeamsRepository.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
using System;
|
||||
using Teams.Entities;
|
||||
|
||||
namespace Teams.Services
|
||||
{
|
||||
public interface ITeamsRepository
|
||||
{
|
||||
Task<Team?> GetTeamAsync(int teamId);
|
||||
Task<(IEnumerable<Team>, PaginationMetadata)> GetTeamsAsync(int pageNumber, int pageSize);
|
||||
}
|
||||
}
|
||||
|
||||
21
teams/Services/PaginationMetadata.cs
Normal file
21
teams/Services/PaginationMetadata.cs
Normal file
@@ -0,0 +1,21 @@
|
||||
using System;
|
||||
|
||||
namespace Teams.Services
|
||||
{
|
||||
public class PaginationMetadata
|
||||
{
|
||||
public int TotalItemCount { get; set; }
|
||||
public int TotalPageCount { get; set; }
|
||||
public int PageSize { get; set; }
|
||||
public int CurrentPage { get; set; }
|
||||
|
||||
public PaginationMetadata(int totalItemCount, int pageSize, int currentPage)
|
||||
{
|
||||
TotalItemCount = totalItemCount;
|
||||
PageSize = pageSize;
|
||||
CurrentPage = currentPage;
|
||||
TotalPageCount = (int)Math.Ceiling(totalItemCount / (double)pageSize);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
36
teams/Services/TeamsRepository.cs
Normal file
36
teams/Services/TeamsRepository.cs
Normal file
@@ -0,0 +1,36 @@
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Teams.DbContexts;
|
||||
using Teams.Entities;
|
||||
|
||||
namespace Teams.Services
|
||||
{
|
||||
public class TeamsRepository : ITeamsRepository
|
||||
{
|
||||
private readonly MlbGameDayContext _context;
|
||||
|
||||
public TeamsRepository(MlbGameDayContext context)
|
||||
{
|
||||
_context = context ?? throw new ArgumentNullException(nameof(context));
|
||||
}
|
||||
|
||||
public async Task<Team?> GetTeamAsync(int teamId)
|
||||
{
|
||||
return await _context.Teams.Where(t => t.Id == teamId).FirstOrDefaultAsync();
|
||||
}
|
||||
|
||||
public async Task<(IEnumerable<Team>, PaginationMetadata)> GetTeamsAsync(int pageNumber, int pageSize)
|
||||
{
|
||||
var collection = _context.Teams as IQueryable<Team>;
|
||||
var totalItemCount = await collection.CountAsync();
|
||||
var paginationMetadata = new PaginationMetadata(totalItemCount, pageSize, pageNumber);
|
||||
var collectionToReturn = await collection.OrderBy(t => t.Name)
|
||||
.Skip(pageSize * (pageNumber - 1))
|
||||
.Take(pageSize)
|
||||
.ToListAsync();
|
||||
|
||||
return (collectionToReturn, paginationMetadata);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
50
teams/Teams.csproj
Normal file
50
teams/Teams.csproj
Normal file
@@ -0,0 +1,50 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<DockerComposeProjectPath>docker-compose.dcproj</DockerComposeProjectPath>
|
||||
<UserSecretsId>d745850b-868c-4b57-ad7a-904de079cb65</UserSecretsId>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="6.0.12">
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="6.0.8" />
|
||||
<PackageReference Include="Serilog.AspNetCore" Version="6.1.0" />
|
||||
<PackageReference Include="Serilog.Sinks.Console" Version="4.1.0" />
|
||||
<PackageReference Include="Serilog.Sinks.File" Version="5.0.0" />
|
||||
<PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="12.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Remove="Entities\" />
|
||||
<None Remove="Models\" />
|
||||
<None Remove="DbContexts\" />
|
||||
<None Remove="Filter\" />
|
||||
<None Remove="Profiles\" />
|
||||
<None Remove="Services\" />
|
||||
<None Remove="Wrappers\" />
|
||||
<None Remove="Microsoft.EntityFrameworkCore" />
|
||||
<None Remove="Microsoft.EntityFrameworkCore.Tools" />
|
||||
<None Remove="Npgsql.EntityFrameworkCore.PostgreSQL" />
|
||||
<None Remove="Serilog.AspNetCore" />
|
||||
<None Remove="Serilog.Sinks.Console" />
|
||||
<None Remove="Serilog.Sinks.File" />
|
||||
<None Remove="AutoMapper.Extensions.Microsoft.DependencyInjection" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Folder Include="Entities\" />
|
||||
<Folder Include="Models\" />
|
||||
<Folder Include="DbContexts\" />
|
||||
<Folder Include="Entities\" />
|
||||
<Folder Include="Filter\" />
|
||||
<Folder Include="Profiles\" />
|
||||
<Folder Include="Services\" />
|
||||
<Folder Include="Wrappers\" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
31
teams/Teams.sln
Normal file
31
teams/Teams.sln
Normal file
@@ -0,0 +1,31 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 16
|
||||
VisualStudioVersion = 25.0.1704.2
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Teams", "Teams.csproj", "{CA6D3C8A-50A5-460F-A2AB-BC57088322B3}"
|
||||
EndProject
|
||||
Project("{E53339B2-1760-4266-BCC7-CA923CBCF16C}") = "docker-compose", "docker-compose.dcproj", "{A089F086-FA22-494F-8322-0B275120213E}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{CA6D3C8A-50A5-460F-A2AB-BC57088322B3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{CA6D3C8A-50A5-460F-A2AB-BC57088322B3}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{CA6D3C8A-50A5-460F-A2AB-BC57088322B3}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{CA6D3C8A-50A5-460F-A2AB-BC57088322B3}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{A089F086-FA22-494F-8322-0B275120213E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{A089F086-FA22-494F-8322-0B275120213E}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{A089F086-FA22-494F-8322-0B275120213E}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{A089F086-FA22-494F-8322-0B275120213E}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {3FE7224D-E56C-4230-88AF-AA2D1A7D4C17}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
27
teams/Wrappers/PagedResponse.cs
Normal file
27
teams/Wrappers/PagedResponse.cs
Normal file
@@ -0,0 +1,27 @@
|
||||
using System;
|
||||
using Teams.Services;
|
||||
|
||||
namespace Teams.Wrappers
|
||||
{
|
||||
public class PagedResponse<T>: Response<T>
|
||||
{
|
||||
public int TotalItemCount { get; set; }
|
||||
public int TotalPageCount { get; set; }
|
||||
public int PageSize { get; set; }
|
||||
public int CurrentPage { get; set; }
|
||||
|
||||
public PagedResponse(T results, PaginationMetadata paginationMetadata)
|
||||
{
|
||||
this.TotalItemCount = paginationMetadata.TotalItemCount;
|
||||
this.TotalPageCount = paginationMetadata.TotalPageCount;
|
||||
this.CurrentPage = paginationMetadata.CurrentPage;
|
||||
this.PageSize = paginationMetadata.PageSize;
|
||||
this.CurrentPage = paginationMetadata.CurrentPage;
|
||||
this.Results = results;
|
||||
this.Message = null;
|
||||
this.Succeeded = true;
|
||||
this.Errors = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
24
teams/Wrappers/Response.cs
Normal file
24
teams/Wrappers/Response.cs
Normal file
@@ -0,0 +1,24 @@
|
||||
using System;
|
||||
namespace Teams.Wrappers
|
||||
{
|
||||
public class Response<T>
|
||||
{
|
||||
public T Results { get; set; }
|
||||
public bool Succeeded { get; set; }
|
||||
public string[] Errors { get; set; }
|
||||
public string Message { get; set; }
|
||||
|
||||
public Response()
|
||||
{
|
||||
}
|
||||
|
||||
public Response(T results)
|
||||
{
|
||||
Succeeded = true;
|
||||
Message = string.Empty;
|
||||
Errors = null;
|
||||
Results = results;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
13
teams/appsettings.Development.json
Normal file
13
teams/appsettings.Development.json
Normal file
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
},
|
||||
"AllowedHosts": "*",
|
||||
"ConnectionStrings": {
|
||||
"DBConnectionString": "Host=localhost;Database=mlb-game-day;Username=postgres;Password=postgres"
|
||||
}
|
||||
}
|
||||
|
||||
10
teams/appsettings.json
Normal file
10
teams/appsettings.json
Normal file
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
},
|
||||
"AllowedHosts": "*"
|
||||
}
|
||||
|
||||
18
teams/docker-compose.dcproj
Normal file
18
teams/docker-compose.dcproj
Normal file
@@ -0,0 +1,18 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="15.0" Sdk="Microsoft.Docker.Sdk" DefaultTargets="Build">
|
||||
<PropertyGroup Label="Globals">
|
||||
<ProjectVersion>2.1</ProjectVersion>
|
||||
<DockerTargetOS>Linux</DockerTargetOS>
|
||||
<ProjectGuid>{A089F086-FA22-494F-8322-0B275120213E}</ProjectGuid>
|
||||
<DockerLaunchBrowser>True</DockerLaunchBrowser>
|
||||
<DockerServiceUrl>{Scheme}://localhost:{ServicePort}/swagger</DockerServiceUrl>
|
||||
<DockerServiceName>teams</DockerServiceName>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<None Include="docker-compose.override.yml">
|
||||
<DependentUpon>docker-compose.yml</DependentUpon>
|
||||
</None>
|
||||
<None Include="docker-compose.yml" />
|
||||
<None Include=".dockerignore" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
13
teams/docker-compose.override.yml
Normal file
13
teams/docker-compose.override.yml
Normal file
@@ -0,0 +1,13 @@
|
||||
version: '3.4'
|
||||
|
||||
services:
|
||||
teams:
|
||||
environment:
|
||||
- ASPNETCORE_ENVIRONMENT=Development
|
||||
- ASPNETCORE_URLS=https://+:443;http://+:80
|
||||
ports:
|
||||
- "80"
|
||||
- "443"
|
||||
volumes:
|
||||
- ~/.aspnet/https:/root/.aspnet/https:ro
|
||||
- ~/.microsoft/usersecrets:/root/.microsoft/usersecrets:ro
|
||||
8
teams/docker-compose.yml
Normal file
8
teams/docker-compose.yml
Normal file
@@ -0,0 +1,8 @@
|
||||
version: '3.4'
|
||||
|
||||
services:
|
||||
teams:
|
||||
image: ${DOCKER_REGISTRY-}teams
|
||||
build:
|
||||
context: .
|
||||
dockerfile: ./Dockerfile
|
||||
Reference in New Issue
Block a user