Skip to content

Commit

Permalink
Update user Api
Browse files Browse the repository at this point in the history
  • Loading branch information
Oktawian-L committed Nov 3, 2019
1 parent 6b235a5 commit a554998
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 7 deletions.
16 changes: 9 additions & 7 deletions SubitonAPI/SubitonAPI/Controllers/UsersController.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System.Security.Claims;
using System.Threading.Tasks;
using AutoMapper;
using Microsoft.AspNetCore.Mvc;
Expand Down Expand Up @@ -54,19 +55,20 @@ public async Task<ActionResult<User>> 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<IActionResult> PutUser(int id, User user)
public async Task<IActionResult> 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
{
Expand All @@ -82,11 +84,11 @@ public async Task<IActionResult> 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.
Expand Down
42 changes: 42 additions & 0 deletions SubitonAPI/SubitonAPI/DTO/UserUpdateDTO.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using SubitonAPI.Helpers;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace SubitonAPI.DTO
{

/// <summary>
/// DTO to get data from front-end
/// </summary>
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; }
}
}
3 changes: 3 additions & 0 deletions SubitonAPI/SubitonAPI/Helpers/AutoMapperProfiles.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ public AutoMapperProfiles()
});
CreateMap<Photo, PhotoDTO>();
CreateMap<PhotoDTO, Photo>();

// from front-end
CreateMap<UserUpdateDTO, User>();
}
}
}

0 comments on commit a554998

Please sign in to comment.