Skip to content

Commit

Permalink
Merge branch 'RSN-14' into RSN-38
Browse files Browse the repository at this point in the history
  • Loading branch information
mkoper02 authored Jun 3, 2024
2 parents 6a56302 + bfadcd3 commit e09b930
Show file tree
Hide file tree
Showing 6 changed files with 479 additions and 447 deletions.
168 changes: 84 additions & 84 deletions Server/ReasnAPI/ReasnAPI/Services/AddressService.cs
Original file line number Diff line number Diff line change
@@ -1,111 +1,111 @@
using ReasnAPI.Models.Database;
using ReasnAPI.Models.DTOs;
using System.Linq.Expressions;

using ReasnAPI.Models.Database;
using ReasnAPI.Models.DTOs;
using System.Linq.Expressions;

namespace ReasnAPI.Services
{
{
public class AddressService(ReasnContext context)
{
{
public AddressDto? CreateAddress(AddressDto? addressDto)
{
{
if (addressDto is null)
{
return null;
}

}

var address = new Address
{
City = addressDto.City,
Country = addressDto.Country,
State = addressDto.State,
Street = addressDto.Street,
ZipCode = addressDto.ZipCode
};

context.Addresses.Add(address);
context.SaveChanges();

return addressDto;
}

{
City = addressDto.City,
Country = addressDto.Country,
State = addressDto.State,
Street = addressDto.Street,
ZipCode = addressDto.ZipCode
};

context.Addresses.Add(address);
context.SaveChanges();

return addressDto;
}

public AddressDto? UpdateAddress(int addressId, AddressDto? addressDto)
{
{
if (addressDto is null)
{
return null;
}

var address = context.Addresses.FirstOrDefault(r => r.Id == addressId);

}

var address = context.Addresses.FirstOrDefault(r => r.Id == addressId);

if (address is null)
{
return null;
}

address.City = addressDto.City;
address.Country = addressDto.Country;
address.Street = addressDto.Street;
address.State = addressDto.State;
address.ZipCode = addressDto.ZipCode;

context.Addresses.Update(address);
context.SaveChanges();

return MapToAddressDto(address);
}

}

address.City = addressDto.City;
address.Country = addressDto.Country;
address.Street = addressDto.Street;
address.State = addressDto.State;
address.ZipCode = addressDto.ZipCode;

context.Addresses.Update(address);
context.SaveChanges();

return MapToAddressDto(address);
}

public bool DeleteAddress(int addressId)
{
var address = context.Addresses.FirstOrDefault(r => r.Id == addressId);

{
var address = context.Addresses.FirstOrDefault(r => r.Id == addressId);

if (address is null)
{
return false;
}

context.Addresses.Remove(address);
context.SaveChanges();

return true;
}

}

context.Addresses.Remove(address);
context.SaveChanges();

return true;
}

public AddressDto? GetAddressById(int addressId)
{
var address = context.Addresses.Find(addressId);

{
var address = context.Addresses.Find(addressId);

if (address is null)
{
return null;
}

return MapToAddressDto(address);
}

}

return MapToAddressDto(address);
}

public IEnumerable<AddressDto?> GetAddressesByFilter(Expression<Func<Address, bool>> filter)
{
return context.Addresses
.Where(filter)
.Select(address => MapToAddressDto(address))
{
return context.Addresses
.Where(filter)
.Select(address => MapToAddressDto(address))
.AsEnumerable();
}

}

public IEnumerable<AddressDto?> GetAllAddresses()
{
return context.Addresses
.Select(address => MapToAddressDto(address))
.AsEnumerable();
}

{
return context.Addresses
.Select(address => MapToAddressDto(address))
.AsEnumerable();
}

