Skip to content

Commit

Permalink
Added IsLiked to mix
Browse files Browse the repository at this point in the history
  • Loading branch information
fergalmoran committed Dec 6, 2024
1 parent 2675fcb commit 3e2a355
Show file tree
Hide file tree
Showing 14 changed files with 2,278 additions and 22 deletions.
14 changes: 7 additions & 7 deletions mixyboos-api/Controllers/MixController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -182,23 +182,23 @@ public async Task<ActionResult<MixDTO>> ToggleLike(Guid id) {
.Where(l => l.MixId.Equals(id) && l.UserId.Equals(user.Id))
.ToListAsync();

if (likes.Count != 0) {
__context.RemoveRange(likes);
await __context.SaveChangesAsync();
return NoContent();
}

var mix = await repository.Get(id);
if (mix is null) {
return NotFound();
}

if (likes.Count != 0) {
__context.RemoveRange(likes);
await __context.SaveChangesAsync();
return Ok(mix.Adapt<MixDTO>());
}

await __context.MixLikes.AddAsync(new MixLike {
Mix = mix,
User = user
});
await __context.SaveChangesAsync();
return Ok();
return Ok(mix.Adapt<MixDTO>());
}

[HttpDelete]
Expand Down
1 change: 1 addition & 0 deletions mixyboos-api/Data/DTO/MixDTO.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public class MixDTO {
public int DownloadCount { get; set; }
public long Duration { get; set; }

public bool IsLiked { get; set; }
public string AudioUrl { get; set; }
public string PcmUrl { get; set; }

Expand Down
18 changes: 14 additions & 4 deletions mixyboos-api/Data/Models/Mix.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,24 @@ namespace MixyBoos.Api.Data.Models;

[Index(nameof(Slug), IsUnique = true)]
public class Mix : BaseEntity, ISluggedEntity {
[Required] public string? Title { get; set; }
[Required] public string? Description { get; set; }
[Required]
[MaxLength(100)]
public required string Title { get; set; }


[Required]
[MaxLength(2000)]
public required string Description { get; set; }

public string? Image { get; set; }

[MaxLength(2000)]
public string? AudioUrl { get; set; }

public bool IsProcessed { get; set; } = false;

public TimeSpan Duration { get; set; }
[Required] public virtual MixyBoosUser? User { get; set; }
[Required] public virtual required MixyBoosUser User { get; set; }

public ICollection<MixPlay>? Plays { get; set; } = new List<MixPlay>();
public ICollection<MixLike>? Likes { get; set; } = new List<MixLike>();
Expand Down
1 change: 1 addition & 0 deletions mixyboos-api/Data/Repositories/MixRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

namespace MixyBoos.Api.Data.Repositories;

//TODO: Perhaps refactor this out to methods on Mix ?
public class MixRepository : Repository<Mix> {
public MixRepository(MixyBoosContext context) : base(context) { }

Expand Down
2 changes: 1 addition & 1 deletion mixyboos-api/Migrations/20241104180729_Initial.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 3e2a355

Please sign in to comment.