Skip to content

Commit

Permalink
fix build errors
Browse files Browse the repository at this point in the history
  • Loading branch information
SjoenH committed Apr 19, 2024
1 parent c657e0f commit 47832e2
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ public async Task<IActionResult> GetBookingRequest([Required] Guid id)
try
{
var bookingRequest = await bookingRequestService.GetBookingRequest(id);
if (bookingRequest == null)
{
return NotFound("Booking request does not exist or does not belong to the current user");
}

return Ok(BookingRequestDto.FromModel(bookingRequest));
}
catch (Exception ex)
Expand Down Expand Up @@ -50,6 +55,11 @@ public async Task<IActionResult> AddBookingRequests([Required] IEnumerable<Creat
try
{
var bookingRequest = await bookingRequestService.AddBookingRequest(requests.First());
if (bookingRequest == null)
{
return BadRequest("Booking request could not be added");
}

return Ok(BookingRequestDto.FromModel(bookingRequest));
}
catch (Exception e)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,23 @@ public class BookingRequestDto(
Guid createdBy,
DateTime? updatedDate,
Guid? updatedBy,
UserEntity user,
PeriodEntity period)
UserEntity? user,
PeriodEntity? period)
{
public Guid Id { get; set; } = id;
public Guid UserId { get; set; } = userId;
public UserEntity User { get; set; } = user;
public PeriodEntity Period { get; set; } = period;
public UserEntity? User { get; set; } = user;
public PeriodEntity? Period { get; set; } = period;
public Guid PeriodId { get; set; } = periodId;
public DateTime CreatedDate { get; set; } = createdDate;
public Guid CreatedBy { get; set; } = createdBy;
public DateTime? UpdatedDate { get; set; } = updatedDate;
public Guid? UpdatedBy { get; set; } = updatedBy;

public static BookingRequestDto FromModel(BookingRequestEntity? e)
public static BookingRequestDto FromModel(BookingRequestEntity e)
{
return new BookingRequestDto(e.Id, e.UserId, e.PeriodId, e.CreatedDate, e.CreatedBy, e.UpdatedDate, e.UpdatedBy,
return new BookingRequestDto(e.Id, e.UserId, e.PeriodId, e.CreatedDate, e.CreatedBy, e.UpdatedDate,
e.UpdatedBy,
e.User, e.Period);
}
}
4 changes: 2 additions & 2 deletions kabinizer-back-end/kabinizer-api/Model/Period.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

namespace kabinizer_api.Model;

public record Period(Guid Id, DateTime PeriodStart, DateTime PeriodEnd, string Title, Guid DrawId)
public record Period(Guid Id, DateTime PeriodStart, DateTime PeriodEnd, string? Title, Guid DrawId)
{
public Period(DateTime periodStart, DateTime periodEnd, string title, Guid DrawId)
public Period(DateTime periodStart, DateTime periodEnd, string? title, Guid DrawId)
: this(Guid.NewGuid(), periodStart, periodEnd, title, DrawId)
{
}
Expand Down
2 changes: 1 addition & 1 deletion kabinizer-back-end/kabinizer-api/Model/User.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace kabinizer_api.Model;

public record User(Guid Id, string Name)
public record User(Guid Id, string? Name)
{
public static User FromEntity(UserEntity u)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,15 @@ public async Task<IEnumerable<BookingRequestEntity>> GetBookingRequests()
throw new Exception("User does not exist");
}

var bookingRequest = new BookingRequestEntity(tokenService.GetUserId(), request.PeriodId, user, period);
var bookingRequest = new BookingRequestEntity
{
PeriodId = period.Id,
UserId = user.Id,
CreatedDate = DateTime.Now,
CreatedBy = user.Id,
User = user,
Period = period
};
entityContext.BookingRequests.Add(bookingRequest);
await entityContext.SaveChangesAsync();
return bookingRequest;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public static byte[] ExportToCsv(IEnumerable<Model.BookingRequest> requests)
using StreamWriter streamWriter = new(memoryStream);
CsvConfiguration config = new(CultureInfo.CurrentCulture) { Delimiter = ";", Encoding = Encoding.UTF8 };
using CsvWriter csv = new(streamWriter, config);

csv.WriteRecords(ConvertToCsvRecords(requests));
streamWriter.Flush();
return memoryStream.ToArray();
Expand All @@ -31,8 +31,8 @@ private static IEnumerable<CsvRecord> ConvertToCsvRecords(IEnumerable<Model.Book
.GroupBy(
req => req.User.Name,
req => ConvertDateToWeekNumber(req.Period.PeriodStart),
(name, weeks) => new CsvRecord(name.ToString(), string.Join(", ", weeks)));
(name, weeks) => new CsvRecord(name?.ToString(), string.Join(", ", weeks)));
}

private record CsvRecord(string Name, string Weeks);
private record CsvRecord(string? Name, string Weeks);
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,16 @@ public class BookingRequestEntity(
DateTime? updatedDate,
Guid? updatedBy,
UserEntity user,
PeriodEntity period)
PeriodEntity period
)
{
public BookingRequestEntity() : this(Guid.NewGuid(), Guid.Empty, Guid.Empty, DateTime.Now, Guid.Empty, null, null,
new UserEntity(), new PeriodEntity { Title = null, DrawId = default }
)
{
}


public Guid Id { get; set; } = id;
public Guid UserId { get; set; } = userId;
public UserEntity User { get; set; } = user;
Expand All @@ -23,9 +31,4 @@ public class BookingRequestEntity(
public Guid CreatedBy { get; set; } = createdBy;
public DateTime? UpdatedDate { get; set; } = updatedDate;
public Guid? UpdatedBy { get; set; } = updatedBy;

public BookingRequestEntity(Guid userId, Guid periodId, UserEntity user, PeriodEntity period) : this(Guid.NewGuid(),
userId, periodId, DateTime.Now, userId, null, null, user, period)
{
}
}
2 changes: 1 addition & 1 deletion kabinizer-back-end/kabinizer-data/Entities/PeriodEntity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public class PeriodEntity
public Guid Id { get; set; }
public DateTime PeriodStart { get; set; }
public DateTime PeriodEnd { get; set; }
public required string Title { get; set; }
public required string? Title { get; set; }

public required Guid DrawId { get; set; }
public DrawEntity? Draw { get; set; }
Expand Down
2 changes: 1 addition & 1 deletion kabinizer-back-end/kabinizer-data/Entities/UserEntity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ namespace kabinizer_data.Entities;
public class UserEntity
{
public Guid Id { get; set; }
public string Name { get; set; }
public string? Name { get; set; }
}

0 comments on commit 47832e2

Please sign in to comment.