POS_Sprint_3 #5

Merged
s426229 merged 10 commits from POS_Sprint_3 into develop 2020-12-30 17:30:24 +01:00
30 changed files with 1357 additions and 893 deletions

View File

@ -13,6 +13,7 @@ using System.Security;
using System.Net;
using System.Linq;
using System.IO;
using Newtonsoft.Json;
namespace Klient.Droid
{
@ -22,6 +23,10 @@ namespace Klient.Droid
public static int PickImageId = 1000;
private static readonly HttpClient client = new HttpClient();
public static Android.Content.Intent photo;
public string savedLogin = "";
public string savedName = "";
public string savedSurname = "";
public string savedEmail = "";
protected override void OnCreate(Bundle savedInstanceState)
{
@ -33,7 +38,7 @@ namespace Klient.Droid
}
[Java.Interop.Export("SignIn")]
async public void SignIn(View v)
async public void SignIn(Android.Views.View v)
{
var Login = FindViewById<EditText>(Resource.Id.Login).Text;
SecureString Password = new NetworkCredential("", FindViewById<EditText>(Resource.Id.Password).Text).SecurePassword;
@ -58,13 +63,17 @@ namespace Klient.Droid
var response = await client.PostAsync("http://10.0.2.2:5001/api/User/SignIn", content);
if (response.StatusCode == HttpStatusCode.OK) SetContentView(Resource.Layout.ekranPoLogowaniu);
}
[Java.Interop.Export("ResetPassword")]
async public void ResetPassword()
if (response.StatusCode == HttpStatusCode.OK)
{
SetContentView(Resource.Layout.ekranLogowania);
savedLogin = Login;
var jsonString = await response.Content.ReadAsStringAsync();
dynamic jsonObject = JsonConvert.DeserializeObject(jsonString);
SetContentView(Resource.Layout.ekranPoLogowaniu);
savedName = jsonObject.user.name;
savedEmail = jsonObject.user.email;
savedSurname = jsonObject.user.surname;
}
}
[Java.Interop.Export("SignUp")]
@ -161,5 +170,46 @@ namespace Klient.Droid
}
}
[Java.Interop.Export("GoToProfil")]
public void GoToProfile(View v)
{
SetContentView(Resource.Layout.ekranProfil);
}
[Java.Interop.Export("Save")]
public async void SaveChanges(View v)
{
var Name = FindViewById<EditText>(Resource.Id.ChangeName).Text;
var Surname = FindViewById<EditText>(Resource.Id.ChangeSurname).Text;
var Email = FindViewById<EditText>(Resource.Id.ChangeEmail).Text;
if (string.IsNullOrEmpty(Name))
{
Name = savedName;
}
if (string.IsNullOrEmpty(Email))
{
Email = savedEmail;
}
if (string.IsNullOrEmpty(Surname))
{
Surname = savedSurname;
}
var values = new Dictionary<string, string>
{
{ "email", Email },
{ "name", Name },
{ "surname", Surname },
{ "login", savedLogin }
};
var content = new FormUrlEncodedContent(values);
var response = await client.PostAsync("http://10.0.2.2:5001/api/User/Update", content);
var responseString = await response.Content.ReadAsStringAsync();
if (response.StatusCode == HttpStatusCode.OK) FindViewById<TextView>(Resource.Id.NullValueProfile).Text = "Zapisano!";
}
}
}

View File

@ -57,6 +57,9 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Newtonsoft.Json">
<Version>12.0.3</Version>
</PackageReference>
<PackageReference Include="Xamarin.Essentials">
<Version>1.5.3.2</Version>
</PackageReference>
@ -137,6 +140,14 @@
<SubType>Designer</SubType>
</AndroidResource>
</ItemGroup>
<ItemGroup>
<AndroidResource Include="Resources\drawable\Obraz3.png" />
</ItemGroup>
<ItemGroup>
<AndroidResource Include="Resources\layout\ekranProfil.xml">
<SubType>Designer</SubType>
</AndroidResource>
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath)\Xamarin\Android\Xamarin.Android.CSharp.targets" />
<ProjectExtensions>
<VisualStudio>

