Skip to content

Commit 4fd0e98

Browse files
committed
Add album repositories, add album service with created methods and add album controllers with related actions
1 parent ff7c14d commit 4fd0e98

27 files changed

+1283
-35
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using CoinyProject.Application.DTO;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Linq;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
8+
namespace CoinyProject.Application.AlbumServices.Interfaces
9+
{
10+
public interface IAlbumElementService
11+
{
12+
Task SetAlbumId(int albumId);
13+
Task AddAlbumElement(AlbumElementCreating albumElement);
14+
Task CommitAlbumElementList();
15+
16+
17+
}
18+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using CoinyProject.Application.DTO;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Linq;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
8+
namespace CoinyProject.Application.AlbumServices.Interfaces
9+
{
10+
public interface IAlbumService
11+
{
12+
Task<int> AddAlbum(AlbumCreating album);
13+
}
14+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
using CoinyProject.Application.AlbumServices.Interfaces;
2+
using CoinyProject.Application.DTO;
3+
using CoinyProject.Core.Domain.Entities;
4+
using CoinyProject.Infrastructure.Data.Repositories;
5+
using Microsoft.EntityFrameworkCore;
6+
using System;
7+
using System.Collections.Generic;
8+
using System.Linq;
9+
using System.Text;
10+
using System.Threading.Tasks;
11+
12+
namespace CoinyProject.Application.AlbumServices.Services
13+
{
14+
public class AlbumElementService : IAlbumElementService
15+
{
16+
private readonly UnitOfWork _unitOfWork;
17+
private int albumId;
18+
public Task SetAlbumId(int id)
19+
{
20+
if(id != 0)
21+
albumId = id;
22+
23+
return Task.CompletedTask;
24+
}
25+
26+
27+
public AlbumElementService(UnitOfWork unitOfWork)
28+
{
29+
_unitOfWork = unitOfWork;
30+
}
31+
32+
33+
public async Task AddAlbumElement(AlbumElementCreating element)
34+
{
35+
if(albumId != 0)
36+
{
37+
AlbumElement _albumElement = new AlbumElement();
38+
39+
_albumElement.AlbumId = albumId;
40+
_albumElement.Name = element.Name;
41+
42+
if (_albumElement.Description != null)
43+
_albumElement.Description = element.Description;
44+
45+
await _unitOfWork.AlbumElementRepository.Add(_albumElement);
46+
}
47+
}
48+
49+
public async Task CommitAlbumElementList()
50+
{
51+
if (albumId != 0)
52+
{
53+
await _unitOfWork.Commit();
54+
}
55+
albumId = 0;
56+
}
57+
}
58+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
using CoinyProject.Application.AlbumServices.Interfaces;
2+
using CoinyProject.Application.DTO;
3+
using CoinyProject.Core.Domain.Entities;
4+
using CoinyProject.Infrastructure.Data;
5+
using CoinyProject.Infrastructure.Data.Migrations;
6+
using CoinyProject.Infrastructure.Data.Repositories;
7+
using Microsoft.EntityFrameworkCore;
8+
using System;
9+
using System.Collections.Generic;
10+
using System.Linq;
11+
using System.Text;
12+
using System.Threading.Tasks;
13+
using System.Xml.Linq;
14+
15+
namespace CoinyProject.Application.AlbumServices.Services
16+
{
17+
public class AlbumService : IAlbumService
18+
{
19+
private readonly UnitOfWork _unitOfWork;
20+
21+
public AlbumService(UnitOfWork unitOfWork)
22+
{
23+
_unitOfWork = unitOfWork;
24+
}
25+
26+
public async Task<int> AddAlbum(AlbumCreating album)
27+
{
28+
Album _album = new Album();
29+
30+
_album.Name = album.Name;
31+
if (album.Description != null)
32+
_album.Description = album.Description;
33+
34+
await _unitOfWork.AlbumRepository.Add(_album);
35+
await _unitOfWork.Commit();
36+
return _album.Id;
37+
}
38+
39+
40+
}
41+
}

src/CoinyProject.Application/CoinyProject.Application.csproj

+4
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,8 @@
66
<Nullable>enable</Nullable>
77
</PropertyGroup>
88

9+
<ItemGroup>
10+
<ProjectReference Include="..\CoinyProject.Infrastructure.Data\CoinyProject.Infrastructure.Data.csproj" />
11+
</ItemGroup>
12+
913
</Project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using CoinyProject.Core.Domain.Entities;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Linq;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
8+
namespace CoinyProject.Application.DTO
9+
{
10+
public class AlbumCreating
11+
{
12+
public string Name { get; set; }
13+
public string? Description { get; set; }
14+
public ICollection<AlbumElement> Elements { get; set; }
15+
}
16+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace CoinyProject.Application.DTO
8+
{
9+
public class AlbumElementCreating
10+
{
11+
public string Name { get; set; }
12+
public string? Description { get; set; }
13+
public byte[]? Image { get; set; }
14+
}
15+
}

src/CoinyProject.Core.Domain/Entities/Album.cs

+5-5
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ public class Album
1010
{
1111
public int Id { get; set; }
1212
public string Name { get; set; }
13-
public string Description { get; set; }
13+
public string? Description { get; set; }
1414
public int Rate { get; set; }
15-
public string UserId { get; set; }
15+
public string? UserId { get; set; }
1616

17-
public virtual User User { get; set; }
18-
public virtual ICollection<AlbumElement> Elements { get; set; }
19-
public virtual ICollection<FavoriteAlbums> FavoriteAlbums { get; set; }
17+
public virtual User? User { get; set; }
18+
public virtual ICollection<AlbumElement>? Elements { get; set; }
19+
public virtual ICollection<FavoriteAlbums>? FavoriteAlbums { get; set; }
2020
}
2121
}

src/CoinyProject.Core.Domain/Entities/AlbumElement.cs

+5-5
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ public class AlbumElement
1212
{
1313
public int Id { get; set; }
1414
public string Name { get; set; }
15-
public string Description { get; set; }
16-
public byte[] Image { get; set; }
17-
public int AlbumId { get; set; }
15+
public string? Description { get; set; }
16+
public byte[]? Image { get; set; }
17+
public int? AlbumId { get; set; }
1818

19-
public virtual Album Album { get; set; }
20-
public virtual Auction Auction { get; set; }
19+
public virtual Album? Album { get; set; }
20+
public virtual Auction? Auction { get; set; }
2121
}
2222
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace CoinyProject.Core.Domain.Interfaces
8+
{
9+
public interface IBaseRepository<TEntity> where TEntity : class
10+
{
11+
Task<TEntity> GetById(int id);
12+
Task<IEnumerable<TEntity>> GetAll();
13+
Task Add(TEntity entity);
14+
Task Remove(TEntity entity);
15+
Task Update(TEntity entity);
16+
17+
}
18+
}

src/CoinyProject.Infrastructure.Data/ApplicationDBContext.cs

+2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ namespace CoinyProject.Infrastructure.Data
1212
{
1313
public class ApplicationDBContext : IdentityDbContext<User>
1414
{
15+
16+
1517
public ApplicationDBContext(DbContextOptions<ApplicationDBContext> options) : base(options) { }
1618

1719
public DbSet<Album> Albums { get; set; }

0 commit comments

Comments
 (0)