final
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Torma Kristóf 2021-05-20 01:36:54 +02:00
parent beab15a7ef
commit 10c1bb008f
Signed by: tormakris
GPG Key ID: DC83C4F2C41B1047
19 changed files with 1632 additions and 19 deletions

View File

@ -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"
}

View File

@ -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<IActionResult> 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<IActionResult> UpdatePause(int funfactId, [FromBody] FunFactDTO funfact)
{
try
{
var obj = await _funfactService.UpdateFunFact(funfactId, funfact);
return Ok(obj);
}
catch (Exception)
{
return NotFound();
}
}
}
}

View File

@ -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<IActionResult> 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<IActionResult> DeletePause(int pauseId)

View File

@ -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<IActionResult> UpdateWeeklyTimeSpan([FromBody] UserDTO user)
{
try
{
var userobj = await _userservice.CreateUser(user);
return Ok(userobj);
}
catch (Exception)
{
return BadRequest();
}
}
}
}

View File

@ -2,6 +2,8 @@
{
public class FunFactDTO
{
public int Id { get; set; }
public double FunFactor { get; set; }
public string Fact { get; set; }

View File

@ -16,5 +16,23 @@ namespace HanyadikHetVan.Data
: base(options)
{
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.Entity<Pause>()
.HasOne(s => s.WeeklyTimeSpan)
.WithMany(s => s.Pauses)
.OnDelete(DeleteBehavior.ClientCascade);
modelBuilder.Entity<FunFact>()
.HasOne(s => s.WeeklyTimeSpan)
.WithMany(s => s.FunFacts)
.OnDelete(DeleteBehavior.ClientCascade);
modelBuilder.Entity<WeeklyTimeSpan>()
.HasOne(s => s.User)
.WithMany(s => s.WeeklyTimeSpans)
.OnDelete(DeleteBehavior.ClientCascade);
}
}
}

View File

@ -0,0 +1,383 @@
// <auto-generated />
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<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int")
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
b.Property<string>("Fact")
.HasColumnType("nvarchar(max)");
b.Property<double>("FunFactor")
.HasColumnType("float");
b.Property<int>("WeeklyTimeSpanId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("WeeklyTimeSpanId");
b.ToTable("FunFacts");
});
modelBuilder.Entity("HanyadikHetVan.Data.Entities.Pause", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int")
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
b.Property<DateTime>("Enddate")
.HasColumnType("datetime2");
b.Property<DateTime>("Startdate")
.HasColumnType("datetime2");
b.Property<int>("WeeklyTimeSpanId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("WeeklyTimeSpanId");
b.ToTable("Pauses");
});
modelBuilder.Entity("HanyadikHetVan.Data.Entities.User", b =>
{
b.Property<string>("Id")
.HasColumnType("nvarchar(450)");
b.Property<int>("AccessFailedCount")
.HasColumnType("int");
b.Property<string>("ConcurrencyStamp")
.IsConcurrencyToken()
.HasColumnType("nvarchar(max)");
b.Property<string>("Email")
.HasMaxLength(256)
.HasColumnType("nvarchar(256)");
b.Property<bool>("EmailConfirmed")
.HasColumnType("bit");
b.Property<bool>("LockoutEnabled")
.HasColumnType("bit");
b.Property<DateTimeOffset?>("LockoutEnd")
.HasColumnType("datetimeoffset");
b.Property<string>("NormalizedEmail")
.HasMaxLength(256)
.HasColumnType("nvarchar(256)");
b.Property<string>("NormalizedUserName")
.HasMaxLength(256)
.HasColumnType("nvarchar(256)");
b.Property<string>("PasswordHash")
.HasColumnType("nvarchar(max)");
b.Property<string>("PhoneNumber")
.HasColumnType("nvarchar(max)");
b.Property<bool>("PhoneNumberConfirmed")
.HasColumnType("bit");
b.Property<string>("SecurityStamp")
.HasColumnType("nvarchar(max)");
b.Property<bool>("TwoFactorEnabled")
.HasColumnType("bit");
b.Property<string>("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<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int")
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
b.Property<DateTime>("Startdate")
.HasColumnType("datetime2");
b.Property<string>("UserId")
.HasColumnType("nvarchar(450)");
b.HasKey("Id");
b.HasIndex("UserId");
b.ToTable("WeeklyTimeSpans");
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRole", b =>
{
b.Property<string>("Id")
.HasColumnType("nvarchar(450)");
b.Property<string>("ConcurrencyStamp")
.IsConcurrencyToken()
.HasColumnType("nvarchar(max)");
b.Property<string>("Name")
.HasMaxLength(256)
.HasColumnType("nvarchar(256)");
b.Property<string>("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<string>", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int")
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
b.Property<string>("ClaimType")
.HasColumnType("nvarchar(max)");
b.Property<string>("ClaimValue")
.HasColumnType("nvarchar(max)");
b.Property<string>("RoleId")
.IsRequired()
.HasColumnType("nvarchar(450)");
b.HasKey("Id");
b.HasIndex("RoleId");
b.ToTable("AspNetRoleClaims");
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim<string>", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int")
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
b.Property<string>("ClaimType")
.HasColumnType("nvarchar(max)");
b.Property<string>("ClaimValue")
.HasColumnType("nvarchar(max)");
b.Property<string>("UserId")
.IsRequired()
.HasColumnType("nvarchar(450)");
b.HasKey("Id");
b.HasIndex("UserId");
b.ToTable("AspNetUserClaims");
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin<string>", b =>
{
b.Property<string>("LoginProvider")
.HasColumnType("nvarchar(450)");
b.Property<string>("ProviderKey")
.HasColumnType("nvarchar(450)");
b.Property<string>("ProviderDisplayName")
.HasColumnType("nvarchar(max)");
b.Property<string>("UserId")
.IsRequired()
.HasColumnType("nvarchar(450)");
b.HasKey("LoginProvider", "ProviderKey");
b.HasIndex("UserId");
b.ToTable("AspNetUserLogins");
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole<string>", b =>
{
b.Property<string>("UserId")
.HasColumnType("nvarchar(450)");
b.Property<string>("RoleId")
.HasColumnType("nvarchar(450)");
b.HasKey("UserId", "RoleId");
b.HasIndex("RoleId");
b.ToTable("AspNetUserRoles");
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken<string>", b =>
{
b.Property<string>("UserId")
.HasColumnType("nvarchar(450)");
b.Property<string>("LoginProvider")
.HasColumnType("nvarchar(450)");
b.Property<string>("Name")
.HasColumnType("nvarchar(450)");
b.Property<string>("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<string>", b =>
{
b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null)
.WithMany()
.HasForeignKey("RoleId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim<string>", b =>
{
b.HasOne("HanyadikHetVan.Data.Entities.User", null)
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin<string>", b =>
{
b.HasOne("HanyadikHetVan.Data.Entities.User", null)
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole<string>", 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<string>", 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
}
}
}

View File

@ -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);
}
}
}

View File

@ -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");
});

View File

@ -9,7 +9,7 @@ namespace HanyadikHetVan.Profiles
public FunFactProfile()
{
CreateMap<FunFact, FunFactDTO>();
CreateMap<FunFactDTO, FunFact>().ForMember(x => x.Id, options => options.Ignore()).ForMember(x => x.WeeklyTimeSpanId, options => options.Ignore()).ForMember(x => x.Id, options => options.Ignore());
CreateMap<FunFactDTO, FunFact>().ForMember(x => x.Id, options => options.Ignore()).ForMember(x => x.WeeklyTimeSpanId, options => options.Ignore()).ForMember(x => x.WeeklyTimeSpan, options => options.Ignore());
}
}
}

