Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(admin-ui): added possibility to add draws, minor text color chan… #100

Open
wants to merge 34 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
74f3020
feat(admin-ui): added possibility to add draws, minor text color chan…
KristofferMarthinsen Apr 16, 2024
fe0fe48
feat(admin-ui): update titles and css
KristofferMarthinsen Apr 16, 2024
3bf6348
feat(admin-ui): add line instead of text
KristofferMarthinsen Apr 16, 2024
8448843
feat(admin-ui): clean up, rename states, move new feature to componen…
KristofferMarthinsen Apr 17, 2024
7e90db2
Merge branch 'main' into admin-ui-fix-henry-bug-too
KristofferMarthinsen Apr 17, 2024
b37edac
chore(admin-ui): generate api update spec tool
KristofferMarthinsen Apr 17, 2024
b1bb542
feat(admin-ui): add endpoint for delete draw
KristofferMarthinsen Apr 17, 2024
9b21663
feat: correct delete endpoint stuff
KristofferMarthinsen Apr 17, 2024
90f6c34
chore: comit stuff
KristofferMarthinsen Apr 17, 2024
768d1d6
Merge branch 'main' into admin-ui-fix-henry-bug-too
KristofferMarthinsen Apr 17, 2024
06d182a
Merge branch 'main' into admin-ui-fix-henry-bug-too
KristofferMarthinsen Apr 17, 2024
0fc8785
chore: date fns
KristofferMarthinsen Apr 17, 2024
5c00e17
feat(admin-ui): can delete stuff
KristofferMarthinsen Apr 17, 2024
5ff0102
chore(admin-ui): remove log
KristofferMarthinsen Apr 17, 2024
99feefa
feat(admin-ui): delete periods, beautiful design
KristofferMarthinsen Apr 18, 2024
d89bdbc
feat(admin-ui): rounded stuff
KristofferMarthinsen Apr 18, 2024
11234bb
feat(admin-ui): put shit up 👷🏽‍♀️
KristofferMarthinsen Apr 18, 2024
3f118f6
chore(admin-ui): wip edit
KristofferMarthinsen Apr 18, 2024
3460316
chore(admin-ui): clean up
KristofferMarthinsen Apr 19, 2024
8f9f960
feat(admin-ui): make title required
KristofferMarthinsen Apr 19, 2024
e00aca5
feat(admin-ui): can update multiple periods in draws
KristofferMarthinsen Apr 22, 2024
66ae2cd
feat(admin-ui): add date-fns
KristofferMarthinsen Apr 22, 2024
62fd2d8
Merge branch 'main' into admin-ui-fix-henry-bug-too
KristofferMarthinsen Apr 22, 2024
f4d000b
chore(admin-ui): add api stuff
KristofferMarthinsen Apr 22, 2024
d80d734
feat(admin-ui): stuff works again after henry refactor
KristofferMarthinsen Apr 23, 2024
b0e5c43
chore(admin-ui): validation
KristofferMarthinsen Apr 23, 2024
3c29988
feat(admin-ui): wiparino
KristofferMarthinsen Apr 25, 2024
98e5945
feat(admin-ui): tanstack wip
KristofferMarthinsen Apr 29, 2024
113fc5f
feat(admin-ui): 🧠
KristofferMarthinsen Apr 29, 2024
f67a9cb
feat(admin-ui): rewrite to tanstack forms 🧑🏽‍🦰
KristofferMarthinsen Apr 30, 2024
a817425
feat(admin-ui): norskifisering
KristofferMarthinsen May 6, 2024
ee752ca
Merge branch 'main' into admin-ui-fix-henry-bug-too
KristofferMarthinsen May 24, 2024
37e395e
chore(admin-ui): remove unused component
KristofferMarthinsen May 24, 2024
7c128e5
chore(admin-ui): refactor draws -> draw -> draws -> draw
KristofferMarthinsen May 24, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 22 additions & 3 deletions kabinizer-back-end/kabinizer-api/Controllers/DrawController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,35 @@ public async Task<ActionResult<DrawEntity>> GetDraw([Required] Guid drawId)
}

[HttpPost]
public async Task<ActionResult<DrawEntity>> CreateDraw([Required] CreateDrawDto draw)
public async Task<ActionResult<ReadDrawDto>> CreateDraw([Required] CreateDrawDto draw)
{
var createdDraw = await drawService.CreateDraw(draw);
return CreatedAtAction(nameof(GetDraws), new { drawId = createdDraw.Id }, createdDraw);
return Ok(ReadDrawDto.FromEntity(createdDraw));
}

