Skip to content

Commit

Permalink
Create and update image methods update
Browse files Browse the repository at this point in the history
  • Loading branch information
mkoper02 committed Jun 22, 2024
1 parent 4ed59ea commit 4c9dbdf
Showing 1 changed file with 27 additions and 4 deletions.
31 changes: 27 additions & 4 deletions Server/ReasnAPI/ReasnAPI/Controllers/MeController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,18 +50,41 @@ public IActionResult UpdateCurrentUser(
[HttpPost]
[Route("image")]
[ProducesResponseType<ImageDto>(StatusCodes.Status201Created)]
public IActionResult AddCurrentUserImage([FromBody] ImageDto imageDto)
public async Task<IActionResult> AddCurrentUserImage([FromForm] IFormFile image)
{
var image = _imageService.CreateImages([imageDto]);
return Ok(image);
using var ms = new MemoryStream();
await image.CopyToAsync(ms);
var fileBytes = ms.ToArray();

var imageDto = new ImageDto
{
ObjectId = _userService.GetCurrentUser().Id,
ObjectType = ObjectType.User,
ImageData = fileBytes
};

var createdImage = _imageService.CreateImages([imageDto]);
return Ok(createdImage);
}

[HttpPut]
[Route("image")]
[ProducesResponseType<ImageDto>(StatusCodes.Status200OK)]
public IActionResult UpdateCurrentUserImage([FromBody] ImageDto imageDto)
public async Task<IActionResult> UpdateCurrentUserImage([FromForm] IFormFile image)
{
var userId = _userService.GetCurrentUser().Id;

using var ms = new MemoryStream();
await image.CopyToAsync(ms);
var fileBytes = ms.ToArray();

var imageDto = new ImageDto
{
ObjectId = userId,
ObjectType = ObjectType.User,
ImageData = fileBytes
};

_imageService.UpdateImageForUser(userId, imageDto);

return Ok(imageDto);
Expand Down

0 comments on commit 4c9dbdf

Please sign in to comment.