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

Edit resource UI #201

Merged
merged 15 commits into from
Jan 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
30 changes: 15 additions & 15 deletions src/deskstar-backend/Deskstar/Controllers/ResourcesController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ public IActionResult UpdateDesk(string deskId, UpdateDeskDto dto)
Guid? roomId = dto.RoomId == null ? null : new Guid(dto.RoomId);
Guid? deskTypeId = dto.DeskTypeId == null ? null : new Guid(dto.DeskTypeId);

_resourceUsecases.UpdateDesk(companyId, deskGuid, dto.DeskName, roomId, deskTypeId);

return Ok();
var desk = _resourceUsecases.UpdateDesk(companyId, deskGuid, dto.DeskName, roomId, deskTypeId);
var updatedDesk = _mapper.Map<Desk, UpdateDeskResponseObject>(desk);
return Ok(updatedDesk);
}
catch (EntityNotFoundException e)
{
Expand Down Expand Up @@ -106,9 +106,9 @@ public IActionResult UpdateDeskType(string deskTypeId, UpdateDeskTypeDto dto)
var deskTypeGuid = new Guid(deskTypeId);
var companyId = _userUsecases.ReadSpecificUser(adminId).CompanyId;

_resourceUsecases.UpdateDeskType(companyId, deskTypeGuid, dto.DeskTypeName);

return Ok();
var deskType = _resourceUsecases.UpdateDeskType(companyId, deskTypeGuid, dto.DeskTypeName);
var updatedDeskType = _mapper.Map<DeskType, UpdateDeskTypeResponseObject>(deskType);
return Ok(updatedDeskType);
}
catch (EntityNotFoundException e)
{
Expand Down Expand Up @@ -155,9 +155,9 @@ public IActionResult UpdateBuilding(string buildingId, UpdateBuildingDto dto)
var buildingGuid = new Guid(buildingId);
var companyId = _userUsecases.ReadSpecificUser(adminId).CompanyId;

_resourceUsecases.UpdateBuilding(companyId, buildingGuid, dto.BuildingName, dto.Location);

return Ok();
var building = _resourceUsecases.UpdateBuilding(companyId, buildingGuid, dto.BuildingName, dto.Location);
var updatedBuilding = _mapper.Map<Building, UpdateBuildingResponseObject>(building);
return Ok(updatedBuilding);
}
catch (EntityNotFoundException e)
{
Expand Down Expand Up @@ -205,9 +205,9 @@ public IActionResult UpdateFloor(string floorId, UpdateFloorDto dto)
var companyId = _userUsecases.ReadSpecificUser(adminId).CompanyId;
Guid? buildingGuid = dto.BuildingId == null ? null : new Guid(dto.BuildingId);

_resourceUsecases.UpdateFloor(companyId, floorGuid, dto.FloorName, buildingGuid);

return Ok();
var floor = _resourceUsecases.UpdateFloor(companyId, floorGuid, dto.FloorName, buildingGuid);
var updatedFloor = _mapper.Map<Floor, UpdateFloorResponseObject>(floor);
return Ok(updatedFloor);
}
catch (EntityNotFoundException e)
{
Expand Down Expand Up @@ -255,9 +255,9 @@ public IActionResult UpdateRoom(string roomId, UpdateRoomDto dto)
var companyId = _userUsecases.ReadSpecificUser(adminId).CompanyId;
Guid? floorId = dto.FloorId == null ? null : new Guid(dto.FloorId);

_resourceUsecases.UpdateRoom(companyId, roomGuid, dto.RoomName, floorId);

return Ok();
var room = _resourceUsecases.UpdateRoom(companyId, roomGuid, dto.RoomName, floorId);
var updatedRoom = _mapper.Map<Room, UpdateRoomResponseObject>(room);
return Ok(updatedRoom);
}
catch (EntityNotFoundException e)
{
Expand Down
47 changes: 26 additions & 21 deletions src/deskstar-backend/Deskstar/Models/AutoMapperConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,33 @@

namespace Deskstar.Models
{
public interface IAutoMapperConfiguration
{
public MapperConfiguration GetConfiguration();
}
public interface IAutoMapperConfiguration
{
public MapperConfiguration GetConfiguration();
}

public class AutoMapperConfiguration : IAutoMapperConfiguration
public class AutoMapperConfiguration : IAutoMapperConfiguration
{
public MapperConfiguration GetConfiguration()
{
public MapperConfiguration GetConfiguration()
{
var config = new MapperConfiguration(cfg =>
{
UserProfileDto.CreateMappings(cfg);
UserProfileCompanyDto.createMappings(cfg);
DeskTypeDto.createMappings(cfg);
ExtendedBooking.createMappings(cfg);
CreateBuildingResponseObject.createMappings(cfg);
CreateDeskResponseObject.createMappings(cfg);
CreateDeskTypeResponseObject.createMappings(cfg);
CreateFloorResponseObject.createMappings(cfg);
CreateRoomResponseObject.createMappings(cfg);
});
return config;
}
var config = new MapperConfiguration(cfg =>
{
UserProfileDto.CreateMappings(cfg);
UserProfileCompanyDto.createMappings(cfg);
DeskTypeDto.createMappings(cfg);
ExtendedBooking.createMappings(cfg);
CreateBuildingResponseObject.createMappings(cfg);
CreateDeskResponseObject.createMappings(cfg);
CreateDeskTypeResponseObject.createMappings(cfg);
CreateFloorResponseObject.createMappings(cfg);
CreateRoomResponseObject.createMappings(cfg);
UpdateBuildingResponseObject.createMappings(cfg);
UpdateDeskResponseObject.createMappings(cfg);
UpdateDeskTypeResponseObject.createMappings(cfg);
UpdateFloorResponseObject.createMappings(cfg);
UpdateRoomResponseObject.createMappings(cfg);
});
return config;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
using System.ComponentModel.DataAnnotations;
using AutoMapper;

namespace Deskstar.Models;

public class CreateBuildingResponseObject
{
public CreateBuildingResponseObject() { }
public CreateBuildingResponseObject() { }

public static void createMappings(IMapperConfigurationExpression cfg)
{
cfg.CreateMap<Entities.Building, CreateBuildingResponseObject>();
}
public static void createMappings(IMapperConfigurationExpression cfg)
{
cfg.CreateMap<Entities.Building, CreateBuildingResponseObject>();
}

public Guid BuildingId { get; set; }
public string BuildingName { get; set; } = null!;
public string Location { get; set; } = null!;
[Required]
public Guid BuildingId { get; set; }
[Required]
public string BuildingName { get; set; } = null!;
[Required]
public string Location { get; set; } = null!;
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace Deskstar.Models;

public class UpdateBuildingDto{
public string? BuildingName;
public string? Location;
public string? BuildingName {get;set;}
public string? Location {get;set;}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System.ComponentModel.DataAnnotations;
using AutoMapper;

namespace Deskstar.Models;

public class UpdateBuildingResponseObject
{
public static void createMappings(IMapperConfigurationExpression cfg)
{
cfg.CreateMap<Entities.Building, UpdateBuildingResponseObject>();
}
[Required]
public Guid BuildingId { get; set; }
[Required]
public string BuildingName { get; set; } = null!;
[Required]
public string Location { get; set; } = null!;
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ namespace Deskstar.Models;

public class UpdateDeskDto
{
public string? DeskName;
public string? RoomId;
public string? DeskTypeId;
public string? DeskName {get;set;}
public string? RoomId {get;set;}
public string? DeskTypeId {get;set;}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using System.ComponentModel.DataAnnotations;
using AutoMapper;

namespace Deskstar.Models;

public class UpdateDeskResponseObject
{
public static void createMappings(IMapperConfigurationExpression cfg)
{
cfg.CreateMap<Entities.Desk, UpdateDeskResponseObject>()
.ForMember(dest => dest.BuildingId, act => act.MapFrom(src => src.Room.Floor.Building.BuildingId))
.ForMember(dest => dest.BuildingName, act => act.MapFrom(src => src.Room.Floor.Building.BuildingName))
.ForMember(dest => dest.Location, act => act.MapFrom(src => src.Room.Floor.Building.Location))
.ForMember(dest => dest.FloorId, act => act.MapFrom(src => src.Room.Floor.FloorId))
.ForMember(dest => dest.FloorName, act => act.MapFrom(src => src.Room.Floor.FloorName))
.ForMember(dest => dest.Location, act => act.MapFrom(src => src.Room.Floor.Building.Location))
.ForMember(dest => dest.RoomId, act => act.MapFrom(src => src.Room.RoomId))
.ForMember(dest => dest.RoomName, act => act.MapFrom(src => src.Room.RoomName))
.ForMember(dest => dest.DeskTypeName, act => act.MapFrom(src => src.DeskType.DeskTypeName));
}
[Required]
public Guid DeskId { get; set; }
[Required]
public string DeskName { get; set; } = null!;
[Required]
public Guid DeskTypeId { get; set; }
[Required]
public string DeskTypeName { get; set; } = null!;
[Required]
public Guid RoomId { get; set; }
[Required]
public string RoomName { get; set; } = null!;
[Required]
public Guid FloorId { get; set; }
[Required]
public string FloorName { get; set; } = null!;
[Required]
public Guid BuildingId { get; set; }
[Required]
public string BuildingName { get; set; } = null!;
[Required]
public string Location { get; set; } = null!;
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
namespace Deskstar.Models;

public class UpdateDeskTypeDto{
public string? DeskTypeName;
public string? DeskTypeName {get;set;}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System.ComponentModel.DataAnnotations;
using AutoMapper;

namespace Deskstar.Models;

public class UpdateDeskTypeResponseObject
{
public static void createMappings(IMapperConfigurationExpression cfg)
{
cfg.CreateMap<Entities.DeskType, UpdateDeskTypeResponseObject>();
}
[Required]
public Guid DeskTypeId { get; set; }
[Required]
public string DeskTypeName { get; set; } = null!;

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace Deskstar.Models;

public class UpdateFloorDto{
public string? FloorName;
public string? BuildingId;
public string? FloorName {get;set;}
public string? BuildingId {get;set;}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using System.ComponentModel.DataAnnotations;
using AutoMapper;

namespace Deskstar.Models;

public class UpdateFloorResponseObject
{
public static void createMappings(IMapperConfigurationExpression cfg)
{
cfg.CreateMap<Entities.Floor, UpdateFloorResponseObject>()
.ForMember(dest => dest.BuildingName, act => act.MapFrom(src => src.Building.BuildingName))
.ForMember(dest => dest.Location, act => act.MapFrom(src => src.Building.Location));
}

[Required]
public Guid FloorId { get; set; }
[Required]
public string FloorName { get; set; } = null!;
[Required]
public Guid BuildingId { get; set; }
[Required]
public string BuildingName { get; set; } = null!;
[Required]
public string Location { get; set; } = null!;
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ namespace Deskstar.Models;

public class UpdateRoomDto
{
public string? FloorId;
public string? RoomName;
public string? FloorId {get;set;}
public string? RoomName {get;set;}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using System.ComponentModel.DataAnnotations;
using AutoMapper;

namespace Deskstar.Models;

public class UpdateRoomResponseObject
{

public static void createMappings(IMapperConfigurationExpression cfg)
{
cfg.CreateMap<Entities.Room, UpdateRoomResponseObject>()
.ForMember(dest => dest.BuildingName, act => act.MapFrom(src => src.Floor.Building.BuildingName))
.ForMember(dest => dest.BuildingId, act => act.MapFrom(src => src.Floor.Building.BuildingId))
.ForMember(dest => dest.FloorName, act => act.MapFrom(src => src.Floor.FloorName))
.ForMember(dest => dest.Location, act => act.MapFrom(src => src.Floor.Building.Location));
}
public Guid RoomId { get; set; }
[Required]
public string RoomName { get; set; } = null!;
[Required]
public Guid FloorId { get; set; }
[Required]
public string FloorName { get; set; } = null!;
[Required]
public Guid BuildingId { get; set; }
[Required]
public string BuildingName { get; set; } = null!;
[Required]
public string Location { get; set; } = null!;
}
Loading