[HttpDelete("{drawId:guid}")]



[HttpPut]

public IActionResult UpdateDraw([Required] UpdateDrawDto draw)
{
try
{
drawService.UpdateDraw(draw);
return new NoContentResult();
}
catch (Exception)
{
return new NotFoundResult();
}
}

[HttpDelete]
public async Task<IActionResult> DeleteDraw([Required] Guid drawId)
{
await drawService.DeleteDraw(drawId);
return NoContent();
}

}
31 changes: 31 additions & 0 deletions kabinizer-back-end/kabinizer-api/Dtos/Draw/ReadDrawDto.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using kabinizer_data.Entities;

namespace kabinizer_api.Dtos.Draw;

public class ReadDrawDto
{
public DateTime DeadlineStart { get; set; }
public DateTime DeadlineEnd { get; set; }
public required string Title { get; set; }
public required List<DrawPeriod> DrawPeriods { get; set; }
public bool IsSpecial { get; set; }

internal static object? FromEntity(DrawEntity createdDraw)

{
return new ReadDrawDto
{
DeadlineStart = createdDraw.DeadlineStart,
DeadlineEnd = createdDraw.DeadlineEnd,
Title = createdDraw.Title,
DrawPeriods = createdDraw.Periods.Select(p => new DrawPeriod
{
Start = p.PeriodStart,
End = p.PeriodEnd,
Title = p.Title
}).ToList(),
IsSpecial = createdDraw.IsSpecial
};
}

}
12 changes: 12 additions & 0 deletions kabinizer-back-end/kabinizer-api/Dtos/Draw/UpdateDrawDto.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
namespace kabinizer_api.Dtos.Draw;

public class UpdateDrawDto
{
public required string Id { get; set; }
public DateTime Start { get; set; }
public DateTime End { get; set; }
public required string Title { get; set; }
public bool IsSpecial { get; set; }

public List<UpdatePeriod>? Periods { get; set; }
}
11 changes: 11 additions & 0 deletions kabinizer-back-end/kabinizer-api/Dtos/Draw/UpdatePeriod.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
namespace kabinizer_api.Dtos.Draw;

public class UpdatePeriod {

public required string Id { get; set; }
public DateTime PeriodStart { get; set; }
public DateTime PeriodEnd { get; set; }
public required string Title { get; set; }

public required string DrawId { get; set; }
}
14 changes: 11 additions & 3 deletions kabinizer-back-end/kabinizer-api/Services/Draw/DrawService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,17 @@ public async Task<DrawEntity> GetDraw(Guid drawId)
/**
* Update a draw
*/
public Task UpdateDraw(Guid drawId)
public void UpdateDraw(UpdateDrawDto draw)
{
throw new NotImplementedException();
var drawToUpdate = entityContext.Draws.Include(d => d.Periods).FirstOrDefault(d => d.Id == Guid.Parse(draw.Id))
?? throw new Exception("Draw not found");

drawToUpdate.DeadlineStart = draw.Start;
drawToUpdate.DeadlineEnd = draw.End;
drawToUpdate.Title = draw.Title;
drawToUpdate.IsSpecial = draw.IsSpecial;
drawToUpdate.Periods = periodService.UpdatePeriods(drawToUpdate.Id, draw.Periods);
entityContext.SaveChanges();
}

