-
Notifications
You must be signed in to change notification settings - Fork 90
Finished project #121
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
Closed
Closed
Finished project #121
Changes from all commits
Commits
Show all changes
2 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,31 @@ | ||
| # Shifts Logger WebAPI | ||
|
|
||
| ## Overview | ||
|
|
||
| A WebAPI + Console application pair that uses http request to access WebAPI data | ||
| and display that data to the user | ||
|
|
||
| ## Requirements | ||
|
|
||
| - WebAPI should record a worker's shifts | ||
| - Should create two applications: a WebAPI and Console UI | ||
| - Validation should occur in UI App | ||
| - API controller should be lean | ||
| - Should use Code-First Approach | ||
| - Shift duration should be calculated based off start and end of shift | ||
|
|
||
| ## Technologies | ||
|
|
||
| - C# | ||
| - Sqlite | ||
| - Spectre.Console | ||
| - EF Core | ||
|
|
||
| ## Looking back | ||
|
|
||
| - Felt pretty similar to previous projects. The exposure to WebAPIs in previous projects before creating my own really helped understand what was going on | ||
| - UI was fairly simple this time around as I had gotten used to planning it in previous projects. I was able to plan it quicker this time | ||
| - Got stuck with Http requests as I didn't know there were different methods that were needed for POST, PUT, and DELETE. Was pretty simple after finding that out | ||
| - Testing with Postman and swagger really helped with understanding how http requests work | ||
| - Feel like i need to study more on the builder methods in the WebAPI program.cs file. Still a little confused on what and why each method is called | ||
|
|
59 changes: 59 additions & 0 deletions
59
ShiftsLogger.WebAPI.davetn657/Controllers/ShiftsController.cs
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,59 @@ | ||
| using Microsoft.AspNetCore.Mvc; | ||
| using ShiftsLogger.WebAPI.davetn657.Data; | ||
| using ShiftsLogger.WebAPI.davetn657.Services; | ||
|
|
||
| namespace ShiftsLogger.WebAPI.davetn657.Controllers | ||
| { | ||
| [ApiController] | ||
| [Route("api/[controller]")] | ||
| public class ShiftsController : ControllerBase | ||
| { | ||
| private readonly ILoggingService _loggingService; | ||
| public ShiftsController(ILoggingService loggingService) | ||
| { | ||
| _loggingService = loggingService; | ||
| } | ||
|
|
||
| [HttpGet] | ||
| public ActionResult<List<Shift>> GetAllShifts() | ||
| { | ||
| return Ok(_loggingService.GetAllShifts()); | ||
| } | ||
|
|
||
| [HttpGet("{id}")] | ||
| public ActionResult<Shift> GetShiftById(int id) | ||
| { | ||
| var result = _loggingService.GetShiftById(id); | ||
|
|
||
| if (result == null) return NotFound(); | ||
|
|
||
| return Ok(result); | ||
| } | ||
|
|
||
| [HttpPost] | ||
| public ActionResult<Shift> CreateShift(Shift shift) | ||
| { | ||
| return Ok(_loggingService.CreateShift(shift)); | ||
| } | ||
|
|
||
| [HttpPut("{id}")] | ||
| public ActionResult<Shift> UpdateShift(int id, Shift updatedShift) | ||
| { | ||
| var result = _loggingService.UpdateShift(id, updatedShift); | ||
|
|
||
| if (result == null) return NotFound(); | ||
|
|
||
| return Ok(result); | ||
| } | ||
|
|
||
| [HttpDelete("{id}")] | ||
| public ActionResult<string> DeleteShift(int id) | ||
| { | ||
| var result = _loggingService.DeleteShift(id); | ||
|
|
||
| if (result == null) return NotFound(); | ||
|
|
||
| return Ok(result); | ||
| } | ||
| } | ||
| } | ||
49 changes: 49 additions & 0 deletions
49
ShiftsLogger.WebAPI.davetn657/Data/Migrations/20260313150020_InitalCreate.Designer.cs
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
38 changes: 38 additions & 0 deletions
38
ShiftsLogger.WebAPI.davetn657/Data/Migrations/20260313150020_InitalCreate.cs
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,38 @@ | ||
| using System; | ||
| using Microsoft.EntityFrameworkCore.Migrations; | ||
|
|
||
| #nullable disable | ||
|
|
||
| namespace ShiftsLogger.WebAPI.davetn657.Data.Migrations | ||
| { | ||
| /// <inheritdoc /> | ||
| public partial class InitalCreate : Migration | ||
| { | ||
| /// <inheritdoc /> | ||
| protected override void Up(MigrationBuilder migrationBuilder) | ||
| { | ||
| migrationBuilder.CreateTable( | ||
| name: "Shifts", | ||
| columns: table => new | ||
| { | ||
| Id = table.Column<int>(type: "INTEGER", nullable: false) | ||
| .Annotation("Sqlite:Autoincrement", true), | ||
| LoggerName = table.Column<string>(type: "TEXT", nullable: false), | ||
| ShiftStart = table.Column<DateTime>(type: "TEXT", nullable: false), | ||
| ShiftEnd = table.Column<DateTime>(type: "TEXT", nullable: false), | ||
| Duration = table.Column<DateTime>(type: "TEXT", nullable: false) | ||
| }, | ||
| constraints: table => | ||
| { | ||
| table.PrimaryKey("PK_Shifts", x => x.Id); | ||
| }); | ||
| } | ||
|
|
||
| /// <inheritdoc /> | ||
| protected override void Down(MigrationBuilder migrationBuilder) | ||
| { | ||
| migrationBuilder.DropTable( | ||
| name: "Shifts"); | ||
| } | ||
| } | ||
| } |
49 changes: 49 additions & 0 deletions
49
ShiftsLogger.WebAPI.davetn657/Data/Migrations/20260317031559_DurationToTimeSpan.Designer.cs
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
55 changes: 55 additions & 0 deletions
55
ShiftsLogger.WebAPI.davetn657/Data/Migrations/20260317031559_DurationToTimeSpan.cs
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,55 @@ | ||
| using System; | ||
| using Microsoft.EntityFrameworkCore.Migrations; | ||
|
|
||
| #nullable disable | ||
|
|
||
| namespace ShiftsLogger.WebAPI.davetn657.Data.Migrations | ||
| { | ||
| /// <inheritdoc /> | ||
| public partial class DurationToTimeSpan : Migration | ||
| { | ||
| /// <inheritdoc /> | ||
| protected override void Up(MigrationBuilder migrationBuilder) | ||
| { | ||
| migrationBuilder.AlterColumn<DateTime>( | ||
| name: "ShiftStart", | ||
| table: "Shifts", | ||
| type: "TEXT", | ||
| nullable: true, | ||
| oldClrType: typeof(DateTime), | ||
| oldType: "TEXT"); | ||
|
|
||
| migrationBuilder.AlterColumn<DateTime>( | ||
| name: "ShiftEnd", | ||
| table: "Shifts", | ||
| type: "TEXT", | ||
| nullable: true, | ||
| oldClrType: typeof(DateTime), | ||
| oldType: "TEXT"); | ||
| } | ||
|
|
||
| /// <inheritdoc /> | ||
| protected override void Down(MigrationBuilder migrationBuilder) | ||
| { | ||
| migrationBuilder.AlterColumn<DateTime>( | ||
| name: "ShiftStart", | ||
| table: "Shifts", | ||
| type: "TEXT", | ||
| nullable: false, | ||
| defaultValue: new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified), | ||
| oldClrType: typeof(DateTime), | ||
| oldType: "TEXT", | ||
| oldNullable: true); | ||
|
|
||
| migrationBuilder.AlterColumn<DateTime>( | ||
| name: "ShiftEnd", | ||
| table: "Shifts", | ||
| type: "TEXT", | ||
| nullable: false, | ||
| defaultValue: new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified), | ||
| oldClrType: typeof(DateTime), | ||
| oldType: "TEXT", | ||
| oldNullable: true); | ||
| } | ||
| } | ||
| } |
49 changes: 49 additions & 0 deletions
49
ShiftsLogger.WebAPI.davetn657/Data/Migrations/20260317120707_TimespanNullable.Designer.cs
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
37 changes: 37 additions & 0 deletions
37
ShiftsLogger.WebAPI.davetn657/Data/Migrations/20260317120707_TimespanNullable.cs
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,37 @@ | ||
| using System; | ||
| using Microsoft.EntityFrameworkCore.Migrations; | ||
|
|
||
| #nullable disable | ||
|
|
||
| namespace ShiftsLogger.WebAPI.davetn657.Data.Migrations | ||
| { | ||
| /// <inheritdoc /> | ||
| public partial class TimespanNullable : Migration | ||
| { | ||
| /// <inheritdoc /> | ||
| protected override void Up(MigrationBuilder migrationBuilder) | ||
| { | ||
| migrationBuilder.AlterColumn<TimeSpan>( | ||
| name: "Duration", | ||
| table: "Shifts", | ||
| type: "TEXT", | ||
| nullable: true, | ||
| oldClrType: typeof(TimeSpan), | ||
| oldType: "TEXT"); | ||
| } | ||
|
|
||
| /// <inheritdoc /> | ||
| protected override void Down(MigrationBuilder migrationBuilder) | ||
| { | ||
| migrationBuilder.AlterColumn<TimeSpan>( | ||
| name: "Duration", | ||
| table: "Shifts", | ||
| type: "TEXT", | ||
| nullable: false, | ||
| defaultValue: new TimeSpan(0, 0, 0, 0, 0), | ||
| oldClrType: typeof(TimeSpan), | ||
| oldType: "TEXT", | ||
| oldNullable: true); | ||
| } | ||
| } | ||
| } |
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.
🟢 Lean API Controller
⭐ The controller follows best practices - it's thin and delegates to the service layer. Well done!