View File

@ -3,5 +3,5 @@
<uses-sdk android:minSdkVersion="21" android:targetSdkVersion="28" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.INTERNET" />
<application android:label="Klient.Android" android:usesCleartextTraffic="true" />
<application android:label="Klient.Android" android:usesCleartextTraffic="true" android:theme="@style/Base.Theme.AppCompat.Light.DarkActionBar" />
</manifest>

View File

@ -15,6 +15,7 @@ using Android.App;
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
[assembly: ComVisible(false)]
[assembly: Application(Theme = "@style/Base.Theme.AppCompat.Light.DarkActionBar")]
// Version information for an assembly consists of the following four values:
//

File diff suppressed because it is too large Load Diff

Binary file not shown.

After

Width:  |  Height:  |  Size: 925 B

View File

@ -8,8 +8,13 @@
android:layout_height="match_parent"
android:background="#ffbdd7f0"
>
<android.support.design.widget.TextInputEditText
<android.support.design.widget.TextInputLayout
android:id="@+id/LayoutLogin"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:hint="Login">
<EditText
android:layout_width="204.0dp"
android:layout_height="58.0dp"
android:id="@+id/Login"
@ -19,46 +24,42 @@
android:layout_centerInParent="false"
android:layout_centerHorizontal="true"
android:layout_alignParentTop="true"
android:hint="Login"
android:gravity="center_horizontal|center_vertical"
android:inputType="text"
android:textColor="#ff000000"
android:textColorHint="#ff6c6767" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputEditText
<android.support.design.widget.TextInputLayout
android:id="@+id/LayoutPassword"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:passwordToggleEnabled="true"
android:layout_below="@+id/LayoutLogin"
android:layout_centerHorizontal="true"
app:passwordToggleTint="@android:color/darker_gray"
android:hint="Hasło"
android:gravity="left">
<EditText
android:layout_width="204.0dp"
android:layout_height="58.0dp"
android:id="@+id/Password"
android:layout_centerHorizontal="true"
android:layout_below="@+id/Login"
android:hint="Hasło"
android:gravity="center_horizontal|center_vertical"
android:inputType="none|textPassword"
android:textColor="#ff000000"
android:textColorHint="#ff6c6767" />
</android.support.design.widget.TextInputLayout>
<Button
android:layout_width="100.5dp"
android:layout_height="50dp"
android:id="@+id/In"
android:layout_below="@id/Password"
android:layout_below="@id/LayoutPassword"
android:layout_alignParentRight="false"
android:gravity="center"
android:onClick="SignIn"
android:text="Zaloguj"
android:layout_centerHorizontal="true"
android:foregroundGravity="center" />
<Button
android:text=" Reset \n Hasła"
android:layout_width="100.5dp"
android:layout_height="50dp"
android:id="@+id/Reset"
android:gravity="center"
android:layout_below="@id/In"
android:layout_alignParentRight="false"
android:autoSizeTextType="uniform"
android:onClick="ResetPassword"
android:textColor="#ff790000"
android:layout_centerHorizontal="true"
android:foregroundGravity="center" />
<Button
android:text="?"
android:layout_width="35.0dp"
@ -79,12 +80,6 @@
android:textColor="#ff000000"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true" />
<Switch
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/LoginPasswordSee"
android:layout_below="@id/Login"
android:layout_toRightOf="@id/Password" />

View File

@ -52,4 +52,25 @@
android:layout_alignParentRight="true"
android:layout_marginRight="75dp"
android:onClick="LoadFromCamera" />
<Button
android:text="?"
android:layout_width="35.0dp"
android:layout_height="35.0dp"
android:id="@+id/helpRegister"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:background="#ff0b31c8"
android:textColor="#fffcfcfc"
android:gravity="center"
android:onClick="HelpRegisterScreen" />
<ImageButton
android:src="@drawable/obraz3"
android:layout_width="63.5dp"
android:layout_height="70.5dp"
android:background="#ffbdd7f0"
android:id="@+id/Profile"
android:layout_alignParentLeft="true"
android:layout_alignParentBottom="true"
android:onClick="GoToProfil"/>
</RelativeLayout>

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
@ -16,6 +16,16 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/SendPhoto"
android:onClick="SendPhoto"/>
android:onClick="SendPhoto"
android:layout_below="@id/Preview" />
<TextView
android:text=""
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/ErrorPhoto"
android:layout_centerHorizontal="true"
android:layout_below="@id/SendPhoto"
android:textColor="#ffd60000" />
</LinearLayout>
</RelativeLayout>