private static AddressDto MapToAddressDto(Address address)
{
{
return new AddressDto
{
Country = address.Country,
City = address.City,
Street = address.Street,
State = address.State,
ZipCode = address.ZipCode
};
}
}
}
{
Country = address.Country,
City = address.City,
Street = address.Street,
State = address.State,
ZipCode = address.ZipCode
};
}
}
}
160 changes: 80 additions & 80 deletions Server/ReasnAPI/ReasnAPI/Services/CommentService.cs
Original file line number Diff line number Diff line change
@@ -1,105 +1,105 @@
using ReasnAPI.Models.Database;
using ReasnAPI.Models.DTOs;
using System.Linq.Expressions;

using ReasnAPI.Models.Database;
using ReasnAPI.Models.DTOs;
using System.Linq.Expressions;

namespace ReasnAPI.Services
{
{
public class CommentService(ReasnContext context)
{
{
public CommentDto? CreateComment(CommentDto? commentDto)
{
{
if (commentDto is null)
{
return null;
}

return null;
}

var comment = new Comment
{
EventId = commentDto.EventId,
Content = commentDto.Content,
UserId = commentDto.UserId,
CreatedAt = DateTime.UtcNow
};

context.Comments.Add(comment);
{
EventId = commentDto.EventId,
Content = commentDto.Content,
UserId = commentDto.UserId,
CreatedAt = DateTime.UtcNow
};

context.Comments.Add(comment);
context.SaveChanges();

return commentDto;
}

return commentDto;
}

public CommentDto? UpdateComment(int commentId, CommentDto? commentDto)
{
{
if (commentDto is null)
{
return null;
}

var comment = context.Comments.FirstOrDefault(r => r.Id == commentId);

return null;
}

var comment = context.Comments.FirstOrDefault(r => r.Id == commentId);

if (comment is null)
{
return null;
}

comment.Content = commentDto.Content;

context.Comments.Update(comment);
context.SaveChanges();

return MapToCommentDto(comment);
}

return null;
}

comment.Content = commentDto.Content;

context.Comments.Update(comment);
context.SaveChanges();

return MapToCommentDto(comment);
}

public bool DeleteComment(int commentId)
{
var comment = context.Comments.FirstOrDefault(r => r.Id == commentId);

{
var comment = context.Comments.FirstOrDefault(r => r.Id == commentId);

if (comment is null)
{
return false;
}

context.Comments.Remove(comment);
context.SaveChanges();

return true;
}

return false;
}

context.Comments.Remove(comment);
context.SaveChanges();

return true;
}

public CommentDto? GetCommentById(int commentId)
{
var comment = context.Comments.Find(commentId);

{
var comment = context.Comments.Find(commentId);

if (comment is null)
{
return null;
}

return MapToCommentDto(comment);
}

return null;
}

return MapToCommentDto(comment);
}

public IEnumerable<CommentDto?> GetCommentsByFilter(Expression<Func<Comment, bool>> filter)
{
return context.Comments
.Where(filter)
.Select(comment => MapToCommentDto(comment))
.AsEnumerable();
}

{
return context.Comments
.Where(filter)
.Select(comment => MapToCommentDto(comment))
.AsEnumerable();
}

public IEnumerable<CommentDto?> GetAllComments()
{
return context.Comments
.Select(comment => MapToCommentDto(comment))
.AsEnumerable();
}

{
return context.Comments
.Select(comment => MapToCommentDto(comment))
.AsEnumerable();
}

private static CommentDto MapToCommentDto(Comment comment)
{
return new CommentDto
{
{
EventId = comment.EventId,
UserId = comment.UserId,
Content = comment.Content,
CreatedAt = comment.CreatedAt
};
}
}
}
UserId = comment.UserId,
Content = comment.Content,
CreatedAt = comment.CreatedAt
};
}
}
}
16 changes: 16 additions & 0 deletions Server/ReasnAPI/ReasnAPI/Services/ObjectTypeService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using ReasnAPI.Models.Database;

namespace ReasnAPI.Services {
public class ObjectTypeService (ReasnContext context) {
private readonly ReasnContext _context = context;

/* TODO: Create following functions for this class
* create
* update
* delete
* get by ID
* get list by filter
* get all
*/
}
}
Loading

0 comments on commit e09b930

Please sign in to comment.