Changeset d76b7ee


Ignore:
Timestamp:
05/12/22 16:36:14 (3 years ago)
Author:
Danilo <danilo.najkov@…>
Branches:
master
Children:
cc4db18
Parents:
7a983b0
Message:

prototype final

Files:
26 added
5 edited

Legend:

Unmodified
Added
Removed
  • resTools_backend/backend/Controllers/ReservationsController.cs

    r7a983b0 rd76b7ee  
    2020    }
    2121
     22    [Authorize]
     23    [HttpGet()]
     24    public async Task<List<ReservationResponse>> GetReservations([FromQuery] DateTime from, [FromQuery] DateTime to)
     25    {
     26        return await _reservationService.GetReservatins(from, to);
     27    }
     28
    2229    [HttpPost()]
    2330    public async Task<IActionResult> CreateReservation([FromBody] CreateReservationRequest req)
  • resTools_backend/backend/Controllers/UsersController.cs

    r7a983b0 rd76b7ee  
    22
    33using backend.DTOs;
     4using backend.Entities;
    45using backend.Helpers;
    56using backend.Models;
     
    2930    }
    3031
     32    [HttpGet("authed")]
     33    public async Task<AuthenticateResponse> IsAuthed()
     34    {
     35        int userId = 0;
     36        try
     37        {
     38            userId = (int)this.HttpContext.Items["User"];
     39        }catch (Exception ex){ return null; }
     40        User user = await _userService.GetById(userId);
     41        return new AuthenticateResponse() { Email=user.Email, Id = user.Id};
     42    }
     43
    3144    [HttpPost("register")]
    3245    public async Task<AuthenticateResponse> Register(CreateUserRequest req)
  • resTools_backend/backend/DTOs/RestaurantResponse.cs

    r7a983b0 rd76b7ee  
    1010        public int? OwnerId { get; set; }
    1111        [JsonProperty]
    12         public List<ReservationResponse> Reservations { get; set; }
    13         [JsonProperty]
    1412        public string Name { get; set; }
    1513    }
  • resTools_backend/backend/Services/ReservationService.cs

    r7a983b0 rd76b7ee  
    1010        public Task CreateReservation(CreateReservationRequest req);
    1111        public Task ChangeReservationStatus(int resId, ReservationStatus status);
     12        public Task<List<ReservationResponse>> GetReservatins(DateTime from, DateTime to);
    1213    }
    1314    public class ReservationService : IReservationService
     
    4849            await _context.SaveChangesAsync();
    4950        }
     51
     52        public async Task<List<ReservationResponse>> GetReservatins(DateTime from, DateTime to)
     53        {
     54            Restaurant res = await _context.Restoraunts
     55                .Include(x => x.Reservations
     56                    .Where(x => x.StartDate.CompareTo(from)>0 && x.StartDate.CompareTo(to)<=0))
     57                .FirstOrDefaultAsync();
     58            var reservations = res.Reservations.Select(t => new ReservationResponse()
     59            {
     60                ContactName = t.ContactName,
     61                ContactNumber = t.ContactNumber,
     62                Persons = t.Persons,
     63                StartDate = t.StartDate,
     64                ReservationStatus = t.ReservationStatus,
     65                Id = t.Id,
     66                ReservationPlace = t.ReservationPlace,
     67                ReservationType = t.ReservationType
     68            }).OrderByDescending(x => x.ReservationStatus == ReservationStatus.New).ToList();
     69            return reservations;
     70        }
    5071    }
    5172}
  • resTools_backend/backend/Services/RestaurantService.cs

    r7a983b0 rd76b7ee  
    3030        {
    3131            RestaurantResponse res = await _context.Restoraunts
    32                 .Include(x => x.Reservations)
    3332                .Select(x => new RestaurantResponse()
    3433                {
     
    3635                    Name = x.Name,
    3736                    OwnerId = x.OwnerFk,
    38                     Reservations = x.Reservations.Select(t => new ReservationResponse()
    39                     {
    40                         ContactName = t.ContactName,
    41                         ContactNumber = t.ContactNumber,
    42                         Persons = t.Persons,
    43                         StartDate = t.StartDate,
    44                         ReservationStatus = t.ReservationStatus,
    45                         Id = t.Id,
    46                         ReservationPlace = t.ReservationPlace,
    47                         ReservationType = t.ReservationType
    48                     }).ToList()
    4937                })
    5038                .FirstOrDefaultAsync();
Note: See TracChangeset for help on using the changeset viewer.