| | 1 | | using Microsoft.AspNetCore.Mvc; |
| | 2 | | using WebApi.DAO; |
| | 3 | | using WebApi.Models; |
| | 4 | |
|
| | 5 | | namespace WebApi.Services |
| | 6 | | { |
| | 7 | | public class SensorDataService : ISensorDataService |
| | 8 | |
|
| | 9 | | { |
| | 10 | | private readonly ISensorDataDAO _sensorDataDao; |
| | 11 | |
|
| 3 | 12 | | public SensorDataService(ISensorDataDAO sensorDataDao) |
| 3 | 13 | | { |
| 3 | 14 | | _sensorDataDao = sensorDataDao; |
| 3 | 15 | | } |
| | 16 | | public async Task<List<SensorData>> GetSensorData(int hallId) |
| 1 | 17 | | { |
| 1 | 18 | | if (hallId == null) |
| | 19 | | { |
| | 20 | | throw new ArgumentNullException(nameof(hallId)); |
| | 21 | | } |
| 1 | 22 | | return await _sensorDataDao.GetSensorDataAsync(hallId); |
| 1 | 23 | | } |
| | 24 | |
|
| | 25 | | public async Task AddSensorDataAsync(SensorData sensorData) |
| 2 | 26 | | { |
| 2 | 27 | | if (sensorData == null) |
| 1 | 28 | | { |
| 1 | 29 | | throw new ArgumentNullException(nameof(sensorData)); |
| | 30 | | } |
| 1 | 31 | | await _sensorDataDao.AddSensorDataAsync(sensorData); |
| 1 | 32 | | } |
| | 33 | | public async Task<List<SensorData>> GetSensorData(int hallId, int limit) |
| 0 | 34 | | { |
| 0 | 35 | | return await _sensorDataDao.GetSensorDataAsync(hallId, limit); |
| 0 | 36 | | } |
| | 37 | | public async Task<List<SensorData>> GetSensorData(int hallId, DateTime startDate, DateTime endDate) |
| 0 | 38 | | { |
| 0 | 39 | | if (hallId == null) |
| | 40 | | { |
| | 41 | | throw new ArgumentNullException(nameof(hallId)); |
| | 42 | | } |
| 0 | 43 | | if (startDate == null || endDate == null) |
| | 44 | | { |
| | 45 | | throw new ArgumentNullException(nameof(startDate)); |
| | 46 | | } |
| | 47 | |
|
| 0 | 48 | | return await _sensorDataDao.GetSensorDataAsync(hallId, startDate, endDate); |
| 0 | 49 | | } |
| | 50 | | } |
| | 51 | | } |