View File

@ -0,0 +1,87 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffbdd7f0">
<android.support.design.widget.TextInputLayout
android:id="@+id/LayoutNameC"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:hint="Imie"
android:layout_alignParentLeft="true">
<android.support.design.widget.TextInputEditText
android:layout_width="204.0dp"
android:layout_height="58.0dp"
android:minWidth="25px"
android:minHeight="25px"
android:id="@+id/ChangeName"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:capitalize="words"
android:textColorHint="#ff6c6767"
android:textColor="#ff000000"
android:inputType="none|textPersonName" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:id="@+id/LayoutSurnameC"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:hint="Nazwisko"
android:layout_below="@id/LayoutNameC"
android:layout_alignParentLeft="true">
<android.support.design.widget.TextInputEditText
android:layout_width="204.0dp"
android:layout_height="58.0dp"
android:minWidth="25px"
android:minHeight="25px"
android:id="@+id/ChangeSurname"
android:textColorHint="#ff6c6767"
android:textColor="#ff000000"
android:inputType="none|textPersonName" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:id="@+id/LayoutEmailC"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:hint="Adres email"
android:layout_below="@id/LayoutSurnameC"
android:layout_alignParentLeft="true">
<android.support.design.widget.TextInputEditText
android:layout_width="204.0dp"
android:layout_height="58.0dp"
android:minWidth="25px"
android:minHeight="25px"
android:id="@+id/ChangeEmail"
android:textColorHint="#ff6c6767"
android:textColor="#ff000000"
android:inputType="none|textEmailAddress" />
</android.support.design.widget.TextInputLayout>
<Button
android:text="Zapisz"
android:layout_width="100.5dp"
android:layout_height="50dp"
android:id="@+id/Save"
android:layout_below="@id/LayoutEmailC"
android:layout_centerHorizontal="true"
android:foregroundGravity="center"
android:gravity="center"
android:onClick="Save"/>
<TextView
android:text=""
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/NullValueProfile"
android:layout_centerHorizontal="true"
android:layout_below="@id/Save"
android:textColor="#ffd60000" />
</RelativeLayout>

View File

