Skip to content

Commit

Permalink
Merge branch 'main' into koroleva/serverCommunication
Browse files Browse the repository at this point in the history
  • Loading branch information
polinaKoroleva05 committed Nov 9, 2024
2 parents 8e0c403 + 3ca6a1e commit a79fc68
Show file tree
Hide file tree
Showing 48 changed files with 1,685 additions and 0 deletions.
24 changes: 24 additions & 0 deletions server/Controllers/CellsController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using Microsoft.AspNetCore.Mvc;
using Warehouse2.Models;
using Warehouse2.Services;

namespace Warehouse2.Controllers
{
[ApiController]
[Route("[controller]")]
public class CellsController : ControllerBase
{
private readonly CellsService _cellsService;

public CellsController(CellsService cellsService)
{
_cellsService = cellsService;
}


[HttpGet]
public async Task<List<Cell>> GetDocsIndices() =>
await _cellsService.ListDocsAsync();
}
}

24 changes: 24 additions & 0 deletions server/Controllers/EventsController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using Core.Arango.Protocol;
using Microsoft.AspNetCore.Mvc;
using Warehouse2.Models;
using Warehouse2.Services;

namespace Warehouse2.Controllers
{
[ApiController]
[Route("[controller]")]
public class EventsController : ControllerBase
{
private readonly EventsService _eventsService;

public EventsController(EventsService eventsService)
{
_eventsService = eventsService;
}


[HttpGet]
public async Task<List<Event>> GetDocsIndices() =>
await _eventsService.ListDocsAsync();
}
}
23 changes: 23 additions & 0 deletions server/Controllers/UsersController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using Microsoft.AspNetCore.Mvc;
using Warehouse2.Models;
using Warehouse2.Services;

namespace Warehouse2.Controllers
{
[ApiController]
[Route("[controller]")]
public class UsersController : ControllerBase
{
private readonly UsersService _usersService;

public UsersController(UsersService usersService)
{
_usersService = usersService;
}


[HttpGet]
public async Task<List<User>> GetDocsIndices() =>
await _usersService.ListDocsAsync();
}
}
23 changes: 23 additions & 0 deletions server/Controllers/WarehousesController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using Microsoft.AspNetCore.Mvc;
using Warehouse2.Models;
using Warehouse2.Services;

namespace Warehouse2.Controllers
{
[ApiController]
[Route("[controller]")]
public class WarehousesController
{
private readonly WarehousesService _warehousesService;

public WarehousesController(WarehousesService warehousesService)
{
_warehousesService = warehousesService;
}


[HttpGet]
public async Task<List<Warehouse>> GetDocsIndices() =>
await _warehousesService.ListDocsAsync();
}
}
27 changes: 27 additions & 0 deletions server/Models/Cell.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@


namespace Warehouse2.Models
{
public class Cell
{
public Cell() {}

public string? Id { get; set; }

public string? warehouseId { get; set; }

public int cellNum { get; set; }

public int tierNum { get; set; }

public bool isFree { get; set; }

public int endOfRent { get; set; }

public float tariffPerDay { get; set; }

public float size { get; set; }

public string[]? listOfEventIds { get; set; }
}
}
27 changes: 27 additions & 0 deletions server/Models/Event.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using Microsoft.VisualBasic;

namespace Warehouse2.Models
{
public class Event
{

public Event(string action, string description, int dat)
{
Action = action;
Descritpion = description;
DateAndTime = dat;
}

public string? Id { get; set; }

public string? CellId { get; set; }

public string? UserId { get; set; }

public string Action { get; set; }

public int DateAndTime { get; set; }

public string Descritpion { get; set; }
}
}
27 changes: 27 additions & 0 deletions server/Models/User.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@


namespace Warehouse2.Models
{
public class User
{
public User() { }

public string Id { get; set; }

public string? NameSurnamePatronymic { get; set; }

public string role { get; set; }

public string login { get; set; }

public string password { get; set; }

public int birthday { get; set; }

public int regDate { get; set; }

public int? editDate { get; set; }

public int indebtedness { get; set; }
}
}
17 changes: 17 additions & 0 deletions server/Models/Warehouse.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
namespace Warehouse2.Models
{
public class Warehouse
{
Warehouse() { }

public string? Id { get; set; }

public string? address { get; set; }

public int? capacity { get; set; }

public string? chiefId { get; set; }

public string[]? cells { get; set; }
}
}
17 changes: 17 additions & 0 deletions server/Models/WarehouseDatabaseSettings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
namespace Warehouse2.Models
{
public class WarehouseDatabaseSettings
{
public string ConnectionString { get; set; } = null!;

public string DatabaseName { get; set; } = null!;

public string CellsCollectionName { get; set; } = null!;

public string EventCollectionName { get; set; } = null!;

public string UsersCollectionName { get; set; } = null!;

public string WarehousesCollectionName { get; set; } = null!;
}
}
35 changes: 35 additions & 0 deletions server/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using Core.Arango;
using Warehouse2.Models;
using Warehouse2.Services;


