From 5bccaa22e50a097054ffb18fa0a6b07ac644c70c Mon Sep 17 00:00:00 2001 From: owenB89 Date: Tue, 26 Mar 2024 18:00:22 +0700 Subject: [PATCH 1/2] Kumpulin dulu biar gak telat --- .gitattributes | 63 +++++++++ .gitignore | 363 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 426 insertions(+) create mode 100644 .gitattributes create mode 100644 .gitignore 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 From 7122b821787e1c400e4aefc9a6a185eef12dce4b Mon Sep 17 00:00:00 2001 From: owenB89 Date: Tue, 26 Mar 2024 18:14:03 +0700 Subject: [PATCH 2/2] commit2 --- NETWebAPIExam/Contracts/Contracts.csproj | 13 ++ .../BookedTicket/CreateBookedTicketRequest.cs | 16 +++ .../Request/BookedTicket/DeleteBookRequesr.cs | 17 +++ .../Request/BookedTicket/EditBookedRequest.cs | 21 ++++ .../Request/BookedTicket/GetBookedRequest.cs | 15 +++ .../Request/Ticket/GetTicketRequest.cs | 19 +++ .../CreateBookedTicketResponse.cs | 29 +++++ .../BookedTicket/DeleteBookedResponse.cs | 16 +++ .../BookedTicket/EditBookedResponse.cs | 16 +++ .../BookedTicket/GetBookedResponse.cs | 18 +++ .../Response/Ticket/GetTicketResponse.cs | 24 ++++ NETWebAPIExam/Entity/Entity.csproj | 13 ++ NETWebAPIExam/Entity/Entity/BookedTicket.cs | 21 ++++ NETWebAPIExam/Entity/Entity/DBContext.cs | 20 ++++ NETWebAPIExam/Entity/Entity/Ticket.cs | 31 +++++ NETWebAPIExam/NETWebAPIExam.sln | 43 +++++++ .../Controllers/BookedTicketController.cs | 111 +++++++++++++++++ .../Controllers/ErrorController.cs | 13 ++ .../Controllers/TicketController.cs | 60 ++++++++++ .../Controllers/WeatherForecastController.cs | 33 +++++ .../NETWebAPIExam/NETWebAPIExam.csproj | 19 +++ .../NETWebAPIExam/NETWebAPIExam.http | 6 + NETWebAPIExam/NETWebAPIExam/Program.cs | 73 +++++++++++ .../Properties/launchSettings.json | 31 +++++ .../NETWebAPIExam/WeatherForecast.cs | 13 ++ .../appsettings.Development.json | 8 ++ NETWebAPIExam/NETWebAPIExam/appsettings.json | 12 ++ NETWebAPIExam/NETWebAPIExam/ticket.db | Bin 0 -> 24576 bytes NETWebAPIExam/NETWebAPIExam/ticket.db-shm | Bin 0 -> 32768 bytes NETWebAPIExam/NETWebAPIExam/ticket.db-wal | Bin 0 -> 20632 bytes .../CreateBookedHandler.cs | 67 +++++++++++ .../DeleteBookedHandler.cs | 59 +++++++++ .../BookedTicketHandler/GetBookedHandler.cs | 45 +++++++ .../RequestHandler/Ticket/GetTicketHandler.cs | 113 ++++++++++++++++++ NETWebAPIExam/Services/Services.csproj | 21 ++++ .../Validators/CreateBookedValidator.cs | 47 ++++++++ .../Validators/DeleteBookedValidator.cs | 57 +++++++++ .../Services/Validators/GetBookedValidator.cs | 33 +++++ 38 files changed, 1153 insertions(+) create mode 100644 NETWebAPIExam/Contracts/Contracts.csproj create mode 100644 NETWebAPIExam/Contracts/Request/BookedTicket/CreateBookedTicketRequest.cs create mode 100644 NETWebAPIExam/Contracts/Request/BookedTicket/DeleteBookRequesr.cs create mode 100644 NETWebAPIExam/Contracts/Request/BookedTicket/EditBookedRequest.cs create mode 100644 NETWebAPIExam/Contracts/Request/BookedTicket/GetBookedRequest.cs create mode 100644 NETWebAPIExam/Contracts/Request/Ticket/GetTicketRequest.cs create mode 100644 NETWebAPIExam/Contracts/Response/BookedTicket/CreateBookedTicketResponse.cs create mode 100644 NETWebAPIExam/Contracts/Response/BookedTicket/DeleteBookedResponse.cs create mode 100644 NETWebAPIExam/Contracts/Response/BookedTicket/EditBookedResponse.cs create mode 100644 NETWebAPIExam/Contracts/Response/BookedTicket/GetBookedResponse.cs create mode 100644 NETWebAPIExam/Contracts/Response/Ticket/GetTicketResponse.cs create mode 100644 NETWebAPIExam/Entity/Entity.csproj create mode 100644 NETWebAPIExam/Entity/Entity/BookedTicket.cs create mode 100644 NETWebAPIExam/Entity/Entity/DBContext.cs create mode 100644 NETWebAPIExam/Entity/Entity/Ticket.cs create mode 100644 NETWebAPIExam/NETWebAPIExam.sln create mode 100644 NETWebAPIExam/NETWebAPIExam/Controllers/BookedTicketController.cs create mode 100644 NETWebAPIExam/NETWebAPIExam/Controllers/ErrorController.cs create mode 100644 NETWebAPIExam/NETWebAPIExam/Controllers/TicketController.cs create mode 100644 NETWebAPIExam/NETWebAPIExam/Controllers/WeatherForecastController.cs create mode 100644 NETWebAPIExam/NETWebAPIExam/NETWebAPIExam.csproj create mode 100644 NETWebAPIExam/NETWebAPIExam/NETWebAPIExam.http create mode 100644 NETWebAPIExam/NETWebAPIExam/Program.cs create mode 100644 NETWebAPIExam/NETWebAPIExam/Properties/launchSettings.json create mode 100644 NETWebAPIExam/NETWebAPIExam/WeatherForecast.cs create mode 100644 NETWebAPIExam/NETWebAPIExam/appsettings.Development.json create mode 100644 NETWebAPIExam/NETWebAPIExam/appsettings.json create mode 100644 NETWebAPIExam/NETWebAPIExam/ticket.db create mode 100644 NETWebAPIExam/NETWebAPIExam/ticket.db-shm create mode 100644 NETWebAPIExam/NETWebAPIExam/ticket.db-wal create mode 100644 NETWebAPIExam/Services/RequestHandler/BookedTicketHandler/CreateBookedHandler.cs create mode 100644 NETWebAPIExam/Services/RequestHandler/BookedTicketHandler/DeleteBookedHandler.cs create mode 100644 NETWebAPIExam/Services/RequestHandler/BookedTicketHandler/GetBookedHandler.cs create mode 100644 NETWebAPIExam/Services/RequestHandler/Ticket/GetTicketHandler.cs create mode 100644 NETWebAPIExam/Services/Services.csproj create mode 100644 NETWebAPIExam/Services/Validators/CreateBookedValidator.cs create mode 100644 NETWebAPIExam/Services/Validators/DeleteBookedValidator.cs create mode 100644 NETWebAPIExam/Services/Validators/GetBookedValidator.cs diff --git a/NETWebAPIExam/Contracts/Contracts.csproj b/NETWebAPIExam/Contracts/Contracts.csproj new file mode 100644 index 0000000..8abcd77 --- /dev/null +++ b/NETWebAPIExam/Contracts/Contracts.csproj @@ -0,0 +1,13 @@ + + + + net8.0 + enable + enable + + + + + + + diff --git a/NETWebAPIExam/Contracts/Request/BookedTicket/CreateBookedTicketRequest.cs b/NETWebAPIExam/Contracts/Request/BookedTicket/CreateBookedTicketRequest.cs new file mode 100644 index 0000000..555e99b --- /dev/null +++ b/NETWebAPIExam/Contracts/Request/BookedTicket/CreateBookedTicketRequest.cs @@ -0,0 +1,16 @@ +using Contracts.Response.BookedTicket; +using MediatR; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Contracts.Request.BookedTicket +{ + public class CreateBookedTicketRequest: IRequest + { + public string TicketCode { get; set; } = string.Empty; + public int Quantity { get; set; } + } +} diff --git a/NETWebAPIExam/Contracts/Request/BookedTicket/DeleteBookRequesr.cs b/NETWebAPIExam/Contracts/Request/BookedTicket/DeleteBookRequesr.cs new file mode 100644 index 0000000..cf4d12c --- /dev/null +++ b/NETWebAPIExam/Contracts/Request/BookedTicket/DeleteBookRequesr.cs @@ -0,0 +1,17 @@ +using Contracts.Response.BookedTicket; +using MediatR; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Contracts.Request.BookedTicket +{ + public class DeleteBookRequesr: IRequest + { + public Guid BookedId { get; set; } + public string TicketCode { get; set; } = string.Empty; + public int Quantity { get; set; } + } +} diff --git a/NETWebAPIExam/Contracts/Request/BookedTicket/EditBookedRequest.cs b/NETWebAPIExam/Contracts/Request/BookedTicket/EditBookedRequest.cs new file mode 100644 index 0000000..9ef299e --- /dev/null +++ b/NETWebAPIExam/Contracts/Request/BookedTicket/EditBookedRequest.cs @@ -0,0 +1,21 @@ +using Contracts.Response.BookedTicket; +using MediatR; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Contracts.Request.BookedTicket +{ + public class EditBookedRequest : UpdateBooked,IRequest + { + public Guid BookedId { get; set; } + } + + public class UpdateBooked + { + public string TicketCode { get; set; } = string.Empty; + public int Quantity { get; set; } + } +} diff --git a/NETWebAPIExam/Contracts/Request/BookedTicket/GetBookedRequest.cs b/NETWebAPIExam/Contracts/Request/BookedTicket/GetBookedRequest.cs new file mode 100644 index 0000000..28b145f --- /dev/null +++ b/NETWebAPIExam/Contracts/Request/BookedTicket/GetBookedRequest.cs @@ -0,0 +1,15 @@ +using Contracts.Response.BookedTicket; +using MediatR; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Contracts.Request.BookedTicket +{ + public class GetBookedRequest: IRequest + { + public Guid BookedId { get; set; } + } +} diff --git a/NETWebAPIExam/Contracts/Request/Ticket/GetTicketRequest.cs b/NETWebAPIExam/Contracts/Request/Ticket/GetTicketRequest.cs new file mode 100644 index 0000000..f81f76d --- /dev/null +++ b/NETWebAPIExam/Contracts/Request/Ticket/GetTicketRequest.cs @@ -0,0 +1,19 @@ +using Contracts.Response.Ticket; +using MediatR; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Contracts.Request.Ticket +{ + public class GetTicketRequest: IRequest + { + public string SearchQuery { get; set; } = string.Empty; + public DateTime MaxDate { get; set; } + public DateTime MinDate { get; set; } + public string OrderBy { get; set; } = string.Empty; + public string OrderState { get; set; } = string.Empty; + } +} diff --git a/NETWebAPIExam/Contracts/Response/BookedTicket/CreateBookedTicketResponse.cs b/NETWebAPIExam/Contracts/Response/BookedTicket/CreateBookedTicketResponse.cs new file mode 100644 index 0000000..340ad4c --- /dev/null +++ b/NETWebAPIExam/Contracts/Response/BookedTicket/CreateBookedTicketResponse.cs @@ -0,0 +1,29 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Contracts.Response.BookedTicket +{ + public class CreateBookedTicketResponse + { + public int PriceSummary { get; set; } + public List TicketPerCategories { get; set; } = new List(); + } + + public class TicketPerCategory + { + public string CategoryName { get; set; } = string.Empty; + public int SummaryPrice { get; set; } + public List Ticketz { get; set; } = new List(); + } + + public class Tickets + { + public Guid Id { get; set; } + public string TicketCode { get; set; } = string.Empty; + public string TicketName { get; set; } = string.Empty; + public int Price { get; set; } + } +} diff --git a/NETWebAPIExam/Contracts/Response/BookedTicket/DeleteBookedResponse.cs b/NETWebAPIExam/Contracts/Response/BookedTicket/DeleteBookedResponse.cs new file mode 100644 index 0000000..3503e96 --- /dev/null +++ b/NETWebAPIExam/Contracts/Response/BookedTicket/DeleteBookedResponse.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Contracts.Response.BookedTicket +{ + public class DeleteBookedResponse + { + public int Quantity { get; set; } + public string CategoryName { get; set; } = string.Empty; + public string TicketCode { get; set; } = string.Empty; + public string TicketName { get; set; } = string.Empty; + } +} diff --git a/NETWebAPIExam/Contracts/Response/BookedTicket/EditBookedResponse.cs b/NETWebAPIExam/Contracts/Response/BookedTicket/EditBookedResponse.cs new file mode 100644 index 0000000..bd28ba7 --- /dev/null +++ b/NETWebAPIExam/Contracts/Response/BookedTicket/EditBookedResponse.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Contracts.Response.BookedTicket +{ + public class EditBookedResponse + { + public int Quantity { get; set; } + public string CategoryName { get; set; } = string.Empty; + public string TicketCode { get; set; } = string.Empty; + public string TicketName { get; set; } = string.Empty; + } +} diff --git a/NETWebAPIExam/Contracts/Response/BookedTicket/GetBookedResponse.cs b/NETWebAPIExam/Contracts/Response/BookedTicket/GetBookedResponse.cs new file mode 100644 index 0000000..3656274 --- /dev/null +++ b/NETWebAPIExam/Contracts/Response/BookedTicket/GetBookedResponse.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Contracts.Response.BookedTicket +{ + public class GetBookedResponse + { + public int Quantity { get; set; } + public string CategoryName { get; set; } = string.Empty; + public string TicketCode { get; set; } = string.Empty; + public string TicketName { get; set; } = string.Empty; + public DateTime EventDate { get; set; } + public int TotalPrice { get; set; } + } +} diff --git a/NETWebAPIExam/Contracts/Response/Ticket/GetTicketResponse.cs b/NETWebAPIExam/Contracts/Response/Ticket/GetTicketResponse.cs new file mode 100644 index 0000000..af80bc8 --- /dev/null +++ b/NETWebAPIExam/Contracts/Response/Ticket/GetTicketResponse.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Contracts.Response.Ticket +{ + public class GetTicketResponse + { + public List Tickets { get; set; } = new List(); + public int TotalTickets { get; set; } + } + + public class DataTicket + { + public DateTime EventDate { get; set; } + public int Quota { get; set; } + public string TicketCode { get; set; } = string.Empty; + public string TicketName { get; set; } = string.Empty; + public string CategoryName { get; set; } = string.Empty; + public int Price { get; set; } + } +} diff --git a/NETWebAPIExam/Entity/Entity.csproj b/NETWebAPIExam/Entity/Entity.csproj new file mode 100644 index 0000000..76081ce --- /dev/null +++ b/NETWebAPIExam/Entity/Entity.csproj @@ -0,0 +1,13 @@ + + + + net8.0 + enable + enable + + + + + + + diff --git a/NETWebAPIExam/Entity/Entity/BookedTicket.cs b/NETWebAPIExam/Entity/Entity/BookedTicket.cs new file mode 100644 index 0000000..bbcb9dd --- /dev/null +++ b/NETWebAPIExam/Entity/Entity/BookedTicket.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Entity.Entity +{ + public class BookedTicket + { + [Key] + public Guid BookedTicketId { get; set; } + [Required] + public int Quantity { get; set; } + [ForeignKey("TicketId")] + public Guid TicketId { get; set; } + public Ticket? ticket { get; set; } + } +} diff --git a/NETWebAPIExam/Entity/Entity/DBContext.cs b/NETWebAPIExam/Entity/Entity/DBContext.cs new file mode 100644 index 0000000..cd814b7 --- /dev/null +++ b/NETWebAPIExam/Entity/Entity/DBContext.cs @@ -0,0 +1,20 @@ +using Microsoft.EntityFrameworkCore; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Entity.Entity +{ + public class DBContext : DbContext + { + public DBContext(DbContextOptions dbContextOptions) : base(dbContextOptions) + { + + } + + public DbSet Tickets => Set(); + public DbSet BookedTickets => Set(); + } +} diff --git a/NETWebAPIExam/Entity/Entity/Ticket.cs b/NETWebAPIExam/Entity/Entity/Ticket.cs new file mode 100644 index 0000000..49b5db7 --- /dev/null +++ b/NETWebAPIExam/Entity/Entity/Ticket.cs @@ -0,0 +1,31 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Entity.Entity +{ + public class Ticket + { + [Key] + public Guid TicketId { get; set; } + [Required] + [StringLength(255)] + public string CategoryName { get; set; } = string.Empty; + [Required] + [StringLength(255)] + public string TicketCode { get; set; } = string.Empty; + [Required] + [StringLength(255)] + public string TicketName { get; set; } = string.Empty; + [Required] + public int Quota { get; set; } + [Required] + public int Price { get; set; } + [Required] + public DateTime EventDate { get; set; } + public List bookedTickets { get; set; } = new List(); + } +} diff --git a/NETWebAPIExam/NETWebAPIExam.sln b/NETWebAPIExam/NETWebAPIExam.sln new file mode 100644 index 0000000..0b58714 --- /dev/null +++ b/NETWebAPIExam/NETWebAPIExam.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}") = "NETWebAPIExam", "NETWebAPIExam\NETWebAPIExam.csproj", "{7C2DED0B-029A-42DC-83A5-190045D3E678}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Entity", "Entity\Entity.csproj", "{482EAA63-4B32-4776-BC44-6ECD7D138124}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Contracts", "Contracts\Contracts.csproj", "{2D82BF99-357F-4A81-B538-7B282E2A5D26}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Services", "Services\Services.csproj", "{E261EAAD-BB48-43CD-8170-A5CFCBEEB21E}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {7C2DED0B-029A-42DC-83A5-190045D3E678}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {7C2DED0B-029A-42DC-83A5-190045D3E678}.Debug|Any CPU.Build.0 = Debug|Any CPU + {7C2DED0B-029A-42DC-83A5-190045D3E678}.Release|Any CPU.ActiveCfg = Release|Any CPU + {7C2DED0B-029A-42DC-83A5-190045D3E678}.Release|Any CPU.Build.0 = Release|Any CPU + {482EAA63-4B32-4776-BC44-6ECD7D138124}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {482EAA63-4B32-4776-BC44-6ECD7D138124}.Debug|Any CPU.Build.0 = Debug|Any CPU + {482EAA63-4B32-4776-BC44-6ECD7D138124}.Release|Any CPU.ActiveCfg = Release|Any CPU + {482EAA63-4B32-4776-BC44-6ECD7D138124}.Release|Any CPU.Build.0 = Release|Any CPU + {2D82BF99-357F-4A81-B538-7B282E2A5D26}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {2D82BF99-357F-4A81-B538-7B282E2A5D26}.Debug|Any CPU.Build.0 = Debug|Any CPU + {2D82BF99-357F-4A81-B538-7B282E2A5D26}.Release|Any CPU.ActiveCfg = Release|Any CPU + {2D82BF99-357F-4A81-B538-7B282E2A5D26}.Release|Any CPU.Build.0 = Release|Any CPU + {E261EAAD-BB48-43CD-8170-A5CFCBEEB21E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {E261EAAD-BB48-43CD-8170-A5CFCBEEB21E}.Debug|Any CPU.Build.0 = Debug|Any CPU + {E261EAAD-BB48-43CD-8170-A5CFCBEEB21E}.Release|Any CPU.ActiveCfg = Release|Any CPU + {E261EAAD-BB48-43CD-8170-A5CFCBEEB21E}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {91C68ACE-854D-4F43-986D-FF7F51684C5E} + EndGlobalSection +EndGlobal diff --git a/NETWebAPIExam/NETWebAPIExam/Controllers/BookedTicketController.cs b/NETWebAPIExam/NETWebAPIExam/Controllers/BookedTicketController.cs new file mode 100644 index 0000000..d03bb54 --- /dev/null +++ b/NETWebAPIExam/NETWebAPIExam/Controllers/BookedTicketController.cs @@ -0,0 +1,111 @@ +using Contracts.Request.BookedTicket; +using Contracts.Request.Ticket; +using Contracts.Response.BookedTicket; +using Contracts.Response.Ticket; +using Entity.Entity; +using FluentValidation; +using FluentValidation.AspNetCore; +using MediatR; +using Microsoft.AspNetCore.Mvc; +using Microsoft.EntityFrameworkCore; +using System.ComponentModel.DataAnnotations; +using System.Threading; + +// For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860 + +namespace NETWebAPIExam.Controllers +{ + [Route("api/v1")] + [ApiController] + public class BookedTicketController : ControllerBase + { + private readonly IMediator _mediator; + private readonly DBContext _db; + + public BookedTicketController(IMediator mediator,DBContext db) + { + _mediator = mediator; + _db = db; + } + // GET: api/ + [HttpGet] + public IEnumerable Get() + { + /*var tdaw = (from t in _db.Tickets + join bt in _db.BookedTickets on t.TicketId equals bt.TicketId + select new BookedTicket + { + BookedTicketId = bt.BookedTicketId + }).AsNoTracking().ToList();*/ + + return new string[] { "value1", "value2" }; + } + + // GET api//5 + [HttpGet("get-booked-ticket/{id}")] + //[Route("Get-Booked-Ticket/{BookedTicketId}")] + public async Task> Get(Guid id, [FromServices] IValidator validator, CancellationToken cancellationToken) + { + var request = new GetBookedRequest + { + BookedId = id, + }; + var validationResult = await validator.ValidateAsync(request); + + if (!validationResult.IsValid) + { + validationResult.AddToModelState(ModelState); + return ValidationProblem(ModelState); + } + var response = await _mediator.Send(request, cancellationToken); + + return Ok(response); + } + + // POST api/ + [HttpPost] + [Route("book-ticket")] + public async Task> Post([FromBody] CreateBookedTicketRequest request, [FromServices] IValidator validator, CancellationToken cancellationToken) + { + var validationResult = await validator.ValidateAsync(request); + + if (!validationResult.IsValid) + { + validationResult.AddToModelState(ModelState); + return ValidationProblem(ModelState); + } + + var response = await _mediator.Send(request, cancellationToken); + + return Ok(response); + } + + // PUT api//5 + [HttpPut("{id}")] + public void Put(int id, [FromBody] string value) + { + } + + // DELETE api//5 + [HttpDelete("/{BookedTicketId}/{KodeTicket}/{Quantity}")] + public async Task> Delete(Guid BookedTicketId,string KodeTicket,int Quantity, [FromServices] IValidator validator, CancellationToken cancellationToken) + { + var request = new DeleteBookRequesr + { + Quantity = Quantity, + BookedId = BookedTicketId, + TicketCode = KodeTicket + }; + var validationResult = await validator.ValidateAsync(request); + + if (!validationResult.IsValid) + { + validationResult.AddToModelState(ModelState); + return ValidationProblem(ModelState); + } + + var response = await _mediator.Send(request, cancellationToken); + return Ok(response); + } + } +} diff --git a/NETWebAPIExam/NETWebAPIExam/Controllers/ErrorController.cs b/NETWebAPIExam/NETWebAPIExam/Controllers/ErrorController.cs new file mode 100644 index 0000000..f5f07c7 --- /dev/null +++ b/NETWebAPIExam/NETWebAPIExam/Controllers/ErrorController.cs @@ -0,0 +1,13 @@ +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; + +namespace NETWebAPIExam.Controllers +{ + [ApiController] + [ApiExplorerSettings(IgnoreApi = true)] + public class ErrorController : ControllerBase + { + [Route("error")] + public IActionResult HandleError() => Problem(); + } +} diff --git a/NETWebAPIExam/NETWebAPIExam/Controllers/TicketController.cs b/NETWebAPIExam/NETWebAPIExam/Controllers/TicketController.cs new file mode 100644 index 0000000..d0a5fc2 --- /dev/null +++ b/NETWebAPIExam/NETWebAPIExam/Controllers/TicketController.cs @@ -0,0 +1,60 @@ +using Contracts.Request.Ticket; +using Contracts.Response.Ticket; +using Entity.Entity; +using MediatR; +using Microsoft.AspNetCore.Mvc; +using System.Globalization; + +// For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860 + +namespace NETWebAPIExam.Controllers +{ + [Route("api/v1")] + [ApiController] + public class TicketController : ControllerBase + { + + private readonly IMediator _mediator; + + public TicketController(IMediator mediator) + { + _mediator = mediator; + } + + // GET: api/ + [HttpGet] + [Route("get-available-ticket")] + public async Task> Get([FromQuery] GetTicketRequest request,CancellationToken cancellationToken) + { + var response = await _mediator.Send(request, cancellationToken); + + return Ok(response); + } + + // GET api//5 + /*[HttpGet("{id}")] + public string Get(int id) + { + return "value"; + }*/ + + // POST api/ + [HttpPost] + public void Post([FromBody] string value) + { + /*var ticket = new Ticket + { + TicketId = Guid.NewGuid(), + EventDate = DateTime.ParseExact(s: "22-11-2024 11:00", format: "dd-MM-yyyy HH:mm", provider: CultureInfo.InvariantCulture), + Quota = 56, + TicketCode = "H001", + TicketName = "Ibis Hotel", + CategoryName = "Hotel", + Price = 450000 + }; + _db.Tickets.Add(ticket); + await _db.SaveChangesAsync();*/ + + } + } +} diff --git a/NETWebAPIExam/NETWebAPIExam/Controllers/WeatherForecastController.cs b/NETWebAPIExam/NETWebAPIExam/Controllers/WeatherForecastController.cs new file mode 100644 index 0000000..d90b6fe --- /dev/null +++ b/NETWebAPIExam/NETWebAPIExam/Controllers/WeatherForecastController.cs @@ -0,0 +1,33 @@ +using Microsoft.AspNetCore.Mvc; + +namespace NETWebAPIExam.Controllers +{ + [ApiController] + [Route("[controller]")] + public class WeatherForecastController : ControllerBase + { + private static readonly string[] Summaries = new[] + { + "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching" + }; + + private readonly ILogger _logger; + + public WeatherForecastController(ILogger logger) + { + _logger = logger; + } + + [HttpGet(Name = "GetWeatherForecast")] + public IEnumerable Get() + { + return Enumerable.Range(1, 5).Select(index => new WeatherForecast + { + Date = DateOnly.FromDateTime(DateTime.Now.AddDays(index)), + TemperatureC = Random.Shared.Next(-20, 55), + Summary = Summaries[Random.Shared.Next(Summaries.Length)] + }) + .ToArray(); + } + } +} diff --git a/NETWebAPIExam/NETWebAPIExam/NETWebAPIExam.csproj b/NETWebAPIExam/NETWebAPIExam/NETWebAPIExam.csproj new file mode 100644 index 0000000..5da7c77 --- /dev/null +++ b/NETWebAPIExam/NETWebAPIExam/NETWebAPIExam.csproj @@ -0,0 +1,19 @@ + + + + net8.0 + enable + enable + + + + + + + + + + + + + diff --git a/NETWebAPIExam/NETWebAPIExam/NETWebAPIExam.http b/NETWebAPIExam/NETWebAPIExam/NETWebAPIExam.http new file mode 100644 index 0000000..de5bf5a --- /dev/null +++ b/NETWebAPIExam/NETWebAPIExam/NETWebAPIExam.http @@ -0,0 +1,6 @@ +@NETWebAPIExam_HostAddress = http://localhost:5254 + +GET {{NETWebAPIExam_HostAddress}}/weatherforecast/ +Accept: application/json + +### diff --git a/NETWebAPIExam/NETWebAPIExam/Program.cs b/NETWebAPIExam/NETWebAPIExam/Program.cs new file mode 100644 index 0000000..9f59aad --- /dev/null +++ b/NETWebAPIExam/NETWebAPIExam/Program.cs @@ -0,0 +1,73 @@ +using Entity.Entity; +using FluentValidation; +using MediatR; +using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.Configuration; +using Serilog; +using Serilog.Events; +using Services.RequestHandler.Ticket; +using Services.Validators; + +var builder = WebApplication.CreateBuilder(args); +var configuration = builder.Configuration; + +builder.Host.UseSerilog((ctx, config) => config + .MinimumLevel.Information() + .WriteTo.Console() + .WriteTo.File("Logs/Log-20240326.log", LogEventLevel.Warning, rollingInterval: RollingInterval.Day) +); + +// 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(GetTicketHandler)); +builder.Services.AddValidatorsFromAssemblyContaining(typeof(CreateBookedValidator)); + +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.UseExceptionHandler("/error"); + +app.UseAuthorization(); + +app.MapControllers(); + +//app.Run(); + +try +{ +Log.Information("Starting web api host."); +app.Run(); +return 0; +} +catch (Exception ex) +{ +Log.Fatal(ex, "Host terminated unexpectedly."); +return 1; +} +finally +{ +Log.CloseAndFlush(); +} + +//public partial class Program { } diff --git a/NETWebAPIExam/NETWebAPIExam/Properties/launchSettings.json b/NETWebAPIExam/NETWebAPIExam/Properties/launchSettings.json new file mode 100644 index 0000000..a88f63d --- /dev/null +++ b/NETWebAPIExam/NETWebAPIExam/Properties/launchSettings.json @@ -0,0 +1,31 @@ +{ + "$schema": "http://json.schemastore.org/launchsettings.json", + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:63578", + "sslPort": 0 + } + }, + "profiles": { + "http": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": true, + "launchUrl": "swagger", + "applicationUrl": "http://localhost:5254", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "launchUrl": "swagger", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + } + } +} diff --git a/NETWebAPIExam/NETWebAPIExam/WeatherForecast.cs b/NETWebAPIExam/NETWebAPIExam/WeatherForecast.cs new file mode 100644 index 0000000..ae170c0 --- /dev/null +++ b/NETWebAPIExam/NETWebAPIExam/WeatherForecast.cs @@ -0,0 +1,13 @@ +namespace NETWebAPIExam +{ + public class WeatherForecast + { + public DateOnly Date { get; set; } + + public int TemperatureC { get; set; } + + public int TemperatureF => 32 + (int)(TemperatureC / 0.5556); + + public string? Summary { get; set; } + } +} diff --git a/NETWebAPIExam/NETWebAPIExam/appsettings.Development.json b/NETWebAPIExam/NETWebAPIExam/appsettings.Development.json new file mode 100644 index 0000000..0c208ae --- /dev/null +++ b/NETWebAPIExam/NETWebAPIExam/appsettings.Development.json @@ -0,0 +1,8 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + } +} diff --git a/NETWebAPIExam/NETWebAPIExam/appsettings.json b/NETWebAPIExam/NETWebAPIExam/appsettings.json new file mode 100644 index 0000000..0265aa2 --- /dev/null +++ b/NETWebAPIExam/NETWebAPIExam/appsettings.json @@ -0,0 +1,12 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + }, + "AllowedHosts": "*", + "ConnectionStrings": { + "Sqlite": "Data Source=ticket.db" + } +} diff --git a/NETWebAPIExam/NETWebAPIExam/ticket.db b/NETWebAPIExam/NETWebAPIExam/ticket.db new file mode 100644 index 0000000000000000000000000000000000000000..35483f820f4fb308488f9c52d03a2d43d8cc8ab9 GIT binary patch literal 24576 zcmeI3&u<$=6vzE5zhf@~RS~L?79&U_F=%FX_7_N{v$M0U)x=2?yJ`EM zPzooiszTz@1GoMW702GWATHeC!i8hSkpm~h+l>?IP*+olLnYoOE6;A8zi;OA)|TFT zlZ^|@-9g8`-rL(r2ewmqtxzfz&e(RLP$X2g%7Sjty+H; zCg$%HYTsBt%>PkagCQPB00|%gB!C2v01`j~NB{}^e+YazF}3jVV)3iDy1QGQ&l{IE zqh9Y;XRFn{cB?b!Zyvlhwnpwws&y?}+HN#seaWtmeN)|DZQAvbx7O`b^+V12(!I;& zsfESG;{Dr$^y+qJ#B$`KGW6Jz(X#%xWOdetW5iQqt8TaSrIy`Xg|of9Y^&AgMr&O* znk~D&c7Al7b$e~Su_D(m+voM=_lI&9_S4-#cW}233vKDMdi_Z2(Bfz%qppU3e%4`f z%;6C1KY;6YvbwGtXPem!Mj+YiI??O8sq}_DWY-_Xm|>3fvWAc-xuImNtFudCWpZI< zu~^9C+P}RG$>nCcKj`JxqpRO!Bd{m#eN>!UIC-*oe2b~+ey}QkHr*kZdqvTa@>%|5yP`I$)8>HhyySCT82HN8yuRrVT4q}++ zvH1abQkq&0VIF~kN^@u0!RP} zAOR$R1dzagL*Qa%y1j7X?PA&S5}rh{&q?TVN`xaE5>gqEge&Se!sFUe=X!(A_Bl#f z<7&5W=U2hxuRn3h1!0VEZZq~FrSN;HJl%ft#5j##3)i6}azckF(4$f8 zI1Y+Uo4ZYlWwu2??V4bt7{i`NSW z?tEB_&BVb%ZWc3l1l;i;<}A>Zc!2_U0e6XX!-R0pb;E!vE*N{hJ9gx*zYm@Ly>xB) z{2B1Y33UhsU;Mz=EX1^8T`5?IM-29`0^__LqdZYGzZNK(j_2=r>)o}jl z{G<7mxxZd+$!LuPkN^@u0!RP}AOR$R1dzZhOklOx){Yi&97t%xGHAp4K}e*>Jd%jm zcReShp>j$lSqCh$In!3YR@{fqD354N1od1J$v7ZXY3?fO#;yoV)K=yy?PA*xBcJ<9 zK;zR(U~+Cqf;dh{$O0Y&&=zGEbizn(B9l{6i6jUZaW!W^jA|mOBZvlYp6~+ghkn^eu9C@d z=*z>S1r6@l1vwo+P(7xJhOU3$2uUODm5k)d`Rr6EBL)wO=CEQx6OfBwZ-Vj}%i8V% zj}7HYnH=?FKlb3`MH2?0@Is#iRJyQ3L1Yn*!vH>GMzbqsaw68DA99!uOJIisd=%gb zj$Fb5PiiU>$sONFF6;l#)lL_z$F<*T53MWKFSXOwTz=P`Vukd#lP7Mhl z0VIF~kN^@u0!RP}AOR$R1jZ3qGO6`sJ>eyjD$ab?jy5UK%w>iqrI*>v(4?p`lNp+n zOQv&0gF?tuu4qu=n9K}KiWd`^p-EXH@Bb@}TAgg!hpE5_!#w{tG0gLSlg4_U|C<=*`M-%_p8uN|zTEzQ6UBW0zlq`B(4}ms literal 0 HcmV?d00001 diff --git a/NETWebAPIExam/NETWebAPIExam/ticket.db-shm b/NETWebAPIExam/NETWebAPIExam/ticket.db-shm new file mode 100644 index 0000000000000000000000000000000000000000..8b9d5a4c9d136147848c901e56fe428cf7fff7f9 GIT binary patch literal 32768 zcmeI)s|^A{5CG6Uej0hfqG2iVfi>+FHO7H%#W+>x}EOsllsf|sdlXU&LY2$`$3ke zhxEoufB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N z0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK%jJiD)d6X^iSxYz)u2k+MFQp zp8|2dq98zk009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZ JfB=EA1U`jdD8T># literal 0 HcmV?d00001 diff --git a/NETWebAPIExam/NETWebAPIExam/ticket.db-wal b/NETWebAPIExam/NETWebAPIExam/ticket.db-wal new file mode 100644 index 0000000000000000000000000000000000000000..f200cb438d496656f963dd61c312d186aadb3799 GIT binary patch literal 20632 zcmeI4J&2q|7{~W^?=IPIK?G9^>LCO3{ehs&XCYZdam#=Ra`qu&Cs-tcO(2C}f?5Sc zAzG#vC0HiGR3d4Fpsm;_KJ&&4C>9S^$??pxaLoSS|IYko-naPQJnP=ue}Ba8J~U-$gh4=nZ|5u|MH=lcH{P_|(=Znju_1Eh+*N?Bh zS)E%wz5HSM!7?oFEiNxM^FKjAjR+6{B0vO)01+SpM1Tkof#X5om7Q%>RhQx;3r29J zoewNpVOi6~8LI*hS&fa6O4jO_6vi?woMm3s%v$!g+!AlZZ#5|F{NZ~7I7CM;r z(ttcPCap2S^DMOxn_0JuF(#{`WKx9;gEL^~e z4yF-HOAS^ej8UUIF^o=D4fu5DufR?e2E+iMGub4Um560(gOASDz+{6NYoj&WXtPPuu-an8Ef9a zF2NqiPKdspyevq&akt~HxMJb<;!VI(*x;Dw(ExPaSGWWZ_ZVt)JKau~8eEVt9MNFW z;8uVgoD37*#>#bzQaO|z+_L}31>X4W?N>kj>Y5g-CYfCwCS0uOO60O;ZP0p`E}(uk_T>5pluGP(A*KjouM078#qQvUC|sCyA*v+dnaOsFDK>x=-0$zBT;SIWU*7)Y zr`JDxkPF;dUxOUr4CDcGNC>X4F0Kymzu+orM1Tko0U|&IhyW2F0z`la5CJ0as1Z28 z{IJ823t)spE`T|!G2{Z6-$fX50gQ0S1u()P7r>mTA94YVaL5HP!XX#H2!~t%BOG!8 LjBwm@0gUi3-Lk}l literal 0 HcmV?d00001 diff --git a/NETWebAPIExam/Services/RequestHandler/BookedTicketHandler/CreateBookedHandler.cs b/NETWebAPIExam/Services/RequestHandler/BookedTicketHandler/CreateBookedHandler.cs new file mode 100644 index 0000000..7ece258 --- /dev/null +++ b/NETWebAPIExam/Services/RequestHandler/BookedTicketHandler/CreateBookedHandler.cs @@ -0,0 +1,67 @@ +using Contracts.Request.BookedTicket; +using Contracts.Response.BookedTicket; +using Entity.Entity; +using MediatR; +using Microsoft.EntityFrameworkCore; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Services.RequestHandler.BookedTicketHandler +{ + public class CreateBookedHandler : IRequestHandler + { + private readonly DBContext _db; + + public CreateBookedHandler(DBContext db) + { + _db = db; + } + + public async Task Handle(CreateBookedTicketRequest request, CancellationToken cancellationToken) + { + var booked = new BookedTicket + { + BookedTicketId = Guid.NewGuid(), + Quantity = request.Quantity, + TicketId = await _db.Tickets.Where(Q=> Q.TicketCode==request.TicketCode).Select(Q => Q.TicketId).FirstOrDefaultAsync() + }; + var existingData = await _db.Tickets.Where(Q => Q.TicketCode == request.TicketCode).Select(Q => Q).FirstOrDefaultAsync(); + + _db.BookedTickets.Add(booked); + var update = existingData.Quota - request.Quantity; + existingData.Quota = update; + await _db.SaveChangesAsync(cancellationToken); + + var tdaw = await (from t in _db.Tickets + join bt in _db.BookedTickets on t.TicketId equals bt.TicketId + select new Tickets + { + Id = bt.BookedTicketId, + TicketCode = t.TicketCode, + TicketName = t.TicketName, + Price = t.Price, + }).AsNoTracking().ToListAsync(cancellationToken); + + var datas = await (from t in _db.Tickets + join bt in _db.BookedTickets on t.TicketId equals bt.TicketId + where t.TicketId == bt.TicketId + select new TicketPerCategory + { + CategoryName = t.CategoryName, + SummaryPrice = request.Quantity*t.Price, + Ticketz = tdaw + }).AsNoTracking().ToListAsync(cancellationToken); + + var response = new CreateBookedTicketResponse + { + PriceSummary = datas.Sum(x => x.SummaryPrice), + TicketPerCategories = datas + }; + + return response; + } + } +} diff --git a/NETWebAPIExam/Services/RequestHandler/BookedTicketHandler/DeleteBookedHandler.cs b/NETWebAPIExam/Services/RequestHandler/BookedTicketHandler/DeleteBookedHandler.cs new file mode 100644 index 0000000..69663ba --- /dev/null +++ b/NETWebAPIExam/Services/RequestHandler/BookedTicketHandler/DeleteBookedHandler.cs @@ -0,0 +1,59 @@ +using Contracts.Request.BookedTicket; +using Contracts.Response.BookedTicket; +using Entity.Entity; +using MediatR; +using Microsoft.EntityFrameworkCore; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Services.RequestHandler.BookedTicketHandler +{ + public class DeleteBookedHandler:IRequestHandler + { + private readonly DBContext _db; + public DeleteBookedHandler(DBContext db) + { + _db = db; + } + + public async Task Handle(DeleteBookRequesr request, CancellationToken cancellationToken) + { + var existingData = await _db.BookedTickets.Where(Q => Q.BookedTicketId == request.BookedId) + .Select(Q => Q).FirstOrDefaultAsync(); + + if (existingData == null) + { + return new DeleteBookedResponse(); + } + + var data = await (from t in _db.Tickets + join bt in _db.BookedTickets on t.TicketId equals bt.TicketId + where bt.BookedTicketId == request.BookedId + select new DeleteBookedResponse + { + Quantity = bt.Quantity-request.Quantity, + CategoryName = t.CategoryName, + TicketCode = t.TicketCode, + TicketName = t.TicketName, + }).AsNoTracking().FirstOrDefaultAsync(cancellationToken); + + existingData.Quantity -= request.Quantity; + if (data == null) + { + return new DeleteBookedResponse(); + } + + if (data.Quantity == 0) + { + _db.BookedTickets.Remove(existingData); + } + + await _db.SaveChangesAsync(cancellationToken); + var result = data; + return result; + } + } +} diff --git a/NETWebAPIExam/Services/RequestHandler/BookedTicketHandler/GetBookedHandler.cs b/NETWebAPIExam/Services/RequestHandler/BookedTicketHandler/GetBookedHandler.cs new file mode 100644 index 0000000..c64ac14 --- /dev/null +++ b/NETWebAPIExam/Services/RequestHandler/BookedTicketHandler/GetBookedHandler.cs @@ -0,0 +1,45 @@ +using Contracts.Request.BookedTicket; +using Contracts.Response.BookedTicket; +using Entity.Entity; +using MediatR; +using Microsoft.EntityFrameworkCore; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Services.RequestHandler.BookedTicketHandler +{ + public class GetBookedHandler: IRequestHandler + { + private readonly DBContext _db; + public GetBookedHandler(DBContext db) + { + _db = db; + } + + public async Task Handle(GetBookedRequest request, CancellationToken cancellationToken) + { + var data = await (from t in _db.Tickets + join bt in _db.BookedTickets on t.TicketId equals bt.TicketId + where bt.BookedTicketId == request.BookedId + select new GetBookedResponse + { + Quantity = bt.Quantity, + CategoryName = t.CategoryName, + TicketCode = t.TicketCode, + TicketName = t.TicketName, + EventDate = t.EventDate, + TotalPrice = bt.Quantity*t.Price + }).AsNoTracking().FirstOrDefaultAsync(cancellationToken); + + if (data == null) + { + return new GetBookedResponse(); + } + var result = data; + return result; + } + } +} diff --git a/NETWebAPIExam/Services/RequestHandler/Ticket/GetTicketHandler.cs b/NETWebAPIExam/Services/RequestHandler/Ticket/GetTicketHandler.cs new file mode 100644 index 0000000..8bfba99 --- /dev/null +++ b/NETWebAPIExam/Services/RequestHandler/Ticket/GetTicketHandler.cs @@ -0,0 +1,113 @@ +using Contracts.Request.Ticket; +using Contracts.Response.Ticket; +using Entity.Entity; +using MediatR; +using Microsoft.EntityFrameworkCore; +using System; +using System.Collections.Generic; +using System.Data.SqlTypes; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Services.RequestHandler.Ticket +{ + public class GetTicketHandler : IRequestHandler + { + private readonly DBContext _db; + + public GetTicketHandler(DBContext db) + { + _db = db; + } + + public async Task Handle(GetTicketRequest request, CancellationToken cancellationToken) + { + var datas = await _db.Tickets.Where(Q=> + DateTime.Compare(Q.EventDate,request.MinDate) >=0 + && DateTime.Compare(Q.EventDate, request.MaxDate) <= 0 + || Q.TicketName.Contains(request.SearchQuery) + || Q.TicketCode.Contains(request.SearchQuery) + || Q.CategoryName.Contains(request.SearchQuery) + /*|| Q.Price.Equals(Int32.Parse(request.SearchQuery))*/ + ) + .Select(Q => new DataTicket + { + EventDate = Q.EventDate, + Quota = Q.Quota, + TicketCode = Q.TicketCode, + TicketName = Q.TicketName, + CategoryName = Q.CategoryName, + Price = Q.Price, + }).OrderBy(Q => Q.TicketCode) + .AsNoTracking() + .ToListAsync(cancellationToken); + + List data = datas.OrderBy(Q => Q.TicketCode).ToList(); + + if (request.OrderState == "asc"|| request.OrderState=="ascending") + { + if (request.OrderBy == "date") + { + data = datas.OrderBy(Q => Q.EventDate).ToList(); + } + else if (request.OrderBy == "quta") + { + data = datas.OrderBy(Q => Q.Quota).ToList(); + } + else if (request.OrderBy == "code") + { + data = datas.OrderBy(Q => Q.TicketCode).ToList(); + } + else if (request.OrderBy == "name") + { + data = datas.OrderBy(Q => Q.TicketName).ToList(); + } + else if (request.OrderBy == "category") + { + data = datas.OrderBy(Q => Q.CategoryName).ToList(); + } + else if (request.OrderBy == "price") + { + data = datas.OrderBy(Q => Q.Price).ToList(); + } + } + else if (request.OrderState == "desc" || request.OrderState == "descending") + { + data = datas.OrderByDescending(Q => Q.TicketCode).ToList(); + if (request.OrderBy == "date") + { + data = datas.OrderByDescending(Q => Q.EventDate).ToList(); + } + else if (request.OrderBy == "quta") + { + data = datas.OrderByDescending(Q => Q.Quota).ToList(); + } + else if (request.OrderBy == "code") + { + data = datas.OrderByDescending(Q => Q.TicketCode).ToList(); + } + else if (request.OrderBy == "name") + { + data = datas.OrderByDescending(Q => Q.TicketName).ToList(); + } + else if (request.OrderBy == "category") + { + data = datas.OrderByDescending(Q => Q.CategoryName).ToList(); + } + else if (request.OrderBy == "price") + { + data = datas.OrderByDescending(Q => Q.Price).ToList(); + } + } + + var response = new GetTicketResponse + { + Tickets = data, + TotalTickets = data.Count + }; + + return response; + } + } +} diff --git a/NETWebAPIExam/Services/Services.csproj b/NETWebAPIExam/Services/Services.csproj new file mode 100644 index 0000000..178a4d7 --- /dev/null +++ b/NETWebAPIExam/Services/Services.csproj @@ -0,0 +1,21 @@ + + + + net8.0 + enable + enable + + + + + + + + + + + + + + + diff --git a/NETWebAPIExam/Services/Validators/CreateBookedValidator.cs b/NETWebAPIExam/Services/Validators/CreateBookedValidator.cs new file mode 100644 index 0000000..0673f53 --- /dev/null +++ b/NETWebAPIExam/Services/Validators/CreateBookedValidator.cs @@ -0,0 +1,47 @@ +using Contracts.Request.BookedTicket; +using Entity.Entity; +using FluentValidation; +using Microsoft.EntityFrameworkCore; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Services.Validators +{ + public class CreateBookedValidator: AbstractValidator + { + private readonly DBContext _db; + + public CreateBookedValidator(DBContext db) + { + _db = db; + + RuleFor(Q => Q.Quantity).NotEmpty().WithMessage("Quantity cannot be empty.") + .MustAsync(CheckQuota).WithMessage("Quantity cannot exceed quota!") + .GreaterThan(0).WithMessage("Quantity cannot be minus!"); + + RuleFor(Q => Q.TicketCode) + .NotEmpty().WithMessage("Ticket code cannot be empty.") + .MustAsync(CheckTicketCode).WithMessage("Ticket code cannot be found!"); + } + public async Task CheckTicketCode(string code, CancellationToken cancellationToken) + { + var idExist = await _db.Tickets.Where(Q => Q.TicketCode == code) + .AsNoTracking() + .AnyAsync(cancellationToken); + + return idExist; + } + + public async Task CheckQuota(int quota, CancellationToken cancellationToken) + { + var idExist = await _db.Tickets.Where(Q => Q.Quota < quota ) + .AsNoTracking() + .AnyAsync(cancellationToken); + + return !idExist; + } + } +} diff --git a/NETWebAPIExam/Services/Validators/DeleteBookedValidator.cs b/NETWebAPIExam/Services/Validators/DeleteBookedValidator.cs new file mode 100644 index 0000000..c756a42 --- /dev/null +++ b/NETWebAPIExam/Services/Validators/DeleteBookedValidator.cs @@ -0,0 +1,57 @@ +using Contracts.Request.BookedTicket; +using Entity.Entity; +using FluentValidation; +using Microsoft.EntityFrameworkCore; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Services.Validators +{ + public class DeleteBookedValidator: AbstractValidator + { + private readonly DBContext _db; + public DeleteBookedValidator(DBContext db) + { + _db = db; + RuleFor(Q => Q.BookedId) + .NotEmpty().WithMessage("Booked id cannot be empty.") + .MustAsync(CheckBookedId).WithMessage("Booked id cannot be found!"); + RuleFor(Q => Q.TicketCode) + .NotEmpty().WithMessage("Ticket code cannot be empty.") + .MustAsync(CheckTicketCode).WithMessage("Ticket code cannot be found!"); + RuleFor(Q => Q.Quantity).NotEmpty().WithMessage("Quantity cannot be empty.") + .MustAsync(CheckQuotaDelete).WithMessage("Quantity cannot exceed quantity of booked tickets!") + .GreaterThan(0).WithMessage("Quantity cannot be minus!"); + } + + public async Task CheckBookedId(Guid id, CancellationToken cancellationToken) + { + var idExist = await _db.BookedTickets.Where(Q => Q.BookedTicketId == id) + .AsNoTracking() + .AnyAsync(cancellationToken); + + return idExist; + } + + public async Task CheckTicketCode(string code, CancellationToken cancellationToken) + { + var idExist = await _db.Tickets.Where(Q => Q.TicketCode == code) + .AsNoTracking() + .AnyAsync(cancellationToken); + + return idExist; + } + + public async Task CheckQuotaDelete(int quota, CancellationToken cancellationToken) + { + var idExist = await _db.BookedTickets.Where(Q => Q.Quantity < quota) + .AsNoTracking() + .AnyAsync(cancellationToken); + + return !idExist; + } + } +} diff --git a/NETWebAPIExam/Services/Validators/GetBookedValidator.cs b/NETWebAPIExam/Services/Validators/GetBookedValidator.cs new file mode 100644 index 0000000..5f59016 --- /dev/null +++ b/NETWebAPIExam/Services/Validators/GetBookedValidator.cs @@ -0,0 +1,33 @@ +using Contracts.Request.BookedTicket; +using Entity.Entity; +using FluentValidation; +using Microsoft.EntityFrameworkCore; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Services.Validators +{ + public class GetBookedValidator: AbstractValidator + { + private readonly DBContext _db; + public GetBookedValidator(DBContext db) + { + _db = db; + RuleFor(Q => Q.BookedId) + .NotEmpty().WithMessage("Booked id cannot be empty.") + .MustAsync(CheckBookedId).WithMessage("Booked id cannot be found!"); + } + + public async Task CheckBookedId(Guid id, CancellationToken cancellationToken) + { + var idExist = await _db.BookedTickets.Where(Q => Q.BookedTicketId == id) + .AsNoTracking() + .AnyAsync(cancellationToken); + + return idExist; + } + } +}