diff --git a/SubitonAPI/SubitonAPI/Controllers/UsersController.cs b/SubitonAPI/SubitonAPI/Controllers/UsersController.cs index 7130073..4fedc72 100644 --- a/SubitonAPI/SubitonAPI/Controllers/UsersController.cs +++ b/SubitonAPI/SubitonAPI/Controllers/UsersController.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using System.Security.Claims; using System.Threading.Tasks; using AutoMapper; using Microsoft.AspNetCore.Mvc; @@ -54,19 +55,20 @@ public async Task> GetUser(int id) return Ok(userToreturn); } - /* + // PUT: api/Users/5 // To protect from overposting attacks, please enable the specific properties you want to bind to, for // more details see https://aka.ms/RazorPagesCRUD. [HttpPut("{id}")] - public async Task PutUser(int id, User user) + public async Task UpdateUser(int id, UserUpdateDTO user) { - if (id != user.Id) + if (id != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value)) { - return BadRequest(); + return Unauthorized(); } + var userFromRepo = await _userRepository.GetUser(id); - _userRepository.Entry(user).State = EntityState.Modified; + /*_userRepository.Entry(user).State = EntityState.Modified; try { @@ -82,11 +84,11 @@ public async Task PutUser(int id, User user) { throw; } - } + }*/ return NoContent(); } - + /* // POST: api/Users // To protect from overposting attacks, please enable the specific properties you want to bind to, for // more details see https://aka.ms/RazorPagesCRUD. diff --git a/SubitonAPI/SubitonAPI/DTO/UserUpdateDTO.cs b/SubitonAPI/SubitonAPI/DTO/UserUpdateDTO.cs new file mode 100644 index 0000000..12a699e --- /dev/null +++ b/SubitonAPI/SubitonAPI/DTO/UserUpdateDTO.cs @@ -0,0 +1,42 @@ +using SubitonAPI.Helpers; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace SubitonAPI.DTO +{ + + /// + /// DTO to get data from front-end + /// + public class UserUpdateDTO + { + public int Id { get; set; } + public AnimalType AnimalType { get; set; } + public string Name { get; set; } + public int Age { get; set; } + public string Gender { get; set; } + public DateTime DateOfBirth { get; set; } + public string Rasa { get; set; } + public DateTime Created { get; set; } + public DateTime LastActive { get; set; } + public string City { get; set; } + public string Country { get; set; } + public string PhotoUrl { get; set; } + public string Height { get; set; } + public string FurColor { get; set; } + public string Weight { get; set; } + public string Nature { get; set; } + public string MartialStatus { get; set; } + + //description + public string Description { get; set; } + public string LookingFor { get; set; } + + // Upodobania + public string Interests { get; set; } + public string FreeTimeActivities { get; set; } + public string Education { get; set; } + } +} diff --git a/SubitonAPI/SubitonAPI/Helpers/AutoMapperProfiles.cs b/SubitonAPI/SubitonAPI/Helpers/AutoMapperProfiles.cs index da1249c..2cc0da9 100644 --- a/SubitonAPI/SubitonAPI/Helpers/AutoMapperProfiles.cs +++ b/SubitonAPI/SubitonAPI/Helpers/AutoMapperProfiles.cs @@ -36,6 +36,9 @@ public AutoMapperProfiles() }); CreateMap(); CreateMap(); + + // from front-end + CreateMap(); } } }