Veronika Milovzorova portfolio/ est

API veebirakendus

Back-end

  • Programmeerimiskeeled nagu näiteks Node.js, PHP, Python
  • Kompileeritud keeled nagu näiteks C#, Java
  • Andmete teisendamine
  • Tarkvaraarhitektuur
  • Turvaprobleemid, autentimine ja autoriseerimine
  • Andmebaaside haldamine

Frontend

  • Märgistus- ja veebikeeled nagu näiteks HTML, CSS, JavaScript ja nendes keeltes kasutatavad abiteegid nagu Sass või JQuery.
  • Asünkrooniliste päringute käsitlemine ja AJAX
  • Kasutajaliides (GUI)
  • Pilditöötlusprogrammid (GIMP või Photoshop)
  • Otsingumootorija jaoks optimeerimine
  • Ligipääsetavusega seotud probleemid

WeatherController

namespace veeb_Milovzorova.Controllers
{
    [ApiController]
    [Route("[controller]")]
    public class WeatherController : ControllerBase
    {
        private static readonly string[] Summaries = new[]
        {
            "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
        };

        private readonly ILogger<WeatherController> _logger;

        public WeatherController(ILogger<WeatherController> logger)
        {
            _logger = logger;
        }

        [HttpGet(Name = "GetWeatherForecast")]
        public IEnumerable<WeatherForecast> Get()
        {
            return Enumerable.Range(1, 5).Select(index => new WeatherForecast
            {
                Date = DateOnly.FromDateTime(DateTime.Now.AddDays(index)),
                TemperatureC = Random.Shared.Next(-20, 55),
                Summary = Summaries[Random.Shared.Next(Summaries.Length)]
            })
            .ToArray();
        }
    }
}

PrimitiivController

namespace veeb_Milovzorova.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    public class PrimitiividController : ControllerBase
    {
        
        [HttpGet("hello-world")]
        public string HelloWorld()
        {
            return "Hello world at " + DateTime.Now;
        }

        
        [HttpGet("hello-variable/{nimi}")]
        public string HelloVariable(string nimi)
        {
            return "Hello " + nimi;
        }

        
        [HttpGet("add/{nr1}/{nr2}")]
        public int AddNumbers(int nr1, int nr2)
        {
            return nr1 + nr2;
        }

        
        [HttpGet("multiply/{nr1}/{nr2}")]
        public int Multiply(int nr1, int nr2)
        {
            return nr1 * nr2;
        }

        
        [HttpGet("do-logs/{arv}")]
        public void DoLogs(int arv)
        {
            for (int i = 0; i < arv; i++)
            {
                Console.WriteLine("See on logi nr " + i);
            }
        }

        
        [HttpGet("random-number/{min}/{max}")]
        public ActionResult<int> GenerateRandomNumber(int min, int max)
        {
            if (min >= max)
            {
                return BadRequest("Min väärtus peab olema väiksem kui max väärtus.");
            }

            Random rand = new Random();
            int randomNumber = rand.Next(min, max + 1); // 
            return randomNumber;
        }

        
        [HttpGet("age/{birthYear}")]
        public ActionResult<string> CalculateAge(int birthYear)
        {
            int currentYear = DateTime.Now.Year;
            int age = currentYear - birthYear;

            
            bool hadBirthday = DateTime.Now >= new DateTime(currentYear, 1, 1).AddYears(age);

            if (!hadBirthday)
            {
                age--; 
            }

            return $"Oled {(hadBirthday ? age : age + 1)} aastat vana.";
        }
    }
}

Kuvab tervituse kuupäeva ja kellaaega

Annab tervituse ja nime

Lisab numbreid

Korrutab numbreid

do-logs/{arv}

Annab välja juhusliku arvu

Arvutab sünniaastat

Toode.cs

namespace veeb_Milovzorova.Models;
public class Toode
{
    public int Id { get; set; }
    public string Name { get; set; }
    public double Price { get; set; }
    public bool IsActive { get; set; }