@ -1,11 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffbdd7f0">
<android.support.design.widget.TextInputLayout
android:id="@+id/LayoutName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:hint="Imie"
android:layout_alignParentLeft="true">
<android.support.design.widget.TextInputEditText
android:layout_width="204.0dp"
android:layout_height="58.0dp"
@ -17,56 +25,92 @@
android:capitalize="words"
android:textColorHint="#ff6c6767"
android:textColor="#ff000000"
android:hint="Imie"
android:gravity="center"
android:inputType="none|textPersonName" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:id="@+id/LayoutSurname"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:hint="Nazwisko"
android:layout_below="@id/LayoutName"
android:layout_alignParentLeft="true">
<android.support.design.widget.TextInputEditText
android:layout_width="204.0dp"
android:layout_height="58.0dp"
android:minWidth="25px"
android:minHeight="25px"
android:id="@+id/Surname"
android:hint="Nazwisko"
android:textColorHint="#ff6c6767"
android:layout_below="@id/Name"
android:gravity="center"
android:textColor="#ff000000"
android:inputType="none|textPersonName" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:id="@+id/LayoutEmail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:hint="Adres email"
android:layout_below="@id/LayoutSurname"
android:layout_alignParentLeft="true">
<android.support.design.widget.TextInputEditText
android:layout_width="204.0dp"
android:layout_height="58.0dp"
android:minWidth="25px"
android:minHeight="25px"
android:id="@+id/Email"
android:layout_below="@+id/NewLogin"
android:hint="Email"
android:gravity="center"
android:textColorHint="#ff6c6767"
android:textColor="#ff000000"
android:inputType="none|textEmailAddress" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:id="@+id/LayoutNewPassword1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:passwordToggleEnabled="true"
app:passwordToggleTint="@android:color/darker_gray"
android:layout_centerHorizontal="true"
android:hint="Hasło"
android:layout_below="@id/LayoutEmail"
android:layout_alignParentLeft="true">
<android.support.design.widget.TextInputEditText
android:layout_width="204.0dp"
android:layout_height="58.0dp"
android:minWidth="25px"
android:minHeight="25px"
android:id="@+id/NewPassword"
android:hint="Hasło"
android:layout_below="@+id/Email"
android:gravity="center"
android:inputType="none|textPassword"
android:textColorHint="#ff6c6767" />
android:inputType="none|textPassword" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:id="@+id/LayoutNewPassword2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:hint="Powtórz hasło"
app:passwordToggleEnabled="true"
app:passwordToggleTint="@android:color/darker_gray"
android:layout_below="@id/LayoutNewPassword1"
android:layout_alignParentLeft="true">
<android.support.design.widget.TextInputEditText
android:layout_width="204.0dp"
android:layout_height="58.0dp"
android:minWidth="25px"
android:minHeight="25px"
android:id="@+id/RepeatPassword"
android:layout_below="@+id/NewPassword"
android:hint="Powtórz hasło"
android:inputType="none|textPassword"
android:gravity="center"
android:textColorHint="#ff6c6767"
android:textColor="#ff000000" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:id="@+id/LayoutNewLogin"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:hint="Login"
android:layout_below="@id/LayoutNewPassword2"
android:layout_alignParentLeft="true">
<android.support.design.widget.TextInputEditText
android:layout_width="204.0dp"
android:layout_height="58.0dp"
@ -74,23 +118,9 @@
android:minHeight="25px"
android:id="@+id/NewLogin"
android:hint="Login"
android:gravity="center"
android:textColorHint="#ff6c6767"
android:textColor="#ff000000"
android:layout_below="@+id/Surname" />
<Switch
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/PasswordSee1"
android:layout_toRightOf="@id/NewPassword"
android:layout_below="@id/Email" />
<Switch
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/PasswordSee2"
android:layout_toRightOf="@id/RepeatPassword"
android:layout_below="@id/NewPassword"
android:checked="false" />
</android.support.design.widget.TextInputLayout>
<Button
android:text=" Załóż \n konto"
android:layout_width="100.5dp"
@ -98,19 +128,11 @@
android:id="@+id/SignUp"
android:autoSizeTextType="uniform"
android:gravity="center"
android:layout_below="@id/RepeatPassword"
android:layout_below="@id/LayoutNewLogin"
android:layout_alignParentRight="false"
android:foregroundGravity="center"
android:layout_centerHorizontal="true"
android:onClick="SignUp" />
<TextView
android:textAppearance="?android:attr/textAppearanceSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/text2"
android:layout_below="@id/Email"
android:layout_alignParentRight="false"
android:layout_toRightOf="@id/NewPassword" />
<TextView
android:text="Poszukiwacz 2020"
android:textAppearance="?android:attr/textAppearanceSmall"
@ -120,7 +142,16 @@
android:textColor="#ff000000"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true" />
<Button
android:text="?"
android:layout_width="35.0dp"
android:layout_height="35.0dp"
android:id="@+id/helpRegister"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:background="#ff0b31c8"
android:textColor="#fffcfcfc"
android:gravity="center"
android:onClick="HelpRegisterScreen" />
</RelativeLayout>

View File