/**
Expand Down Expand Up @@ -102,4 +110,4 @@ public async Task DeleteDraw(Guid drawId)
.ToListAsync();
return draws.Select(Model.Draw.FromObject);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,25 @@ public List<PeriodEntity> CreatePeriods(Guid drawId, List<DrawPeriod> drawPeriod
return periodEntities;
}

internal List<PeriodEntity>? UpdatePeriods(Guid id, List<UpdatePeriod>? periods)
{
ArgumentNullException.ThrowIfNull(periods);

List<PeriodEntity> periodEntities = new();
foreach (UpdatePeriod updatePeriod in periods) {
PeriodEntity periodEntity = new()
{
PeriodStart = updatePeriod.PeriodStart,
PeriodEnd = updatePeriod.PeriodEnd,
Title = updatePeriod.Title,
DrawId = Guid.Parse(updatePeriod.DrawId)
};
periodEntities.Add(periodEntity);
}
return periodEntities;
}


private PeriodEntity CreateSinglePeriod(DrawPeriod drawPeriod, Guid drawId)
{
if (drawPeriod.Title?.Trim().Length == 0)
Expand Down Expand Up @@ -80,4 +99,4 @@ public async Task<List<PeriodEntity>> GetPastPeriods() =>
await entityContext.Periods.Where(p => p.PeriodEnd < DateTime.Now).ToListAsync();

public async Task<IEnumerable<PeriodEntity>> GetAllPeriods() => await entityContext.Periods.ToListAsync();
}
}
4 changes: 3 additions & 1 deletion kabinizer-back-end/kabinizer-data/Entities/DrawEntity.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
using System.ComponentModel.DataAnnotations.Schema;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;

namespace kabinizer_data.Entities;

[Table("Draw")]
public class DrawEntity
{
[Key]
public Guid Id { get; set; }
public DateTime DeadlineStart { get; set; }
public DateTime DeadlineEnd { get; set; }
Expand Down
9 changes: 4 additions & 5 deletions kabinizer-front-end/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,15 @@ export { CancelablePromise, CancelError } from "./core/CancelablePromise";
export { OpenAPI } from "./core/OpenAPI";
export type { OpenAPIConfig } from "./core/OpenAPI";

export type { BookingRequestDto } from "./models/BookingRequestDto";
export type { BookingRequest } from "./models/BookingRequest";
export type { CreateBookingRequestDto } from "./models/CreateBookingRequestDto";
export type { CreateDrawDto } from "./models/CreateDrawDto";
export type { Draw } from "./models/Draw";
export type { DrawEntity } from "./models/DrawEntity";
export type { DrawPeriod } from "./models/DrawPeriod";
export type { Period } from "./models/Period";
export type { PeriodEntity } from "./models/PeriodEntity";
export type { ProblemDetails } from "./models/ProblemDetails";
export type { ReadPeriodDto } from "./models/ReadPeriodDto";
export type { UpdateDrawDto } from "./models/UpdateDrawDto";
export type { UpdatePeriod } from "./models/UpdatePeriod";
export type { User } from "./models/User";

export { BookingRequestService } from "./services/BookingRequestService";
export { DrawService } from "./services/DrawService";
Expand Down
13 changes: 13 additions & 0 deletions kabinizer-front-end/api/models/BookingRequest.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/* generated using openapi-typescript-codegen -- do no edit */
/* istanbul ignore file */
/* tslint:disable */
/* eslint-disable */

import type { Period } from "./Period";
import type { User } from "./User";

export type BookingRequest = {
bookingRequestId?: string;
period?: Period;
user?: User;
};
14 changes: 0 additions & 14 deletions kabinizer-front-end/api/models/BookingRequestDto.ts

This file was deleted.

16 changes: 0 additions & 16 deletions kabinizer-front-end/api/models/DrawEntity.ts

This file was deleted.

16 changes: 0 additions & 16 deletions kabinizer-front-end/api/models/PeriodEntity.ts

This file was deleted.

12 changes: 0 additions & 12 deletions kabinizer-front-end/api/models/ReadPeriodDto.ts

This file was deleted.

14 changes: 14 additions & 0 deletions kabinizer-front-end/api/models/UpdateDrawDto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/* generated using openapi-typescript-codegen -- do no edit */
/* istanbul ignore file */
/* tslint:disable */
/* eslint-disable */

import type { UpdatePeriod } from "./UpdatePeriod";

export type UpdateDrawDto = {
id?: string | null;
end?: string;
title?: string | null;
isSpecial?: boolean;
periods?: Array<UpdatePeriod> | null;
};
12 changes: 12 additions & 0 deletions kabinizer-front-end/api/models/UpdatePeriod.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/* generated using openapi-typescript-codegen -- do no edit */
/* istanbul ignore file */
/* tslint:disable */
/* eslint-disable */

export type UpdatePeriod = {
id?: string | null;
periodStart?: string;
periodEnd?: string;
title?: string | null;
drawId?: string | null;
};
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,7 @@
/* tslint:disable */
/* eslint-disable */

export type ProblemDetails = Record<string, any>;
export type User = {
id?: string;
name?: string | null;
};
Loading