    public Toode(int id, string name, double price, bool isActive)
    {
        Id = id;
        Name = name;
        Price = price;
        IsActive = isActive;
    }
}

TootedController

namespace veeb_Milovzorova.Controllers
{
    [Route("api/tooted")]
    [ApiController]
    public class TootedController : ControllerBase
    {
        private static List<Toode> _tooted = new()
        {
            new Toode(1, "Koola", 1.5, true),
            new Toode(2, "Fanta", 1.0, false),
            new Toode(3, "Sprite", 1.7, true),
            new Toode(4, "Vichy", 2.0, true),
            new Toode(5, "Vitamin well", 2.5, true)
        };

        // GET /tooted
        [HttpGet]
        public ActionResult<List<Toode>> KoikTooted()
        {
            return Ok(_tooted);
        }

        // POST /tooted/lisa
        [HttpPost("lisa")]
        public ActionResult<List<Toode>> LisaToode([FromBody] Toode toode)
        {
            _tooted.Add(toode);
            return Ok(_tooted);
        }

        // DELETE /tooted/kustuta-koik
        [HttpDelete("kustuta-koik")]
        public ActionResult KustutaKoik()
        {
            _tooted.Clear();
            return Ok("Kõik tooted on kustutatud!");
        }

        // PATCH /tooted/hind-dollaritesse/{kurss}
        [HttpPatch("hind-dollaritesse/{kurss}")]
        public ActionResult<List<Toode>> UuendaKoigiToodeteHinnad(double kurss)
        {
            foreach (var toode in _tooted)
            {
                toode.Price *= kurss;
            }
            return Ok(_tooted);
        }

        // PUT /tooted/deaktiveeri-koik
        [HttpPut("deaktiveeri-koik")]
        public ActionResult<List<Toode>> DeaktiveeriKoik()
        {
            foreach (var toode in _tooted)
            {
                toode.IsActive = false;
            }
            return Ok(_tooted);
        }

        // GET /tooted/kalleim-toode
        [HttpGet("kalleim-toode")]
        public ActionResult<Toode> KalleimToode()
        {
            if (!_tooted.Any()) return NotFound("Tooteid ei ole saadaval!");
            var kalleimToode = _tooted.OrderByDescending(t => t.Price).FirstOrDefault();
            return Ok(kalleimToode);
        }
    }
}

näitab kõiki tooteid

lisab tooteid

kustutab kõik tooted

lisab kaubale määra

deaktiveerib kõik tooted valeks

näitab kõige kallimat toodet

ToodeController

namespace veeb_Milovzorova.Controllers
{
    [Route("api/toode")]
    [ApiController]
    public class ToodeController : ControllerBase
    {
        private static List<Toode> _tooted = new()
        {
            new Toode(1, "Koola", 1.5, true),
            new Toode(2, "Fanta", 1.0, false),
            new Toode(3, "Sprite", 1.7, true),
            new Toode(4, "Vichy", 2.0, true),
            new Toode(5, "Vitamin well", 2.5, true)
        };

        // DELETE /toode/kustuta/{index}
        [HttpDelete("kustuta/{index}")]
        public ActionResult<List<Toode>> Kustuta(int index)
        {
            if (index < 1 || index > _tooted.Count) return NotFound("Toodet ei leitud!");
            _tooted.RemoveAt(index - 1);
            return Ok(_tooted);
        }

        // PUT /toode/lylitus-tegevus/{index}
        [HttpPut("lylitus-tegevus/{index}")]
        public ActionResult<List<Toode>> MuudaAktiivsust(int index)
        {
            if (index < 1 || index > _tooted.Count) return NotFound("Toodet ei leitud!");
            _tooted[index - 1].IsActive = !_tooted[index - 1].IsActive;
            return Ok(_tooted);
        }

        // PUT /toode/muuta-nimi/{index}/{uusNimi}
        [HttpPut("muuta-nimi/{index}/{uusNimi}")]
        public ActionResult<List<Toode>> MuudaNime(int index, string uusNimi)
        {
            if (index < 1 || index > _tooted.Count) return NotFound("Toodet ei leitud!");
            _tooted[index - 1].Name = uusNimi;
            return Ok(_tooted);
        }