View File

@ -32,5 +32,30 @@ namespace HanyadikHetVan.Services
var funfact = await _dbContext.FunFacts.Where(x => x.Id == funfactId).FirstOrDefaultAsync();
return funfact.FunFactor;
}
public async Task<bool> 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<FunFactDTO> UpdateFunFact(int funfactId, FunFactDTO funfact)
{
var funfactentity = _mapper.Map<FunFactDTO, FunFact>(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<FunFact, FunFactDTO>(newff);
}
}
}

View File

@ -27,9 +27,17 @@ namespace HanyadikHetVan.Services
return _mapper.Map<List<Pause>, List<PauseDTO>>(pauses);
}
public async Task<PauseDTO> AddPause(PauseDTO pause)
public async Task<PauseDTO> 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<PauseDTO, Pause>(pause);
pauseEntity.WeeklyTimeSpanId = pause.WeeklyTimeSpanId;
var obj = _dbContext.Pauses.Add(pauseEntity);
await _dbContext.SaveChangesAsync();
return _mapper.Map<Pause, PauseDTO>(obj.Entity);

View File

@ -14,23 +14,23 @@ namespace HanyadikHetVan.Services
{
_userManager = userManager ?? throw new ArgumentNullException(nameof(userManager));
}
public async Task<UserDTO> CreateUser(string email, string password)
public async Task<UserDTO> 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 };
}
}
}

View File

@ -24,25 +24,25 @@ namespace HanyadikHetVan.Services
public async Task<List<WeeklyTimeSpanDTO>> 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<WeeklyTimeSpan>, List<WeeklyTimeSpanDTO>>(wts);
}
public async Task<WeeklyTimeSpanDTO> 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<WeeklyTimeSpan, WeeklyTimeSpanDTO>(wts);
}
public async Task<List<PauseDTO>> 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<ICollection<Pause>, List<PauseDTO>>(pauses.Pauses);
}
public async Task<WeeklyTimeSpanDTO> 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<List<WeeklyTimeSpan>, WeeklyTimeSpanDTO>(wts);
}

View File

@ -38,6 +38,7 @@ namespace HanyadikHetVan
services.AddAutoMapper(Assembly.GetExecutingAssembly());
services.AddTransient<WeeklyTimeSpanService>();
services.AddTransient<PauseService>();
services.AddTransient<UserService>();
services.AddTransient<FunFactService>();
services.AddTransient<HanyadikHetVanEntityService>();
services.AddTransient<HanyadikHetVanJsonService>();

File diff suppressed because one or more lines are too long

View File

@ -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": [
""
]
}
}
]
}

View File

@ -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": [
""
]
}
}
]
}

View File

@ -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": [
""
]
}
}
]
}