-
Notifications
You must be signed in to change notification settings - Fork 0
Created 6 models and corresponding controllers enabling CRUD operations #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
## Ignore Visual Studio user-specific files | ||
*.suo | ||
*.user | ||
*.userosscache | ||
*.sln.docstates | ||
|
||
## Ignore Visual Studio 2015+ cache directory | ||
.vs/ | ||
|
||
## Ignore build results | ||
[Bb]in/ | ||
[Oo]bj/ | ||
[Ll]og/ | ||
[Dd]ebug*/ | ||
[Rr]elease*/ | ||
|
||
## Ignore test results | ||
[Tt]est[Rr]esult*/ | ||
[Bb]uild[Ll]og.* | ||
|
||
## Ignore NuGet packages | ||
*.nupkg | ||
/packages/ | ||
*.nuget.props | ||
*.nuget.targets | ||
|
||
## Ignore Click-Once publish directory | ||
publish/ | ||
|
||
## Ignore Azure publish settings | ||
*.publishproj | ||
*.azurePubxml | ||
#*.pubxml | ||
PublishScripts/ | ||
|
||
## Ignore temporary files | ||
*.tmp | ||
*.log | ||
|
||
## Ignore database files | ||
*.mdf | ||
*.ldf | ||
|
||
## Ignore VSCode settings (optional, if you're using VSCode too) | ||
.vscode/ | ||
|
||
## OS-specific files | ||
.DS_Store |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
using LabProject.Enums; | ||
using LabProject.Models; | ||
using Microsoft.AspNetCore.Mvc; | ||
|
||
namespace LabProject.Controllers | ||
{ | ||
[Route("api/[controller]")] | ||
[ApiController] | ||
public class AppointmentController : ControllerBase | ||
{ | ||
private static List<Appointment> Appointments = new List<Appointment> | ||
{ | ||
new Appointment { Id = 1, ClientId = 1, ProviderId = 1, ServiceId = 1, LocationId = 1, DateTime = DateTime.Today, Status = AppointmentStatus.Completed }, | ||
new Appointment { Id = 2, ClientId = 2, ProviderId = 1, ServiceId = 2, LocationId = 1, DateTime = DateTime.Today.AddDays(1) } | ||
}; | ||
|
||
/// <summary> | ||
/// Gets all appointments in the system. | ||
/// </summary> | ||
/// <returns>A list of all appointments.</returns> | ||
/// <response code="200">Returns the list of all appointments.</response> | ||
[HttpGet] | ||
public ActionResult<IEnumerable<Appointment>> GetAppointments() | ||
{ | ||
return Ok(Appointments); | ||
} | ||
|
||
/// <summary> | ||
/// Gets a specific appointment by ID. | ||
/// </summary> | ||
/// <param name="id">The unique identifier of the appointment.</param> | ||
/// <returns>The requested appointment.</returns> | ||
/// <response code="200">Returns the appointment with the given ID.</response> | ||
/// <response code="404">No appointment found with the specified ID.</response> | ||
[HttpGet("{id}")] | ||
public ActionResult<Appointment> GetAppointmentById([FromRoute] int id) | ||
{ | ||
var appointment = Appointments.FirstOrDefault(a => a.Id == id); | ||
if (appointment is null) | ||
{ | ||
return NotFound(); | ||
} | ||
return Ok(appointment); | ||
} | ||
|
||
/// <summary> | ||
/// Creates a new appointment. | ||
/// </summary> | ||
/// <param name="appointment">The appointment object to create.</param> | ||
/// <returns>The created appointment.</returns> | ||
/// <response code="201">The appointment was created successfully.</response> | ||
[HttpPost] | ||
public ActionResult<Appointment> CreateAppointment([FromBody] Appointment appointment) | ||
{ | ||
appointment.Id = Appointments.Any() ? Appointments.Max(a => a.Id) + 1 : 1; | ||
Appointments.Add(appointment); | ||
return CreatedAtAction(nameof(GetAppointmentById), new { id = appointment.Id }, appointment); | ||
} | ||
|
||
/// <summary> | ||
/// Updates an existing appointment. | ||
/// </summary> | ||
/// <param name="id">The ID of the appointment to update.</param> | ||
/// <param name="updatedAppointment">The updated appointment data.</param> | ||
/// <returns>The updated appointment.</returns> | ||
/// <response code="200">The appointment was updated successfully.</response> | ||
/// <response code="404">No appointment found with the specified ID.</response> | ||
[HttpPut("{id}")] | ||
public ActionResult UpdateAppointment([FromRoute] int id, [FromBody] Appointment updatedAppointment) | ||
{ | ||
var appointment = Appointments.FirstOrDefault(a => a.Id == id); | ||
if (appointment is null) | ||
{ | ||
return NotFound(); | ||
} | ||
|
||
appointment.ClientId = updatedAppointment.ClientId; | ||
appointment.ProviderId = updatedAppointment.ProviderId; | ||
appointment.ServiceId = updatedAppointment.ServiceId; | ||
appointment.LocationId = updatedAppointment.LocationId; | ||
appointment.DateTime = updatedAppointment.DateTime; | ||
appointment.Status = updatedAppointment.Status; | ||
|
||
return Ok(appointment); | ||
} | ||
|
||
/// <summary> | ||
/// Deletes an appointment by ID. | ||
/// </summary> | ||
/// <param name="id">The unique identifier of the appointment to delete.</param> | ||
/// <returns>Status of the deletion.</returns> | ||
/// <response code="200">The appointment was deleted successfully.</response> | ||
/// <response code="404">No appointment found with the specified ID.</response> | ||
[HttpDelete("{id}")] | ||
public ActionResult DeleteAppointment([FromRoute] int id) | ||
{ | ||
var appointment = Appointments.FirstOrDefault(a => a.Id == id); | ||
if (appointment is null) | ||
{ | ||
return NotFound(); | ||
} | ||
|
||
Appointments.Remove(appointment); | ||
return Ok(); | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
using LabProject.Models; | ||
using Microsoft.AspNetCore.Mvc; | ||
|
||
namespace LabProject.Controllers | ||
{ | ||
[Route("api/[controller]")] | ||
[ApiController] | ||
public class ClientController : ControllerBase | ||
{ | ||
private static List<Client> Clients = new List<Client> | ||
{ | ||
new Client {Id = 1, Name = "Mary Sue", EmailAddress = "[email protected]", Phone = "123456789"}, | ||
new Client {Id = 2, Name = "Jane Doe", EmailAddress = "[email protected]", Phone = "987654321"} | ||
}; | ||
|
||
/// <summary> | ||
/// Gets all clients in the system. | ||
/// </summary> | ||
/// <returns>A list of all clients.</returns> | ||
/// <response code="200">Returns the list of all clients.</response> | ||
[HttpGet] | ||
public ActionResult<IEnumerable<Client>> GetClients() | ||
{ | ||
return Ok(Clients); | ||
} | ||
|
||
/// <summary> | ||
/// Gets a specific client by ID. | ||
/// </summary> | ||
/// <param name="id">The unique identifier of the client.</param> | ||
/// <returns>The requested client.</returns> | ||
/// <response code="200">Returns the client with the given ID.</response> | ||
/// <response code="404">No client found with the specified ID.</response> | ||
[HttpGet("{id}")] | ||
public ActionResult<Client> GetClientById([FromRoute] int id) | ||
{ | ||
var client = Clients.FirstOrDefault(c => c.Id == id); | ||
if (client is null) | ||
{ | ||
return NotFound(); | ||
} | ||
return Ok(client); | ||
} | ||
|
||
/// <summary> | ||
/// Creates a new client. | ||
/// </summary> | ||
/// <param name="client">The client data to create.</param> | ||
/// <returns>The created client.</returns> | ||
/// <response code="201">The client was created successfully.</response> | ||
[HttpPost] | ||
public ActionResult<Client> CreateClient([FromBody] Client client) | ||
{ | ||
client.Id = Clients.Any() ? Clients.Max(c => c.Id) + 1 : 1; | ||
Clients.Add(client); | ||
return CreatedAtAction(nameof(GetClientById), new { id = client.Id }, client); | ||
} | ||
|
||
/// <summary> | ||
/// Updates an existing client. | ||
/// </summary> | ||
/// <param name="id">The ID of the client to update.</param> | ||
/// <param name="client">The updated client data.</param> | ||
/// <returns>The updated client.</returns> | ||
/// <response code="200">The client was updated successfully.</response> | ||
/// <response code="404">No client found with the specified ID.</response> | ||
[HttpPut("{id}")] | ||
public ActionResult UpdateClient([FromRoute] int id, [FromBody] Client client) | ||
{ | ||
var clientToUpdate = Clients.FirstOrDefault(c => c.Id == id); | ||
if (clientToUpdate is null) | ||
{ | ||
return NotFound(); | ||
} | ||
clientToUpdate.Name = client.Name; | ||
clientToUpdate.EmailAddress = client.EmailAddress; | ||
clientToUpdate.Phone = client.Phone; | ||
return Ok(clientToUpdate); | ||
} | ||
|
||
/// <summary> | ||
/// Deletes a client by its ID. | ||
/// </summary> | ||
/// <param name="id">The unique identifier of the client to delete.</param> | ||
/// <returns>Status of the deletion.</returns> | ||
/// <response code="200">The client was deleted successfully.</response> | ||
/// <response code="404">No client found with the specified ID.</response> | ||
[HttpDelete("{id}")] | ||
public ActionResult DeleteClient([FromRoute] int id) | ||
{ | ||
var client = Clients.FirstOrDefault(c => c.Id == id); | ||
if (client is null) | ||
{ | ||
return NotFound(); | ||
} | ||
Clients.Remove(client); | ||
return Ok(); | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
using LabProject.Models; | ||
using Microsoft.AspNetCore.Mvc; | ||
|
||
namespace LabProject.Controllers | ||
{ | ||
[Route("api/[controller]")] | ||
[ApiController] | ||
public class LocationController : ControllerBase | ||
{ | ||
private static List<Location> Locations = new List<Location> | ||
{ | ||
new Location {Id = 1, Name = "Best Beauty", Address = "Main street 12", City = "Gdansk", Phone = "123456789"}, | ||
new Location {Id = 2, Name = "New you", Address = "City square", City = "Warsaw", Phone = "987654321"}, | ||
}; | ||
|
||
/// <summary> | ||
/// Gets all locations in the system. | ||
/// </summary> | ||
/// <returns>A list of all locations.</returns> | ||
/// <response code="200">Returns the list of all locations.</response> | ||
[HttpGet] | ||
public ActionResult<IEnumerable<Location>> GetLocations() | ||
{ | ||
return Ok(Locations); | ||
} | ||
|
||
/// <summary> | ||
/// Retrieves a specific location by its ID. | ||
/// </summary> | ||
/// <param name="id">The unique identifier of the location.</param> | ||
/// <returns>The location matching the ID.</returns> | ||
/// <response code="200">Returns the location with the specified ID.</response> | ||
/// <response code="404">No location found with the specified ID.</response> | ||
[HttpGet("{id}")] | ||
public ActionResult<Location> GetLocationById([FromRoute] int id) | ||
{ | ||
var location = Locations.FirstOrDefault(l => l.Id == id); | ||
if (location is null) | ||
{ | ||
return NotFound(); | ||
} | ||
return Ok(location); | ||
} | ||
|
||
/// <summary> | ||
/// Creates a new location. | ||
/// </summary> | ||
/// <param name="location">The location data to create.</param> | ||
/// <returns>The created location.</returns> | ||
/// <response code="201">The location was created successfully.</response> | ||
[HttpPost] | ||
public ActionResult<Location> CreateLocation([FromBody] Location location) | ||
{ | ||
location.Id = Locations.Any() ? Locations.Max(l => l.Id) + 1 : 1; | ||
Locations.Add(location); | ||
return CreatedAtAction(nameof(GetLocationById), new { id = location.Id }, location); | ||
} | ||
|
||
/// <summary> | ||
/// Updates an existing location. | ||
/// </summary> | ||
/// <param name="id">The ID of the location to update.</param> | ||
/// <param name="location">The updated location data.</param> | ||
/// <returns>The updated location.</returns> | ||
/// <response code="200">The location was updated successfully.</response> | ||
/// <response code="404">No location found with the specified ID.</response> | ||
[HttpPut("{id}")] | ||
public ActionResult UpdateLocation([FromRoute] int id, [FromBody] Location location) | ||
{ | ||
var locationToUpdate = Locations.FirstOrDefault(l => l.Id == id); | ||
if (locationToUpdate is null) | ||
{ | ||
return NotFound(); | ||
} | ||
|
||
locationToUpdate.Name = location.Name; | ||
locationToUpdate.Address = location.Address; | ||
locationToUpdate.City = location.City; | ||
locationToUpdate.Phone = location.Phone; | ||
|
||
return Ok(locationToUpdate); | ||
} | ||
|
||
/// <summary> | ||
/// Deletes a location by its ID. | ||
/// </summary> | ||
/// <param name="id">The unique identifier of the location to delete.</param> | ||
/// <returns>Status of the deletion.</returns> | ||
/// <response code="200">The location was deleted successfully.</response> | ||
/// <response code="404">No location found with the specified ID.</response> | ||
[HttpDelete("{id}")] | ||
public ActionResult DeleteLocation([FromRoute] int id) | ||
{ | ||
var location = Locations.FirstOrDefault(l => l.Id == id); | ||
if (location is null) | ||
{ | ||
return NotFound(); | ||
} | ||
|
||
Locations.Remove(location); | ||
return Ok(); | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
well. With such git ignore file we can't work. I'd suggest smth like this
`## Ignore Visual Studio temporary files, build results, and
files generated by popular Visual Studio add-ons.
User-specific files
*.vs
*.suo
*.user
*.userosscache
*.sln.docstates
User-specific files (MonoDevelop/Xamarin Studio)
*.userprefs
Build results
[Dd]ebug/
[Dd]ebugPublic/
[Rr]elease/
[Rr]eleases/
x64/
x86/
bld/
[Bb]in/
[Oo]bj/
[Ll]og/
Visual Studio 2015 cache/options directory
.vs/
Uncomment if you have tasks that create the project's static files in wwwroot
#wwwroot/
MSTest test Results
[Tt]est[Rr]esult*/
[Bb]uild[Ll]og.*
NUNIT
*.VisualState.xml
TestResult.xml
Build Results of an ATL Project
[Dd]ebugPS/
[Rr]eleasePS/
dlldata.c
DNX
project.lock.json
artifacts/
*_i.c
*_p.c
*_i.h
*.ilk
*.meta
*.obj
*.pch
*.pdb
*.pgc
*.pgd
*.rsp
*.sbr
*.tlb
*.tli
*.tlh
*.tmp
*.tmp_proj
*.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
TFS 2012 Local Workspace
$tf/
Guidance Automation Toolkit
*.gpState
ReSharper is a .NET coding add-in
_ReSharper*/
*.[Rr]e[Ss]harper
*.DotSettings.user
JustCode is a .NET coding add-in
.JustCode
TeamCity is a build add-in
_TeamCity*
DotCover is a Code Coverage Tool
*.dotCover
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
TODO: Comment the next line if you want to checkin your web deploy settings
but database connection strings (with potential passwords) will be unencrypted
#*.pubxml
*.publishproj
Microsoft Azure Web App publish settings. Comment the next line if you want to
checkin your Azure Web App publish settings, but sensitive information contained
in these scripts will be unencrypted
PublishScripts/
NuGet Packages
*.nupkg
The packages folder can be ignored because of Package Restore
*/packages/
except build/, which is used as an MSBuild target.
!**/packages/build/
Uncomment if necessary however generally it will be regenerated when needed
#!**/packages/repositories.config
NuGet v3's project.json files produces more ignoreable 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
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
*.pfx
*.publishsettings
node_modules/
orleans.codegen.cs
Since there are multiple workflows, uncomment next line to ignore bower_components
(github/gitignore#1529 (comment))
#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
SQL Server files
*.mdf
*.ldf
Business Intelligence projects
*.rdl.data
*.bim.layout
.bim_.settings
Microsoft Fakes
FakesAssemblies/
GhostDoc plugin setting file
*.GhostDoc.xml
Node.js Tools for Visual Studio
.ntvs_analysis.dat
Visual Studio 6 build log
*.plg
Visual Studio 6 workspace options file
*.opt
Visual Studio LightSwitch build output
**/.HTMLClient/GeneratedArtifacts
**/.DesktopClient/GeneratedArtifacts
**/.DesktopClient/ModelManifest.xml
**/.Server/GeneratedArtifacts
**/*.Server/ModelManifest.xml
_Pvt_Extensions
Paket dependency manager
.paket/paket.exe
paket-files/
FAKE - F# Make
.fake/
JetBrains Rider
.idea/
*.sln.iml
Visual Studio Database Projects
*.jfm
SonarQube local files
.sonarqube
/src/.cr/personal/FavoritesList
.vscode/
.DS_Store
`