        // PUT /toode/update-price/{index}/{kordaja}
        [HttpPut("uuendus-hind/{index}/{kordaja}")]
        public ActionResult<List<Toode>> UuendaHinda(int index, double kordaja)
        {
            if (index < 1 || index > _tooted.Count) return NotFound("Toodet ei leitud!");
            _tooted[index - 1].Price *= kordaja;
            return Ok(_tooted);
        }

        // GET /toode/{index}
        [HttpGet("{index}")]
        public ActionResult<Toode> SaadaToode(int index)
        {
            if (index < 1 || index > _tooted.Count) return NotFound("Toodet ei leitud!");
            return Ok(_tooted[index - 1]);
        }
    }
}

kustutab toode

muutab aktiivsust

muutab toode nimi

uuendab toode hinda

näitab toode id, mis oli valitud

kasutaja

kasutaja.cs
namespace veeb_Milovzorova.Models
{
    public class Kasutaja
    {
        public int Id { get; set; }
        public string KasutajaNimi { get; set; }
        public string Parool { get; set; }
        public string Eesnimi { get; set; }
        public string Perenimi { get; set; }

        public Kasutaja(int id, string kasutajaNimi, string parool, string eesnimi, string perenimi)
        {
            Id = id;
            KasutajaNimi = kasutajaNimi;
            Parool = parool;
            Eesnimi = eesnimi;
            Perenimi = perenimi;
        }
    }
}
KasutajaController
namespace veeb_Milovzorova.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    public class KasutajaController : ControllerBase
    {
        private static List<Kasutaja> _kasutajad = new()
        {
            new Kasutaja(1, "ver1", "ver123", "Veronika", "Milovzorova"),
            
        };

        // GET /api/kasutaja
        [HttpGet]
        public ActionResult<List<Kasutaja>> Get()
        {
            return Ok(_kasutajad);
        }

        // GET /api/kasutaja/{id}
        [HttpGet("{id}")]
        public ActionResult<Kasutaja> Get(int id)
        {
            var kasutaja = _kasutajad.FirstOrDefault(k => k.Id == id);
            if (kasutaja == null)
            {
                return NotFound("Kasutajat ei leitud!");
            }
            return Ok(kasutaja);
        }

        private static int _nextId = 1;
        // POST /api/kasutaja
        [HttpPost]
        public ActionResult<Kasutaja> Create([FromBody] Kasutaja kasutaja)
        {
            kasutaja.Id = _nextId++; // Увеличиваем _nextId для следующего пользователя
            _kasutajad.Add(kasutaja);
            return CreatedAtAction(nameof(Get), new { id = kasutaja.Id }, kasutaja);
        }

        // PUT /api/kasutaja/{id}
        [HttpPut("{id}")]
        public ActionResult Update(int id, [FromBody] Kasutaja kasutaja)
        {
            var existingUser = _kasutajad.FirstOrDefault(k => k.Id == id);
            if (existingUser == null)
            {
                return NotFound("Kasutajat ei leitud!");
            }

            existingUser.KasutajaNimi = kasutaja.KasutajaNimi;
            existingUser.Parool = kasutaja.Parool;
            existingUser.Eesnimi = kasutaja.Eesnimi;
            existingUser.Perenimi = kasutaja.Perenimi;

            return NoContent();
        }

        // DELETE /api/kasutaja/{id}
        [HttpDelete("{id}")]
        public ActionResult Delete(int id)
        {
            var kasutaja = _kasutajad.FirstOrDefault(k => k.Id == id);
            if (kasutaja == null)
            {
                return NotFound("Kasutajat ei leitud!");
            }
            _kasutajad.Remove(kasutaja);
            return NoContent();
        }
    }
}

Tagastab kõigi kasutajate loendi

