From 10c1bb008f4286395cdb1df710b9eed91b64aa90 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torma=20Krist=C3=B3f?= Date: Thu, 20 May 2021 01:36:54 +0200 Subject: [PATCH] final --- HanyadikHetVan.postman_environment.json | 49 +++ .../Controllers/V2/FunFactController.cs | 38 ++ .../Controllers/V2/PauseController.cs | 8 +- .../Controllers/V2/UserController.cs | 46 +++ HanyadikHetVan/DTO/FunFactDTO.cs | 2 + HanyadikHetVan/Data/ApplicationDbContext.cs | 18 + ...19232012_ChangeCascadeBehavior.Designer.cs | 383 ++++++++++++++++++ .../20210519232012_ChangeCascadeBehavior.cs | 61 +++ .../ApplicationDbContextModelSnapshot.cs | 7 +- HanyadikHetVan/Profiles/FunFactProfile.cs | 2 +- HanyadikHetVan/Services/FunFactService.cs | 25 ++ HanyadikHetVan/Services/PauseService.cs | 10 +- HanyadikHetVan/Services/UserService.cs | 10 +- .../Services/WeeklyTimeSpanService.cs | 8 +- HanyadikHetVan/Startup.cs | 1 + Insomnia.json | 2 +- PartOne.postman_collection.json | 343 ++++++++++++++++ PartThree.postman_collection.json | 335 +++++++++++++++ PartTwo.postman_collection.json | 303 ++++++++++++++ 19 files changed, 1632 insertions(+), 19 deletions(-) create mode 100644 HanyadikHetVan.postman_environment.json create mode 100644 HanyadikHetVan/Controllers/V2/UserController.cs create mode 100644 HanyadikHetVan/Data/Migrations/20210519232012_ChangeCascadeBehavior.Designer.cs create mode 100644 HanyadikHetVan/Data/Migrations/20210519232012_ChangeCascadeBehavior.cs create mode 100644 PartOne.postman_collection.json create mode 100644 PartThree.postman_collection.json create mode 100644 PartTwo.postman_collection.json diff --git a/HanyadikHetVan.postman_environment.json b/HanyadikHetVan.postman_environment.json new file mode 100644 index 0000000..e3a7980 --- /dev/null +++ b/HanyadikHetVan.postman_environment.json @@ -0,0 +1,49 @@ +{ + "id": "096c7048-9d56-4e98-8c69-4c8d01dbb115", + "name": "HanyadikHetVan", + "values": [ + { + "key": "token", + "value": "", + "enabled": true + }, + { + "key": "wtsid", + "value": "", + "enabled": true + }, + { + "key": "pauseid", + "value": "", + "enabled": true + }, + { + "key": "admin_username", + "value": "testuser", + "enabled": true + }, + { + "key": "admin_password", + "value": "Alma123.", + "enabled": true + }, + { + "key": "username", + "value": "123test@tester.com", + "enabled": true + }, + { + "key": "password", + "value": "asdfghjkl123456789.A", + "enabled": true + }, + { + "key": "ffid", + "value": "", + "enabled": true + } + ], + "_postman_variable_scope": "environment", + "_postman_exported_at": "2021-05-19T23:36:24.220Z", + "_postman_exported_using": "Postman/8.4.0" +} \ No newline at end of file diff --git a/HanyadikHetVan/Controllers/V2/FunFactController.cs b/HanyadikHetVan/Controllers/V2/FunFactController.cs index de9d8c9..0139536 100644 --- a/HanyadikHetVan/Controllers/V2/FunFactController.cs +++ b/HanyadikHetVan/Controllers/V2/FunFactController.cs @@ -1,10 +1,12 @@ using HanyadikHetVan.DTO; using HanyadikHetVan.Services; +using Microsoft.AspNetCore.Authentication.JwtBearer; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using System; using System.Collections.Generic; +using System.Net.Mime; using System.Threading.Tasks; namespace HanyadikHetVan.Controllers.V2 @@ -52,5 +54,41 @@ namespace HanyadikHetVan.Controllers.V2 return NotFound(); } } + + [HttpDelete("{funfactId}")] + [Authorize(Policy = "AdminPolicy", AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)] + [ProducesResponseType(StatusCodes.Status200OK, Type = typeof(bool))] + [ProducesResponseType(StatusCodes.Status404NotFound)] + [ProducesResponseType(StatusCodes.Status401Unauthorized)] + public async Task DeleteFunFact(int funfactId) + { + var result = await _funfactService.DeleteFunFact(funfactId); + if (result) + { + return Ok(result); + } + else + { + return NotFound(); + } + } + [HttpPut("{funfactId}")] + [Authorize(Policy = "AdminPolicy", AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)] + [Consumes(MediaTypeNames.Application.Json)] + [ProducesResponseType(StatusCodes.Status200OK, Type = typeof(FunFactDTO))] + [ProducesResponseType(StatusCodes.Status404NotFound)] + [ProducesResponseType(StatusCodes.Status401Unauthorized)] + public async Task UpdatePause(int funfactId, [FromBody] FunFactDTO funfact) + { + try + { + var obj = await _funfactService.UpdateFunFact(funfactId, funfact); + return Ok(obj); + } + catch (Exception) + { + return NotFound(); + } + } } } diff --git a/HanyadikHetVan/Controllers/V2/PauseController.cs b/HanyadikHetVan/Controllers/V2/PauseController.cs index 9c9af19..f7cbe4a 100644 --- a/HanyadikHetVan/Controllers/V2/PauseController.cs +++ b/HanyadikHetVan/Controllers/V2/PauseController.cs @@ -8,6 +8,7 @@ using System; using System.Collections.Generic; using System.Net.Mime; using System.Threading.Tasks; +using System.Security.Claims; namespace HanyadikHetVan.Controllers.V2 { @@ -25,25 +26,24 @@ namespace HanyadikHetVan.Controllers.V2 [HttpPost] [Authorize] [Consumes(MediaTypeNames.Application.Json)] - [ProducesResponseType(StatusCodes.Status201Created, Type = typeof(WeeklyTimeSpanDTO))] + [ProducesResponseType(StatusCodes.Status201Created, Type = typeof(PauseDTO))] [ProducesResponseType(StatusCodes.Status400BadRequest)] [ProducesResponseType(StatusCodes.Status401Unauthorized)] public async Task AddPause([FromBody] PauseDTO pause) { try { - var obj = await _pauseService.AddPause(pause); + var obj = await _pauseService.AddPause(this.User.FindFirst(ClaimTypes.NameIdentifier).Value, pause); return CreatedAtAction(nameof(GetPauseById),new { pauseId = obj.Id } ,obj); } catch (Exception) { - return BadRequest(); } } [HttpDelete("{pauseId}")] [Authorize(Policy = "AdminPolicy", AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)] - [ProducesResponseType(StatusCodes.Status200OK, Type = typeof(WeeklyTimeSpanDTO))] + [ProducesResponseType(StatusCodes.Status200OK, Type = typeof(bool))] [ProducesResponseType(StatusCodes.Status404NotFound)] [ProducesResponseType(StatusCodes.Status401Unauthorized)] public async Task DeletePause(int pauseId) diff --git a/HanyadikHetVan/Controllers/V2/UserController.cs b/HanyadikHetVan/Controllers/V2/UserController.cs new file mode 100644 index 0000000..898472d --- /dev/null +++ b/HanyadikHetVan/Controllers/V2/UserController.cs @@ -0,0 +1,46 @@ +using HanyadikHetVan.DTO; +using HanyadikHetVan.Services; +using Microsoft.AspNetCore.Authentication.JwtBearer; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Net.Mime; +using System.Threading.Tasks; + +namespace HanyadikHetVan.Controllers.V2 +{ + [ApiVersion("2.0")] + [Route("api/v{version:apiVersion}/[controller]")] + [ApiController] + public class UserController : Controller + { + private readonly UserService _userservice; + + public UserController(UserService userservice) + { + _userservice = userservice ?? throw new ArgumentNullException(nameof(userservice)); + } + + [HttpPost] + [Authorize(Policy = "AdminPolicy", AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)] + [Consumes(MediaTypeNames.Application.Json)] + [ProducesResponseType(StatusCodes.Status200OK, Type = typeof(UserDTO))] + [ProducesResponseType(StatusCodes.Status400BadRequest)] + [ProducesResponseType(StatusCodes.Status401Unauthorized)] + public async Task UpdateWeeklyTimeSpan([FromBody] UserDTO user) + { + try + { + var userobj = await _userservice.CreateUser(user); + return Ok(userobj); + } + catch (Exception) + { + return BadRequest(); + } + } + } +} diff --git a/HanyadikHetVan/DTO/FunFactDTO.cs b/HanyadikHetVan/DTO/FunFactDTO.cs index 6f204ae..2d96932 100644 --- a/HanyadikHetVan/DTO/FunFactDTO.cs +++ b/HanyadikHetVan/DTO/FunFactDTO.cs @@ -2,6 +2,8 @@ { public class FunFactDTO { + public int Id { get; set; } + public double FunFactor { get; set; } public string Fact { get; set; } diff --git a/HanyadikHetVan/Data/ApplicationDbContext.cs b/HanyadikHetVan/Data/ApplicationDbContext.cs index a2cffd8..280eb51 100644 --- a/HanyadikHetVan/Data/ApplicationDbContext.cs +++ b/HanyadikHetVan/Data/ApplicationDbContext.cs @@ -16,5 +16,23 @@ namespace HanyadikHetVan.Data : base(options) { } + protected override void OnModelCreating(ModelBuilder modelBuilder) + { + base.OnModelCreating(modelBuilder); + modelBuilder.Entity() + .HasOne(s => s.WeeklyTimeSpan) + .WithMany(s => s.Pauses) + .OnDelete(DeleteBehavior.ClientCascade); + + modelBuilder.Entity() + .HasOne(s => s.WeeklyTimeSpan) + .WithMany(s => s.FunFacts) + .OnDelete(DeleteBehavior.ClientCascade); + + modelBuilder.Entity() + .HasOne(s => s.User) + .WithMany(s => s.WeeklyTimeSpans) + .OnDelete(DeleteBehavior.ClientCascade); + } } } diff --git a/HanyadikHetVan/Data/Migrations/20210519232012_ChangeCascadeBehavior.Designer.cs b/HanyadikHetVan/Data/Migrations/20210519232012_ChangeCascadeBehavior.Designer.cs new file mode 100644 index 0000000..b0d9f49 --- /dev/null +++ b/HanyadikHetVan/Data/Migrations/20210519232012_ChangeCascadeBehavior.Designer.cs @@ -0,0 +1,383 @@ +// +using System; +using HanyadikHetVan.Data; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +namespace HanyadikHetVan.Data.Migrations +{ + [DbContext(typeof(ApplicationDbContext))] + [Migration("20210519232012_ChangeCascadeBehavior")] + partial class ChangeCascadeBehavior + { + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("Relational:MaxIdentifierLength", 128) + .HasAnnotation("ProductVersion", "5.0.6") + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + + modelBuilder.Entity("HanyadikHetVan.Data.Entities.FunFact", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int") + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + + b.Property("Fact") + .HasColumnType("nvarchar(max)"); + + b.Property("FunFactor") + .HasColumnType("float"); + + b.Property("WeeklyTimeSpanId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("WeeklyTimeSpanId"); + + b.ToTable("FunFacts"); + }); + + modelBuilder.Entity("HanyadikHetVan.Data.Entities.Pause", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int") + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + + b.Property("Enddate") + .HasColumnType("datetime2"); + + b.Property("Startdate") + .HasColumnType("datetime2"); + + b.Property("WeeklyTimeSpanId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("WeeklyTimeSpanId"); + + b.ToTable("Pauses"); + }); + + modelBuilder.Entity("HanyadikHetVan.Data.Entities.User", b => + { + b.Property("Id") + .HasColumnType("nvarchar(450)"); + + b.Property("AccessFailedCount") + .HasColumnType("int"); + + b.Property("ConcurrencyStamp") + .IsConcurrencyToken() + .HasColumnType("nvarchar(max)"); + + b.Property("Email") + .HasMaxLength(256) + .HasColumnType("nvarchar(256)"); + + b.Property("EmailConfirmed") + .HasColumnType("bit"); + + b.Property("LockoutEnabled") + .HasColumnType("bit"); + + b.Property("LockoutEnd") + .HasColumnType("datetimeoffset"); + + b.Property("NormalizedEmail") + .HasMaxLength(256) + .HasColumnType("nvarchar(256)"); + + b.Property("NormalizedUserName") + .HasMaxLength(256) + .HasColumnType("nvarchar(256)"); + + b.Property("PasswordHash") + .HasColumnType("nvarchar(max)"); + + b.Property("PhoneNumber") + .HasColumnType("nvarchar(max)"); + + b.Property("PhoneNumberConfirmed") + .HasColumnType("bit"); + + b.Property("SecurityStamp") + .HasColumnType("nvarchar(max)"); + + b.Property("TwoFactorEnabled") + .HasColumnType("bit"); + + b.Property("UserName") + .HasMaxLength(256) + .HasColumnType("nvarchar(256)"); + + b.HasKey("Id"); + + b.HasIndex("NormalizedEmail") + .HasDatabaseName("EmailIndex"); + + b.HasIndex("NormalizedUserName") + .IsUnique() + .HasDatabaseName("UserNameIndex") + .HasFilter("[NormalizedUserName] IS NOT NULL"); + + b.ToTable("AspNetUsers"); + }); + + modelBuilder.Entity("HanyadikHetVan.Data.Entities.WeeklyTimeSpan", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int") + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + + b.Property("Startdate") + .HasColumnType("datetime2"); + + b.Property("UserId") + .HasColumnType("nvarchar(450)"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("WeeklyTimeSpans"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRole", b => + { + b.Property("Id") + .HasColumnType("nvarchar(450)"); + + b.Property("ConcurrencyStamp") + .IsConcurrencyToken() + .HasColumnType("nvarchar(max)"); + + b.Property("Name") + .HasMaxLength(256) + .HasColumnType("nvarchar(256)"); + + b.Property("NormalizedName") + .HasMaxLength(256) + .HasColumnType("nvarchar(256)"); + + b.HasKey("Id"); + + b.HasIndex("NormalizedName") + .IsUnique() + .HasDatabaseName("RoleNameIndex") + .HasFilter("[NormalizedName] IS NOT NULL"); + + b.ToTable("AspNetRoles"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int") + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + + b.Property("ClaimType") + .HasColumnType("nvarchar(max)"); + + b.Property("ClaimValue") + .HasColumnType("nvarchar(max)"); + + b.Property("RoleId") + .IsRequired() + .HasColumnType("nvarchar(450)"); + + b.HasKey("Id"); + + b.HasIndex("RoleId"); + + b.ToTable("AspNetRoleClaims"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int") + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + + b.Property("ClaimType") + .HasColumnType("nvarchar(max)"); + + b.Property("ClaimValue") + .HasColumnType("nvarchar(max)"); + + b.Property("UserId") + .IsRequired() + .HasColumnType("nvarchar(450)"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("AspNetUserClaims"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => + { + b.Property("LoginProvider") + .HasColumnType("nvarchar(450)"); + + b.Property("ProviderKey") + .HasColumnType("nvarchar(450)"); + + b.Property("ProviderDisplayName") + .HasColumnType("nvarchar(max)"); + + b.Property("UserId") + .IsRequired() + .HasColumnType("nvarchar(450)"); + + b.HasKey("LoginProvider", "ProviderKey"); + + b.HasIndex("UserId"); + + b.ToTable("AspNetUserLogins"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => + { + b.Property("UserId") + .HasColumnType("nvarchar(450)"); + + b.Property("RoleId") + .HasColumnType("nvarchar(450)"); + + b.HasKey("UserId", "RoleId"); + + b.HasIndex("RoleId"); + + b.ToTable("AspNetUserRoles"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => + { + b.Property("UserId") + .HasColumnType("nvarchar(450)"); + + b.Property("LoginProvider") + .HasColumnType("nvarchar(450)"); + + b.Property("Name") + .HasColumnType("nvarchar(450)"); + + b.Property("Value") + .HasColumnType("nvarchar(max)"); + + b.HasKey("UserId", "LoginProvider", "Name"); + + b.ToTable("AspNetUserTokens"); + }); + + modelBuilder.Entity("HanyadikHetVan.Data.Entities.FunFact", b => + { + b.HasOne("HanyadikHetVan.Data.Entities.WeeklyTimeSpan", "WeeklyTimeSpan") + .WithMany("FunFacts") + .HasForeignKey("WeeklyTimeSpanId") + .OnDelete(DeleteBehavior.ClientCascade) + .IsRequired(); + + b.Navigation("WeeklyTimeSpan"); + }); + + modelBuilder.Entity("HanyadikHetVan.Data.Entities.Pause", b => + { + b.HasOne("HanyadikHetVan.Data.Entities.WeeklyTimeSpan", "WeeklyTimeSpan") + .WithMany("Pauses") + .HasForeignKey("WeeklyTimeSpanId") + .OnDelete(DeleteBehavior.ClientCascade) + .IsRequired(); + + b.Navigation("WeeklyTimeSpan"); + }); + + modelBuilder.Entity("HanyadikHetVan.Data.Entities.WeeklyTimeSpan", b => + { + b.HasOne("HanyadikHetVan.Data.Entities.User", "User") + .WithMany("WeeklyTimeSpans") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.ClientCascade); + + b.Navigation("User"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => + { + b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null) + .WithMany() + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => + { + b.HasOne("HanyadikHetVan.Data.Entities.User", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => + { + b.HasOne("HanyadikHetVan.Data.Entities.User", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => + { + b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null) + .WithMany() + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("HanyadikHetVan.Data.Entities.User", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => + { + b.HasOne("HanyadikHetVan.Data.Entities.User", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("HanyadikHetVan.Data.Entities.User", b => + { + b.Navigation("WeeklyTimeSpans"); + }); + + modelBuilder.Entity("HanyadikHetVan.Data.Entities.WeeklyTimeSpan", b => + { + b.Navigation("FunFacts"); + + b.Navigation("Pauses"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/HanyadikHetVan/Data/Migrations/20210519232012_ChangeCascadeBehavior.cs b/HanyadikHetVan/Data/Migrations/20210519232012_ChangeCascadeBehavior.cs new file mode 100644 index 0000000..8f3ceeb --- /dev/null +++ b/HanyadikHetVan/Data/Migrations/20210519232012_ChangeCascadeBehavior.cs @@ -0,0 +1,61 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +namespace HanyadikHetVan.Data.Migrations +{ + public partial class ChangeCascadeBehavior : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropForeignKey( + name: "FK_FunFacts_WeeklyTimeSpans_WeeklyTimeSpanId", + table: "FunFacts"); + + migrationBuilder.DropForeignKey( + name: "FK_Pauses_WeeklyTimeSpans_WeeklyTimeSpanId", + table: "Pauses"); + + migrationBuilder.AddForeignKey( + name: "FK_FunFacts_WeeklyTimeSpans_WeeklyTimeSpanId", + table: "FunFacts", + column: "WeeklyTimeSpanId", + principalTable: "WeeklyTimeSpans", + principalColumn: "Id", + onDelete: ReferentialAction.Restrict); + + migrationBuilder.AddForeignKey( + name: "FK_Pauses_WeeklyTimeSpans_WeeklyTimeSpanId", + table: "Pauses", + column: "WeeklyTimeSpanId", + principalTable: "WeeklyTimeSpans", + principalColumn: "Id", + onDelete: ReferentialAction.Restrict); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropForeignKey( + name: "FK_FunFacts_WeeklyTimeSpans_WeeklyTimeSpanId", + table: "FunFacts"); + + migrationBuilder.DropForeignKey( + name: "FK_Pauses_WeeklyTimeSpans_WeeklyTimeSpanId", + table: "Pauses"); + + migrationBuilder.AddForeignKey( + name: "FK_FunFacts_WeeklyTimeSpans_WeeklyTimeSpanId", + table: "FunFacts", + column: "WeeklyTimeSpanId", + principalTable: "WeeklyTimeSpans", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + + migrationBuilder.AddForeignKey( + name: "FK_Pauses_WeeklyTimeSpans_WeeklyTimeSpanId", + table: "Pauses", + column: "WeeklyTimeSpanId", + principalTable: "WeeklyTimeSpans", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + } + } +} diff --git a/HanyadikHetVan/Data/Migrations/ApplicationDbContextModelSnapshot.cs b/HanyadikHetVan/Data/Migrations/ApplicationDbContextModelSnapshot.cs index ca5a9b3..cca5142 100644 --- a/HanyadikHetVan/Data/Migrations/ApplicationDbContextModelSnapshot.cs +++ b/HanyadikHetVan/Data/Migrations/ApplicationDbContextModelSnapshot.cs @@ -286,7 +286,7 @@ namespace HanyadikHetVan.Data.Migrations b.HasOne("HanyadikHetVan.Data.Entities.WeeklyTimeSpan", "WeeklyTimeSpan") .WithMany("FunFacts") .HasForeignKey("WeeklyTimeSpanId") - .OnDelete(DeleteBehavior.Cascade) + .OnDelete(DeleteBehavior.ClientCascade) .IsRequired(); b.Navigation("WeeklyTimeSpan"); @@ -297,7 +297,7 @@ namespace HanyadikHetVan.Data.Migrations b.HasOne("HanyadikHetVan.Data.Entities.WeeklyTimeSpan", "WeeklyTimeSpan") .WithMany("Pauses") .HasForeignKey("WeeklyTimeSpanId") - .OnDelete(DeleteBehavior.Cascade) + .OnDelete(DeleteBehavior.ClientCascade) .IsRequired(); b.Navigation("WeeklyTimeSpan"); @@ -307,7 +307,8 @@ namespace HanyadikHetVan.Data.Migrations { b.HasOne("HanyadikHetVan.Data.Entities.User", "User") .WithMany("WeeklyTimeSpans") - .HasForeignKey("UserId"); + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.ClientCascade); b.Navigation("User"); }); diff --git a/HanyadikHetVan/Profiles/FunFactProfile.cs b/HanyadikHetVan/Profiles/FunFactProfile.cs index 82e97dc..10d295b 100644 --- a/HanyadikHetVan/Profiles/FunFactProfile.cs +++ b/HanyadikHetVan/Profiles/FunFactProfile.cs @@ -9,7 +9,7 @@ namespace HanyadikHetVan.Profiles public FunFactProfile() { CreateMap(); - CreateMap().ForMember(x => x.Id, options => options.Ignore()).ForMember(x => x.WeeklyTimeSpanId, options => options.Ignore()).ForMember(x => x.Id, options => options.Ignore()); + CreateMap().ForMember(x => x.Id, options => options.Ignore()).ForMember(x => x.WeeklyTimeSpanId, options => options.Ignore()).ForMember(x => x.WeeklyTimeSpan, options => options.Ignore()); } } } diff --git a/HanyadikHetVan/Services/FunFactService.cs b/HanyadikHetVan/Services/FunFactService.cs index 12f954e..96e597e 100644 --- a/HanyadikHetVan/Services/FunFactService.cs +++ b/HanyadikHetVan/Services/FunFactService.cs @@ -32,5 +32,30 @@ namespace HanyadikHetVan.Services var funfact = await _dbContext.FunFacts.Where(x => x.Id == funfactId).FirstOrDefaultAsync(); return funfact.FunFactor; } + + public async Task DeleteFunFact(int funfactId) + { + try + { + var item = await _dbContext.FunFacts.Where(x => x.Id == funfactId).FirstOrDefaultAsync(); + _dbContext.FunFacts.Remove(item); + await _dbContext.SaveChangesAsync(); + return true; + } + catch (Exception) + { + return false; + } + } + + public async Task UpdateFunFact(int funfactId, FunFactDTO funfact) + { + var funfactentity = _mapper.Map(funfact); + funfactentity.Id = funfactId; + _dbContext.FunFacts.Update(funfactentity); + await _dbContext.SaveChangesAsync(); + var newff = await _dbContext.FunFacts.Where(x => x.Id == funfactId).FirstOrDefaultAsync(); + return _mapper.Map(newff); + } } } diff --git a/HanyadikHetVan/Services/PauseService.cs b/HanyadikHetVan/Services/PauseService.cs index 4e9e0b4..27193c9 100644 --- a/HanyadikHetVan/Services/PauseService.cs +++ b/HanyadikHetVan/Services/PauseService.cs @@ -27,9 +27,17 @@ namespace HanyadikHetVan.Services return _mapper.Map, List>(pauses); } - public async Task AddPause(PauseDTO pause) + public async Task AddPause(string userId, PauseDTO pause) { + var wts = await _dbContext.WeeklyTimeSpans.Include(x => x.Pauses).Where(x => x.UserId == userId && x.Id == pause.WeeklyTimeSpanId).FirstOrDefaultAsync(); + + if (wts == null) + { + throw new Exception("Not found"); + } + var pauseEntity = _mapper.Map(pause); + pauseEntity.WeeklyTimeSpanId = pause.WeeklyTimeSpanId; var obj = _dbContext.Pauses.Add(pauseEntity); await _dbContext.SaveChangesAsync(); return _mapper.Map(obj.Entity); diff --git a/HanyadikHetVan/Services/UserService.cs b/HanyadikHetVan/Services/UserService.cs index d5eead4..a8ee3f4 100644 --- a/HanyadikHetVan/Services/UserService.cs +++ b/HanyadikHetVan/Services/UserService.cs @@ -14,23 +14,23 @@ namespace HanyadikHetVan.Services { _userManager = userManager ?? throw new ArgumentNullException(nameof(userManager)); } - public async Task CreateUser(string email, string password) + public async Task CreateUser(UserDTO user) { var newUser = new User { - UserName = email, - Email = email, + UserName = user.Email, + Email = user.Email, EmailConfirmed = true, }; - var result = await _userManager.CreateAsync(newUser,password); + var result = await _userManager.CreateAsync(newUser, user.Password); if (!result.Succeeded) { throw new Exception("Failed to create user."); } - return new UserDTO() { Email = email }; + return new UserDTO() { Email = user.Email }; } } } diff --git a/HanyadikHetVan/Services/WeeklyTimeSpanService.cs b/HanyadikHetVan/Services/WeeklyTimeSpanService.cs index e0509ad..b829a45 100644 --- a/HanyadikHetVan/Services/WeeklyTimeSpanService.cs +++ b/HanyadikHetVan/Services/WeeklyTimeSpanService.cs @@ -24,25 +24,25 @@ namespace HanyadikHetVan.Services public async Task> GetAllWeeklyTimeSpans() { - var wts = await _dbContext.WeeklyTimeSpans.Include(x => x.Pauses).ToListAsync(); + var wts = await _dbContext.WeeklyTimeSpans.Include(x => x.Pauses).Include(x => x.FunFacts).ToListAsync(); return _mapper.Map, List>(wts); } public async Task GetWeeklyTimeSpan(int weeklytimespanId) { - var wts = await _dbContext.WeeklyTimeSpans.Include(x => x.Pauses).Where(x => x.Id == weeklytimespanId).FirstOrDefaultAsync(); + var wts = await _dbContext.WeeklyTimeSpans.Include(x => x.Pauses).Include(x => x.FunFacts).Where(x => x.Id == weeklytimespanId).FirstOrDefaultAsync(); return _mapper.Map(wts); } public async Task> GetPausesOfWeeklyTimeSpan(int weeklytimespanId) { - var pauses = await _dbContext.WeeklyTimeSpans.Include(x => x.Pauses).Where(x => x.Id == weeklytimespanId).FirstOrDefaultAsync(); + var pauses = await _dbContext.WeeklyTimeSpans.Include(x => x.Pauses).Include(x => x.FunFacts).Where(x => x.Id == weeklytimespanId).FirstOrDefaultAsync(); return _mapper.Map, List>(pauses.Pauses); } public async Task GetWeeklyTimeSpanByStartdate(DateTime startTime) { - var wts = await _dbContext.WeeklyTimeSpans.Include(x => x.Pauses).Where(x => x.Startdate.Date.Equals(startTime.Date)).ToListAsync(); + var wts = await _dbContext.WeeklyTimeSpans.Include(x => x.Pauses).Include(x => x.FunFacts).Where(x => x.Startdate.Date.Equals(startTime.Date)).ToListAsync(); return _mapper.Map, WeeklyTimeSpanDTO>(wts); } diff --git a/HanyadikHetVan/Startup.cs b/HanyadikHetVan/Startup.cs index 3497af7..bdf2967 100644 --- a/HanyadikHetVan/Startup.cs +++ b/HanyadikHetVan/Startup.cs @@ -38,6 +38,7 @@ namespace HanyadikHetVan services.AddAutoMapper(Assembly.GetExecutingAssembly()); services.AddTransient(); services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); diff --git a/Insomnia.json b/Insomnia.json index 4d70e25..ebb918c 100644 --- a/Insomnia.json +++ b/Insomnia.json @@ -1 +1 @@ -{"_type":"export","__export_format":4,"__export_date":"2021-05-18T17:38:15.292Z","__export_source":"insomnia.desktop.app:v2021.3.0","resources":[{"_id":"req_d1ce12920703411bb9239086d5eebeaf","parentId":"wrk_f357700b92cd436684cbaa092faddb11","modified":1621358836406,"created":1621358764056,"url":"","name":"Login","description":"","method":"GET","body":{},"parameters":[],"headers":[{"name":"CLIENT_ID","value":"postman","description":"","id":"pair_15ae3c2fcba54b498cb7a0472a300c03"},{"name":"CLIENT_SECRET","value":"xmYYS/lSPIz5IdbgUXNbp66JYSejHbw7/oFXy7CLk8s=","description":"","id":"pair_792b4774ecc74d1fa6668b34b007966f"},{"name":"","value":"","description":"","id":"pair_02f1429d1c7b4742a50026136ccfb60c"}],"authentication":{},"metaSortKey":-1621358764056,"isPrivate":false,"settingStoreCookies":true,"settingSendCookies":true,"settingDisableRenderRequestBody":false,"settingEncodeUrl":true,"settingRebuildPath":true,"settingFollowRedirects":"global","_type":"request"},{"_id":"wrk_f357700b92cd436684cbaa092faddb11","parentId":null,"modified":1621358491167,"created":1621358491167,"name":"HanyadikHetVan","description":"","scope":"collection","_type":"workspace"},{"_id":"req_87fc2e4796ae4fada37c7669d5b03209","parentId":"wrk_f357700b92cd436684cbaa092faddb11","modified":1621358697962,"created":1621358525104,"url":"https://127.0.0.1:5001/api/test/unprotected","name":"Test Unprotected","description":"","method":"GET","body":{},"parameters":[],"headers":[],"authentication":{},"metaSortKey":-1621358525104,"isPrivate":false,"settingStoreCookies":true,"settingSendCookies":true,"settingDisableRenderRequestBody":false,"settingEncodeUrl":true,"settingRebuildPath":true,"settingFollowRedirects":"global","_type":"request"},{"_id":"req_deaaea3ec86b436398e5a0bb91547ed6","parentId":"wrk_f357700b92cd436684cbaa092faddb11","modified":1621359446725,"created":1621358708070,"url":"https://127.0.0.1:5001/api/test/protected","name":"Test Protected","description":"","method":"GET","body":{},"parameters":[],"headers":[],"authentication":{"type":"oauth2","grantType":"password","clientId":"postman","clientSecret":"cunci","scope":"openid profile user_role api.readwrite","accessTokenUrl":"https://localhost:5001/connect/token","password":"Asdfghjkl0.","username":"valami@valami.com","credentialsInBody":true},"metaSortKey":-1621358525054,"isPrivate":false,"settingStoreCookies":true,"settingSendCookies":true,"settingDisableRenderRequestBody":false,"settingEncodeUrl":true,"settingRebuildPath":true,"settingFollowRedirects":"global","_type":"request"},{"_id":"env_3678daf1d98efdcce76cc3814492161dfc393bd6","parentId":"wrk_f357700b92cd436684cbaa092faddb11","modified":1621358492714,"created":1621358492714,"name":"Base Environment","data":{},"dataPropertyOrder":null,"color":null,"isPrivate":false,"metaSortKey":1621358492715,"_type":"environment"},{"_id":"jar_3678daf1d98efdcce76cc3814492161dfc393bd6","parentId":"wrk_f357700b92cd436684cbaa092faddb11","modified":1621358492771,"created":1621358492771,"name":"Default Jar","cookies":[],"_type":"cookie_jar"},{"_id":"spc_602f99b584af4a05a041b16758dfd954","parentId":"wrk_f357700b92cd436684cbaa092faddb11","modified":1621358491227,"created":1621358491227,"fileName":"HanyadikHetVan","contents":"","contentType":"yaml","_type":"api_spec"}]} \ No newline at end of file +{"_type":"export","__export_format":4,"__export_date":"2021-05-19T23:28:41.031Z","__export_source":"insomnia.desktop.app:v2021.3.0","resources":[{"_id":"req_87fc2e4796ae4fada37c7669d5b03209","parentId":"wrk_f357700b92cd436684cbaa092faddb11","modified":1621393098640,"created":1621358525104,"url":"https://127.0.0.1:5001/api/v1/test/unprotected","name":"Test Unprotected","description":"","method":"GET","body":{},"parameters":[],"headers":[],"authentication":{},"metaSortKey":-1621358525104,"isPrivate":false,"settingStoreCookies":true,"settingSendCookies":true,"settingDisableRenderRequestBody":false,"settingEncodeUrl":true,"settingRebuildPath":true,"settingFollowRedirects":"global","_type":"request"},{"_id":"wrk_f357700b92cd436684cbaa092faddb11","parentId":null,"modified":1621358491167,"created":1621358491167,"name":"HanyadikHetVan","description":"","scope":"collection","_type":"workspace"},{"_id":"req_deaaea3ec86b436398e5a0bb91547ed6","parentId":"wrk_f357700b92cd436684cbaa092faddb11","modified":1621393156611,"created":1621358708070,"url":"https://127.0.0.1:5001/api/v1/test/protected","name":"Test Protected","description":"","method":"GET","body":{},"parameters":[],"headers":[],"authentication":{"type":"oauth2","grantType":"password","clientId":"postman","clientSecret":"cunci","scope":"openid profile user_role api.readwrite","accessTokenUrl":"https://localhost:5001/connect/token","password":"Asdfghjkl0.","username":"valami@valami.com","credentialsInBody":true},"metaSortKey":-1621358525054,"isPrivate":false,"settingStoreCookies":true,"settingSendCookies":true,"settingDisableRenderRequestBody":false,"settingEncodeUrl":true,"settingRebuildPath":true,"settingFollowRedirects":"global","_type":"request"},{"_id":"req_d1ce12920703411bb9239086d5eebeaf","parentId":"wrk_f357700b92cd436684cbaa092faddb11","modified":1621358836406,"created":1621358764056,"url":"","name":"Login","description":"","method":"GET","body":{},"parameters":[],"headers":[{"name":"CLIENT_ID","value":"postman","description":"","id":"pair_15ae3c2fcba54b498cb7a0472a300c03"},{"name":"CLIENT_SECRET","value":"xmYYS/lSPIz5IdbgUXNbp66JYSejHbw7/oFXy7CLk8s=","description":"","id":"pair_792b4774ecc74d1fa6668b34b007966f"},{"name":"","value":"","description":"","id":"pair_02f1429d1c7b4742a50026136ccfb60c"}],"authentication":{},"metaSortKey":-1621358764056,"isPrivate":false,"settingStoreCookies":true,"settingSendCookies":true,"settingDisableRenderRequestBody":false,"settingEncodeUrl":true,"settingRebuildPath":true,"settingFollowRedirects":"global","_type":"request"},{"_id":"req_11187004cad44b659ae72ba97b23280b","parentId":"wrk_f357700b92cd436684cbaa092faddb11","modified":1621454522682,"created":1621437459351,"url":"https://127.0.0.1:5001/api/v1/test/roleprotected","name":"Test RoleProtected","description":"","method":"GET","body":{},"parameters":[],"headers":[],"authentication":{"type":"oauth2","grantType":"password","clientId":"postman","clientSecret":"cunci","scope":"openid profile user_role api.readwrite","accessTokenUrl":"https://localhost:5001/connect/token","password":"Alma123.","username":"testuser","credentialsInBody":true},"metaSortKey":-1621358525004,"isPrivate":false,"settingStoreCookies":true,"settingSendCookies":true,"settingDisableRenderRequestBody":false,"settingEncodeUrl":true,"settingRebuildPath":true,"settingFollowRedirects":"global","_type":"request"},{"_id":"req_c783fb5559dc47f8b64bed8d9e163f2b","parentId":"wrk_f357700b92cd436684cbaa092faddb11","modified":1621444308533,"created":1621437816623,"url":"https://127.0.0.1:5001/api/v2/HanyadikHetVan/my","name":"Misc Testing","description":"","method":"GET","body":{},"parameters":[],"headers":[],"authentication":{"type":"oauth2","grantType":"password","clientId":"postman","clientSecret":"cunci","scope":"openid profile user_role api.readwrite","accessTokenUrl":"https://localhost:5001/connect/token","password":"Alma123.","username":"testuser","credentialsInBody":true},"metaSortKey":-1621358524954,"isPrivate":false,"settingStoreCookies":true,"settingSendCookies":true,"settingDisableRenderRequestBody":false,"settingEncodeUrl":true,"settingRebuildPath":true,"settingFollowRedirects":"global","_type":"request"},{"_id":"req_9d695df935a7438183f8236cc6e9b99c","parentId":"wrk_f357700b92cd436684cbaa092faddb11","modified":1621461288205,"created":1621453054062,"url":"https://localhost:5001/connect/token","name":"Manual Login","description":"","method":"POST","body":{"mimeType":"application/x-www-form-urlencoded","params":[{"name":"client_id","value":"postman","description":"","id":"pair_c5379b5d86414f3cbcfd4401178e2d86"},{"name":"client_secret","value":"cunci","description":"","id":"pair_16e8dadad81e41f8bf79a9f3fb987288"},{"name":"scope","value":"openid profile user_role api.readwrite","description":"","id":"pair_7cebe3353292488a89b54c22b914d75f"},{"name":"username","value":"testuser","description":"","id":"pair_66432bda0b8341428db80c99c9be20e6"},{"name":"password","value":"Alma123.","description":"","id":"pair_66f3327363f84d2d90a45bf280ea4292"},{"name":"grant_type","value":"password","description":"","id":"pair_c5258db6645b41a8aacab733bf15e9f0"},{"name":"","value":"","description":"","id":"pair_68bc5cb16118428990cb5d3221aaa9eb"}]},"parameters":[],"headers":[{"name":"Content-Type","value":"application/x-www-form-urlencoded","id":"pair_c32ecd7909c742e1a3c7d22c28360d7b"}],"authentication":{},"metaSortKey":-1621453054062,"isPrivate":false,"settingStoreCookies":true,"settingSendCookies":true,"settingDisableRenderRequestBody":false,"settingEncodeUrl":true,"settingRebuildPath":true,"settingFollowRedirects":"global","_type":"request"},{"_id":"req_58ea33e0a7c649d0ab67f70a46cdaa53","parentId":"wrk_f357700b92cd436684cbaa092faddb11","modified":1621460830534,"created":1621460780373,"url":"https://127.0.0.1:5001/api/v2/WeeklyTimeSpan","name":"Test AddWeeklyTimeSpan","description":"","method":"POST","body":{"mimeType":"application/json","text":"{\n \"startdate\": \"2021-05-19T21:46:42.345Z\",\n \"pauses\": [\n {\n \"startdate\": \"2021-05-19T21:46:42.345Z\",\n \"enddate\": \"2021-05-19T21:46:42.345Z\"\n }\n ],\n \"funFacts\": [\n {\n \"funFactor\": 0,\n \"fact\": \"string\"\n }\n ]\n}"},"parameters":[],"headers":[{"name":"Content-Type","value":"application/json","id":"pair_647cb2161fbe402bb6738d1007052931"}],"authentication":{"type":"oauth2","grantType":"password","clientId":"postman","clientSecret":"cunci","scope":"openid profile user_role api.readwrite","accessTokenUrl":"https://localhost:5001/connect/token","password":"Alma123.","username":"testuser","credentialsInBody":true},"metaSortKey":-1621358524979,"isPrivate":false,"settingStoreCookies":true,"settingSendCookies":true,"settingDisableRenderRequestBody":false,"settingEncodeUrl":true,"settingRebuildPath":true,"settingFollowRedirects":"global","_type":"request"},{"_id":"req_1eaba895d0e849549f03d8471e868bcb","parentId":"wrk_f357700b92cd436684cbaa092faddb11","modified":1621460845748,"created":1621460837180,"url":"https://127.0.0.1:5001/api/v2/WeeklyTimeSpan","name":"Test AddWeeklyTimeSpan-NotAdmin","description":"","method":"POST","body":{"mimeType":"application/json","text":"{\n \"startdate\": \"2021-05-19T21:46:42.345Z\",\n \"pauses\": [\n {\n \"startdate\": \"2021-05-19T21:46:42.345Z\",\n \"enddate\": \"2021-05-19T21:46:42.345Z\"\n }\n ],\n \"funFacts\": [\n {\n \"funFactor\": 0,\n \"fact\": \"string\"\n }\n ]\n}"},"parameters":[],"headers":[{"name":"Content-Type","value":"application/json","id":"pair_647cb2161fbe402bb6738d1007052931"}],"authentication":{"type":"oauth2","grantType":"password","clientId":"postman","clientSecret":"cunci","scope":"openid profile user_role api.readwrite","accessTokenUrl":"https://localhost:5001/connect/token","password":"asdfghjkl123.A","username":"tormakristof@tormakristof.eu","credentialsInBody":true},"metaSortKey":-1621358524966.5,"isPrivate":false,"settingStoreCookies":true,"settingSendCookies":true,"settingDisableRenderRequestBody":false,"settingEncodeUrl":true,"settingRebuildPath":true,"settingFollowRedirects":"global","_type":"request"},{"_id":"req_30defd91f49844588296178a23727dc6","parentId":"wrk_f357700b92cd436684cbaa092faddb11","modified":1621460955268,"created":1621460921951,"url":"https://127.0.0.1:5001/api/v2/User","name":"Test AdminAddUser","description":"","method":"POST","body":{"mimeType":"application/json","text":"{\n \"email\": \"asdfghjkl@test1.com\",\n \"password\": \"asdfghjkl123456789.A\"\n}"},"parameters":[],"headers":[{"name":"Content-Type","value":"application/json","id":"pair_647cb2161fbe402bb6738d1007052931"}],"authentication":{"type":"oauth2","grantType":"password","clientId":"postman","clientSecret":"cunci","scope":"openid profile user_role api.readwrite","accessTokenUrl":"https://localhost:5001/connect/token","password":"Alma123.","username":"testuser","credentialsInBody":true},"metaSortKey":-1621358524972.75,"isPrivate":false,"settingStoreCookies":true,"settingSendCookies":true,"settingDisableRenderRequestBody":false,"settingEncodeUrl":true,"settingRebuildPath":true,"settingFollowRedirects":"global","_type":"request"},{"_id":"req_8bed07e7443748c288e1888a9aced4e8","parentId":"wrk_f357700b92cd436684cbaa092faddb11","modified":1621463804280,"created":1621463721078,"url":"https://127.0.0.1:5001/api/v2/Pause","name":"Test AddPause","description":"","method":"POST","body":{"mimeType":"application/json","text":"{\n \"weeklyTimeSpanId\": 4,\n \"startdate\": \"2021-03-19T22:25:15.867Z\",\n \"enddate\": \"2021-03-22T22:25:15.867Z\"\n}"},"parameters":[],"headers":[{"name":"Content-Type","value":"application/json","id":"pair_647cb2161fbe402bb6738d1007052931"}],"authentication":{"type":"oauth2","grantType":"password","clientId":"postman","clientSecret":"cunci","scope":"openid profile user_role api.readwrite","accessTokenUrl":"https://localhost:5001/connect/token","password":"asdfghjkl123456789.A","username":"123test@tester.com","credentialsInBody":true},"metaSortKey":-1621358524960.25,"isPrivate":false,"settingStoreCookies":true,"settingSendCookies":true,"settingDisableRenderRequestBody":false,"settingEncodeUrl":true,"settingRebuildPath":true,"settingFollowRedirects":"global","_type":"request"},{"_id":"env_3678daf1d98efdcce76cc3814492161dfc393bd6","parentId":"wrk_f357700b92cd436684cbaa092faddb11","modified":1621358492714,"created":1621358492714,"name":"Base Environment","data":{},"dataPropertyOrder":null,"color":null,"isPrivate":false,"metaSortKey":1621358492715,"_type":"environment"},{"_id":"jar_3678daf1d98efdcce76cc3814492161dfc393bd6","parentId":"wrk_f357700b92cd436684cbaa092faddb11","modified":1621358492771,"created":1621358492771,"name":"Default Jar","cookies":[],"_type":"cookie_jar"},{"_id":"spc_602f99b584af4a05a041b16758dfd954","parentId":"wrk_f357700b92cd436684cbaa092faddb11","modified":1621358491227,"created":1621358491227,"fileName":"HanyadikHetVan","contents":"","contentType":"yaml","_type":"api_spec"}]} \ No newline at end of file diff --git a/PartOne.postman_collection.json b/PartOne.postman_collection.json new file mode 100644 index 0000000..666406d --- /dev/null +++ b/PartOne.postman_collection.json @@ -0,0 +1,343 @@ +{ + "info": { + "_postman_id": "3571c7a1-93a7-434a-a412-8931ae5b2ee2", + "name": "PartOne", + "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json" + }, + "item": [ + { + "name": "UseOldAPI", + "request": { + "auth": { + "type": "noauth" + }, + "method": "GET", + "header": [], + "url": { + "raw": "https://localhost:5001/api/v1/HanyadikHetVan", + "protocol": "https", + "host": [ + "localhost" + ], + "port": "5001", + "path": [ + "api", + "v1", + "HanyadikHetVan" + ] + } + }, + "response": [] + }, + { + "name": "AdminLogin", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "var jsonData = JSON.parse(responseBody);\r", + "pm.environment.set(\"token\", jsonData.access_token);" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [], + "body": { + "mode": "urlencoded", + "urlencoded": [ + { + "key": "client_id", + "value": "postman", + "type": "text" + }, + { + "key": "client_secret", + "value": "cunci", + "type": "text" + }, + { + "key": "scope", + "value": "openid profile user_role api.readwrite", + "type": "text" + }, + { + "key": "username", + "value": "{{admin_username}}", + "type": "text" + }, + { + "key": "password", + "value": "{{admin_password}}", + "type": "text" + }, + { + "key": "grant_type", + "value": "password", + "type": "text" + } + ] + }, + "url": { + "raw": "https://localhost:5001/connect/token", + "protocol": "https", + "host": [ + "localhost" + ], + "port": "5001", + "path": [ + "connect", + "token" + ] + } + }, + "response": [] + }, + { + "name": "AdminCreateUser", + "request": { + "auth": { + "type": "bearer", + "bearer": [ + { + "key": "token", + "value": "{{token}}", + "type": "string" + } + ] + }, + "method": "POST", + "header": [], + "body": { + "mode": "raw", + "raw": "{\r\n \"email\": \"{{username}}\",\r\n \"password\": \"{{password}}\"\r\n}", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "https://localhost:5001/api/v2/User", + "protocol": "https", + "host": [ + "localhost" + ], + "port": "5001", + "path": [ + "api", + "v2", + "User" + ] + } + }, + "response": [] + }, + { + "name": "UserLogin", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "var jsonData = JSON.parse(responseBody);\r", + "pm.environment.set(\"token\", jsonData.access_token);" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [], + "body": { + "mode": "urlencoded", + "urlencoded": [ + { + "key": "client_id", + "value": "postman", + "type": "text" + }, + { + "key": "client_secret", + "value": "cunci", + "type": "text" + }, + { + "key": "scope", + "value": "openid profile user_role api.readwrite", + "type": "text" + }, + { + "key": "username", + "value": "{{username}}", + "type": "text" + }, + { + "key": "password", + "value": "{{password}}", + "type": "text" + }, + { + "key": "grant_type", + "value": "password", + "type": "text" + } + ] + }, + "url": { + "raw": "https://localhost:5001/connect/token", + "protocol": "https", + "host": [ + "localhost" + ], + "port": "5001", + "path": [ + "connect", + "token" + ] + } + }, + "response": [] + }, + { + "name": "UserCreateWTS", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "var jsonData = JSON.parse(responseBody);\r", + "pm.environment.set(\"wtsid\", jsonData.id);" + ], + "type": "text/javascript" + } + } + ], + "request": { + "auth": { + "type": "bearer", + "bearer": [ + { + "key": "token", + "value": "{{token}}", + "type": "string" + } + ] + }, + "method": "POST", + "header": [], + "body": { + "mode": "raw", + "raw": "{\r\n \"startdate\": \"2021-03-19T21:46:42.345Z\",\r\n \"pauses\": [\r\n {\r\n \"startdate\": \"2021-04-19T21:46:42.345Z\",\r\n \"enddate\": \"2021-04-29T21:46:42.345Z\"\r\n }\r\n ],\r\n \"funFacts\": [\r\n {\r\n \"funFactor\": 1.2,\r\n \"fact\": \"Ez vicces 7 het volt.\"\r\n }\r\n ]\r\n}", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "https://localhost:5001/api/v2/WeeklyTimeSpan", + "protocol": "https", + "host": [ + "localhost" + ], + "port": "5001", + "path": [ + "api", + "v2", + "WeeklyTimeSpan" + ] + } + }, + "response": [] + }, + { + "name": "GetUserDefault", + "request": { + "auth": { + "type": "bearer", + "bearer": [ + { + "key": "token", + "value": "{{token}}", + "type": "string" + } + ] + }, + "method": "GET", + "header": [], + "url": { + "raw": "https://localhost:5001/api/v2/HanyadikHetVan/my", + "protocol": "https", + "host": [ + "localhost" + ], + "port": "5001", + "path": [ + "api", + "v2", + "HanyadikHetVan", + "my" + ] + } + }, + "response": [] + }, + { + "name": "GetWTSId", + "request": { + "auth": { + "type": "bearer", + "bearer": [ + { + "key": "token", + "value": "{{token}}", + "type": "string" + } + ] + }, + "method": "GET", + "header": [], + "url": { + "raw": "https://localhost:5001/api/v2/WeeklyTimeSpan/{{wtsid}}", + "protocol": "https", + "host": [ + "localhost" + ], + "port": "5001", + "path": [ + "api", + "v2", + "WeeklyTimeSpan", + "{{wtsid}}" + ] + } + }, + "response": [] + } + ], + "event": [ + { + "listen": "prerequest", + "script": { + "type": "text/javascript", + "exec": [ + "" + ] + } + }, + { + "listen": "test", + "script": { + "type": "text/javascript", + "exec": [ + "" + ] + } + } + ] +} \ No newline at end of file diff --git a/PartThree.postman_collection.json b/PartThree.postman_collection.json new file mode 100644 index 0000000..303e859 --- /dev/null +++ b/PartThree.postman_collection.json @@ -0,0 +1,335 @@ +{ + "info": { + "_postman_id": "502a1115-3b6a-4a52-a4de-39d3fa9f5bdb", + "name": "PartThree", + "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json" + }, + "item": [ + { + "name": "UserLogin", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "var jsonData = JSON.parse(responseBody);\r", + "pm.environment.set(\"token\", jsonData.access_token);" + ], + "type": "text/javascript" + } + } + ], + "request": { + "auth": { + "type": "noauth" + }, + "method": "POST", + "header": [], + "body": { + "mode": "urlencoded", + "urlencoded": [ + { + "key": "client_id", + "value": "postman", + "type": "text" + }, + { + "key": "client_secret", + "value": "cunci", + "type": "text" + }, + { + "key": "scope", + "value": "openid profile user_role api.readwrite", + "type": "text" + }, + { + "key": "username", + "value": "{{username}}", + "type": "text" + }, + { + "key": "password", + "value": "{{password}}", + "type": "text" + }, + { + "key": "grant_type", + "value": "password", + "type": "text" + } + ] + }, + "url": { + "raw": "https://localhost:5001/connect/token", + "protocol": "https", + "host": [ + "localhost" + ], + "port": "5001", + "path": [ + "connect", + "token" + ] + } + }, + "response": [] + }, + { + "name": "CreateNewWTS", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "var jsonData = JSON.parse(responseBody);\r", + "pm.environment.set(\"wtsid\", jsonData.id);" + ], + "type": "text/javascript" + } + } + ], + "request": { + "auth": { + "type": "bearer", + "bearer": [ + { + "key": "token", + "value": "{{token}}", + "type": "string" + } + ] + }, + "method": "POST", + "header": [], + "body": { + "mode": "raw", + "raw": "{\r\n \"startdate\": \"2021-01-01T21:46:42.345Z\",\r\n \"funFacts\": [\r\n {\r\n \"funFactor\": 1.2,\r\n \"fact\": \"Ez vicces 7 het volt.\"\r\n },\r\n {\r\n \"funFactor\": 2.1,\r\n \"fact\": \"Lyaly de faraszto lesz.\"\r\n },\r\n {\r\n \"funFactor\": 6.9,\r\n \"fact\": \"Tul kell elni.\"\r\n }\r\n ]\r\n}", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "https://localhost:5001/api/v2/WeeklyTimeSpan", + "protocol": "https", + "host": [ + "localhost" + ], + "port": "5001", + "path": [ + "api", + "v2", + "WeeklyTimeSpan" + ] + } + }, + "response": [] + }, + { + "name": "GetFunFactsOfWTS", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "var jsonData = JSON.parse(responseBody);\r", + "pm.environment.set(\"ffid\", jsonData[0].id);" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "GET", + "header": [], + "url": { + "raw": "https://localhost:5001/api/v2/FunFact/WeeklyTimeSpan/{{wtsid}}", + "protocol": "https", + "host": [ + "localhost" + ], + "port": "5001", + "path": [ + "api", + "v2", + "FunFact", + "WeeklyTimeSpan", + "{{wtsid}}" + ] + } + }, + "response": [] + }, + { + "name": "AdminLogin", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "var jsonData = JSON.parse(responseBody);\r", + "pm.environment.set(\"token\", jsonData.access_token);" + ], + "type": "text/javascript" + } + } + ], + "request": { + "auth": { + "type": "noauth" + }, + "method": "POST", + "header": [], + "body": { + "mode": "urlencoded", + "urlencoded": [ + { + "key": "client_id", + "value": "postman", + "type": "text" + }, + { + "key": "client_secret", + "value": "cunci", + "type": "text" + }, + { + "key": "scope", + "value": "openid profile user_role api.readwrite", + "type": "text" + }, + { + "key": "username", + "value": "{{admin_username}}", + "type": "text" + }, + { + "key": "password", + "value": "{{admin_password}}", + "type": "text" + }, + { + "key": "grant_type", + "value": "password", + "type": "text" + } + ] + }, + "url": { + "raw": "https://localhost:5001/connect/token", + "protocol": "https", + "host": [ + "localhost" + ], + "port": "5001", + "path": [ + "connect", + "token" + ] + } + }, + "response": [] + }, + { + "name": "DeleteFunFact", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "var jsonData = JSON.parse(responseBody);\r", + "pm.environment.set(\"pauseid\", jsonData.id);" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "DELETE", + "header": [], + "url": { + "raw": "https://localhost:5001/api/v2/FunFact/{{ffid}}", + "protocol": "https", + "host": [ + "localhost" + ], + "port": "5001", + "path": [ + "api", + "v2", + "FunFact", + "{{ffid}}" + ] + } + }, + "response": [] + }, + { + "name": "SeeUpdatedFunFactArray", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "var jsonData = JSON.parse(responseBody);\r", + "pm.environment.set(\"ffid\", jsonData[0].id);" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "GET", + "header": [], + "url": { + "raw": "https://localhost:5001/api/v2/FunFact/WeeklyTimeSpan/{{wtsid}}", + "protocol": "https", + "host": [ + "localhost" + ], + "port": "5001", + "path": [ + "api", + "v2", + "FunFact", + "WeeklyTimeSpan", + "{{wtsid}}" + ] + } + }, + "response": [] + } + ], + "auth": { + "type": "bearer", + "bearer": [ + { + "key": "token", + "value": "{{token}}", + "type": "string" + } + ] + }, + "event": [ + { + "listen": "prerequest", + "script": { + "type": "text/javascript", + "exec": [ + "" + ] + } + }, + { + "listen": "test", + "script": { + "type": "text/javascript", + "exec": [ + "" + ] + } + } + ] +} \ No newline at end of file diff --git a/PartTwo.postman_collection.json b/PartTwo.postman_collection.json new file mode 100644 index 0000000..a59d13e --- /dev/null +++ b/PartTwo.postman_collection.json @@ -0,0 +1,303 @@ +{ + "info": { + "_postman_id": "a75b1318-dde6-4c61-a12c-5471a16903b2", + "name": "PartTwo", + "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json" + }, + "item": [ + { + "name": "AddPauseToWeeklyTimeSpan", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "var jsonData = JSON.parse(responseBody);\r", + "pm.environment.set(\"pauseid\", jsonData.id);" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [], + "body": { + "mode": "raw", + "raw": "{\r\n \"weeklyTimeSpanId\": {{wtsid}},\r\n \"startdate\": \"2021-03-19T22:25:15.867Z\",\r\n \"enddate\": \"2021-03-22T22:25:15.867Z\"\r\n}", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "https://localhost:5001/api/v2/Pause", + "protocol": "https", + "host": [ + "localhost" + ], + "port": "5001", + "path": [ + "api", + "v2", + "Pause" + ] + } + }, + "response": [] + }, + { + "name": "GetUserDefault", + "request": { + "method": "GET", + "header": [], + "url": { + "raw": "https://localhost:5001/api/v2/HanyadikHetVan/my", + "protocol": "https", + "host": [ + "localhost" + ], + "port": "5001", + "path": [ + "api", + "v2", + "HanyadikHetVan", + "my" + ] + } + }, + "response": [] + }, + { + "name": "InspectPause", + "request": { + "method": "GET", + "header": [], + "url": { + "raw": "https://localhost:5001/api/v2/Pause/{{pauseid}}", + "protocol": "https", + "host": [ + "localhost" + ], + "port": "5001", + "path": [ + "api", + "v2", + "Pause", + "{{pauseid}}" + ] + } + }, + "response": [] + }, + { + "name": "InspectWTS", + "request": { + "method": "GET", + "header": [], + "url": { + "raw": "https://localhost:5001/api/v2/WeeklyTimeSpan/{{wtsid}}", + "protocol": "https", + "host": [ + "localhost" + ], + "port": "5001", + "path": [ + "api", + "v2", + "WeeklyTimeSpan", + "{{wtsid}}" + ] + } + }, + "response": [] + }, + { + "name": "AdminLogin", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "var jsonData = JSON.parse(responseBody);\r", + "pm.environment.set(\"token\", jsonData.access_token);" + ], + "type": "text/javascript" + } + } + ], + "request": { + "auth": { + "type": "noauth" + }, + "method": "POST", + "header": [], + "body": { + "mode": "urlencoded", + "urlencoded": [ + { + "key": "client_id", + "value": "postman", + "type": "text" + }, + { + "key": "client_secret", + "value": "cunci", + "type": "text" + }, + { + "key": "scope", + "value": "openid profile user_role api.readwrite", + "type": "text" + }, + { + "key": "username", + "value": "{{admin_username}}", + "type": "text" + }, + { + "key": "password", + "value": "{{admin_password}}", + "type": "text" + }, + { + "key": "grant_type", + "value": "password", + "type": "text" + } + ] + }, + "url": { + "raw": "https://localhost:5001/connect/token", + "protocol": "https", + "host": [ + "localhost" + ], + "port": "5001", + "path": [ + "connect", + "token" + ] + } + }, + "response": [] + }, + { + "name": "DeletePause", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "var jsonData = JSON.parse(responseBody);\r", + "pm.environment.set(\"pauseid\", jsonData.id);" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "DELETE", + "header": [], + "url": { + "raw": "https://localhost:5001/api/v2/Pause/{{pauseid}}", + "protocol": "https", + "host": [ + "localhost" + ], + "port": "5001", + "path": [ + "api", + "v2", + "Pause", + "{{pauseid}}" + ] + } + }, + "response": [] + }, + { + "name": "InspectWTS-AfterDelete", + "request": { + "method": "GET", + "header": [], + "url": { + "raw": "https://localhost:5001/api/v2/WeeklyTimeSpan/{{wtsid}}", + "protocol": "https", + "host": [ + "localhost" + ], + "port": "5001", + "path": [ + "api", + "v2", + "WeeklyTimeSpan", + "{{wtsid}}" + ] + } + }, + "response": [] + }, + { + "name": "UpdateWTS", + "request": { + "method": "PUT", + "header": [], + "body": { + "mode": "raw", + "raw": "{\r\n \"id\": {{wtsid}},\r\n \"startdate\": \"2021-01-19T22:50:31.312Z\"\r\n}", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "https://localhost:5001/api/v2/WeeklyTimeSpan", + "protocol": "https", + "host": [ + "localhost" + ], + "port": "5001", + "path": [ + "api", + "v2", + "WeeklyTimeSpan" + ] + } + }, + "response": [] + } + ], + "auth": { + "type": "bearer", + "bearer": [ + { + "key": "token", + "value": "{{token}}", + "type": "string" + } + ] + }, + "event": [ + { + "listen": "prerequest", + "script": { + "type": "text/javascript", + "exec": [ + "" + ] + } + }, + { + "listen": "test", + "script": { + "type": "text/javascript", + "exec": [ + "" + ] + } + } + ] +} \ No newline at end of file