-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f2c4a1b
commit fd59120
Showing
16 changed files
with
465 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using AutoMapper; | ||
using MusicService.Dtos.Song; | ||
using MusicService.Models; | ||
|
||
namespace MusicService | ||
{ | ||
public class AutoMapperProfile : Profile | ||
{ | ||
public AutoMapperProfile() | ||
{ | ||
//All "Song" related mappings | ||
CreateMap<Song, GetSongDto>(); | ||
CreateMap<AddSongDto, Song>(); | ||
CreateMap<UpdateSongDto, Song>(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
using Microsoft.AspNetCore.Authorization; | ||
using Microsoft.AspNetCore.Mvc; | ||
using MusicService.Dtos.Song; | ||
using MusicService.Services; | ||
using MusicService.Services.Song; | ||
|
||
namespace MusicService.Controllers | ||
{ | ||
[Route("api/[controller]")] | ||
[ApiController] | ||
public class SongController : ControllerBase | ||
{ | ||
|
||
private readonly ISongService _songService; | ||
|
||
public SongController(ISongService songService) | ||
{ | ||
_songService = songService; | ||
} | ||
|
||
[HttpGet("all")] | ||
public async Task<ActionResult<ServiceResponse<List<GetSongDto>>>> GetAllSongs() | ||
{ | ||
var response = await _songService.GetAllSongs(); | ||
|
||
if (response.Data == null) | ||
return StatusCode(StatusCodes.Status404NotFound, response); | ||
|
||
return StatusCode(StatusCodes.Status200OK, response); | ||
} | ||
|
||
[HttpGet("{songId}")] | ||
public async Task<ActionResult<ServiceResponse<GetSongDto>>> GetSong(int songId) | ||
{ | ||
var response = await _songService.GetSong(songId); | ||
|
||
if (response.Data == null) | ||
return StatusCode(StatusCodes.Status404NotFound, response); | ||
|
||
return StatusCode(StatusCodes.Status200OK, response); | ||
} | ||
|
||
[HttpPost] | ||
public async Task<ActionResult<ServiceResponse<GetSongDto>>> AddSong(AddSongDto request) | ||
{ | ||
var songResponse = await _songService.AddSong(request); | ||
|
||
if (!songResponse.Success) | ||
return StatusCode(StatusCodes.Status404NotFound, songResponse); | ||
|
||
return StatusCode(StatusCodes.Status201Created, songResponse); | ||
} | ||
|
||
[HttpPut] | ||
public async Task<ActionResult<ServiceResponse<GetSongDto>>> UpdateSong(UpdateSongDto request) | ||
{ | ||
var response = await _songService.UpdateSong(request); | ||
|
||
if (response.Data == null) | ||
return StatusCode(StatusCodes.Status404NotFound, response); | ||
|
||
return StatusCode(StatusCodes.Status200OK, response); | ||
} | ||
|
||
/*[HttpDelete("{songId}")] | ||
public async Task<ActionResult<ServiceResponse<GetSongDto>>> DeleteSong(int songId) | ||
{ | ||
/*var response = await _songService; | ||
if (response.Data == null) | ||
return StatusCode(StatusCodes.Status404NotFound, response); | ||
return StatusCode(StatusCodes.Status200OK, response); | ||
}*/ | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
namespace MusicService.Dtos.Song | ||
{ | ||
public class AddSongDto | ||
{ | ||
public string Name { get; set; } = string.Empty; | ||
public string Description { get; set; } = string.Empty; | ||
public string Adress { get; set; } = string.Empty; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
namespace MusicService.Dtos.Song | ||
{ | ||
public class GetSongDto | ||
{ | ||
public int Id { get; set; } = 0; | ||
public string Name { get; set; } = string.Empty; | ||
public string Description { get; set; } = string.Empty; | ||
public string Adress { get; set; } = string.Empty; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
namespace MusicService.Dtos.Song | ||
{ | ||
public class UpdateSongDto | ||
{ | ||
public int Id { get; set; } = 0; | ||
public string Name { get; set; } = string.Empty; | ||
public string Description { get; set; } = string.Empty; | ||
public string Adress { get; set; } = string.Empty; | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
MusicService/Migrations/20240418225548_Initialcreate.Designer.cs
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
using Microsoft.EntityFrameworkCore.Migrations; | ||
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; | ||
|
||
#nullable disable | ||
|
||
namespace MusicService.Migrations | ||
{ | ||
/// <inheritdoc /> | ||
public partial class Initialcreate : Migration | ||
{ | ||
/// <inheritdoc /> | ||
protected override void Up(MigrationBuilder migrationBuilder) | ||
{ | ||
migrationBuilder.CreateTable( | ||
name: "song", | ||
columns: table => new | ||
{ | ||
Id = table.Column<int>(type: "integer", nullable: false) | ||
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), | ||
Name = table.Column<string>(type: "text", nullable: false), | ||
Description = table.Column<string>(type: "text", nullable: false), | ||
Adress = table.Column<string>(type: "text", nullable: false) | ||
}, | ||
constraints: table => | ||
{ | ||
table.PrimaryKey("PK_song", x => x.Id); | ||
}); | ||
} | ||
|
||
/// <inheritdoc /> | ||
protected override void Down(MigrationBuilder migrationBuilder) | ||
{ | ||
migrationBuilder.DropTable( | ||
name: "song"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// <auto-generated /> | ||
using Microsoft.EntityFrameworkCore; | ||
using Microsoft.EntityFrameworkCore.Infrastructure; | ||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion; | ||
using MusicService.Data; | ||
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; | ||
|
||
#nullable disable | ||
|
||
namespace MusicService.Migrations | ||
{ | ||
[DbContext(typeof(DataContext))] | ||
partial class DataContextModelSnapshot : ModelSnapshot | ||
{ | ||
protected override void BuildModel(ModelBuilder modelBuilder) | ||
{ | ||
#pragma warning disable 612, 618 | ||
modelBuilder | ||
.HasAnnotation("ProductVersion", "7.0.11") | ||
.HasAnnotation("Relational:MaxIdentifierLength", 63); | ||
|
||
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); | ||
|
||
modelBuilder.Entity("MusicService.Models.Song", b => | ||
{ | ||
b.Property<int>("Id") | ||
.ValueGeneratedOnAdd() | ||
.HasColumnType("integer"); | ||
|
||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id")); | ||
|
||
b.Property<string>("Adress") | ||
.IsRequired() | ||
.HasColumnType("text"); | ||
|
||
b.Property<string>("Description") | ||
.IsRequired() | ||
.HasColumnType("text"); | ||
|
||
b.Property<string>("Name") | ||
.IsRequired() | ||
.HasColumnType("text"); | ||
|
||
b.HasKey("Id"); | ||
|
||
b.ToTable("song"); | ||
}); | ||
#pragma warning restore 612, 618 | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
using System.ComponentModel.DataAnnotations; | ||
|
||
namespace MusicService.Models | ||
{ | ||
public class Song | ||
{ | ||
[Key] | ||
public int Id { get; set; } | ||
[Required] | ||
public string Name { get; set; } = string.Empty; | ||
[Required] | ||
public string Description { get; set; } = string.Empty; | ||
[Required] | ||
public string Adress { get; set; } = string.Empty; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.