Tagastab kasutaja määratud identifikaatoriga {id}

Loob uue kasutaja

Värskendab teavet olemasoleva kasutaja kohta määratud ID-ga

Kustutab määratud identifikaatoriga {id} kasutaja

ParcelMachineController.cs

namespace veeb_Milovzorova.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    public class ParcelMachineController : ControllerBase
    {
        private readonly HttpClient _httpClient;

        public ParcelMachineController(HttpClient httpClient)
        {
            _httpClient = httpClient;
        }

        [HttpGet]
        public async Task<IActionResult> GetParcelMachines()
        {
            var response = await _httpClient.GetAsync("https://www.omniva.ee/locations.json");
            var responseBody = await response.Content.ReadAsStringAsync();
            return Content(responseBody, "application/json");
        }
    }
}

näitab kõik pakiautomaatid

Nordpool

NoordpoolController.cs
namespace veeb_Milovzorova.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    public class NordpoolController : ControllerBase
    {

        private readonly HttpClient _httpClient;

        public NordpoolController(HttpClient httpClient)
        {
            _httpClient = httpClient;
        }

        [HttpGet("{country}/{start}/{end}")]
        public async Task<IActionResult> GetNordPoolPrices(
            string country,
            string start,
            string end)
        {
            var response = await _httpClient.GetAsync(
                $"https://dashboard.elering.ee/api/nps/price?start={start}&end={end}");
            var responseBody = await response.Content.ReadAsStringAsync();
            Console.WriteLine(responseBody);

            var jsonDoc = JsonDocument.Parse(responseBody);
            var dataProperty = jsonDoc.RootElement.GetProperty("data");

            string prices;

            switch (country)
            {
                case "ee":
                    prices = dataProperty.GetProperty("ee").ToString();
                    Console.WriteLine(responseBody);

                    return Content(prices, "application/json");

                case "lv":
                    prices = dataProperty.GetProperty("lv").ToString();
                    return Content(prices, "application/json");

                case "lt":
                    prices = dataProperty.GetProperty("lt").ToString();
                    return Content(prices, "application/json");

                case "fi":
                    prices = dataProperty.GetProperty("fi").ToString();
                    return Content(prices, "application/json");

                default:
                    return BadRequest("Invalid country code.");
            }
        }
    }
}

GET/api/Nordpool/{country}/{start}/{end}

payment

PaymentController.cs
namespace veeb_Milovzorova.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    public class PaymentController : ControllerBase
    {
        private readonly HttpClient _httpClient;

        public PaymentController(HttpClient httpClient)
        {
            _httpClient = httpClient;
        }

        [HttpGet("{sum}")]
        public async Task<IActionResult> MakePayment(string sum)
        {
            var paymentData = new
            {
                api_username = "e36eb40f5ec87fa2",
                account_name = "EUR3D1",
                amount = sum,
                order_reference = Math.Ceiling(new Random().NextDouble() * 999999),
                nonce = $"a9b7f7e7as{DateTime.Now}{new Random().NextDouble() * 999999}",
                timestamp = DateTime.Now,
                customer_url = "https://maksmine.web.app/makse"
            };

            var json = JsonSerializer.Serialize(paymentData);
            var content = new StringContent(json, Encoding.UTF8, "application/json");

            var client = new HttpClient();
            client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", "ZTM2ZWI0MGY1ZWM4N2ZhMjo3YjkxYTNiOWUxYjc0NTI0YzJlOWZjMjgyZjhhYzhjZA==");

            var response = await client.PostAsync("https://igw-demo.every-pay.com/api/v4/payments/oneoff", content);

            if (response.IsSuccessStatusCode)
            {
                var responseContent = await response.Content.ReadAsStringAsync();
                var jsonDoc = JsonDocument.Parse(responseContent);
                var paymentLink = jsonDoc.RootElement.GetProperty("payment_link");
                return Ok(paymentLink);
            }
            else
            {
                return BadRequest("Payment failed.");
            }
        }
    }
}

annab linki maksmiseks

et