From d53caaea6094136bac3d01ce9dd2782bb1819fe2 Mon Sep 17 00:00:00 2001 From: transtrike Date: Thu, 25 Mar 2021 12:22:54 +0200 Subject: Profile Picture implemented; Tests and Front end work await --- .../ProfilePicture/ProfilePictureWebModel.cs | 9 +++++ .../User/ProfilePictureWebModel.cs | 7 ---- .../User/UpdateProfilePictureWebModel.cs | 9 ----- .../Extensions/ConfigureDependencyInjection.cs | 7 ++-- .../Mapping/ProfilePictureMappings.cs | 16 +++++++++ .../Configurations/Mapping/UserMappings.cs | 3 -- .../Controllers/ProfilePictureController.cs | 42 ++++++++++++---------- 7 files changed, 52 insertions(+), 41 deletions(-) create mode 100644 src/Web/DevHive.Web.Models/ProfilePicture/ProfilePictureWebModel.cs delete mode 100644 src/Web/DevHive.Web.Models/User/ProfilePictureWebModel.cs delete mode 100644 src/Web/DevHive.Web.Models/User/UpdateProfilePictureWebModel.cs create mode 100644 src/Web/DevHive.Web/Configurations/Mapping/ProfilePictureMappings.cs (limited to 'src/Web') diff --git a/src/Web/DevHive.Web.Models/ProfilePicture/ProfilePictureWebModel.cs b/src/Web/DevHive.Web.Models/ProfilePicture/ProfilePictureWebModel.cs new file mode 100644 index 0000000..3fe201c --- /dev/null +++ b/src/Web/DevHive.Web.Models/ProfilePicture/ProfilePictureWebModel.cs @@ -0,0 +1,9 @@ +using Microsoft.AspNetCore.Http; + +namespace DevHive.Web.Models.ProfilePicture +{ + public class ProfilePictureWebModel + { + public IFormFile Picture { get; set; } + } +} diff --git a/src/Web/DevHive.Web.Models/User/ProfilePictureWebModel.cs b/src/Web/DevHive.Web.Models/User/ProfilePictureWebModel.cs deleted file mode 100644 index e09ee08..0000000 --- a/src/Web/DevHive.Web.Models/User/ProfilePictureWebModel.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace DevHive.Web.Models.User -{ - public class ProfilePictureWebModel - { - public string ProfilePictureURL { get; set; } - } -} diff --git a/src/Web/DevHive.Web.Models/User/UpdateProfilePictureWebModel.cs b/src/Web/DevHive.Web.Models/User/UpdateProfilePictureWebModel.cs deleted file mode 100644 index 196d1e7..0000000 --- a/src/Web/DevHive.Web.Models/User/UpdateProfilePictureWebModel.cs +++ /dev/null @@ -1,9 +0,0 @@ -using Microsoft.AspNetCore.Http; - -namespace DevHive.Web.Models.User -{ - public class UpdateProfilePictureWebModel - { - public IFormFile Picture { get; set; } - } -} diff --git a/src/Web/DevHive.Web/Configurations/Extensions/ConfigureDependencyInjection.cs b/src/Web/DevHive.Web/Configurations/Extensions/ConfigureDependencyInjection.cs index a0d0979..20b66e1 100644 --- a/src/Web/DevHive.Web/Configurations/Extensions/ConfigureDependencyInjection.cs +++ b/src/Web/DevHive.Web/Configurations/Extensions/ConfigureDependencyInjection.cs @@ -17,20 +17,22 @@ namespace DevHive.Web.Configurations.Extensions services.AddTransient(); services.AddTransient(); services.AddTransient(); - services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); - services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); + services.AddTransient(); services.AddTransient(options => new CloudinaryService( @@ -43,7 +45,6 @@ namespace DevHive.Web.Configurations.Extensions signingKey: Encoding.ASCII.GetBytes(configuration.GetSection("Jwt").GetSection("signingKey").Value), validationIssuer: configuration.GetSection("Jwt").GetSection("validationIssuer").Value, audience: configuration.GetSection("Jwt").GetSection("audience").Value)); - services.AddTransient(); } } } diff --git a/src/Web/DevHive.Web/Configurations/Mapping/ProfilePictureMappings.cs b/src/Web/DevHive.Web/Configurations/Mapping/ProfilePictureMappings.cs new file mode 100644 index 0000000..8c12a20 --- /dev/null +++ b/src/Web/DevHive.Web/Configurations/Mapping/ProfilePictureMappings.cs @@ -0,0 +1,16 @@ +using System; +using AutoMapper; +using DevHive.Web.Models.ProfilePicture; +using DevHive.Services.Models.ProfilePicture; + +namespace DevHive.Web.Configurations.Mapping +{ + public class ProfilePictureMappings : Profile + { + public ProfilePictureMappings() + { + CreateMap() + .ForMember(dest => dest.ProfilePictureFormFile, src => src.MapFrom(p => p.Picture)); + } + } +} diff --git a/src/Web/DevHive.Web/Configurations/Mapping/UserMappings.cs b/src/Web/DevHive.Web/Configurations/Mapping/UserMappings.cs index 14aaa3a..dabec93 100644 --- a/src/Web/DevHive.Web/Configurations/Mapping/UserMappings.cs +++ b/src/Web/DevHive.Web/Configurations/Mapping/UserMappings.cs @@ -23,9 +23,6 @@ namespace DevHive.Web.Configurations.Mapping CreateMap(); CreateMap(); - CreateMap(); - CreateMap(); - CreateMap(); CreateMap(); } diff --git a/src/Web/DevHive.Web/Controllers/ProfilePictureController.cs b/src/Web/DevHive.Web/Controllers/ProfilePictureController.cs index 2eec99e..1c736f6 100644 --- a/src/Web/DevHive.Web/Controllers/ProfilePictureController.cs +++ b/src/Web/DevHive.Web/Controllers/ProfilePictureController.cs @@ -1,8 +1,12 @@ using System; using System.Threading.Tasks; -using DevHive.Web.Models.User; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; +using DevHive.Services.Interfaces; +using DevHive.Services.Models.ProfilePicture; +using DevHive.Common.Jwt.Interfaces; +using AutoMapper; +using DevHive.Web.Models.ProfilePicture; namespace DevHive.Web.Controllers { @@ -13,36 +17,36 @@ namespace DevHive.Web.Controllers [Route("api/[controller]")] public class ProfilePictureController { - // private readonly ProfilePictureService _profilePictureService; + private readonly IProfilePictureService _profilePictureService; + private readonly IJwtService _jwtService; + private readonly IMapper _profilePictureMapper; - // public ProfilePictureController(ProfilePictureService profilePictureService) - // { - // this._profilePictureService = profilePictureService; - // } + public ProfilePictureController(IProfilePictureService profilePictureService, IJwtService jwtService, IMapper profilePictureMapper) + { + this._profilePictureService = profilePictureService; + this._jwtService = jwtService; + this._profilePictureMapper = profilePictureMapper; + } /// /// Alter the profile picture of a user /// /// The user's Id - /// The new profile picture + /// The new profile picture /// JWT Bearer Token - /// ??? + /// The URL of the new profile picture [HttpPut] - [Route("ProfilePicture")] [Authorize(Roles = "User,Admin")] - public async Task UpdateProfilePicture(Guid userId, [FromForm] UpdateProfilePictureWebModel updateProfilePictureWebModel, [FromHeader] string authorization) + public async Task UpdateProfilePicture(Guid userId, [FromForm] ProfilePictureWebModel profilePictureWebModel, [FromHeader] string authorization) { - throw new NotImplementedException(); - // if (!await this._userService.ValidJWT(userId, authorization)) - // return new UnauthorizedResult(); - - // UpdateProfilePictureServiceModel updateProfilePictureServiceModel = this._userMapper.Map(updateProfilePictureWebModel); - // updateProfilePictureServiceModel.UserId = userId; + if (!this._jwtService.ValidateToken(userId, authorization)) + return new UnauthorizedResult(); - // ProfilePictureServiceModel profilePictureServiceModel = await this._userService.UpdateProfilePicture(updateProfilePictureServiceModel); - // ProfilePictureWebModel profilePictureWebModel = this._userMapper.Map(profilePictureServiceModel); + ProfilePictureServiceModel profilePictureServiceModel = this._profilePictureMapper.Map(profilePictureWebModel); + profilePictureServiceModel.UserId = userId; - // return new AcceptedResult("UpdateProfilePicture", profilePictureWebModel); + string url = await this._profilePictureService.UpdateProfilePicture(profilePictureServiceModel); + return new OkObjectResult(new { URL = url }); } } } -- cgit v1.2.3 From 416fd94399bf0b58fc0d201c0294f0869517a743 Mon Sep 17 00:00:00 2001 From: transtrike Date: Fri, 26 Mar 2021 22:05:07 +0200 Subject: Rating's GetById and GetRatingByPostAndUser return null if User hasn't rated; Updated connection string --- src/Services/DevHive.Services/Services/RatingService.cs | 10 ++++++---- src/Web/DevHive.Web/appsettings.json | 2 +- 2 files changed, 7 insertions(+), 5 deletions(-) (limited to 'src/Web') diff --git a/src/Services/DevHive.Services/Services/RatingService.cs b/src/Services/DevHive.Services/Services/RatingService.cs index 1f77a6e..9d8f4b0 100644 --- a/src/Services/DevHive.Services/Services/RatingService.cs +++ b/src/Services/DevHive.Services/Services/RatingService.cs @@ -57,8 +57,9 @@ namespace DevHive.Services.Services #region Read public async Task GetRatingById(Guid ratingId) { - Rating rating = await this._ratingRepository.GetByIdAsync(ratingId) ?? - throw new ArgumentException("The rating does not exist"); + Rating rating = await this._ratingRepository.GetByIdAsync(ratingId); + if (rating is null) + return null; ReadRatingServiceModel readRatingServiceModel = this._mapper.Map(rating); readRatingServiceModel.UserId = rating.User.Id; @@ -68,8 +69,9 @@ namespace DevHive.Services.Services public async Task GetRatingByPostAndUser(Guid userId, Guid postId) { - Rating rating = await this._ratingRepository.GetRatingByUserAndPostId(userId, postId) ?? - throw new ArgumentException("The rating does not exist"); + Rating rating = await this._ratingRepository.GetRatingByUserAndPostId(userId, postId); + if (rating is null) + return null; ReadRatingServiceModel readRatingServiceModel = this._mapper.Map(rating); readRatingServiceModel.UserId = rating.User.Id; diff --git a/src/Web/DevHive.Web/appsettings.json b/src/Web/DevHive.Web/appsettings.json index fcf9805..053007d 100644 --- a/src/Web/DevHive.Web/appsettings.json +++ b/src/Web/DevHive.Web/appsettings.json @@ -5,7 +5,7 @@ "audience": "" }, "ConnectionStrings": { - "DEV": "Server=localhost;Port=5432;Database=API;User Id=postgres;Password=;" + "DEV": "Server=localhost;Port=5432;Database=DevHive API;User Id=postgres;Password=;" }, "Cloud": { "cloudName": "devhive", -- cgit v1.2.3 From 7d5544626c21b90da0b538da83c112c0f8adec9d Mon Sep 17 00:00:00 2001 From: Syndamia Date: Sat, 27 Mar 2021 08:48:49 +0200 Subject: Updated database name in appsettings and ConnectionString --- src/Data/DevHive.Data/ConnectionString.json | 4 ++-- src/Web/DevHive.Web/appsettings.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'src/Web') diff --git a/src/Data/DevHive.Data/ConnectionString.json b/src/Data/DevHive.Data/ConnectionString.json index c8300b2..1281a1c 100644 --- a/src/Data/DevHive.Data/ConnectionString.json +++ b/src/Data/DevHive.Data/ConnectionString.json @@ -1,5 +1,5 @@ { "ConnectionStrings": { - "DEV": "Server=localhost;Port=5432;Database=API;User Id=postgres;Password=password;" + "DEV": "Server=localhost;Port=5432;Database=DevHive_API;User Id=postgres;Password=password;" } -} \ No newline at end of file +} diff --git a/src/Web/DevHive.Web/appsettings.json b/src/Web/DevHive.Web/appsettings.json index 053007d..036af82 100644 --- a/src/Web/DevHive.Web/appsettings.json +++ b/src/Web/DevHive.Web/appsettings.json @@ -5,7 +5,7 @@ "audience": "" }, "ConnectionStrings": { - "DEV": "Server=localhost;Port=5432;Database=DevHive API;User Id=postgres;Password=;" + "DEV": "Server=localhost;Port=5432;Database=DevHive_API;User Id=postgres;Password=;" }, "Cloud": { "cloudName": "devhive", -- cgit v1.2.3 From 15904cb3d2ef9442b682322353c378ab321520e5 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Sun, 28 Mar 2021 17:43:41 +0300 Subject: Improved formating of response from exception middleware --- src/Web/DevHive.Web/Middleware/ExceptionMiddleware.cs | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'src/Web') diff --git a/src/Web/DevHive.Web/Middleware/ExceptionMiddleware.cs b/src/Web/DevHive.Web/Middleware/ExceptionMiddleware.cs index f159b69..e2521bd 100644 --- a/src/Web/DevHive.Web/Middleware/ExceptionMiddleware.cs +++ b/src/Web/DevHive.Web/Middleware/ExceptionMiddleware.cs @@ -2,7 +2,7 @@ using System; using System.Net; using System.Threading.Tasks; using Microsoft.AspNetCore.Http; -using Microsoft.Extensions.Logging; +using Newtonsoft.Json; namespace DevHive.Web.Middleware { @@ -32,11 +32,14 @@ namespace DevHive.Web.Middleware context.Response.ContentType = "application/json"; context.Response.StatusCode = (int)HttpStatusCode.BadRequest; - return context.Response.WriteAsync(new - { - context.Response.StatusCode, - exception.Message - }.ToString()); + // Made to ressemble the formatting of property validation errors (like [MinLength(3)]) + string message = JsonConvert.SerializeObject(new { + errors = new { + Exception = new String[] { exception.Message } + } + }); + + return context.Response.WriteAsync(message); } } } -- cgit v1.2.3 From fb421f1ab78c1358af5dddc467db7ab02a59110d Mon Sep 17 00:00:00 2001 From: transtrike Date: Fri, 2 Apr 2021 11:30:02 +0300 Subject: Introduced Logger; Replaced DevExcHandler with Custom; Logging Errors to file; Replaced Console logger for requests --- .../DevHive.Common.Models.csproj | 2 +- src/Common/DevHive.Common/DevHive.Common.csproj | 4 +-- .../DevHive.Data.Models/DevHive.Data.Models.csproj | 4 +-- .../DevHive.Data.Tests/DevHive.Data.Tests.csproj | 4 +-- src/Data/DevHive.Data/DevHive.Data.csproj | 6 ++-- .../DevHive.Services.Models.csproj | 2 +- .../DevHive.Services.Tests.csproj | 4 +-- .../DevHive.Services/DevHive.Services.csproj | 8 ++--- .../DevHive.Web.Models/DevHive.Web.Models.csproj | 2 +- src/Web/DevHive.Web.Tests/DevHive.Web.Tests.csproj | 2 +- .../Configurations/Extensions/ConfigureDatabase.cs | 2 +- src/Web/DevHive.Web/DevHive.Web.csproj | 31 ++++++++++-------- .../DevHive.Web/Middleware/ExceptionMiddleware.cs | 8 ++--- src/Web/DevHive.Web/Program.cs | 26 ++++++++++++++- src/Web/DevHive.Web/Startup.cs | 6 +++- src/Web/DevHive.Web/appsettings.json | 38 +++++++++++++++++++--- 16 files changed, 103 insertions(+), 46 deletions(-) (limited to 'src/Web') diff --git a/src/Common/DevHive.Common.Models/DevHive.Common.Models.csproj b/src/Common/DevHive.Common.Models/DevHive.Common.Models.csproj index a952c59..db8d1c9 100644 --- a/src/Common/DevHive.Common.Models/DevHive.Common.Models.csproj +++ b/src/Common/DevHive.Common.Models/DevHive.Common.Models.csproj @@ -4,7 +4,7 @@ - + true diff --git a/src/Common/DevHive.Common/DevHive.Common.csproj b/src/Common/DevHive.Common/DevHive.Common.csproj index cd60d85..a5758f4 100644 --- a/src/Common/DevHive.Common/DevHive.Common.csproj +++ b/src/Common/DevHive.Common/DevHive.Common.csproj @@ -6,6 +6,6 @@ net5.0 - + - + \ No newline at end of file diff --git a/src/Data/DevHive.Data.Models/DevHive.Data.Models.csproj b/src/Data/DevHive.Data.Models/DevHive.Data.Models.csproj index d249c77..2958f86 100644 --- a/src/Data/DevHive.Data.Models/DevHive.Data.Models.csproj +++ b/src/Data/DevHive.Data.Models/DevHive.Data.Models.csproj @@ -4,7 +4,7 @@ - - + + \ No newline at end of file diff --git a/src/Data/DevHive.Data.Tests/DevHive.Data.Tests.csproj b/src/Data/DevHive.Data.Tests/DevHive.Data.Tests.csproj index 25b2b39..e9b33e5 100644 --- a/src/Data/DevHive.Data.Tests/DevHive.Data.Tests.csproj +++ b/src/Data/DevHive.Data.Tests/DevHive.Data.Tests.csproj @@ -4,12 +4,12 @@ false - + - + diff --git a/src/Data/DevHive.Data/DevHive.Data.csproj b/src/Data/DevHive.Data/DevHive.Data.csproj index fcdb7ae..62320f7 100644 --- a/src/Data/DevHive.Data/DevHive.Data.csproj +++ b/src/Data/DevHive.Data/DevHive.Data.csproj @@ -5,14 +5,14 @@ - - + + runtime; build; native; contentfiles; analyzers; buildtransitive all - + diff --git a/src/Services/DevHive.Services.Models/DevHive.Services.Models.csproj b/src/Services/DevHive.Services.Models/DevHive.Services.Models.csproj index a55972a..2345a8e 100644 --- a/src/Services/DevHive.Services.Models/DevHive.Services.Models.csproj +++ b/src/Services/DevHive.Services.Models/DevHive.Services.Models.csproj @@ -4,7 +4,7 @@ - + diff --git a/src/Services/DevHive.Services.Tests/DevHive.Services.Tests.csproj b/src/Services/DevHive.Services.Tests/DevHive.Services.Tests.csproj index d85eea2..4a7237b 100644 --- a/src/Services/DevHive.Services.Tests/DevHive.Services.Tests.csproj +++ b/src/Services/DevHive.Services.Tests/DevHive.Services.Tests.csproj @@ -4,12 +4,12 @@ false - + - + diff --git a/src/Services/DevHive.Services/DevHive.Services.csproj b/src/Services/DevHive.Services/DevHive.Services.csproj index f51c1b6..2468711 100644 --- a/src/Services/DevHive.Services/DevHive.Services.csproj +++ b/src/Services/DevHive.Services/DevHive.Services.csproj @@ -4,15 +4,15 @@ - + runtime; build; native; contentfiles; analyzers; buildtransitive all - + - - + + diff --git a/src/Web/DevHive.Web.Models/DevHive.Web.Models.csproj b/src/Web/DevHive.Web.Models/DevHive.Web.Models.csproj index 9d62eee..79c856f 100644 --- a/src/Web/DevHive.Web.Models/DevHive.Web.Models.csproj +++ b/src/Web/DevHive.Web.Models/DevHive.Web.Models.csproj @@ -8,6 +8,6 @@ - + \ No newline at end of file diff --git a/src/Web/DevHive.Web.Tests/DevHive.Web.Tests.csproj b/src/Web/DevHive.Web.Tests/DevHive.Web.Tests.csproj index 5099119..49a9173 100644 --- a/src/Web/DevHive.Web.Tests/DevHive.Web.Tests.csproj +++ b/src/Web/DevHive.Web.Tests/DevHive.Web.Tests.csproj @@ -8,7 +8,7 @@ - + diff --git a/src/Web/DevHive.Web/Configurations/Extensions/ConfigureDatabase.cs b/src/Web/DevHive.Web/Configurations/Extensions/ConfigureDatabase.cs index 1bd8df0..b4c49b4 100644 --- a/src/Web/DevHive.Web/Configurations/Extensions/ConfigureDatabase.cs +++ b/src/Web/DevHive.Web/Configurations/Extensions/ConfigureDatabase.cs @@ -18,7 +18,7 @@ namespace DevHive.Web.Configurations.Extensions { services.AddDbContext(options => { - options.EnableSensitiveDataLogging(true); + // options.EnableSensitiveDataLogging(true); options.UseNpgsql(configuration.GetConnectionString("DEV"), options => { options.UseQuerySplittingBehavior(QuerySplittingBehavior.SplitQuery); diff --git a/src/Web/DevHive.Web/DevHive.Web.csproj b/src/Web/DevHive.Web/DevHive.Web.csproj index 39322ae..5b3a920 100644 --- a/src/Web/DevHive.Web/DevHive.Web.csproj +++ b/src/Web/DevHive.Web/DevHive.Web.csproj @@ -9,25 +9,30 @@ true - - - + + + runtime; build; native; contentfiles; analyzers; buildtransitive all - - - - - - - - - - + + + + + + + + + + + + + + + diff --git a/src/Web/DevHive.Web/Middleware/ExceptionMiddleware.cs b/src/Web/DevHive.Web/Middleware/ExceptionMiddleware.cs index e2521bd..ebec5e8 100644 --- a/src/Web/DevHive.Web/Middleware/ExceptionMiddleware.cs +++ b/src/Web/DevHive.Web/Middleware/ExceptionMiddleware.cs @@ -32,12 +32,8 @@ namespace DevHive.Web.Middleware context.Response.ContentType = "application/json"; context.Response.StatusCode = (int)HttpStatusCode.BadRequest; - // Made to ressemble the formatting of property validation errors (like [MinLength(3)]) - string message = JsonConvert.SerializeObject(new { - errors = new { - Exception = new String[] { exception.Message } - } - }); + // Made to resemble the formatting of property validation errors (like [MinLength(3)]) + string message = JsonConvert.SerializeObject(new { Error = exception.Message }); return context.Response.WriteAsync(message); } diff --git a/src/Web/DevHive.Web/Program.cs b/src/Web/DevHive.Web/Program.cs index fdb6889..e7c47a9 100644 --- a/src/Web/DevHive.Web/Program.cs +++ b/src/Web/DevHive.Web/Program.cs @@ -1,5 +1,8 @@ +using System; using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.Hosting; +using Microsoft.Extensions.Configuration; +using Serilog; namespace DevHive.Web { @@ -11,11 +14,32 @@ namespace DevHive.Web public static void Main(string[] args) { - CreateHostBuilder(args).Build().Run(); + var config = new ConfigurationBuilder() + .AddJsonFile("appsettings.json") + .Build(); + + Log.Logger = new LoggerConfiguration() + .ReadFrom.Configuration(config) + .CreateLogger(); + + try + { + Log.Information("Application Starting Up"); + CreateHostBuilder(args).Build().Run(); + } + catch (Exception ex) + { + Log.Fatal(ex, "The application failed to start correctly."); + } + finally + { + Log.CloseAndFlush(); + } } public static IHostBuilder CreateHostBuilder(string[] args) => Host.CreateDefaultBuilder(args) + .UseSerilog() .ConfigureWebHostDefaults(webBuilder => { webBuilder.ConfigureKestrel(opt => opt.ListenLocalhost(HTTP_PORT)); diff --git a/src/Web/DevHive.Web/Startup.cs b/src/Web/DevHive.Web/Startup.cs index 002c718..05a75d9 100644 --- a/src/Web/DevHive.Web/Startup.cs +++ b/src/Web/DevHive.Web/Startup.cs @@ -5,6 +5,7 @@ using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using DevHive.Web.Configurations.Extensions; using Newtonsoft.Json; +using Serilog; namespace DevHive.Web { @@ -46,7 +47,8 @@ namespace DevHive.Web if (env.IsDevelopment()) { - app.UseDeveloperExceptionPage(); + app.UseExceptionHandlerMiddlewareConfiguration(); + // app.UseDeveloperExceptionPage(); } else { @@ -58,6 +60,8 @@ namespace DevHive.Web app.UseDatabaseConfiguration(); app.UseAutoMapperConfiguration(); + app.UseSerilogRequestLogging(); + app.UseEndpoints(endpoints => { endpoints.MapControllerRoute( diff --git a/src/Web/DevHive.Web/appsettings.json b/src/Web/DevHive.Web/appsettings.json index 036af82..84d534d 100644 --- a/src/Web/DevHive.Web/appsettings.json +++ b/src/Web/DevHive.Web/appsettings.json @@ -12,11 +12,39 @@ "apiKey": "488664116365813", "apiSecret": "" }, - "Logging": { - "LogLevel": { + "Serilog": { + "Using": [], + "LevelSwitches": { + "$consoleSwitch": "Verbose", + "$fileSwitch": "Error" + }, + "MinimumLevel": { "Default": "Information", - "Microsoft": "Warning", - "Microsoft.Hosting.Lifetime": "Information" - } + "Override": { + "Microsoft": "Warning", + "System": "Warning" + } + }, + "Enrich": [ + "FromLogContext", + "WithMachineName", + "WithProcessId", + "WithThreadId" + ], + "WriteTo": [ + { + "Name": "Console", + "Args": { + "levelSwitch": "$consoleSwitch" + } + }, + { + "Name": "File", + "Args": { + "path": "./Logs/errors.log", + "levelSwitch": "$fileSwitch" + } + } + ] } } -- cgit v1.2.3 From b0c6c6e1795a1cc8fe82a60ce16a263ab4cad397 Mon Sep 17 00:00:00 2001 From: transtrike Date: Fri, 2 Apr 2021 23:53:11 +0300 Subject: ReadProfilePic endpoint implemented --- .../DevHive.Services/Interfaces/IProfilePictureService.cs | 7 ------- .../DevHive.Web/Controllers/ProfilePictureController.cs | 14 ++++++++++++++ 2 files changed, 14 insertions(+), 7 deletions(-) (limited to 'src/Web') diff --git a/src/Services/DevHive.Services/Interfaces/IProfilePictureService.cs b/src/Services/DevHive.Services/Interfaces/IProfilePictureService.cs index c455831..edf2775 100644 --- a/src/Services/DevHive.Services/Interfaces/IProfilePictureService.cs +++ b/src/Services/DevHive.Services/Interfaces/IProfilePictureService.cs @@ -6,13 +6,6 @@ namespace DevHive.Services.Interfaces { public interface IProfilePictureService { - /// - /// Inserts a user's profile picture in the database and cloud - /// - /// User's Guid and his/hers profile picture as file - /// The new profile picture's URL in the cloud - Task InsertProfilePicture(ProfilePictureServiceModel profilePictureServiceModel); - /// /// Get a profile picture by it's Guid /// diff --git a/src/Web/DevHive.Web/Controllers/ProfilePictureController.cs b/src/Web/DevHive.Web/Controllers/ProfilePictureController.cs index 1c736f6..9a76e2c 100644 --- a/src/Web/DevHive.Web/Controllers/ProfilePictureController.cs +++ b/src/Web/DevHive.Web/Controllers/ProfilePictureController.cs @@ -28,6 +28,20 @@ namespace DevHive.Web.Controllers this._profilePictureMapper = profilePictureMapper; } + /// + /// Get the URL of user's profile picture + /// + /// The profile picture's Id + /// JWT Bearer Token + /// The URL of the profile picture + [HttpGet] + [AllowAnonymous] + public async Task ReadProfilePicture(Guid profilePictureId, [FromHeader] string authorization) + { + string profilePicURL = await this._profilePictureService.GetProfilePictureById(profilePictureId); + return new OkObjectResult(new { ProfilePictureURL = profilePicURL} ); + } + /// /// Alter the profile picture of a user /// -- cgit v1.2.3