var builder = WebApplication.CreateBuilder(args);

// Add services to the container.

builder.Services.Configure<WarehouseDatabaseSettings>(
builder.Configuration.GetSection("WarehouseDatabase"));

builder.Services.AddSingleton<EventsService>();
builder.Services.AddSingleton<CellsService>();
builder.Services.AddSingleton<UsersService>();
builder.Services.AddSingleton<WarehousesService>();
//builder.Services.AddArango(builder.Configuration.GetConnectionString("ConnctingString"));

builder.Services.AddControllers();
builder.Services.AddSwaggerGen();

var app = builder.Build();

// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
}

app.UseAuthorization();

app.MapControllers();

app.Run();
31 changes: 31 additions & 0 deletions server/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"$schema": "http://json.schemastore.org/launchsettings.json",
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:38294",
"sslPort": 0
}
},
"profiles": {
"http": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"launchUrl": "swagger",
"applicationUrl": "http://localhost:5085",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"launchUrl": "swagger",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}
31 changes: 31 additions & 0 deletions server/Services/CellsService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using Core.Arango;
using Microsoft.Extensions.Options;
using Warehouse2.Models;

namespace Warehouse2.Services
{
public class CellsService
{
private readonly IArangoContext _arango;

private readonly string _dbName;

private readonly string _collectionName;

public CellsService(IOptions<WarehouseDatabaseSettings> WarehouseDatabaseSettings)
{
_arango = new ArangoContext(WarehouseDatabaseSettings.Value.ConnectionString);

_dbName = WarehouseDatabaseSettings.Value.DatabaseName;

_collectionName = WarehouseDatabaseSettings.Value.CellsCollectionName;

}


public async Task<List<Cell>> ListDocsAsync()
{
return await _arango.Query.FindAsync<Cell>(_dbName, _collectionName, $"x");
}
}
}
39 changes: 39 additions & 0 deletions server/Services/EventsService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using Core.Arango;
using Core.Arango.Modules;
using Core.Arango.Protocol;
using Microsoft.Extensions.Options;
using Newtonsoft.Json.Linq;
using System.Collections.Generic;
using System;
using Warehouse2.Models;

namespace Warehouse2.Services
{
public class EventsService
{
private readonly IArangoContext _arango;

private readonly string _dbName;

private readonly string _collectionName;

public EventsService(IOptions<WarehouseDatabaseSettings> WarehouseDatabaseSettings)
{
_arango = new ArangoContext(WarehouseDatabaseSettings.Value.ConnectionString);

_dbName = WarehouseDatabaseSettings.Value.DatabaseName;

_collectionName = WarehouseDatabaseSettings.Value.EventCollectionName;

}

/* public async Task<List<Event>> GetAsync() =>
await _arango.Document.GetManyAsync<Event>(_dbName, _collectionName, new List<string> { "28163" }); // only for one now !!!!!
*/
public async Task<List<Event>> ListDocsAsync()
{
//FormattableString filter = $"x";
return await _arango.Query.FindAsync<Event>(_dbName, _collectionName, $"x");
}
}
}
31 changes: 31 additions & 0 deletions server/Services/UsersService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using Core.Arango;
using Microsoft.Extensions.Options;
using Warehouse2.Models;

namespace Warehouse2.Services
{
public class UsersService
{
private readonly IArangoContext _arango;

private readonly string _dbName;

private readonly string _collectionName;

public UsersService(IOptions<WarehouseDatabaseSettings> WarehouseDatabaseSettings)
{
_arango = new ArangoContext(WarehouseDatabaseSettings.Value.ConnectionString);

_dbName = WarehouseDatabaseSettings.Value.DatabaseName;

_collectionName = WarehouseDatabaseSettings.Value.UsersCollectionName;

}


public async Task<List<User>> ListDocsAsync()
{
return await _arango.Query.FindAsync<User>(_dbName, _collectionName, $"x");
}
}
}
Loading

0 comments on commit a79fc68

Please sign in to comment.