diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..1ff0c42 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,63 @@ +############################################################################### +# Set default behavior to automatically normalize line endings. +############################################################################### +* text=auto + +############################################################################### +# Set default behavior for command prompt diff. +# +# This is need for earlier builds of msysgit that does not have it on by +# default for csharp files. +# Note: This is only used by command line +############################################################################### +#*.cs diff=csharp + +############################################################################### +# Set the merge driver for project and solution files +# +# Merging from the command prompt will add diff markers to the files if there +# are conflicts (Merging from VS is not affected by the settings below, in VS +# the diff markers are never inserted). Diff markers may cause the following +# file extensions to fail to load in VS. An alternative would be to treat +# these files as binary and thus will always conflict and require user +# intervention with every merge. To do so, just uncomment the entries below +############################################################################### +#*.sln merge=binary +#*.csproj merge=binary +#*.vbproj merge=binary +#*.vcxproj merge=binary +#*.vcproj merge=binary +#*.dbproj merge=binary +#*.fsproj merge=binary +#*.lsproj merge=binary +#*.wixproj merge=binary +#*.modelproj merge=binary +#*.sqlproj merge=binary +#*.wwaproj merge=binary + +############################################################################### +# behavior for image files +# +# image files are treated as binary by default. +############################################################################### +#*.jpg binary +#*.png binary +#*.gif binary + +############################################################################### +# diff behavior for common document formats +# +# Convert binary document formats to text before diffing them. This feature +# is only available from the command line. Turn it on by uncommenting the +# entries below. +############################################################################### +#*.doc diff=astextplain +#*.DOC diff=astextplain +#*.docx diff=astextplain +#*.DOCX diff=astextplain +#*.dot diff=astextplain +#*.DOT diff=astextplain +#*.pdf diff=astextplain +#*.PDF diff=astextplain +#*.rtf diff=astextplain +#*.RTF diff=astextplain diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9491a2f --- /dev/null +++ b/.gitignore @@ -0,0 +1,363 @@ +## 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 \ No newline at end of file diff --git a/ASP.NET WEB API Exam.pdf b/ASP.NET WEB API Exam.pdf new file mode 100644 index 0000000..f7c9269 Binary files /dev/null and b/ASP.NET WEB API Exam.pdf differ diff --git a/Contracts/Contracts.csproj b/Contracts/Contracts.csproj new file mode 100644 index 0000000..8abcd77 --- /dev/null +++ b/Contracts/Contracts.csproj @@ -0,0 +1,13 @@ + + + + net8.0 + enable + enable + + + + + + + diff --git a/Contracts/RequestModels/BookTicketsRequest.cs b/Contracts/RequestModels/BookTicketsRequest.cs new file mode 100644 index 0000000..926c460 --- /dev/null +++ b/Contracts/RequestModels/BookTicketsRequest.cs @@ -0,0 +1,17 @@ +using Contracts.ResponseModels; +using MediatR; + +namespace Contracts.RequestModels +{ + public class BookTicketsRequest : IRequest + { + public List BookTicketRequestDatas { get; set; } = new List(); + } + + public class BookTicketRequestDataModel + { + public string TicketCode { get; set; } = string.Empty; + + public int Quantity { get; set; } = 0; + } +} diff --git a/Contracts/RequestModels/DeleteTicketsRequest.cs b/Contracts/RequestModels/DeleteTicketsRequest.cs new file mode 100644 index 0000000..904651d --- /dev/null +++ b/Contracts/RequestModels/DeleteTicketsRequest.cs @@ -0,0 +1,14 @@ +using Contracts.ResponseModels; +using MediatR; + +namespace Contracts.RequestModels +{ + public class DeleteTicketsRequest : IRequest + { + public Guid BookedTickedId { get; set; } = Guid.NewGuid(); + + public string TicketCode { get; set; } = string.Empty; + + public int Quantity { get; set; } = 0; + } +} diff --git a/Contracts/RequestModels/GetAvailableTicketsRequest.cs b/Contracts/RequestModels/GetAvailableTicketsRequest.cs new file mode 100644 index 0000000..7ceb24e --- /dev/null +++ b/Contracts/RequestModels/GetAvailableTicketsRequest.cs @@ -0,0 +1,26 @@ +using Contracts.ResponseModels; +using MediatR; + +namespace Contracts.RequestModels +{ + public class GetAvailableTicketsRequest : IRequest + { + public string CategoryName { get; set; } = string.Empty; + + public string TicketCode { get; set; } = string.Empty; + + public string TicketName { get; set;} = string.Empty; + + public decimal Price { get; set; } = decimal.Zero; + + public DateTimeOffset? MinEventDate { get; set; } + + public DateTimeOffset? MaxEventDate { get; set; } + + // order by "semua kolom dari yang ditampilkan di result." + public string OrderBy { get; set; } = string.Empty; + + // "kolom penentu untuk data akan diurutkan secara ascending atau descending." + public string OrderState { get; set; } = string.Empty; + } +} diff --git a/Contracts/RequestModels/GetBookingDetailRequest.cs b/Contracts/RequestModels/GetBookingDetailRequest.cs new file mode 100644 index 0000000..6bdc4f4 --- /dev/null +++ b/Contracts/RequestModels/GetBookingDetailRequest.cs @@ -0,0 +1,10 @@ +using Contracts.ResponseModels; +using MediatR; + +namespace Contracts.RequestModels +{ + public class GetBookingDetailRequest : IRequest + { + public Guid BookedTicketId { get; set; } = Guid.NewGuid(); + } +} diff --git a/Contracts/RequestModels/UpdateBookingRequest.cs b/Contracts/RequestModels/UpdateBookingRequest.cs new file mode 100644 index 0000000..bedbd4d --- /dev/null +++ b/Contracts/RequestModels/UpdateBookingRequest.cs @@ -0,0 +1,22 @@ +using Contracts.ResponseModels; +using MediatR; + +namespace Contracts.RequestModels +{ + public class UpdateBookingRequest : UpdateBookingRequestDataListModel, IRequest + { + public Guid BookedTicketId { get; set; } = Guid.NewGuid(); + } + + public class UpdateBookingRequestDataListModel + { + public List Tickets { get; set; } = new List(); + } + + public class UpdateBookingRequestDataModel + { + public string TicketCode { get; set; } = string.Empty; + + public int Quantity { get; set; } = 0; + } +} diff --git a/Contracts/ResponseModels/BookTicketsResponse.cs b/Contracts/ResponseModels/BookTicketsResponse.cs new file mode 100644 index 0000000..3be7cd5 --- /dev/null +++ b/Contracts/ResponseModels/BookTicketsResponse.cs @@ -0,0 +1,27 @@ +namespace Contracts.ResponseModels +{ + public class BookTicketsResponse + { + public decimal PriceSummary { get; set; } = decimal.Zero; + + public List TicketPerCategories { get; set; } = new List(); + } + + public class BookCategoryResponseDataModel + { + public string CategoryName { get; set; } = string.Empty; + + public decimal SummaryPrice { get; set; } = decimal.Zero; + + public List Tickets { get; set; } = new List(); + } + + public class BookTicketResponseDataModel + { + public string TicketCode { get; set; } = string.Empty; + + public string TicketName { get; set; } = string.Empty; + + public decimal Price { get; set; } = decimal.Zero; + } +} diff --git a/Contracts/ResponseModels/DeleteTicketsResponse.cs b/Contracts/ResponseModels/DeleteTicketsResponse.cs new file mode 100644 index 0000000..7b87ca1 --- /dev/null +++ b/Contracts/ResponseModels/DeleteTicketsResponse.cs @@ -0,0 +1,18 @@ +namespace Contracts.ResponseModels +{ + public class DeleteTicketsResponse + { + public List Tickets { get; set; } = new List(); + } + + public class DeleteTicketResponseDataModel + { + public string TicketCode { get; set; } = string.Empty; + + public string TicketName { get; set; } = string.Empty; + + public int Quantity { get; set; } = 0; + + public string CategoryName { get; set; } = string.Empty; + } +} diff --git a/Contracts/ResponseModels/GetAvailableTicketsResponse.cs b/Contracts/ResponseModels/GetAvailableTicketsResponse.cs new file mode 100644 index 0000000..e15839a --- /dev/null +++ b/Contracts/ResponseModels/GetAvailableTicketsResponse.cs @@ -0,0 +1,22 @@ +namespace Contracts.ResponseModels +{ + public class GetAvailableTicketsResponse + { + public List AvailableTicketDatas { get; set; } = new List(); + } + + public class AvailableTicketData + { + public DateTimeOffset EventDate { get; set; } = DateTimeOffset.UtcNow; + + public int Quota { get; set; } = 1; + + public string TicketCode { get; set; } = string.Empty; + + public string TicketName { get; set; } = string.Empty; + + public string CategoryName { get; set; } = string.Empty; + + public decimal Price { get; set; } = decimal.Zero; + } +} diff --git a/Contracts/ResponseModels/GetBookingDetailResponse.cs b/Contracts/ResponseModels/GetBookingDetailResponse.cs new file mode 100644 index 0000000..6e635b3 --- /dev/null +++ b/Contracts/ResponseModels/GetBookingDetailResponse.cs @@ -0,0 +1,23 @@ +namespace Contracts.ResponseModels +{ + public class GetBookingDetailResponse + { + public List DataList { get; set; } = new List(); + } + + public class GetBookingDetailDataListModel + { + public int QtyPerCategory { get; set; } = 0; + public string CategoryName { get; set; } = string.Empty; + public List Tickets { get; set; } = new List(); + } + + public class GetBookingDetailDataModel + { + public string TicketCode { get; set; } = string.Empty; + + public string TicketName { get; set; } = string.Empty; + + public DateTimeOffset? EventDate { get; set; } + } +} diff --git a/Contracts/ResponseModels/UpdateBookingResponse.cs b/Contracts/ResponseModels/UpdateBookingResponse.cs new file mode 100644 index 0000000..e7d983c --- /dev/null +++ b/Contracts/ResponseModels/UpdateBookingResponse.cs @@ -0,0 +1,18 @@ +namespace Contracts.ResponseModels +{ + public class UpdateBookingResponse + { + public List Tickets { get; set; } = new List(); + } + + public class UpdateBookingResponseDataModel + { + public string TicketCode { get; set; } = string.Empty; + + public string TicketName { get; set; } = string.Empty; + + public int Quantity { get; set; } = 0; + + public string CategoryName { get; set; } = string.Empty; + } +} \ No newline at end of file diff --git a/Entity/Database/exam.db b/Entity/Database/exam.db new file mode 100644 index 0000000..fd93d01 Binary files /dev/null and b/Entity/Database/exam.db differ diff --git a/Entity/Database/exam.db-shm b/Entity/Database/exam.db-shm new file mode 100644 index 0000000..fe9ac28 Binary files /dev/null and b/Entity/Database/exam.db-shm differ diff --git a/Entity/Database/exam.db-wal b/Entity/Database/exam.db-wal new file mode 100644 index 0000000..e69de29 diff --git a/Entity/Entity.csproj b/Entity/Entity.csproj new file mode 100644 index 0000000..f461364 --- /dev/null +++ b/Entity/Entity.csproj @@ -0,0 +1,17 @@ + + + + net8.0 + enable + enable + + + + + + + + + + + diff --git a/Entity/Entity/BookedTicket.cs b/Entity/Entity/BookedTicket.cs new file mode 100644 index 0000000..0dfa8f4 --- /dev/null +++ b/Entity/Entity/BookedTicket.cs @@ -0,0 +1,16 @@ +using System.ComponentModel.DataAnnotations; + +namespace Entity.Entity +{ + public class BookedTicket + { + [Key] + public Guid BookedTicketId { get; set; } = Guid.NewGuid(); + + //public List Tickets { get; set; } = new List(); + + //public ICollection? TicketBookedTicketMappings { get; set; } + + public List TicketBookedTicketMappings { get; set; } = new List(); + } +} diff --git a/Entity/Entity/Category.cs b/Entity/Entity/Category.cs new file mode 100644 index 0000000..fd664da --- /dev/null +++ b/Entity/Entity/Category.cs @@ -0,0 +1,16 @@ +using System.ComponentModel.DataAnnotations; + +namespace Entity.Entity +{ + public class Category + { + [Key] + public string CategoryId { get; set; } = string.Empty; + + [Required] + [StringLength(255)] + public string CategoryName { get; set; } = string.Empty; + + public List Tickets { get; set; } = new List(); + } +} diff --git a/Entity/Entity/DBContext.cs b/Entity/Entity/DBContext.cs new file mode 100644 index 0000000..b6cb270 --- /dev/null +++ b/Entity/Entity/DBContext.cs @@ -0,0 +1,16 @@ +using Microsoft.EntityFrameworkCore; + +namespace Entity.Entity +{ + public class DBContext : DbContext + { + public DBContext(DbContextOptions dbContextOptions) : base (dbContextOptions) + { + } + + public DbSet Tickets => Set(); + public DbSet Categories => Set(); + public DbSet BookedTickets => Set(); + public DbSet TicketBookedTicketMappings => Set(); + } +} diff --git a/Entity/Entity/Ticket.cs b/Entity/Entity/Ticket.cs new file mode 100644 index 0000000..d6681ca --- /dev/null +++ b/Entity/Entity/Ticket.cs @@ -0,0 +1,36 @@ +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; + +namespace Entity.Entity +{ + public class Ticket + { + [Key] + [StringLength(255)] + public string TicketCode { get; set; } = string.Empty; + + [Required] + [StringLength(255)] + public string TicketName { get; set; } = string.Empty; + + [Required] + public decimal Price { get; set; } = decimal.Zero; + + [Required] + public int Quota { get; set; } = 0; + + [Required] + public DateTimeOffset EventDate { get; set; } = DateTimeOffset.UtcNow; + + public string CategoryId { get; set; } = string.Empty; + + [ForeignKey("CategoryId")] + public Category? Category { get; set; } + + //public List BookedTickets { get; set; } = new List(); + + //public ICollection? TicketBookedTicketMappings { get; set; } + + public List TicketBookedTicketMappings { get; set; } = new List(); + } +} diff --git a/Entity/Entity/TicketBookedTicketMapping.cs b/Entity/Entity/TicketBookedTicketMapping.cs new file mode 100644 index 0000000..b50daf2 --- /dev/null +++ b/Entity/Entity/TicketBookedTicketMapping.cs @@ -0,0 +1,23 @@ +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; + +namespace Entity.Entity +{ + public class TicketBookedTicketMapping + { + [Key] + public Guid MappingId { get; set; } = Guid.NewGuid(); + + public Guid BookedTicketId { get; set; } = Guid.NewGuid(); + + public string TicketCode { get; set; } = string.Empty; + + public int TicketQuantity { get; set; } = 0; + + [ForeignKey("BookedTicketId")] + public BookedTicket? BookedTicket { get; set; } + + [ForeignKey("TicketCode")] + public Ticket? Ticket { get; set; } + } +} diff --git a/ExamNETWebAPI.sln b/ExamNETWebAPI.sln new file mode 100644 index 0000000..3a123a5 --- /dev/null +++ b/ExamNETWebAPI.sln @@ -0,0 +1,43 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.9.34622.214 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ExamNETWebAPI", "ExamNETWebAPI\ExamNETWebAPI.csproj", "{83463038-2B9C-49B0-A100-CA1D1EF39E5E}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Entity", "Entity\Entity.csproj", "{9D005E85-7508-4956-B049-63D043E605B5}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Services", "Services\Services.csproj", "{F1D6FF73-9EA1-495C-82E2-0618529443D4}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Contracts", "Contracts\Contracts.csproj", "{6EFF5204-BF8F-441E-92EC-94E8B5E238D7}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {83463038-2B9C-49B0-A100-CA1D1EF39E5E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {83463038-2B9C-49B0-A100-CA1D1EF39E5E}.Debug|Any CPU.Build.0 = Debug|Any CPU + {83463038-2B9C-49B0-A100-CA1D1EF39E5E}.Release|Any CPU.ActiveCfg = Release|Any CPU + {83463038-2B9C-49B0-A100-CA1D1EF39E5E}.Release|Any CPU.Build.0 = Release|Any CPU + {9D005E85-7508-4956-B049-63D043E605B5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {9D005E85-7508-4956-B049-63D043E605B5}.Debug|Any CPU.Build.0 = Debug|Any CPU + {9D005E85-7508-4956-B049-63D043E605B5}.Release|Any CPU.ActiveCfg = Release|Any CPU + {9D005E85-7508-4956-B049-63D043E605B5}.Release|Any CPU.Build.0 = Release|Any CPU + {F1D6FF73-9EA1-495C-82E2-0618529443D4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {F1D6FF73-9EA1-495C-82E2-0618529443D4}.Debug|Any CPU.Build.0 = Debug|Any CPU + {F1D6FF73-9EA1-495C-82E2-0618529443D4}.Release|Any CPU.ActiveCfg = Release|Any CPU + {F1D6FF73-9EA1-495C-82E2-0618529443D4}.Release|Any CPU.Build.0 = Release|Any CPU + {6EFF5204-BF8F-441E-92EC-94E8B5E238D7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {6EFF5204-BF8F-441E-92EC-94E8B5E238D7}.Debug|Any CPU.Build.0 = Debug|Any CPU + {6EFF5204-BF8F-441E-92EC-94E8B5E238D7}.Release|Any CPU.ActiveCfg = Release|Any CPU + {6EFF5204-BF8F-441E-92EC-94E8B5E238D7}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {0955F8C2-7D27-4035-870E-E0CD5DD2BB7B} + EndGlobalSection +EndGlobal diff --git a/ExamNETWebAPI/Controllers/BookingController.cs b/ExamNETWebAPI/Controllers/BookingController.cs new file mode 100644 index 0000000..da65903 --- /dev/null +++ b/ExamNETWebAPI/Controllers/BookingController.cs @@ -0,0 +1,79 @@ +using Contracts.RequestModels; +using Contracts.ResponseModels; +using MediatR; +using Microsoft.AspNetCore.Mvc; + +// For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860 + +namespace ExamNETWebAPI.Controllers +{ + [Route("api/v1/")] + [ApiController] + public class BookingController : ControllerBase + { + private readonly IMediator _mediator; + + public BookingController(IMediator mediator) + { + _mediator = mediator; + } + + [HttpGet("get-available-ticket")] //TODO ganti route Booking GET + public async Task> Get([FromQuery] GetAvailableTicketsRequest request, CancellationToken cancellationToken) + { + var response = await _mediator.Send(request, cancellationToken); + + return Ok(response); + } + + [HttpGet("get-booked-ticket/{id}")] + public async Task> Get(Guid id, CancellationToken cancellationToken) + { + var request = new GetBookingDetailRequest + { + BookedTicketId = id + }; + + var response = await _mediator.Send(request, cancellationToken); + + return Ok(response); + } + + [HttpPost("book-ticket")] + public async Task> Post([FromBody] BookTicketsRequest request, CancellationToken cancellationToken) + { + var response = await _mediator.Send(request, cancellationToken); + + return Ok(response); + } + + [HttpPut("edit-booked-ticket/{id}")] + public async Task> Put(Guid id, [FromBody] UpdateBookingRequestDataListModel model, CancellationToken cancellationToken) + { + var request = new UpdateBookingRequest + { + BookedTicketId = id, + Tickets = model.Tickets, + }; + + var response = await _mediator.Send(request, cancellationToken); + + return Ok(response); + } + + [HttpDelete("revoke-ticket/{id}/{ticketCode}/{qty}")] + public async Task> Delete(Guid id, string ticketCode, int qty, CancellationToken cancellationToken) + { + var request = new DeleteTicketsRequest + { + BookedTickedId = id, + TicketCode = ticketCode, + Quantity = qty, + }; + + var response = await _mediator.Send(request, cancellationToken); + + return Ok(response); + } + } +} diff --git a/ExamNETWebAPI/ExamNETWebAPI.csproj b/ExamNETWebAPI/ExamNETWebAPI.csproj new file mode 100644 index 0000000..d5f32db --- /dev/null +++ b/ExamNETWebAPI/ExamNETWebAPI.csproj @@ -0,0 +1,18 @@ + + + + net8.0 + enable + enable + + + + + + + + + + + + diff --git a/ExamNETWebAPI/ExamNETWebAPI.http b/ExamNETWebAPI/ExamNETWebAPI.http new file mode 100644 index 0000000..697494a --- /dev/null +++ b/ExamNETWebAPI/ExamNETWebAPI.http @@ -0,0 +1,7 @@ +@ExamNETWebAPI_HostAddress = http://localhost:5255 + +GET {{ExamNETWebAPI_HostAddress}}/weatherforecast/ +Accept: application/json + +### + diff --git a/ExamNETWebAPI/Program.cs b/ExamNETWebAPI/Program.cs new file mode 100644 index 0000000..491c0c6 --- /dev/null +++ b/ExamNETWebAPI/Program.cs @@ -0,0 +1,44 @@ +using Entity.Entity; +using MediatR; +using Microsoft.EntityFrameworkCore; +using Services.RequestHandlers; + +var builder = WebApplication.CreateBuilder(args); +var configuration = builder.Configuration; + +// Add services to the container. + +builder.Services.AddControllers(); +// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle +builder.Services.AddEndpointsApiExplorer(); +builder.Services.AddSwaggerGen(); + +builder.Services.AddDbContextPool(dbContextBuilder => +{ + dbContextBuilder.UseSqlite(configuration.GetConnectionString("Sqlite")); +}); + +builder.Services.AddMediatR(typeof(GetAvailableTicketsHandler)); + +var app = builder.Build(); + +// Configure the HTTP request pipeline. +if (app.Environment.IsDevelopment()) +{ + app.UseSwagger(); + app.UseSwaggerUI(); + + using var scope = app.Services.CreateScope(); + var db = scope.ServiceProvider.GetRequiredService(); + db.Database.EnsureCreated(); +} + +app.UseAuthorization(); + +app.MapControllers(); + +app.Run(); + +public partial class Program +{ +} diff --git a/ExamNETWebAPI/Properties/launchSettings.json b/ExamNETWebAPI/Properties/launchSettings.json new file mode 100644 index 0000000..cc7eba4 --- /dev/null +++ b/ExamNETWebAPI/Properties/launchSettings.json @@ -0,0 +1,31 @@ +{ + "profiles": { + "http": { + "commandName": "Project", + "launchBrowser": true, + "launchUrl": "swagger", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + }, + "dotnetRunMessages": true, + "applicationUrl": "http://localhost:5255" + }, + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "launchUrl": "swagger", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + } + }, + "$schema": "http://json.schemastore.org/launchsettings.json", + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:62898", + "sslPort": 0 + } + } +} \ No newline at end of file diff --git a/ExamNETWebAPI/appsettings.Development.json b/ExamNETWebAPI/appsettings.Development.json new file mode 100644 index 0000000..0c208ae --- /dev/null +++ b/ExamNETWebAPI/appsettings.Development.json @@ -0,0 +1,8 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + } +} diff --git a/ExamNETWebAPI/appsettings.json b/ExamNETWebAPI/appsettings.json new file mode 100644 index 0000000..0687221 --- /dev/null +++ b/ExamNETWebAPI/appsettings.json @@ -0,0 +1,12 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + }, + "AllowedHosts": "*", + "ConnectionStrings": { + "Sqlite": "Data Source=../Entity/Database/exam.db" + } +} \ No newline at end of file diff --git a/Services/RequestHandlers/BookTicketsHandler.cs b/Services/RequestHandlers/BookTicketsHandler.cs new file mode 100644 index 0000000..d1b712a --- /dev/null +++ b/Services/RequestHandlers/BookTicketsHandler.cs @@ -0,0 +1,109 @@ +using Contracts.RequestModels; +using Contracts.ResponseModels; +using Entity.Entity; +using MediatR; +using Microsoft.EntityFrameworkCore; + +namespace Services.RequestHandlers +{ + public class BookTicketsHandler : IRequestHandler + { + private readonly DBContext _db; + + public BookTicketsHandler(DBContext db) + { + _db = db; + } + + public async Task Handle(BookTicketsRequest request, CancellationToken cancellationToken) + { + var bookedTicket = new BookedTicket + { + BookedTicketId = Guid.NewGuid(), + }; + + var list = new List(); + + foreach (var data in request.BookTicketRequestDatas) + { + var temp = new TicketBookedTicketMapping() + { + MappingId = Guid.NewGuid(), + BookedTicketId = bookedTicket.BookedTicketId, + TicketCode = data.TicketCode, + TicketQuantity = data.Quantity, + }; + + list.Add(temp); + } + + _db.TicketBookedTicketMappings.AddRange(list); + _db.BookedTickets.Add(bookedTicket); + await _db.SaveChangesAsync(cancellationToken); + + //TODO update quota + + var datas = await (from m in _db.TicketBookedTicketMappings + join t in _db.Tickets on m.TicketCode equals t.TicketCode + join c in _db.Categories on t.CategoryId equals c.CategoryId + where m.BookedTicketId == bookedTicket.BookedTicketId + select new BookTicketsHandlerHelperModel + { + TicketCode = t.TicketCode, + TicketName = t.TicketName, + Price = t.Price, + Quantity = m.TicketQuantity, + CategoryName = c.CategoryName + }).AsNoTracking().ToListAsync(); + + var categories = await _db.Categories.Select(Q => Q.CategoryName).AsNoTracking().ToListAsync(); + + var response = new BookTicketsResponse(); + + foreach (var category in categories) + { + var ticketListPerCategory = new BookCategoryResponseDataModel + { + CategoryName = category, + }; + + foreach (var data in datas) + { + if (data.CategoryName == category) + { + var ticketData = new BookTicketResponseDataModel + { + TicketCode = data.TicketCode, + TicketName = data.TicketName, + Price = data.Price, + }; + ticketListPerCategory.SummaryPrice += data.Price * data.Quantity; + ticketListPerCategory.Tickets.Add(ticketData); + } + } + + response.PriceSummary += ticketListPerCategory.SummaryPrice; + + if (ticketListPerCategory.Tickets.Count > 0) + { + response.TicketPerCategories.Add(ticketListPerCategory); + } + } + + return response; + } + + public class BookTicketsHandlerHelperModel //TODO Pindahin, ato bikin anonymus kalo aman + { + public string TicketCode { get; set; } = string.Empty; + + public string TicketName { get; set; } = string.Empty; + + public decimal Price { get; set; } = decimal.Zero; + + public int Quantity { get; set; } = 0; + + public string CategoryName { get; set; } = string.Empty; + } + } +} diff --git a/Services/RequestHandlers/DeleteTicketHandler.cs b/Services/RequestHandlers/DeleteTicketHandler.cs new file mode 100644 index 0000000..fec30e5 --- /dev/null +++ b/Services/RequestHandlers/DeleteTicketHandler.cs @@ -0,0 +1,66 @@ +using Contracts.RequestModels; +using Contracts.ResponseModels; +using Entity.Entity; +using MediatR; +using Microsoft.EntityFrameworkCore; + +namespace Services.RequestHandlers +{ + public class DeleteTicketHandler : IRequestHandler + { + private readonly DBContext _db; + + public DeleteTicketHandler(DBContext db) + { + _db = db; + } + + public async Task Handle(DeleteTicketsRequest request, CancellationToken cancellationToken) + { + var targetData = await (from m in _db.TicketBookedTicketMappings + join t in _db.Tickets on m.TicketCode equals t.TicketCode + join c in _db.Categories on t.CategoryId equals c.CategoryId + where m.BookedTicketId == request.BookedTickedId + && m.TicketCode == request.TicketCode + select m).FirstOrDefaultAsync(cancellationToken); + + targetData.TicketQuantity -= request.Quantity; + + if (targetData.TicketQuantity <= 0) + { + _db.TicketBookedTicketMappings.Remove(targetData); + } + + await _db.SaveChangesAsync(cancellationToken); + + var datas = await (from m in _db.TicketBookedTicketMappings + join t in _db.Tickets on m.TicketCode equals t.TicketCode + join c in _db.Categories on t.CategoryId equals c.CategoryId + where m.BookedTicketId == request.BookedTickedId + select new DeleteTicketResponseDataModel + { + TicketCode = t.TicketCode, + TicketName = t.TicketName, + Quantity = m.TicketQuantity, + CategoryName = c.CategoryName + }).ToListAsync(cancellationToken); //TODO no tracking? + + var response = new DeleteTicketsResponse(); + + if (datas == null) + { + var bookedTicketRow = await _db.BookedTickets.Where(Q => Q.BookedTicketId == request.BookedTickedId).Select(Q => Q).FirstOrDefaultAsync(cancellationToken); + + _db.BookedTickets.Remove(bookedTicketRow); //TODO BookedTicket belum ke remove + + await _db.SaveChangesAsync(cancellationToken); + } + else + { + response.Tickets = datas; + } + + return response; + } + } +} diff --git a/Services/RequestHandlers/GetAvailableTicketsHandler.cs b/Services/RequestHandlers/GetAvailableTicketsHandler.cs new file mode 100644 index 0000000..8378ed7 --- /dev/null +++ b/Services/RequestHandlers/GetAvailableTicketsHandler.cs @@ -0,0 +1,121 @@ +using Contracts.RequestModels; +using Contracts.ResponseModels; +using Entity.Entity; +using MediatR; +using Microsoft.EntityFrameworkCore; + +namespace Services.RequestHandlers +{ + public class GetAvailableTicketsHandler : IRequestHandler + { + private readonly DBContext _db; + + public GetAvailableTicketsHandler(DBContext db) + { + _db = db; + } + + public async Task Handle(GetAvailableTicketsRequest request, CancellationToken cancellationToken) + { + var query = (from t in _db.Tickets + join c in _db.Categories on t.CategoryId equals c.CategoryId + where c.CategoryName.ToLower().Contains(request.CategoryName.ToLower()) + && t.TicketCode.ToLower().Contains(request.TicketCode.ToLower()) + && t.TicketName.ToLower().Contains(request.TicketName.ToLower()) + && (request.Price == 0 || t.Price <= request.Price) + && (request.MinEventDate == null || t.EventDate >= request.MinEventDate) + && (request.MaxEventDate == null || t.EventDate <= request.MaxEventDate) + select new AvailableTicketData + { + EventDate = t.EventDate, + Quota = t.Quota, + TicketCode = t.TicketCode, + TicketName = t.TicketName, + CategoryName = c.CategoryName, + Price = t.Price, + }); + + switch (request.OrderBy) //TODO at least orderby price sama quota masih ngaco + { + case "CategoryName": + if (request.OrderState != "Descending") + { + query.OrderBy(t => t.CategoryName); + } + else + { + query.OrderByDescending(t => t.CategoryName); + } + break; + + case "TicketCode": + if (request.OrderState != "Descending") + { + query.OrderBy(t => t.TicketCode); + } + else + { + query.OrderByDescending(t => t.TicketCode); + } + break; + + case "TicketName": + if (request.OrderState != "Descending") + { + query.OrderBy(t => t.TicketName); + } + else + { + query.OrderByDescending(t => t.TicketName); + } + break; + + case "Price": + if (request.OrderState != "Descending") + { + query.OrderBy(t => Convert.ToDecimal(t.Price)); + } + else + { + query.OrderByDescending(t => Convert.ToDecimal(t.Price)); + } + break; + + case "EventDate": + if (request.OrderState != "Descending") + { + query.OrderBy(t => t.EventDate); + } + else + { + query.OrderByDescending(t => t.EventDate); + } + break; + + case "Quota": + if (request.OrderState != "Descending") + { + query.OrderBy(t => t.Quota); + } + else + { + query.OrderByDescending(t => t.Quota); + } + break; + + default: + query = query.OrderBy(t => t.TicketCode); + break; + } + + var datas = await query.AsNoTracking().ToListAsync(cancellationToken); + + var response = new GetAvailableTicketsResponse + { + AvailableTicketDatas = datas + }; + + return response; + } + } +} diff --git a/Services/RequestHandlers/GetBookingDetailHandler.cs b/Services/RequestHandlers/GetBookingDetailHandler.cs new file mode 100644 index 0000000..0b53e28 --- /dev/null +++ b/Services/RequestHandlers/GetBookingDetailHandler.cs @@ -0,0 +1,80 @@ +using Contracts.RequestModels; +using Contracts.ResponseModels; +using Entity.Entity; +using MediatR; +using Microsoft.EntityFrameworkCore; + +namespace Services.RequestHandlers +{ + public class GetBookingDetailHandler : IRequestHandler + { + private readonly DBContext _db; + public GetBookingDetailHandler(DBContext db) + { + _db = db; + } + + public async Task Handle(GetBookingDetailRequest request, CancellationToken cancellationToken) + { + var datas = await (from m in _db.TicketBookedTicketMappings + join t in _db.Tickets on m.TicketCode equals t.TicketCode + join c in _db.Categories on t.CategoryId equals c.CategoryId + where m.BookedTicketId == request.BookedTicketId + select new GetBookingDetailHandlerHelperModel + { + TicketCode = t.TicketCode, + TicketName = t.TicketName, + EventDate = t.EventDate, + Quantity = m.TicketQuantity, + CategoryName = c.CategoryName + }).AsNoTracking().ToListAsync(); + + var categories = await _db.Categories.Select(Q => Q.CategoryName).AsNoTracking().ToListAsync(); + + var response = new GetBookingDetailResponse(); + + foreach (var category in categories) + { + var ticketListPerCategory = new GetBookingDetailDataListModel + { + CategoryName = category, + }; + + foreach (var data in datas) + { + if (data.CategoryName == category) + { + var ticketData = new GetBookingDetailDataModel + { + TicketCode = data.TicketCode, + TicketName = data.TicketName, + EventDate = data.EventDate, + }; + ticketListPerCategory.QtyPerCategory += data.Quantity; + ticketListPerCategory.Tickets.Add(ticketData); + } + } + + if (ticketListPerCategory.Tickets.Count > 0) + { + response.DataList.Add(ticketListPerCategory); + } + } + + return response; + } + + public class GetBookingDetailHandlerHelperModel //TODO Pindahin, ato bikin anonymus kalo aman + { + public string TicketCode { get; set; } = string.Empty; + + public string TicketName { get; set; } = string.Empty; + + public DateTimeOffset? EventDate { get; set; } + + public int Quantity { get; set; } = 0; + + public string CategoryName { get; set; } = string.Empty; + } + } +} diff --git a/Services/RequestHandlers/UpdateBookingHandler.cs b/Services/RequestHandlers/UpdateBookingHandler.cs new file mode 100644 index 0000000..21914f7 --- /dev/null +++ b/Services/RequestHandlers/UpdateBookingHandler.cs @@ -0,0 +1,69 @@ +using Contracts.RequestModels; +using Contracts.ResponseModels; +using Entity.Entity; +using MediatR; +using Microsoft.EntityFrameworkCore; + +namespace Services.RequestHandlers +{ + public class UpdateBookingHandler : IRequestHandler + { + private readonly DBContext _db; + + public UpdateBookingHandler(DBContext db) + { + _db = db; + } + + public async Task Handle(UpdateBookingRequest request, CancellationToken cancellationToken) + { + var tempTicketcodeList = new List(); + + foreach (var item in request.Tickets) + { + tempTicketcodeList.Add(item.TicketCode); + } + + var datas = await (from m in _db.TicketBookedTicketMappings + join t in _db.Tickets on m.TicketCode equals t.TicketCode + join c in _db.Categories on t.CategoryId equals c.CategoryId + where m.BookedTicketId == request.BookedTicketId + && tempTicketcodeList.Contains(m.TicketCode) + select m).ToListAsync(); + + foreach (var data in datas) + { + foreach (var item in request.Tickets) + { + if (data.TicketCode == item.TicketCode) + { + data.TicketQuantity = item.Quantity; + break; + } + } + } + + await _db.SaveChangesAsync(cancellationToken); + + var datas2 = await (from m in _db.TicketBookedTicketMappings + join t in _db.Tickets on m.TicketCode equals t.TicketCode + join c in _db.Categories on t.CategoryId equals c.CategoryId + where m.BookedTicketId == request.BookedTicketId + && tempTicketcodeList.Contains(m.TicketCode) + select new UpdateBookingResponseDataModel + { + TicketCode = t.TicketCode, + TicketName = t.TicketName, + Quantity = m.TicketQuantity, + CategoryName = c.CategoryName + }).ToListAsync(cancellationToken); + + var response = new UpdateBookingResponse + { + Tickets = datas2 + }; + + return response; + } + } +} diff --git a/Services/Services.csproj b/Services/Services.csproj new file mode 100644 index 0000000..178a4d7 --- /dev/null +++ b/Services/Services.csproj @@ -0,0 +1,21 @@ + + + + net8.0 + enable + enable + + + + + + + + + + + + + + +