@ -4,7 +4,7 @@
<style name="MainTheme" parent="MainTheme.Base">
</style>
<!-- Base theme applied no matter what API -->
<style name="MainTheme.Base" parent="Theme.AppCompat.Light.DarkActionBar">
<style name="MainTheme.Base" parent="Theme.AppCompat">
<!--If you are using revision 22.1 please use just windowNoTitle. Without android:-->
<item name="windowNoTitle">true</item>
<!--We will be using the toolbar so no need to show ActionBar-->
@ -20,6 +20,7 @@
<!-- You can also set colorControlNormal, colorControlActivated
colorControlHighlight and colorSwitchThumbNormal. -->
<item name="windowActionModeOverlay">true</item>
<item name="android:textColorHint">#ff000000</item>
<item name="android:datePickerDialogTheme">@style/AppCompatDialogStyle</item>
</style>

View File

@ -13,8 +13,8 @@ namespace Serwer.Api.Controllers
[ApiController]
public class ImageController : ControllerBase
{
private readonly IImageService _imageService;
public ImageController(IImageService imageService)
private readonly IImageHandler _imageService;
public ImageController(IImageHandler imageService)
{
_imageService = imageService;
}

View File

@ -0,0 +1,28 @@
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Serwer.Infrastructure.Services;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace Serwer.Api.Controllers
{
[Route("api/[controller]")]
[ApiController]
public class SearchController : ControllerBase
{
private readonly ISearchService _searchService;
public SearchController(ISearchService searchService)
{
_searchService = searchService;
}
[HttpGet("{query}")]
public async Task<IActionResult> Search(string query)
{
var results = await _searchService.Search(query);
return Ok(results);
}
}
}

View File

@ -1,4 +1,5 @@
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Serwer.Infrastructure.DTO;
using Serwer.Infrastructure.Services;
@ -35,6 +36,14 @@ namespace Serwer.Api.Controllers
return Ok(user);
}
[Authorize]
[HttpPost("Update")]
public async Task<IActionResult> Update([FromForm]UpdateUserModel request)
{
var user = await _userService.UpdateAsync(request);
return Ok(user);
}
[HttpGet("Test")]
public IActionResult Test()
{

View File

@ -0,0 +1,38 @@
using Microsoft.AspNetCore.Http;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Threading.Tasks;
namespace Serwer.Api.Framework
{
public class ExceptionHandlerMiddleware
{
private readonly RequestDelegate _next;
public ExceptionHandlerMiddleware(RequestDelegate next)
{
_next = next;
}
public async Task Invoke(HttpContext context)
{
try
{
await _next(context);
}
catch (Exception ex)
{
await HandleExceptionAsync(context, ex);
}
}
private static Task HandleExceptionAsync(HttpContext context, Exception exception)
{
var statusCode = HttpStatusCode.BadRequest;
context.Response.StatusCode = (int)statusCode;
return context.Response.WriteAsync($"Error: {exception.Message}");
}
}
}

View File

@ -15,6 +15,7 @@ using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using Microsoft.IdentityModel.Tokens;
using Microsoft.OpenApi.Models;
using Serwer.Api.Framework;
using Serwer.Core.Repositories;
using Serwer.Infrastructure.Mappers;
using Serwer.Infrastructure.Repositories;
@ -41,9 +42,30 @@ namespace Serwer.Api
services.AddSwaggerGen(c =>
{
c.SwaggerDoc("v1", new OpenApiInfo { Title = "Serwer.Api", Version = "v1" });
var jwtSecurityScheme = new OpenApiSecurityScheme
{
Scheme = "bearer",
BearerFormat = "JWT",
Name = "JWT Authentication",
In = ParameterLocation.Header,
Type = SecuritySchemeType.Http,
Description = "Put **_ONLY_** your JWT Bearer token on textbox below!",
Reference = new OpenApiReference
{
Id = JwtBearerDefaults.AuthenticationScheme,
Type = ReferenceType.SecurityScheme
}
};
c.AddSecurityDefinition(jwtSecurityScheme.Reference.Id, jwtSecurityScheme);
c.AddSecurityRequirement(new OpenApiSecurityRequirement
{
{ jwtSecurityScheme, Array.Empty<string>() }
});
});
var hostEnviroment = new HostEnviroment { RootPath = WebRootPath};
var hostEnviroment = new HostEnviroment { RootPath = WebRootPath };
var jwtSettings = new JwtSettings()
{
Issuer = "PoszukiwaczInc",
@ -67,8 +89,9 @@ namespace Serwer.Api
services.AddSingleton<IMapper>(AutoMapperConfig.Initialize());
services.AddSingleton<IJwtHandler, JwtHandler>(sp => new JwtHandler(jwtSettings));
services.AddScoped<IUserRepository, UserRepository>();
services.AddScoped<IImageService, ImageService>();
services.AddScoped<IImageHandler, ImageHandler>();
services.AddScoped<IUserService, UserService>();
services.AddScoped<ISearchService, SearchService>();
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
@ -88,6 +111,8 @@ namespace Serwer.Api
}
app.UseRouting();
app.UseMiddleware(typeof(ExceptionHandlerMiddleware));
app.UseAuthentication();
app.UseAuthorization();

View File

@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Serwer.Core.Domain
{
public class SearchResult
{
}
}

View File

@ -18,14 +18,15 @@ namespace Serwer.Core.Domain
public DateTime UpdatedAt { get; protected set; }
protected User() { }
public User(string email, string name, string surname, string login, string password)
public User(Guid id, string email, string name, string surname, string login, string password)
{
Id = Guid.NewGuid();
Id = id;
SetEmail(email);
SetName(name);
SetSurname(surname);
SetLogin(login);
SetPassword(password);
CreatedAt = DateTime.UtcNow;
}
public void SetEmail(string email)

View File

@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Serwer.Infrastructure.DTO
{
public class SearchResultDTO
{
public string Title { get; set; }
public string Link { get; set; }
public string Snippet { get; set; }
}
}

View File

@ -8,6 +8,7 @@ namespace Serwer.Infrastructure.DTO
{
public class UserDto
{
public Guid Id { get; set; }
public string Email { get; set; }
public string Name { get; set; }
public string Surname { get; set; }

View File

@ -1,4 +1,5 @@
using System;
using Serwer.Core.Domain;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
@ -8,6 +9,6 @@ namespace Serwer.Infrastructure.Services
{
public interface IImageHandler
{
Task<string> Process(string name, string contentType, byte[] bytes);
}
}

View File

@ -1,14 +1,13 @@
using Serwer.Core.Domain;
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Serwer.Infrastructure.DTO;
namespace Serwer.Infrastructure.Services
{
public interface IImageService
public interface ISearchService
{
Task<string> Process(string name, string contentType, byte[] bytes);
Task<IList<SearchResultDTO>> Search(string query);
}
}

View File

@ -1,4 +1,5 @@
using Serwer.Infrastructure.DTO;
using Serwer.Infrastructure.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
@ -11,5 +12,6 @@ namespace Serwer.Infrastructure.Services
{
Task RegisterAsync(string email, string name, string surname, string login, string password);
Task<SignedUserDto> SignInAsync(string login, string password);
Task<UserDto> UpdateAsync(UpdateUserModel userModel);
}
}

View File

@ -1,12 +1,30 @@
using System;
using Serwer.Core.Domain;
using Serwer.Infrastructure.Settings;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Tesseract;
namespace Serwer.Infrastructure.Services
{
class ImageHandler
public class ImageHandler : IImageHandler
{
private readonly ISet<File> _files = new HashSet<File>();
private readonly string _env;
public ImageHandler(IHostEnviroment hostEnviroment)
{
_env = hostEnviroment.RootPath;
}
public async Task<string> Process(string name, string contentType, byte[] bytes)
{
var engine = new TesseractEngine(System.IO.Path.Combine(_env, "tessdata"),"eng+equ", EngineMode.Default);
var img = Pix.LoadFromMemory(bytes);
var res = engine.Process(img);
var txt = res.GetText();
return await Task.FromResult(txt);
}
}
}

View File

@ -1,30 +0,0 @@
using Serwer.Core.Domain;
using Serwer.Infrastructure.Settings;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Tesseract;
namespace Serwer.Infrastructure.Services
{
public class ImageService : IImageService
{
private readonly ISet<File> _files = new HashSet<File>();
private readonly string _env;
public ImageService(IHostEnviroment hostEnviroment)
{
_env = hostEnviroment.RootPath;
}
public async Task<string> Process(string name, string contentType, byte[] bytes)
{
var engine = new TesseractEngine(System.IO.Path.Combine(_env, "tessdata"),"eng+equ", EngineMode.Default);
var img = Pix.LoadFromMemory(bytes);
var res = engine.Process(img);
var txt = res.GetText();
return await Task.FromResult(txt);
}
}
}

View File

@ -0,0 +1,46 @@
using Google.Apis.Customsearch.v1;
using Google.Apis.Services;
using Newtonsoft.Json;
using Serwer.Infrastructure.DTO;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Text.Json.Serialization;
using System.Threading.Tasks;
namespace Serwer.Infrastructure.Services
{
public class SearchService : ISearchService
{
private readonly IImageHandler _imageHandler;
private const string apiKey = "AIzaSyCagG6QyQyBuJNb1YDuK25qSzoC0Rrjo0c";
private const string searchEngineId = "17b946686537c46e3";
public SearchService(IImageHandler imageHandler)
{
_imageHandler = imageHandler;
}
public async Task<IList<SearchResultDTO>> Search(string query)
{
WebRequest webRequest = WebRequest.Create($"https://www.googleapis.com/customsearch/v1?key={apiKey}&cx={searchEngineId}&q={query}");
using (var stream = new StreamReader(webRequest.GetResponse().GetResponseStream()))
{
var response = await stream.ReadToEndAsync();
dynamic jsonData = JsonConvert.DeserializeObject(response);
var results = new List<SearchResultDTO>();
foreach(var item in jsonData.items)
{
results.Add(new SearchResultDTO
{
Title = item.title,
Link = item.link,
Snippet = item.snippet
});
}
return results;
}
}
}
}

View File

@ -3,6 +3,7 @@ using Serwer.Core.Domain;
using Serwer.Core.Repositories;
using Serwer.Infrastructure.DTO;
using Serwer.Infrastructure.Mappers;
using Serwer.Infrastructure.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
@ -30,7 +31,7 @@ namespace Serwer.Infrastructure.Services
{
throw new Exception($"User with login: {login} already exists.");
}
var user = new User(email, name, surname, login, password);
var user = new User(Guid.NewGuid(), email, name, surname, login, password);
await _userRepository.AddAsync(user);
}
@ -54,5 +55,24 @@ namespace Serwer.Infrastructure.Services
Jwt = _mapper.Map<JwtDto>(jwt)
};
}
public async Task<UserDto> UpdateAsync(UpdateUserModel userModel)
{
var user = await _userRepository.GetAsync(userModel.Id);
if(user == null)
{
throw new Exception("User not found.");
}
var userLoginTaken = await _userRepository.GetAsync(userModel.Login);
if(userLoginTaken != null && userLoginTaken.Id != user.Id)
{
throw new Exception("User login taken.");
}
var newUser = new User(user.Id, userModel.Email, userModel.Name, userModel.Surname, userModel.Login, userModel.Password);
await _userRepository.UpdateAsync(newUser);
newUser = await _userRepository.GetAsync(user.Id);
return _mapper.Map<UserDto>(newUser);
}
}
}

View File

@ -6,6 +6,8 @@
<ItemGroup>
<PackageReference Include="AutoMapper" Version="10.1.1" />
<PackageReference Include="Google.Apis.Customsearch.v1" Version="1.49.0.2084" />
<PackageReference Include="Google.Apis.CustomSearchAPI.v1" Version="1.49.0.2172" />
<PackageReference Include="Microsoft.IdentityModel.Tokens" Version="6.8.0" />
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="6.8.0" />
<PackageReference Include="Tesseract" Version="4.1.1" />

View File

@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Serwer.Infrastructure.ViewModels
{
public class UpdateUserModel
{
public Guid Id { get; set; }
public string Email { get; set; }
public string Name { get; set; }
public string Surname { get; set; }
public string Login { get; set; }
public string Password { get; set; } = null;
}
}