From 9fd63759620b6fdd4a745a91d6c16491e7ef9071 Mon Sep 17 00:00:00 2001 From: PC_KYJ Date: Sun, 31 Dec 2023 12:37:09 +0900 Subject: [PATCH 01/12] =?UTF-8?q?Rename,=20Remove:=20DB=20User=20=EA=B5=AC?= =?UTF-8?q?=EC=A1=B0=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- EveryPinApi.Entites/Models/User.cs | 2 -- EveryPinApi/EveryPinApi.csproj | 4 ++++ ...180933_CreatingIdentityTables.Designer.cs} | 24 +++++++++---------- ... 20231230180933_CreatingIdentityTables.cs} | 14 +++++------ .../RepositoryContextModelSnapshot.cs | 20 ++++++++-------- Repository/Configuration/UserConfiguration.cs | 2 -- 6 files changed, 33 insertions(+), 33 deletions(-) rename EveryPinApi/Migrations/{20231219145404_Initial.Designer.cs => 20231230180933_CreatingIdentityTables.Designer.cs} (95%) rename EveryPinApi/Migrations/{20231219145404_Initial.cs => 20231230180933_CreatingIdentityTables.cs} (94%) diff --git a/EveryPinApi.Entites/Models/User.cs b/EveryPinApi.Entites/Models/User.cs index 685b3d7..07a67d9 100644 --- a/EveryPinApi.Entites/Models/User.cs +++ b/EveryPinApi.Entites/Models/User.cs @@ -10,8 +10,6 @@ namespace Entites.Models { public class User : IdentityUser { - [Column("UserId")] - public Guid Id { get; set; } public string? GoogleId { get; set; } public string? GoogleName { get; set; } public string? GoogleEmail { get; set; } diff --git a/EveryPinApi/EveryPinApi.csproj b/EveryPinApi/EveryPinApi.csproj index e20868a..96a4c1c 100644 --- a/EveryPinApi/EveryPinApi.csproj +++ b/EveryPinApi/EveryPinApi.csproj @@ -29,4 +29,8 @@ + + + + diff --git a/EveryPinApi/Migrations/20231219145404_Initial.Designer.cs b/EveryPinApi/Migrations/20231230180933_CreatingIdentityTables.Designer.cs similarity index 95% rename from EveryPinApi/Migrations/20231219145404_Initial.Designer.cs rename to EveryPinApi/Migrations/20231230180933_CreatingIdentityTables.Designer.cs index c18dfa3..4ecb35e 100644 --- a/EveryPinApi/Migrations/20231219145404_Initial.Designer.cs +++ b/EveryPinApi/Migrations/20231230180933_CreatingIdentityTables.Designer.cs @@ -12,8 +12,8 @@ namespace EveryPinApi.Migrations { [DbContext(typeof(RepositoryContext))] - [Migration("20231219145404_Initial")] - partial class Initial + [Migration("20231230180933_CreatingIdentityTables")] + partial class CreatingIdentityTables { /// protected override void BuildTargetModel(ModelBuilder modelBuilder) @@ -145,7 +145,7 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) new { Id = new Guid("a13ffaa2-c689-4d24-8f65-12df4b9d724c"), - CreatedDate = new DateTime(2023, 12, 19, 23, 54, 4, 144, DateTimeKind.Local).AddTicks(4513), + CreatedDate = new DateTime(2023, 12, 31, 3, 9, 33, 266, DateTimeKind.Local).AddTicks(4220), Name = "홍홍홍", SelfIntroduction = "안녕하세요, 홍길동입니다.", UserId = new Guid("b85489c1-2b74-4db9-89f0-234f926f5ea0") @@ -153,7 +153,7 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) new { Id = new Guid("8b23a1d6-860a-4ff2-becd-d7c8a8c238a5"), - CreatedDate = new DateTime(2023, 12, 19, 23, 54, 4, 144, DateTimeKind.Local).AddTicks(4516), + CreatedDate = new DateTime(2023, 12, 31, 3, 9, 33, 266, DateTimeKind.Local).AddTicks(4224), Name = "Yi Sun-sin", SelfIntroduction = "명량해전의 이순신 입니다.", UserId = new Guid("f3d72088-6d16-4b5b-9689-11d1f93bb212") @@ -248,9 +248,9 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.HasData( new { - Id = "b7c0b1ba-6010-4d1e-99ad-4a31fcbb7464", + Id = "147f50b6-46bd-467e-811f-fa01ae984912", AccessFailedCount = 0, - ConcurrencyStamp = "293c6be9-ccfe-4513-840c-412f87028b3b", + ConcurrencyStamp = "2aa333c4-54f1-4781-809f-d3d15e45e6b0", EmailConfirmed = false, GoogleEmail = "test01@gmail.com", GoogleId = "test01", @@ -258,14 +258,14 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) LockoutEnabled = false, PhoneNumberConfirmed = false, ProfileId = new Guid("a13ffaa2-c689-4d24-8f65-12df4b9d724c"), - SecurityStamp = "0e64e058-b989-4af3-bd4e-d245190154a6", + SecurityStamp = "bdb064ce-a3a8-48a3-a021-b54ede8ea958", TwoFactorEnabled = false }, new { - Id = "f76de4d7-d101-438b-ac8a-e1fdec16dac6", + Id = "539fb06a-f3fe-493c-98b6-4d64e6cd6d58", AccessFailedCount = 0, - ConcurrencyStamp = "241949cc-d28b-4dd0-b268-25c0d8b5be5f", + ConcurrencyStamp = "70b71192-b1ee-401f-b9a7-573342152bb5", EmailConfirmed = false, KakaoEmail = "test02@naver.com", KakaoId = "test02", @@ -273,7 +273,7 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) LockoutEnabled = false, PhoneNumberConfirmed = false, ProfileId = new Guid("8b23a1d6-860a-4ff2-becd-d7c8a8c238a5"), - SecurityStamp = "afbc37d2-c30c-4137-b70e-621f5be3696b", + SecurityStamp = "fb615259-86f6-4c74-9ea4-8ea7cdbf87b2", TwoFactorEnabled = false }); }); @@ -307,13 +307,13 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.HasData( new { - Id = "7d6ecc8f-648e-4cd1-809e-26048b9b4106", + Id = "55d45176-c0bc-4a53-beb1-bc386aff26a8", Name = "Manager", NormalizedName = "MANAGER" }, new { - Id = "8d32e547-254a-4c18-a466-20bb91c54fef", + Id = "8ce698c2-09f8-4f94-a04b-247c04582e04", Name = "Administrator", NormalizedName = "ADMINISTRATOR" }); diff --git a/EveryPinApi/Migrations/20231219145404_Initial.cs b/EveryPinApi/Migrations/20231230180933_CreatingIdentityTables.cs similarity index 94% rename from EveryPinApi/Migrations/20231219145404_Initial.cs rename to EveryPinApi/Migrations/20231230180933_CreatingIdentityTables.cs index acadea8..91299d1 100644 --- a/EveryPinApi/Migrations/20231219145404_Initial.cs +++ b/EveryPinApi/Migrations/20231230180933_CreatingIdentityTables.cs @@ -8,7 +8,7 @@ namespace EveryPinApi.Migrations { /// - public partial class Initial : Migration + public partial class CreatingIdentityTables : Migration { /// protected override void Up(MigrationBuilder migrationBuilder) @@ -257,8 +257,8 @@ protected override void Up(MigrationBuilder migrationBuilder) columns: new[] { "Id", "ConcurrencyStamp", "Name", "NormalizedName" }, values: new object[,] { - { "7d6ecc8f-648e-4cd1-809e-26048b9b4106", null, "Manager", "MANAGER" }, - { "8d32e547-254a-4c18-a466-20bb91c54fef", null, "Administrator", "ADMINISTRATOR" } + { "55d45176-c0bc-4a53-beb1-bc386aff26a8", null, "Manager", "MANAGER" }, + { "8ce698c2-09f8-4f94-a04b-247c04582e04", null, "Administrator", "ADMINISTRATOR" } }); migrationBuilder.InsertData( @@ -266,8 +266,8 @@ protected override void Up(MigrationBuilder migrationBuilder) columns: new[] { "Id", "AccessFailedCount", "ConcurrencyStamp", "Email", "EmailConfirmed", "GoogleEmail", "GoogleId", "GoogleName", "KakaoEmail", "KakaoId", "KakaoName", "LockoutEnabled", "LockoutEnd", "NormalizedEmail", "NormalizedUserName", "PasswordHash", "PhoneNumber", "PhoneNumberConfirmed", "ProfileId", "SecurityStamp", "TwoFactorEnabled", "UserName" }, values: new object[,] { - { "b7c0b1ba-6010-4d1e-99ad-4a31fcbb7464", 0, "293c6be9-ccfe-4513-840c-412f87028b3b", null, false, "test01@gmail.com", "test01", "홍길동", null, null, null, false, null, null, null, null, null, false, new Guid("a13ffaa2-c689-4d24-8f65-12df4b9d724c"), "0e64e058-b989-4af3-bd4e-d245190154a6", false, null }, - { "f76de4d7-d101-438b-ac8a-e1fdec16dac6", 0, "241949cc-d28b-4dd0-b268-25c0d8b5be5f", null, false, null, null, null, "test02@naver.com", "test02", "이순신", false, null, null, null, null, null, false, new Guid("8b23a1d6-860a-4ff2-becd-d7c8a8c238a5"), "afbc37d2-c30c-4137-b70e-621f5be3696b", false, null } + { "147f50b6-46bd-467e-811f-fa01ae984912", 0, "2aa333c4-54f1-4781-809f-d3d15e45e6b0", null, false, "test01@gmail.com", "test01", "홍길동", null, null, null, false, null, null, null, null, null, false, new Guid("a13ffaa2-c689-4d24-8f65-12df4b9d724c"), "bdb064ce-a3a8-48a3-a021-b54ede8ea958", false, null }, + { "539fb06a-f3fe-493c-98b6-4d64e6cd6d58", 0, "70b71192-b1ee-401f-b9a7-573342152bb5", null, false, null, null, null, "test02@naver.com", "test02", "이순신", false, null, null, null, null, null, false, new Guid("8b23a1d6-860a-4ff2-becd-d7c8a8c238a5"), "fb615259-86f6-4c74-9ea4-8ea7cdbf87b2", false, null } }); migrationBuilder.InsertData( @@ -275,8 +275,8 @@ protected override void Up(MigrationBuilder migrationBuilder) columns: new[] { "ProfileId", "CreatedDate", "Name", "PhotoUrl", "SelfIntroduction", "UpdatedDate", "UserId" }, values: new object[,] { - { new Guid("8b23a1d6-860a-4ff2-becd-d7c8a8c238a5"), new DateTime(2023, 12, 19, 23, 54, 4, 144, DateTimeKind.Local).AddTicks(4516), "Yi Sun-sin", null, "명량해전의 이순신 입니다.", null, new Guid("f3d72088-6d16-4b5b-9689-11d1f93bb212") }, - { new Guid("a13ffaa2-c689-4d24-8f65-12df4b9d724c"), new DateTime(2023, 12, 19, 23, 54, 4, 144, DateTimeKind.Local).AddTicks(4513), "홍홍홍", null, "안녕하세요, 홍길동입니다.", null, new Guid("b85489c1-2b74-4db9-89f0-234f926f5ea0") } + { new Guid("8b23a1d6-860a-4ff2-becd-d7c8a8c238a5"), new DateTime(2023, 12, 31, 3, 9, 33, 266, DateTimeKind.Local).AddTicks(4224), "Yi Sun-sin", null, "명량해전의 이순신 입니다.", null, new Guid("f3d72088-6d16-4b5b-9689-11d1f93bb212") }, + { new Guid("a13ffaa2-c689-4d24-8f65-12df4b9d724c"), new DateTime(2023, 12, 31, 3, 9, 33, 266, DateTimeKind.Local).AddTicks(4220), "홍홍홍", null, "안녕하세요, 홍길동입니다.", null, new Guid("b85489c1-2b74-4db9-89f0-234f926f5ea0") } }); migrationBuilder.CreateIndex( diff --git a/EveryPinApi/Migrations/RepositoryContextModelSnapshot.cs b/EveryPinApi/Migrations/RepositoryContextModelSnapshot.cs index 4556667..ab51b70 100644 --- a/EveryPinApi/Migrations/RepositoryContextModelSnapshot.cs +++ b/EveryPinApi/Migrations/RepositoryContextModelSnapshot.cs @@ -142,7 +142,7 @@ protected override void BuildModel(ModelBuilder modelBuilder) new { Id = new Guid("a13ffaa2-c689-4d24-8f65-12df4b9d724c"), - CreatedDate = new DateTime(2023, 12, 19, 23, 54, 4, 144, DateTimeKind.Local).AddTicks(4513), + CreatedDate = new DateTime(2023, 12, 31, 3, 9, 33, 266, DateTimeKind.Local).AddTicks(4220), Name = "홍홍홍", SelfIntroduction = "안녕하세요, 홍길동입니다.", UserId = new Guid("b85489c1-2b74-4db9-89f0-234f926f5ea0") @@ -150,7 +150,7 @@ protected override void BuildModel(ModelBuilder modelBuilder) new { Id = new Guid("8b23a1d6-860a-4ff2-becd-d7c8a8c238a5"), - CreatedDate = new DateTime(2023, 12, 19, 23, 54, 4, 144, DateTimeKind.Local).AddTicks(4516), + CreatedDate = new DateTime(2023, 12, 31, 3, 9, 33, 266, DateTimeKind.Local).AddTicks(4224), Name = "Yi Sun-sin", SelfIntroduction = "명량해전의 이순신 입니다.", UserId = new Guid("f3d72088-6d16-4b5b-9689-11d1f93bb212") @@ -245,9 +245,9 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.HasData( new { - Id = "b7c0b1ba-6010-4d1e-99ad-4a31fcbb7464", + Id = "147f50b6-46bd-467e-811f-fa01ae984912", AccessFailedCount = 0, - ConcurrencyStamp = "293c6be9-ccfe-4513-840c-412f87028b3b", + ConcurrencyStamp = "2aa333c4-54f1-4781-809f-d3d15e45e6b0", EmailConfirmed = false, GoogleEmail = "test01@gmail.com", GoogleId = "test01", @@ -255,14 +255,14 @@ protected override void BuildModel(ModelBuilder modelBuilder) LockoutEnabled = false, PhoneNumberConfirmed = false, ProfileId = new Guid("a13ffaa2-c689-4d24-8f65-12df4b9d724c"), - SecurityStamp = "0e64e058-b989-4af3-bd4e-d245190154a6", + SecurityStamp = "bdb064ce-a3a8-48a3-a021-b54ede8ea958", TwoFactorEnabled = false }, new { - Id = "f76de4d7-d101-438b-ac8a-e1fdec16dac6", + Id = "539fb06a-f3fe-493c-98b6-4d64e6cd6d58", AccessFailedCount = 0, - ConcurrencyStamp = "241949cc-d28b-4dd0-b268-25c0d8b5be5f", + ConcurrencyStamp = "70b71192-b1ee-401f-b9a7-573342152bb5", EmailConfirmed = false, KakaoEmail = "test02@naver.com", KakaoId = "test02", @@ -270,7 +270,7 @@ protected override void BuildModel(ModelBuilder modelBuilder) LockoutEnabled = false, PhoneNumberConfirmed = false, ProfileId = new Guid("8b23a1d6-860a-4ff2-becd-d7c8a8c238a5"), - SecurityStamp = "afbc37d2-c30c-4137-b70e-621f5be3696b", + SecurityStamp = "fb615259-86f6-4c74-9ea4-8ea7cdbf87b2", TwoFactorEnabled = false }); }); @@ -304,13 +304,13 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.HasData( new { - Id = "7d6ecc8f-648e-4cd1-809e-26048b9b4106", + Id = "55d45176-c0bc-4a53-beb1-bc386aff26a8", Name = "Manager", NormalizedName = "MANAGER" }, new { - Id = "8d32e547-254a-4c18-a466-20bb91c54fef", + Id = "8ce698c2-09f8-4f94-a04b-247c04582e04", Name = "Administrator", NormalizedName = "ADMINISTRATOR" }); diff --git a/Repository/Configuration/UserConfiguration.cs b/Repository/Configuration/UserConfiguration.cs index 8103842..555a0eb 100644 --- a/Repository/Configuration/UserConfiguration.cs +++ b/Repository/Configuration/UserConfiguration.cs @@ -16,7 +16,6 @@ public void Configure(EntityTypeBuilder builder) builder.HasData( new User { - Id = new Guid("b85489c1-2b74-4db9-89f0-234f926f5ea0"), GoogleId = "test01", GoogleName = "홍길동", GoogleEmail = "test01@gmail.com", @@ -27,7 +26,6 @@ public void Configure(EntityTypeBuilder builder) }, new User { - Id = new Guid("f3d72088-6d16-4b5b-9689-11d1f93bb212"), GoogleId = null, GoogleName = null, GoogleEmail = null, From 5de6a26ba0a71399e671544754a1e50742594555 Mon Sep 17 00:00:00 2001 From: KYJ_Laptop Date: Mon, 1 Jan 2024 16:13:20 +0900 Subject: [PATCH 02/12] =?UTF-8?q?Feat:=20Dto=20=ED=8F=B4=EB=8D=94=20?= =?UTF-8?q?=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Shared/DataTransferObject/CommentDto.cs | 16 ++++++++++++++++ Shared/DataTransferObject/LikeDto.cs | 13 +++++++++++++ Shared/DataTransferObject/PostDto.cs | 12 ++++++++++++ Shared/DataTransferObject/PostPhotoDto.cs | 12 ++++++++++++ Shared/DataTransferObject/ProfileDto.cs | 12 ++++++++++++ Shared/Shared.csproj | 13 +++++++++++++ 6 files changed, 78 insertions(+) create mode 100644 Shared/DataTransferObject/CommentDto.cs create mode 100644 Shared/DataTransferObject/LikeDto.cs create mode 100644 Shared/DataTransferObject/PostDto.cs create mode 100644 Shared/DataTransferObject/PostPhotoDto.cs create mode 100644 Shared/DataTransferObject/ProfileDto.cs create mode 100644 Shared/Shared.csproj diff --git a/Shared/DataTransferObject/CommentDto.cs b/Shared/DataTransferObject/CommentDto.cs new file mode 100644 index 0000000..9848963 --- /dev/null +++ b/Shared/DataTransferObject/CommentDto.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Shared.DataTransferObject +{ + public record CommentDto(Guid Id, Guid UserId, string? CommentMessage, DateTime? CreatedDate) + { + //public Guid Id { get; set; } + //public Guid UserId { get; set; } + //public string? CommentMessage { get; set; } + //public DateTime? CreatedDate { get; set; } + } +} diff --git a/Shared/DataTransferObject/LikeDto.cs b/Shared/DataTransferObject/LikeDto.cs new file mode 100644 index 0000000..5b58e01 --- /dev/null +++ b/Shared/DataTransferObject/LikeDto.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Shared.DataTransferObject +{ + public record LikeDto(Guid Id, Guid UserId, DateTime? CreatedDate) + { + + } +} diff --git a/Shared/DataTransferObject/PostDto.cs b/Shared/DataTransferObject/PostDto.cs new file mode 100644 index 0000000..d9670e7 --- /dev/null +++ b/Shared/DataTransferObject/PostDto.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Shared.DataTransferObject +{ + public record PostDto + { + } +} diff --git a/Shared/DataTransferObject/PostPhotoDto.cs b/Shared/DataTransferObject/PostPhotoDto.cs new file mode 100644 index 0000000..5bacb52 --- /dev/null +++ b/Shared/DataTransferObject/PostPhotoDto.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Shared.DataTransferObject +{ + public record PostPhotoDto + { + } +} diff --git a/Shared/DataTransferObject/ProfileDto.cs b/Shared/DataTransferObject/ProfileDto.cs new file mode 100644 index 0000000..8c57939 --- /dev/null +++ b/Shared/DataTransferObject/ProfileDto.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Shared.DataTransferObject +{ + public record ProfileDto + { + } +} diff --git a/Shared/Shared.csproj b/Shared/Shared.csproj new file mode 100644 index 0000000..3a314ed --- /dev/null +++ b/Shared/Shared.csproj @@ -0,0 +1,13 @@ + + + + net7.0 + enable + enable + + + + + + + From 4ee50021039daa4f97ad50d9fe51b7b83f044b6c Mon Sep 17 00:00:00 2001 From: KYJ_Laptop Date: Mon, 1 Jan 2024 16:40:42 +0900 Subject: [PATCH 03/12] =?UTF-8?q?Refactor:=20API=20DTO=EB=A1=9C=20?= =?UTF-8?q?=EB=B0=98=ED=99=98=ED=95=98=EB=8F=84=EB=A1=9D=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/UserController.cs | 32 ----------------- Service.Contracts/IServiceManager.cs | 2 +- Service.Contracts/Models/ICommentService.cs | 4 +-- Service.Contracts/Models/ILikeService.cs | 4 +-- Service.Contracts/Models/IPostPhotoService.cs | 4 +-- Service.Contracts/Models/IPostService.cs | 4 +-- Service.Contracts/Models/IProfileService.cs | 4 +-- Service.Contracts/Models/IUserService.cs | 14 -------- Service.Contracts/Service.Contracts.csproj | 4 +-- Service/Models/CommentService.cs | 10 +++--- Service/Models/LikeService.cs | 7 ++-- Service/Models/PostPhotoService.cs | 7 ++-- Service/Models/PostService.cs | 7 ++-- Service/Models/ProfileService.cs | 7 ++-- Service/Models/UserService.cs | 35 ------------------- Service/ServiceManager.cs | 6 ++-- Shared/DataTransferObject/CommentDto.cs | 8 +---- Shared/DataTransferObject/LikeDto.cs | 5 +-- Shared/DataTransferObject/PostDto.cs | 7 ++-- Shared/DataTransferObject/PostPhotoDto.cs | 4 +-- Shared/DataTransferObject/ProfileDto.cs | 4 +-- Shared/Shared.csproj | 4 +-- 22 files changed, 51 insertions(+), 132 deletions(-) delete mode 100644 EveryPinApi.Presentation/Controllers/UserController.cs delete mode 100644 Service.Contracts/Models/IUserService.cs delete mode 100644 Service/Models/UserService.cs diff --git a/EveryPinApi.Presentation/Controllers/UserController.cs b/EveryPinApi.Presentation/Controllers/UserController.cs deleted file mode 100644 index 5554dd2..0000000 --- a/EveryPinApi.Presentation/Controllers/UserController.cs +++ /dev/null @@ -1,32 +0,0 @@ -using Microsoft.AspNetCore.Mvc; -using Service.Contracts; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace EveryPinApi.Presentation.Controllers -{ - [Route("api/user")] - [ApiController] - public class UserController : ControllerBase - { - private readonly IServiceManager _service; - public UserController(IServiceManager service) => _service = service; - - [HttpGet] - public IActionResult GetAllLike() - { - try - { - var users = _service.UserService.GetAllUser(trackChanges: false); - return Ok(users); - } - catch - { - return StatusCode(500, "Internal server error"); - } - } - } -} diff --git a/Service.Contracts/IServiceManager.cs b/Service.Contracts/IServiceManager.cs index 6b04401..8513e87 100644 --- a/Service.Contracts/IServiceManager.cs +++ b/Service.Contracts/IServiceManager.cs @@ -14,7 +14,7 @@ public interface IServiceManager IPostPhotoService PostPhotoService { get; } IPostService PostService { get; } IProfileService ProfileService { get; } - IUserService UserService { get; } + //IUserService UserService { get; } } } diff --git a/Service.Contracts/Models/ICommentService.cs b/Service.Contracts/Models/ICommentService.cs index add905b..f4fdd1c 100644 --- a/Service.Contracts/Models/ICommentService.cs +++ b/Service.Contracts/Models/ICommentService.cs @@ -1,4 +1,4 @@ -using Entites.Models; +using Shared.DataTransferObject; using System; using System.Collections.Generic; using System.Linq; @@ -9,6 +9,6 @@ namespace Service.Contracts.Models { public interface ICommentService { - IEnumerable GetAllComment(bool trackChanges); + IEnumerable GetAllComment(bool trackChanges); } } diff --git a/Service.Contracts/Models/ILikeService.cs b/Service.Contracts/Models/ILikeService.cs index 0fe95b6..2a6c078 100644 --- a/Service.Contracts/Models/ILikeService.cs +++ b/Service.Contracts/Models/ILikeService.cs @@ -1,4 +1,4 @@ -using Entites.Models; +using Shared.DataTransferObject; using System; using System.Collections.Generic; using System.Linq; @@ -9,6 +9,6 @@ namespace Service.Contracts.Models { public interface ILikeService { - IEnumerable GetAllLike(bool trackChanges); + IEnumerable GetAllLike(bool trackChanges); } } diff --git a/Service.Contracts/Models/IPostPhotoService.cs b/Service.Contracts/Models/IPostPhotoService.cs index b135ca1..7a85fd8 100644 --- a/Service.Contracts/Models/IPostPhotoService.cs +++ b/Service.Contracts/Models/IPostPhotoService.cs @@ -1,4 +1,4 @@ -using Entites.Models; +using Shared.DataTransferObject; using System; using System.Collections.Generic; using System.Linq; @@ -9,6 +9,6 @@ namespace Service.Contracts.Models { public interface IPostPhotoService { - IEnumerable GetAllPostPhoto(bool trackChanges); + IEnumerable GetAllPostPhoto(bool trackChanges); } } diff --git a/Service.Contracts/Models/IPostService.cs b/Service.Contracts/Models/IPostService.cs index 43db093..3be5aef 100644 --- a/Service.Contracts/Models/IPostService.cs +++ b/Service.Contracts/Models/IPostService.cs @@ -1,4 +1,4 @@ -using Entites.Models; +using Shared.DataTransferObject; using System; using System.Collections.Generic; using System.Linq; @@ -9,6 +9,6 @@ namespace Service.Contracts.Models { public interface IPostService { - IEnumerable GetAllPost(bool trackChanges); + IEnumerable GetAllPost(bool trackChanges); } } diff --git a/Service.Contracts/Models/IProfileService.cs b/Service.Contracts/Models/IProfileService.cs index 8c1f199..c044370 100644 --- a/Service.Contracts/Models/IProfileService.cs +++ b/Service.Contracts/Models/IProfileService.cs @@ -1,4 +1,4 @@ -using Entites.Models; +using Shared.DataTransferObject; using System; using System.Collections.Generic; using System.Linq; @@ -9,6 +9,6 @@ namespace Service.Contracts.Models { public interface IProfileService { - IEnumerable GetAllProfile(bool trackChanges); + IEnumerable GetAllProfile(bool trackChanges); } } diff --git a/Service.Contracts/Models/IUserService.cs b/Service.Contracts/Models/IUserService.cs deleted file mode 100644 index c30d881..0000000 --- a/Service.Contracts/Models/IUserService.cs +++ /dev/null @@ -1,14 +0,0 @@ -using Entites.Models; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Service.Contracts.Models -{ - public interface IUserService - { - IEnumerable GetAllUser(bool trackChanges); - } -} diff --git a/Service.Contracts/Service.Contracts.csproj b/Service.Contracts/Service.Contracts.csproj index ab55243..987a2e9 100644 --- a/Service.Contracts/Service.Contracts.csproj +++ b/Service.Contracts/Service.Contracts.csproj @@ -1,4 +1,4 @@ - + net7.0 @@ -7,7 +7,7 @@ - + diff --git a/Service/Models/CommentService.cs b/Service/Models/CommentService.cs index 8461655..c9a539d 100644 --- a/Service/Models/CommentService.cs +++ b/Service/Models/CommentService.cs @@ -1,5 +1,5 @@ using Contracts.Repository; -using Entites.Models; +using Shared.DataTransferObject; using Service.Contracts.Models; using System; using System.Collections.Generic; @@ -21,12 +21,14 @@ public CommentService(IRepositoryManager repository) //_logger = logger; } - public IEnumerable GetAllComment(bool trackChanges) + public IEnumerable GetAllComment(bool trackChanges) { try { - var companies = _repository.Comment.GetAllComment(trackChanges); - return companies; + var comments = _repository.Comment.GetAllComment(trackChanges); + var commentsDto = comments.Select(c => new CommentDto(c.Id, c.UserId, c.CommentMessage, c.CreatedDate)).ToList(); + + return commentsDto; } catch (Exception ex) { diff --git a/Service/Models/LikeService.cs b/Service/Models/LikeService.cs index b6cd2d6..63f3267 100644 --- a/Service/Models/LikeService.cs +++ b/Service/Models/LikeService.cs @@ -1,5 +1,6 @@ using Contracts.Repository; using Entites.Models; +using Shared.DataTransferObject; using System; using System.Collections.Generic; using System.Linq; @@ -17,12 +18,14 @@ public LikeService(IRepositoryManager repository) _repository = repository; } - public IEnumerable GetAllLike(bool trackChanges) + public IEnumerable GetAllLike(bool trackChanges) { try { var likes = _repository.Like.GetAllLike(trackChanges); - return likes; + var likesDto = likes.Select(c => new LikeDto(c.Id, c.UserId, c.CreatedDate)).ToList(); + + return likesDto; } catch (Exception ex) { diff --git a/Service/Models/PostPhotoService.cs b/Service/Models/PostPhotoService.cs index fbca09f..17fe0f1 100644 --- a/Service/Models/PostPhotoService.cs +++ b/Service/Models/PostPhotoService.cs @@ -1,5 +1,6 @@ using Contracts.Repository; using Entites.Models; +using Shared.DataTransferObject; using System; using System.Collections.Generic; using System.Linq; @@ -17,12 +18,14 @@ public PostPhotoService(IRepositoryManager repository) _repository = repository; } - public IEnumerable GetAllPostPhoto(bool trackChanges) + public IEnumerable GetAllPostPhoto(bool trackChanges) { try { var postPhotos = _repository.PostPhoto.GetAllPostPhoto(trackChanges); - return postPhotos; + var postPhotosDto = postPhotos.Select(p => new PostPhotoDto(p.Id, p.photoUrl)).ToList(); + + return postPhotosDto; } catch (Exception ex) { diff --git a/Service/Models/PostService.cs b/Service/Models/PostService.cs index 1b3e46e..c0936f0 100644 --- a/Service/Models/PostService.cs +++ b/Service/Models/PostService.cs @@ -1,5 +1,6 @@ using Contracts.Repository; using Entites.Models; +using Shared.DataTransferObject; using System; using System.Collections.Generic; using System.Linq; @@ -17,12 +18,14 @@ public PostService(IRepositoryManager repository) _repository = repository; } - public IEnumerable GetAllPost(bool trackChanges) + public IEnumerable GetAllPost(bool trackChanges) { try { var posts = _repository.Post.GetAllPost(trackChanges); - return posts; + var postsDto = posts.Select(p => new PostDto(p.PostId, p.PostContent, p.PostPhotos, p.Likes, p.Comments, p.UpdateDate, p.CreatedDate)).ToList(); + + return postsDto; } catch (Exception ex) { diff --git a/Service/Models/ProfileService.cs b/Service/Models/ProfileService.cs index fb8388f..4509e74 100644 --- a/Service/Models/ProfileService.cs +++ b/Service/Models/ProfileService.cs @@ -1,5 +1,6 @@ using Contracts.Repository; using Entites.Models; +using Shared.DataTransferObject; using System; using System.Collections.Generic; using System.Linq; @@ -17,12 +18,14 @@ public ProfileService(IRepositoryManager repository) _repository = repository; } - public IEnumerable GetAllProfile(bool trackChanges) + public IEnumerable GetAllProfile(bool trackChanges) { try { var profiles = _repository.Profile.GetAllProfile(trackChanges); - return profiles; + var profilesDto = profiles.Select(p => new ProfileDto(p.Id, p.Name, p.SelfIntroduction, p.PhotoUrl, p.UserId, p.UpdatedDate, p.CreatedDate)); + + return profilesDto; } catch (Exception ex) { diff --git a/Service/Models/UserService.cs b/Service/Models/UserService.cs deleted file mode 100644 index 3e9c89f..0000000 --- a/Service/Models/UserService.cs +++ /dev/null @@ -1,35 +0,0 @@ -using Contracts.Repository; -using Entites.Models; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Service.Contracts.Models -{ - internal sealed class UserService : IUserService - { - private readonly IRepositoryManager _repository; - - public UserService(IRepositoryManager repository) - { - _repository = repository; - } - - public IEnumerable GetAllUser(bool trackChanges) - { - try - { - var users = _repository.User.GetAllUser(trackChanges); - return users; - } - catch (Exception ex) - { - //_logger.LogError($"Something went wrong in the { nameof(GetAllCompanies) } service method { ex }"); - - throw; - } - } - } -} diff --git a/Service/ServiceManager.cs b/Service/ServiceManager.cs index 4787a5e..5ab29e0 100644 --- a/Service/ServiceManager.cs +++ b/Service/ServiceManager.cs @@ -17,7 +17,7 @@ public sealed class ServiceManager : IServiceManager private readonly Lazy _postPhotoService; private readonly Lazy _postService; private readonly Lazy _profileService; - private readonly Lazy _userService; + //private readonly Lazy _userService; public ServiceManager(IRepositoryManager repositoryManager) { @@ -26,7 +26,7 @@ public ServiceManager(IRepositoryManager repositoryManager) _postPhotoService = new Lazy(() => new PostPhotoService(repositoryManager)); _postService = new Lazy(() => new PostService(repositoryManager)); _profileService = new Lazy(() => new ProfileService(repositoryManager)); - _userService = new Lazy(() => new UserService(repositoryManager)); + //_userService = new Lazy(() => new UserService(repositoryManager)); } public ICommentService CommentService => _commentService.Value; @@ -34,6 +34,6 @@ public ServiceManager(IRepositoryManager repositoryManager) public IPostPhotoService PostPhotoService => _postPhotoService.Value; public IPostService PostService => _postService.Value; public IProfileService ProfileService => _profileService.Value; - public IUserService UserService => _userService.Value; + //public IUserService UserService => _userService.Value; } } diff --git a/Shared/DataTransferObject/CommentDto.cs b/Shared/DataTransferObject/CommentDto.cs index 9848963..1284c71 100644 --- a/Shared/DataTransferObject/CommentDto.cs +++ b/Shared/DataTransferObject/CommentDto.cs @@ -6,11 +6,5 @@ namespace Shared.DataTransferObject { - public record CommentDto(Guid Id, Guid UserId, string? CommentMessage, DateTime? CreatedDate) - { - //public Guid Id { get; set; } - //public Guid UserId { get; set; } - //public string? CommentMessage { get; set; } - //public DateTime? CreatedDate { get; set; } - } + public record CommentDto(Guid Id, Guid UserId, string? CommentMessage, DateTime? CreatedDate); } diff --git a/Shared/DataTransferObject/LikeDto.cs b/Shared/DataTransferObject/LikeDto.cs index 5b58e01..c899a05 100644 --- a/Shared/DataTransferObject/LikeDto.cs +++ b/Shared/DataTransferObject/LikeDto.cs @@ -6,8 +6,5 @@ namespace Shared.DataTransferObject { - public record LikeDto(Guid Id, Guid UserId, DateTime? CreatedDate) - { - - } + public record LikeDto(Guid Id, Guid UserId, DateTime? CreatedDate); } diff --git a/Shared/DataTransferObject/PostDto.cs b/Shared/DataTransferObject/PostDto.cs index d9670e7..d3c62db 100644 --- a/Shared/DataTransferObject/PostDto.cs +++ b/Shared/DataTransferObject/PostDto.cs @@ -1,4 +1,5 @@ -using System; +using Entites.Models; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -6,7 +7,5 @@ namespace Shared.DataTransferObject { - public record PostDto - { - } + public record PostDto(Guid PostId, string? PostContent, ICollection PostPhotos, ICollection Likes, ICollection Comments, DateTime? UpdateDate, DateTime? CreatedDate); } diff --git a/Shared/DataTransferObject/PostPhotoDto.cs b/Shared/DataTransferObject/PostPhotoDto.cs index 5bacb52..97fecb1 100644 --- a/Shared/DataTransferObject/PostPhotoDto.cs +++ b/Shared/DataTransferObject/PostPhotoDto.cs @@ -6,7 +6,5 @@ namespace Shared.DataTransferObject { - public record PostPhotoDto - { - } + public record PostPhotoDto(Guid Id, string? photoUrl); } diff --git a/Shared/DataTransferObject/ProfileDto.cs b/Shared/DataTransferObject/ProfileDto.cs index 8c57939..ca5788e 100644 --- a/Shared/DataTransferObject/ProfileDto.cs +++ b/Shared/DataTransferObject/ProfileDto.cs @@ -6,7 +6,5 @@ namespace Shared.DataTransferObject { - public record ProfileDto - { - } + public record ProfileDto(Guid Id, string? Name, string? SelfIntroduction, string? PhotoUrl, Guid UserId, DateTime? UpdatedDate, DateTime? CreatedDate); } diff --git a/Shared/Shared.csproj b/Shared/Shared.csproj index 3a314ed..253d81e 100644 --- a/Shared/Shared.csproj +++ b/Shared/Shared.csproj @@ -1,4 +1,4 @@ - + net7.0 @@ -7,7 +7,7 @@ - + From b8023ae92a850704146f2985c0dd6a254e98d1b6 Mon Sep 17 00:00:00 2001 From: KYJ_Laptop Date: Mon, 1 Jan 2024 16:41:20 +0900 Subject: [PATCH 04/12] =?UTF-8?q?Fix:=20=EC=86=94=EB=A3=A8=EC=85=98=20?= =?UTF-8?q?=EC=B0=B8=EC=A1=B0=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- EveryPinApi.sln | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/EveryPinApi.sln b/EveryPinApi.sln index 595c808..4d64c40 100644 --- a/EveryPinApi.sln +++ b/EveryPinApi.sln @@ -15,7 +15,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Service.Contracts", "Servic EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Service", "Service\Service.csproj", "{767347CD-A22E-4F08-973E-949BA54E4E2E}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EveryPinApi.Presentation", "EveryPinApi.Presentation\EveryPinApi.Presentation.csproj", "{D42FD03D-81F5-4E10-BF6F-69CF3C5383DE}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EveryPinApi.Presentation", "EveryPinApi.Presentation\EveryPinApi.Presentation.csproj", "{D42FD03D-81F5-4E10-BF6F-69CF3C5383DE}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Shared", "Shared\Shared.csproj", "{DA7C6E93-07A1-4EDB-8744-3B17233BFA68}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -51,6 +53,10 @@ Global {D42FD03D-81F5-4E10-BF6F-69CF3C5383DE}.Debug|Any CPU.Build.0 = Debug|Any CPU {D42FD03D-81F5-4E10-BF6F-69CF3C5383DE}.Release|Any CPU.ActiveCfg = Release|Any CPU {D42FD03D-81F5-4E10-BF6F-69CF3C5383DE}.Release|Any CPU.Build.0 = Release|Any CPU + {DA7C6E93-07A1-4EDB-8744-3B17233BFA68}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {DA7C6E93-07A1-4EDB-8744-3B17233BFA68}.Debug|Any CPU.Build.0 = Debug|Any CPU + {DA7C6E93-07A1-4EDB-8744-3B17233BFA68}.Release|Any CPU.ActiveCfg = Release|Any CPU + {DA7C6E93-07A1-4EDB-8744-3B17233BFA68}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE From 83e6e8b4ef2370dec83f62539bb3c9c11c481876 Mon Sep 17 00:00:00 2001 From: KYJ_Laptop Date: Mon, 1 Jan 2024 17:32:12 +0900 Subject: [PATCH 05/12] =?UTF-8?q?Feat:=20AutoMapper=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- EveryPinApi/MappingProfile.cs | 22 ++++++++++++++++++++++ EveryPinApi/Program.cs | 8 +++++++- Service/Models/CommentService.cs | 8 ++++++-- Service/Models/LikeService.cs | 11 ++++++++--- Service/Models/PostPhotoService.cs | 13 +++++++++---- Service/Models/PostService.cs | 13 +++++++++---- Service/Models/ProfileService.cs | 13 +++++++++---- Service/Service.csproj | 4 ++++ Service/ServiceManager.cs | 15 ++++++++------- 9 files changed, 82 insertions(+), 25 deletions(-) create mode 100644 EveryPinApi/MappingProfile.cs diff --git a/EveryPinApi/MappingProfile.cs b/EveryPinApi/MappingProfile.cs new file mode 100644 index 0000000..ad07173 --- /dev/null +++ b/EveryPinApi/MappingProfile.cs @@ -0,0 +1,22 @@ +using AutoMapper; +using Entites.Models; +using Shared.DataTransferObject; +using static Microsoft.EntityFrameworkCore.DbLoggerCategory.Database; + +namespace EveryPinApi +{ + public class MappingProfile : AutoMapper.Profile + { + public MappingProfile() + { + CreateMap(); + CreateMap(); + CreateMap() + .ForMember(dest => dest.PostPhotos, opt => opt.MapFrom(m => m.PostPhotos)) + .ForMember(dest => dest.Likes, opt => opt.MapFrom(m => m.Likes)) + .ForMember(dest => dest.Comments, opt => opt.MapFrom(m => m.Comments)); + CreateMap(); + CreateMap(); + } + } +} diff --git a/EveryPinApi/Program.cs b/EveryPinApi/Program.cs index 8586189..a388d5a 100644 --- a/EveryPinApi/Program.cs +++ b/EveryPinApi/Program.cs @@ -1,16 +1,17 @@ using EveryPinApi.Extensions; +using Service; using Microsoft.AspNetCore.HttpOverrides; var builder = WebApplication.CreateBuilder(args); // Add services to the container. - builder.Services.ConfigureCors(); // CORS builder.Services.ConfigureRepositoryManager(); // RepositoryManager ߰ builder.Services.ConfigureServiceManager(); // ServiceManager ߰ builder.Services.ConfigureSqlContext(builder.Configuration); +// Presentation Layer ControllerBase ϵ builder.Services.AddControllers() .AddApplicationPart(typeof(EveryPinApi.Presentation.AssemblyReference).Assembly); @@ -22,10 +23,15 @@ builder.Services.ConfigureLoggerFile(); builder.Services.ConfigureLoggerBlob(); builder.Logging.AddAzureWebAppDiagnostics(); + // Auth builder.Services.AddAuthentication(); builder.Services.ConfigureIdentity(); +// AutoMapper +builder.Services.AddAutoMapper(typeof(Program)); + + var app = builder.Build(); diff --git a/Service/Models/CommentService.cs b/Service/Models/CommentService.cs index c9a539d..7380a3c 100644 --- a/Service/Models/CommentService.cs +++ b/Service/Models/CommentService.cs @@ -7,6 +7,7 @@ using System.Text; using System.Threading.Tasks; using static Microsoft.EntityFrameworkCore.DbLoggerCategory.Database; +using AutoMapper; namespace Service.Models { @@ -14,11 +15,13 @@ internal sealed class CommentService : ICommentService { private readonly IRepositoryManager _repository; //private readonly ILoggerManager _logger; + private readonly IMapper _mapper; - public CommentService(IRepositoryManager repository) + public CommentService(IRepositoryManager repository, IMapper mapper) { _repository = repository; //_logger = logger; + _mapper = mapper; } public IEnumerable GetAllComment(bool trackChanges) @@ -26,7 +29,8 @@ public IEnumerable GetAllComment(bool trackChanges) try { var comments = _repository.Comment.GetAllComment(trackChanges); - var commentsDto = comments.Select(c => new CommentDto(c.Id, c.UserId, c.CommentMessage, c.CreatedDate)).ToList(); + //var commentsDto = comments.Select(c => new CommentDto(c.Id, c.UserId, c.CommentMessage, c.CreatedDate)).ToList(); + var commentsDto = _mapper.Map>(comments); return commentsDto; } diff --git a/Service/Models/LikeService.cs b/Service/Models/LikeService.cs index 63f3267..0a844b5 100644 --- a/Service/Models/LikeService.cs +++ b/Service/Models/LikeService.cs @@ -1,4 +1,5 @@ -using Contracts.Repository; +using AutoMapper; +using Contracts.Repository; using Entites.Models; using Shared.DataTransferObject; using System; @@ -6,16 +7,20 @@ using System.Linq; using System.Text; using System.Threading.Tasks; +using System.Xml.Linq; namespace Service.Contracts.Models { internal sealed class LikeService : ILikeService { private readonly IRepositoryManager _repository; + //private readonly ILoggerManager _logger; + private readonly IMapper _mapper; - public LikeService(IRepositoryManager repository) + public LikeService(IRepositoryManager repository, IMapper mapper) { _repository = repository; + _mapper = mapper; } public IEnumerable GetAllLike(bool trackChanges) @@ -23,7 +28,7 @@ public IEnumerable GetAllLike(bool trackChanges) try { var likes = _repository.Like.GetAllLike(trackChanges); - var likesDto = likes.Select(c => new LikeDto(c.Id, c.UserId, c.CreatedDate)).ToList(); + var likesDto = _mapper.Map>(likes); return likesDto; } diff --git a/Service/Models/PostPhotoService.cs b/Service/Models/PostPhotoService.cs index 17fe0f1..2b74048 100644 --- a/Service/Models/PostPhotoService.cs +++ b/Service/Models/PostPhotoService.cs @@ -1,4 +1,5 @@ -using Contracts.Repository; +using AutoMapper; +using Contracts.Repository; using Entites.Models; using Shared.DataTransferObject; using System; @@ -6,16 +7,20 @@ using System.Linq; using System.Text; using System.Threading.Tasks; +using System.Xml.Linq; namespace Service.Contracts.Models { internal sealed class PostPhotoService : IPostPhotoService { private readonly IRepositoryManager _repository; + //private readonly ILoggerManager _logger; + private readonly IMapper _mapper; - public PostPhotoService(IRepositoryManager repository) + public PostPhotoService(IRepositoryManager repository, IMapper mapper) { _repository = repository; + _mapper = mapper; } public IEnumerable GetAllPostPhoto(bool trackChanges) @@ -23,8 +28,8 @@ public IEnumerable GetAllPostPhoto(bool trackChanges) try { var postPhotos = _repository.PostPhoto.GetAllPostPhoto(trackChanges); - var postPhotosDto = postPhotos.Select(p => new PostPhotoDto(p.Id, p.photoUrl)).ToList(); - + var postPhotosDto = _mapper.Map>(postPhotos); + return postPhotosDto; } catch (Exception ex) diff --git a/Service/Models/PostService.cs b/Service/Models/PostService.cs index c0936f0..0795269 100644 --- a/Service/Models/PostService.cs +++ b/Service/Models/PostService.cs @@ -1,4 +1,5 @@ -using Contracts.Repository; +using AutoMapper; +using Contracts.Repository; using Entites.Models; using Shared.DataTransferObject; using System; @@ -6,16 +7,20 @@ using System.Linq; using System.Text; using System.Threading.Tasks; +using System.Xml.Linq; namespace Service.Contracts.Models { internal sealed class PostService : IPostService { private readonly IRepositoryManager _repository; + //private readonly ILoggerManager _logger; + private readonly IMapper _mapper; - public PostService(IRepositoryManager repository) + public PostService(IRepositoryManager repository, IMapper mapper) { _repository = repository; + _mapper = mapper; } public IEnumerable GetAllPost(bool trackChanges) @@ -23,8 +28,8 @@ public IEnumerable GetAllPost(bool trackChanges) try { var posts = _repository.Post.GetAllPost(trackChanges); - var postsDto = posts.Select(p => new PostDto(p.PostId, p.PostContent, p.PostPhotos, p.Likes, p.Comments, p.UpdateDate, p.CreatedDate)).ToList(); - + var postsDto = _mapper.Map>(posts); + return postsDto; } catch (Exception ex) diff --git a/Service/Models/ProfileService.cs b/Service/Models/ProfileService.cs index 4509e74..1a78ddb 100644 --- a/Service/Models/ProfileService.cs +++ b/Service/Models/ProfileService.cs @@ -1,4 +1,5 @@ -using Contracts.Repository; +using AutoMapper; +using Contracts.Repository; using Entites.Models; using Shared.DataTransferObject; using System; @@ -6,16 +7,20 @@ using System.Linq; using System.Text; using System.Threading.Tasks; +using System.Xml.Linq; namespace Service.Contracts.Models { internal sealed class ProfileService : IProfileService { private readonly IRepositoryManager _repository; + //private readonly ILoggerManager _logger; + private readonly IMapper _mapper; - public ProfileService(IRepositoryManager repository) + public ProfileService(IRepositoryManager repository, IMapper mapper) { _repository = repository; + _mapper = mapper; } public IEnumerable GetAllProfile(bool trackChanges) @@ -23,8 +28,8 @@ public IEnumerable GetAllProfile(bool trackChanges) try { var profiles = _repository.Profile.GetAllProfile(trackChanges); - var profilesDto = profiles.Select(p => new ProfileDto(p.Id, p.Name, p.SelfIntroduction, p.PhotoUrl, p.UserId, p.UpdatedDate, p.CreatedDate)); - + var profilesDto = _mapper.Map>(profiles); + return profilesDto; } catch (Exception ex) diff --git a/Service/Service.csproj b/Service/Service.csproj index 32d14cd..1bae81d 100644 --- a/Service/Service.csproj +++ b/Service/Service.csproj @@ -6,6 +6,10 @@ enable + + + + diff --git a/Service/ServiceManager.cs b/Service/ServiceManager.cs index 5ab29e0..75274fc 100644 --- a/Service/ServiceManager.cs +++ b/Service/ServiceManager.cs @@ -1,4 +1,5 @@ -using Contracts.Repository; +using AutoMapper; +using Contracts.Repository; using Service.Contracts; using Service.Contracts.Models; using Service.Models; @@ -19,13 +20,13 @@ public sealed class ServiceManager : IServiceManager private readonly Lazy _profileService; //private readonly Lazy _userService; - public ServiceManager(IRepositoryManager repositoryManager) + public ServiceManager(IRepositoryManager repositoryManager, IMapper mapper) { - _commentService = new Lazy(() => new CommentService(repositoryManager)); - _likeService = new Lazy(() => new LikeService(repositoryManager)); - _postPhotoService = new Lazy(() => new PostPhotoService(repositoryManager)); - _postService = new Lazy(() => new PostService(repositoryManager)); - _profileService = new Lazy(() => new ProfileService(repositoryManager)); + _commentService = new Lazy(() => new CommentService(repositoryManager, mapper)); + _likeService = new Lazy(() => new LikeService(repositoryManager, mapper)); + _postPhotoService = new Lazy(() => new PostPhotoService(repositoryManager, mapper)); + _postService = new Lazy(() => new PostService(repositoryManager, mapper)); + _profileService = new Lazy(() => new ProfileService(repositoryManager, mapper)); //_userService = new Lazy(() => new UserService(repositoryManager)); } From e11036c79b3a598a09a8c2b69859de36d40b5030 Mon Sep 17 00:00:00 2001 From: KYJ_Laptop Date: Tue, 9 Jan 2024 19:18:06 +0900 Subject: [PATCH 06/12] =?UTF-8?q?Refactor:=20IdentityUser=20=EC=82=AC?= =?UTF-8?q?=EC=9A=A9=20=EC=A0=84=EC=9C=BC=EB=A1=9C=20=EC=88=98=EC=A0=95=20?= =?UTF-8?q?=EB=B0=8F=20=EB=AA=A8=EB=8D=B8=20=EA=B4=80=EA=B3=84=20=EA=B0=9C?= =?UTF-8?q?=EC=84=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- EveryPinApi.Entites/Entites.csproj | 4 -- .../Models/CodeOAuthPlatform.cs | 18 ++++++++ EveryPinApi.Entites/Models/Comment.cs | 8 ++-- EveryPinApi.Entites/Models/Like.cs | 12 +++-- EveryPinApi.Entites/Models/Post.cs | 15 ++----- EveryPinApi.Entites/Models/PostPhoto.cs | 6 ++- EveryPinApi.Entites/Models/Profile.cs | 8 ++-- EveryPinApi.Entites/Models/User.cs | 19 ++++---- EveryPinApi/Extensions/ServiceExtensions.cs | 28 ++++++------ EveryPinApi/Program.cs | 2 +- .../Configuration/ProfileConfiguration.cs | 44 +++++++++---------- Repository/Configuration/RoleConfiguration.cs | 31 ------------- Repository/Configuration/UserConfiguration.cs | 44 +++++++++---------- Repository/RepositoryContext.cs | 9 ++-- Service/Models/CommentService.cs | 1 - 15 files changed, 118 insertions(+), 131 deletions(-) create mode 100644 EveryPinApi.Entites/Models/CodeOAuthPlatform.cs delete mode 100644 Repository/Configuration/RoleConfiguration.cs diff --git a/EveryPinApi.Entites/Entites.csproj b/EveryPinApi.Entites/Entites.csproj index 6a1fe12..cfadb03 100644 --- a/EveryPinApi.Entites/Entites.csproj +++ b/EveryPinApi.Entites/Entites.csproj @@ -6,8 +6,4 @@ enable - - - - diff --git a/EveryPinApi.Entites/Models/CodeOAuthPlatform.cs b/EveryPinApi.Entites/Models/CodeOAuthPlatform.cs new file mode 100644 index 0000000..7926eb2 --- /dev/null +++ b/EveryPinApi.Entites/Models/CodeOAuthPlatform.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Entites.Models +{ + public class CodeOAuthPlatform + { + [Column("CodeId")] + public int Id { get; set; } + [Required] + public string? PlatformName { get; set; } + } +} diff --git a/EveryPinApi.Entites/Models/Comment.cs b/EveryPinApi.Entites/Models/Comment.cs index a1c8040..0be9fb4 100644 --- a/EveryPinApi.Entites/Models/Comment.cs +++ b/EveryPinApi.Entites/Models/Comment.cs @@ -10,10 +10,12 @@ namespace Entites.Models public class Comment { [Column("CommentId")] - public Guid Id { get; set; } - [ForeignKey(nameof(User))] - public Guid UserId { get; set; } + public int Id { get; set; } public string? CommentMessage { get; set; } public DateTime? CreatedDate { get; set; } = DateTime.Now; + + [ForeignKey(nameof(User))] + public int UserId { get; set; } + public User User { get; set; } = null!; } } diff --git a/EveryPinApi.Entites/Models/Like.cs b/EveryPinApi.Entites/Models/Like.cs index 3a087ff..839517a 100644 --- a/EveryPinApi.Entites/Models/Like.cs +++ b/EveryPinApi.Entites/Models/Like.cs @@ -10,9 +10,15 @@ namespace Entites.Models public class Like { [Column("LikeId")] - public Guid Id { get; set; } - [ForeignKey(nameof(User))] - public Guid UserId { get; set; } + public int Id { get; set; } public DateTime? CreatedDate { get; set; } = DateTime.Now; + + [ForeignKey(nameof(Post))] + public int PostId { get; set; } + public Post Post { get; set; } = null!; + + [ForeignKey(nameof(User))] + public int UserId { get; set; } + public User User { get; set; } = null!; } } diff --git a/EveryPinApi.Entites/Models/Post.cs b/EveryPinApi.Entites/Models/Post.cs index 2879516..ecc7fa8 100644 --- a/EveryPinApi.Entites/Models/Post.cs +++ b/EveryPinApi.Entites/Models/Post.cs @@ -9,19 +9,12 @@ namespace Entites.Models { public class Post { - public Post() - { - this.PostPhotos = new HashSet(); - this.Likes = new HashSet(); - this.Comments = new HashSet(); - } - [Column("PostId")] - public Guid PostId { get; set; } + public int PostId { get; set; } public string? PostContent { get; set; } - public virtual ICollection PostPhotos { get; set; } - public virtual ICollection Likes { get; set; } - public virtual ICollection Comments { get; set; } + public ICollection PostPhotos { get; } = new List(); + public ICollection Likes { get; } = new List(); + public ICollection Comments { get; } = new List(); public DateTime? UpdateDate { get; set; } = null; public DateTime? CreatedDate { get; set; } = DateTime.Now; } diff --git a/EveryPinApi.Entites/Models/PostPhoto.cs b/EveryPinApi.Entites/Models/PostPhoto.cs index d61eff1..292e2d8 100644 --- a/EveryPinApi.Entites/Models/PostPhoto.cs +++ b/EveryPinApi.Entites/Models/PostPhoto.cs @@ -11,7 +11,11 @@ namespace Entites.Models public class PostPhoto { [Column("PostPhotoId")] - public Guid Id { get; set; } + public int Id { get; set; } public string? photoUrl; + + [ForeignKey(nameof(Post))] + public int PostId { get; set; } + public Post Post { get; set; } = null!; } } diff --git a/EveryPinApi.Entites/Models/Profile.cs b/EveryPinApi.Entites/Models/Profile.cs index e902480..88f1d17 100644 --- a/EveryPinApi.Entites/Models/Profile.cs +++ b/EveryPinApi.Entites/Models/Profile.cs @@ -10,13 +10,15 @@ namespace Entites.Models public class Profile { [Column("ProfileId")] - public Guid Id { get; set; } + public int Id { get; set; } public string? Name { get; set; } public string? SelfIntroduction { get; set; } public string? PhotoUrl { get; set; } - [ForeignKey(nameof(User))] - public Guid UserId { get; set; } public DateTime? UpdatedDate { get; set; } = null; public DateTime? CreatedDate { get; set; } = DateTime.Now; + + [ForeignKey(nameof(User))] + public int UserId { get; set; } + public User User { get; set; } = null!; } } diff --git a/EveryPinApi.Entites/Models/User.cs b/EveryPinApi.Entites/Models/User.cs index 07a67d9..a2a85e5 100644 --- a/EveryPinApi.Entites/Models/User.cs +++ b/EveryPinApi.Entites/Models/User.cs @@ -1,5 +1,4 @@ -using Microsoft.AspNetCore.Identity; -using System; +using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations.Schema; using System.Linq; @@ -8,15 +7,15 @@ namespace Entites.Models { - public class User : IdentityUser + public class User { - public string? GoogleId { get; set; } - public string? GoogleName { get; set; } - public string? GoogleEmail { get; set; } - public string? KakaoId { get; set; } - public string? KakaoName { get; set; } - public string? KakaoEmail { get; set; } + [Column("UserId")] + public int Id { get; set; } + public string? Name { get; set; } + public string? Email { get; set; } + [ForeignKey(nameof(Profile))] - public Guid ProfileId { get; set; } + public int ProfileId { get; set; } + public Profile Profile { get; set; } = null!; } } diff --git a/EveryPinApi/Extensions/ServiceExtensions.cs b/EveryPinApi/Extensions/ServiceExtensions.cs index b078417..67d2615 100644 --- a/EveryPinApi/Extensions/ServiceExtensions.cs +++ b/EveryPinApi/Extensions/ServiceExtensions.cs @@ -56,19 +56,19 @@ public static void ConfigureServiceManager(this IServiceCollection services) => public static void ConfigureSqlContext(this IServiceCollection services, IConfiguration configuration) => services.AddSqlServer(configuration.GetConnectionString("everypindb")); - public static void ConfigureIdentity(this IServiceCollection services) - { - var builder = services.AddIdentity(o => - { - o.Password.RequireDigit = true; - o.Password.RequireLowercase = false; - o.Password.RequireUppercase = false; - o.Password.RequireNonAlphanumeric = false; - o.Password.RequiredLength = 10; - o.User.RequireUniqueEmail = true; - }) - .AddEntityFrameworkStores() - .AddDefaultTokenProviders(); - } + //public static void ConfigureIdentity(this IServiceCollection services) + //{ + // var builder = services.AddIdentity(o => + // { + // o.Password.RequireDigit = true; + // o.Password.RequireLowercase = false; + // o.Password.RequireUppercase = false; + // o.Password.RequireNonAlphanumeric = false; + // o.Password.RequiredLength = 10; + // o.User.RequireUniqueEmail = true; + // }) + // .AddEntityFrameworkStores() + // .AddDefaultTokenProviders(); + //} } } diff --git a/EveryPinApi/Program.cs b/EveryPinApi/Program.cs index a388d5a..97b4faa 100644 --- a/EveryPinApi/Program.cs +++ b/EveryPinApi/Program.cs @@ -26,7 +26,7 @@ // Auth builder.Services.AddAuthentication(); -builder.Services.ConfigureIdentity(); +//builder.Services.ConfigureIdentity(); // AutoMapper builder.Services.AddAutoMapper(typeof(Program)); diff --git a/Repository/Configuration/ProfileConfiguration.cs b/Repository/Configuration/ProfileConfiguration.cs index 887c76d..24c4d98 100644 --- a/Repository/Configuration/ProfileConfiguration.cs +++ b/Repository/Configuration/ProfileConfiguration.cs @@ -13,28 +13,28 @@ public class ProfileConfiguration : IEntityTypeConfiguration { public void Configure(EntityTypeBuilder builder) { - builder.HasData( - new Profile - { - Id = new Guid("a13ffaa2-c689-4d24-8f65-12df4b9d724c"), - Name = "홍홍홍", - SelfIntroduction = "안녕하세요, 홍길동입니다.", - PhotoUrl = null, - UserId = new Guid("b85489c1-2b74-4db9-89f0-234f926f5ea0"), - UpdatedDate = null, - CreatedDate = DateTime.Now - }, - new Profile - { - Id = new Guid("8b23a1d6-860a-4ff2-becd-d7c8a8c238a5"), - Name = "Yi Sun-sin", - SelfIntroduction = "명량해전의 이순신 입니다.", - PhotoUrl = null, - UserId = new Guid("f3d72088-6d16-4b5b-9689-11d1f93bb212"), - UpdatedDate = null, - CreatedDate = DateTime.Now - } - ); + //builder.HasData( + // new Profile + // { + // Id = new Guid("a13ffaa2-c689-4d24-8f65-12df4b9d724c"), + // Name = "홍홍홍", + // SelfIntroduction = "안녕하세요, 홍길동입니다.", + // PhotoUrl = null, + // UserId = new Guid("b85489c1-2b74-4db9-89f0-234f926f5ea0"), + // UpdatedDate = null, + // CreatedDate = DateTime.Now + // }, + // new Profile + // { + // Id = new Guid("8b23a1d6-860a-4ff2-becd-d7c8a8c238a5"), + // Name = "Yi Sun-sin", + // SelfIntroduction = "명량해전의 이순신 입니다.", + // PhotoUrl = null, + // UserId = new Guid("f3d72088-6d16-4b5b-9689-11d1f93bb212"), + // UpdatedDate = null, + // CreatedDate = DateTime.Now + // } + //); } } } diff --git a/Repository/Configuration/RoleConfiguration.cs b/Repository/Configuration/RoleConfiguration.cs deleted file mode 100644 index fa9eba0..0000000 --- a/Repository/Configuration/RoleConfiguration.cs +++ /dev/null @@ -1,31 +0,0 @@ -using Microsoft.AspNetCore.Identity; -using Microsoft.EntityFrameworkCore.Metadata.Builders; -using Microsoft.EntityFrameworkCore; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Repository.Configuration -{ - public class RoleConfiguration : IEntityTypeConfiguration - { - public void Configure(EntityTypeBuilder builder) - { - builder.HasData( - new IdentityRole - { - Name = "Manager", - NormalizedName = "MANAGER" - }, - new IdentityRole - { - Name = "Administrator", - NormalizedName = "ADMINISTRATOR" - } - ); - } - } - -} diff --git a/Repository/Configuration/UserConfiguration.cs b/Repository/Configuration/UserConfiguration.cs index 555a0eb..3b5e685 100644 --- a/Repository/Configuration/UserConfiguration.cs +++ b/Repository/Configuration/UserConfiguration.cs @@ -13,28 +13,28 @@ public class UserConfiguration : IEntityTypeConfiguration { public void Configure(EntityTypeBuilder builder) { - builder.HasData( - new User - { - GoogleId = "test01", - GoogleName = "홍길동", - GoogleEmail = "test01@gmail.com", - KakaoId = null, - KakaoName = null, - KakaoEmail = null, - ProfileId = new Guid("a13ffaa2-c689-4d24-8f65-12df4b9d724c") - }, - new User - { - GoogleId = null, - GoogleName = null, - GoogleEmail = null, - KakaoId = "test02", - KakaoName = "이순신", - KakaoEmail = "test02@naver.com", - ProfileId = new Guid("8b23a1d6-860a-4ff2-becd-d7c8a8c238a5") - } - ); + //builder.HasData( + // new User + // { + // GoogleId = "test01", + // GoogleName = "홍길동", + // GoogleEmail = "test01@gmail.com", + // KakaoId = null, + // KakaoName = null, + // KakaoEmail = null, + // ProfileId = new Guid("a13ffaa2-c689-4d24-8f65-12df4b9d724c") + // }, + // new User + // { + // GoogleId = null, + // GoogleName = null, + // GoogleEmail = null, + // KakaoId = "test02", + // KakaoName = "이순신", + // KakaoEmail = "test02@naver.com", + // ProfileId = new Guid("8b23a1d6-860a-4ff2-becd-d7c8a8c238a5") + // } + //); } } } diff --git a/Repository/RepositoryContext.cs b/Repository/RepositoryContext.cs index 85defd8..d11a244 100644 --- a/Repository/RepositoryContext.cs +++ b/Repository/RepositoryContext.cs @@ -1,5 +1,4 @@ using Entites.Models; -using Microsoft.AspNetCore.Identity.EntityFrameworkCore; using Microsoft.EntityFrameworkCore; using Repository.Configuration; @@ -11,7 +10,7 @@ namespace Repository { - public class RepositoryContext : IdentityDbContext + public class RepositoryContext: DbContext { public RepositoryContext(DbContextOptions options): base(options) { @@ -22,9 +21,9 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) { base.OnModelCreating(modelBuilder); // 더미 데이터 생성 - modelBuilder.ApplyConfiguration(new UserConfiguration()); - modelBuilder.ApplyConfiguration(new ProfileConfiguration()); - modelBuilder.ApplyConfiguration(new RoleConfiguration()); + //modelBuilder.ApplyConfiguration(new UserConfiguration()); + //modelBuilder.ApplyConfiguration(new ProfileConfiguration()); + //modelBuilder.ApplyConfiguration(new RoleConfiguration()); } public DbSet? Users { get; set; } diff --git a/Service/Models/CommentService.cs b/Service/Models/CommentService.cs index 7380a3c..2a3b1ad 100644 --- a/Service/Models/CommentService.cs +++ b/Service/Models/CommentService.cs @@ -6,7 +6,6 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -using static Microsoft.EntityFrameworkCore.DbLoggerCategory.Database; using AutoMapper; namespace Service.Models From 6c46f3a3dc5337f660a774b8e9920ecd6d75195f Mon Sep 17 00:00:00 2001 From: KYJ_Laptop Date: Tue, 9 Jan 2024 21:17:37 +0900 Subject: [PATCH 07/12] =?UTF-8?q?Refactor:=20=EB=AA=A8=EB=8D=B8=20?= =?UTF-8?q?=EA=B4=80=EA=B3=84=20=EA=B0=9C=EC=84=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Models/CodeOAuthPlatform.cs | 2 +- EveryPinApi.Entites/Models/Comment.cs | 11 +- EveryPinApi.Entites/Models/Like.cs | 13 +- EveryPinApi.Entites/Models/PostPhoto.cs | 8 +- EveryPinApi.Entites/Models/Profile.cs | 7 +- EveryPinApi.Entites/Models/User.cs | 10 +- EveryPinApi/EveryPinApi.csproj | 1 + ...0180933_CreatingIdentityTables.Designer.cs | 511 ------------------ .../20231230180933_CreatingIdentityTables.cs | 377 ------------- .../20240109120726_edit-models.Designer.cs | 279 ++++++++++ .../Migrations/20240109120726_edit-models.cs | 210 +++++++ ...240109121241_add-PostPhoto-url.Designer.cs | 279 ++++++++++ .../20240109121241_add-PostPhoto-url.cs | 22 + .../RepositoryContextModelSnapshot.cs | 438 ++++----------- EveryPinApi/Program.cs | 1 - Repository/RepositoryContext.cs | 31 ++ 16 files changed, 953 insertions(+), 1247 deletions(-) delete mode 100644 EveryPinApi/Migrations/20231230180933_CreatingIdentityTables.Designer.cs delete mode 100644 EveryPinApi/Migrations/20231230180933_CreatingIdentityTables.cs create mode 100644 EveryPinApi/Migrations/20240109120726_edit-models.Designer.cs create mode 100644 EveryPinApi/Migrations/20240109120726_edit-models.cs create mode 100644 EveryPinApi/Migrations/20240109121241_add-PostPhoto-url.Designer.cs create mode 100644 EveryPinApi/Migrations/20240109121241_add-PostPhoto-url.cs diff --git a/EveryPinApi.Entites/Models/CodeOAuthPlatform.cs b/EveryPinApi.Entites/Models/CodeOAuthPlatform.cs index 7926eb2..cc939e9 100644 --- a/EveryPinApi.Entites/Models/CodeOAuthPlatform.cs +++ b/EveryPinApi.Entites/Models/CodeOAuthPlatform.cs @@ -10,7 +10,7 @@ namespace Entites.Models { public class CodeOAuthPlatform { - [Column("CodeId")] + [Column("PlatformCodeId")] public int Id { get; set; } [Required] public string? PlatformName { get; set; } diff --git a/EveryPinApi.Entites/Models/Comment.cs b/EveryPinApi.Entites/Models/Comment.cs index 0be9fb4..d34ff4b 100644 --- a/EveryPinApi.Entites/Models/Comment.cs +++ b/EveryPinApi.Entites/Models/Comment.cs @@ -11,11 +11,14 @@ public class Comment { [Column("CommentId")] public int Id { get; set; } + + public int? PostId { get; set; } + public Post? Post { get; set; } + + public int? UserId { get; set; } + public User? User { get; set; } + public string? CommentMessage { get; set; } public DateTime? CreatedDate { get; set; } = DateTime.Now; - - [ForeignKey(nameof(User))] - public int UserId { get; set; } - public User User { get; set; } = null!; } } diff --git a/EveryPinApi.Entites/Models/Like.cs b/EveryPinApi.Entites/Models/Like.cs index 839517a..a7c2641 100644 --- a/EveryPinApi.Entites/Models/Like.cs +++ b/EveryPinApi.Entites/Models/Like.cs @@ -11,14 +11,13 @@ public class Like { [Column("LikeId")] public int Id { get; set; } - public DateTime? CreatedDate { get; set; } = DateTime.Now; - [ForeignKey(nameof(Post))] - public int PostId { get; set; } - public Post Post { get; set; } = null!; + public int? PostId { get; set; } + public Post? Post { get; set; } - [ForeignKey(nameof(User))] - public int UserId { get; set; } - public User User { get; set; } = null!; + public int? UserId { get; set; } + public User? User { get; set; } + + public DateTime? CreatedDate { get; set; } = DateTime.Now; } } diff --git a/EveryPinApi.Entites/Models/PostPhoto.cs b/EveryPinApi.Entites/Models/PostPhoto.cs index 292e2d8..7c5998b 100644 --- a/EveryPinApi.Entites/Models/PostPhoto.cs +++ b/EveryPinApi.Entites/Models/PostPhoto.cs @@ -12,10 +12,10 @@ public class PostPhoto { [Column("PostPhotoId")] public int Id { get; set; } - public string? photoUrl; - [ForeignKey(nameof(Post))] - public int PostId { get; set; } - public Post Post { get; set; } = null!; + public int? PostId { get; set; } + public Post? Post { get; set; } + + public string? photoUrl { get; set; } } } diff --git a/EveryPinApi.Entites/Models/Profile.cs b/EveryPinApi.Entites/Models/Profile.cs index 88f1d17..300ba29 100644 --- a/EveryPinApi.Entites/Models/Profile.cs +++ b/EveryPinApi.Entites/Models/Profile.cs @@ -11,14 +11,15 @@ public class Profile { [Column("ProfileId")] public int Id { get; set; } + + public int? UserId { get; set; } + public User? User { get; set; } + public string? Name { get; set; } public string? SelfIntroduction { get; set; } public string? PhotoUrl { get; set; } public DateTime? UpdatedDate { get; set; } = null; public DateTime? CreatedDate { get; set; } = DateTime.Now; - [ForeignKey(nameof(User))] - public int UserId { get; set; } - public User User { get; set; } = null!; } } diff --git a/EveryPinApi.Entites/Models/User.cs b/EveryPinApi.Entites/Models/User.cs index a2a85e5..497a70c 100644 --- a/EveryPinApi.Entites/Models/User.cs +++ b/EveryPinApi.Entites/Models/User.cs @@ -11,11 +11,13 @@ public class User { [Column("UserId")] public int Id { get; set; } + public int PlatformCodeId { get; set; } + public Profile? Profile { get; set; } + public ICollection Like { get; set; } = new List(); public string? Name { get; set; } public string? Email { get; set; } - - [ForeignKey(nameof(Profile))] - public int ProfileId { get; set; } - public Profile Profile { get; set; } = null!; + public DateTime CreatedDate { get; set; } + public DateTime LastLoginDate { get; set; } + public bool DeleteCheck { get; set; } } } diff --git a/EveryPinApi/EveryPinApi.csproj b/EveryPinApi/EveryPinApi.csproj index 215766c..caa6dd8 100644 --- a/EveryPinApi/EveryPinApi.csproj +++ b/EveryPinApi/EveryPinApi.csproj @@ -4,6 +4,7 @@ net7.0 enable enable + 8f17b0ff-654c-4ca5-bac4-0c9f6c2f23cb diff --git a/EveryPinApi/Migrations/20231230180933_CreatingIdentityTables.Designer.cs b/EveryPinApi/Migrations/20231230180933_CreatingIdentityTables.Designer.cs deleted file mode 100644 index 4ecb35e..0000000 --- a/EveryPinApi/Migrations/20231230180933_CreatingIdentityTables.Designer.cs +++ /dev/null @@ -1,511 +0,0 @@ -// -using System; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Metadata; -using Microsoft.EntityFrameworkCore.Migrations; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; -using Repository; - -#nullable disable - -namespace EveryPinApi.Migrations -{ - [DbContext(typeof(RepositoryContext))] - [Migration("20231230180933_CreatingIdentityTables")] - partial class CreatingIdentityTables - { - /// - protected override void BuildTargetModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder - .HasAnnotation("ProductVersion", "7.0.14") - .HasAnnotation("Relational:MaxIdentifierLength", 128); - - SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); - - modelBuilder.Entity("Entites.Models.Comment", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uniqueidentifier") - .HasColumnName("CommentId"); - - b.Property("CommentMessage") - .HasColumnType("nvarchar(max)"); - - b.Property("CreatedDate") - .HasColumnType("datetime2"); - - b.Property("PostId") - .HasColumnType("uniqueidentifier"); - - b.Property("UserId") - .HasColumnType("uniqueidentifier"); - - b.HasKey("Id"); - - b.HasIndex("PostId"); - - b.ToTable("Comments"); - }); - - modelBuilder.Entity("Entites.Models.Like", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uniqueidentifier") - .HasColumnName("LikeId"); - - b.Property("CreatedDate") - .HasColumnType("datetime2"); - - b.Property("PostId") - .HasColumnType("uniqueidentifier"); - - b.Property("UserId") - .HasColumnType("uniqueidentifier"); - - b.HasKey("Id"); - - b.HasIndex("PostId"); - - b.ToTable("Likes"); - }); - - modelBuilder.Entity("Entites.Models.Post", b => - { - b.Property("PostId") - .ValueGeneratedOnAdd() - .HasColumnType("uniqueidentifier") - .HasColumnName("PostId"); - - b.Property("CreatedDate") - .HasColumnType("datetime2"); - - b.Property("PostContent") - .HasColumnType("nvarchar(max)"); - - b.Property("UpdateDate") - .HasColumnType("datetime2"); - - b.HasKey("PostId"); - - b.ToTable("Posts"); - }); - - modelBuilder.Entity("Entites.Models.PostPhoto", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uniqueidentifier") - .HasColumnName("PostPhotoId"); - - b.Property("PostId") - .HasColumnType("uniqueidentifier"); - - b.HasKey("Id"); - - b.HasIndex("PostId"); - - b.ToTable("PostPhotos"); - }); - - modelBuilder.Entity("Entites.Models.Profile", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uniqueidentifier") - .HasColumnName("ProfileId"); - - b.Property("CreatedDate") - .HasColumnType("datetime2"); - - b.Property("Name") - .HasColumnType("nvarchar(max)"); - - b.Property("PhotoUrl") - .HasColumnType("nvarchar(max)"); - - b.Property("SelfIntroduction") - .HasColumnType("nvarchar(max)"); - - b.Property("UpdatedDate") - .HasColumnType("datetime2"); - - b.Property("UserId") - .HasColumnType("uniqueidentifier"); - - b.HasKey("Id"); - - b.ToTable("Profiles"); - - b.HasData( - new - { - Id = new Guid("a13ffaa2-c689-4d24-8f65-12df4b9d724c"), - CreatedDate = new DateTime(2023, 12, 31, 3, 9, 33, 266, DateTimeKind.Local).AddTicks(4220), - Name = "홍홍홍", - SelfIntroduction = "안녕하세요, 홍길동입니다.", - UserId = new Guid("b85489c1-2b74-4db9-89f0-234f926f5ea0") - }, - new - { - Id = new Guid("8b23a1d6-860a-4ff2-becd-d7c8a8c238a5"), - CreatedDate = new DateTime(2023, 12, 31, 3, 9, 33, 266, DateTimeKind.Local).AddTicks(4224), - Name = "Yi Sun-sin", - SelfIntroduction = "명량해전의 이순신 입니다.", - UserId = new Guid("f3d72088-6d16-4b5b-9689-11d1f93bb212") - }); - }); - - modelBuilder.Entity("Entites.Models.User", b => - { - b.Property("Id") - .HasColumnType("nvarchar(450)"); - - b.Property("AccessFailedCount") - .HasColumnType("int"); - - b.Property("ConcurrencyStamp") - .IsConcurrencyToken() - .HasColumnType("nvarchar(max)"); - - b.Property("Email") - .HasMaxLength(256) - .HasColumnType("nvarchar(256)"); - - b.Property("EmailConfirmed") - .HasColumnType("bit"); - - b.Property("GoogleEmail") - .HasColumnType("nvarchar(max)"); - - b.Property("GoogleId") - .HasColumnType("nvarchar(max)"); - - b.Property("GoogleName") - .HasColumnType("nvarchar(max)"); - - b.Property("KakaoEmail") - .HasColumnType("nvarchar(max)"); - - b.Property("KakaoId") - .HasColumnType("nvarchar(max)"); - - b.Property("KakaoName") - .HasColumnType("nvarchar(max)"); - - b.Property("LockoutEnabled") - .HasColumnType("bit"); - - b.Property("LockoutEnd") - .HasColumnType("datetimeoffset"); - - b.Property("NormalizedEmail") - .HasMaxLength(256) - .HasColumnType("nvarchar(256)"); - - b.Property("NormalizedUserName") - .HasMaxLength(256) - .HasColumnType("nvarchar(256)"); - - b.Property("PasswordHash") - .HasColumnType("nvarchar(max)"); - - b.Property("PhoneNumber") - .HasColumnType("nvarchar(max)"); - - b.Property("PhoneNumberConfirmed") - .HasColumnType("bit"); - - b.Property("ProfileId") - .HasColumnType("uniqueidentifier"); - - b.Property("SecurityStamp") - .HasColumnType("nvarchar(max)"); - - b.Property("TwoFactorEnabled") - .HasColumnType("bit"); - - b.Property("UserName") - .HasMaxLength(256) - .HasColumnType("nvarchar(256)"); - - b.HasKey("Id"); - - b.HasIndex("NormalizedEmail") - .HasDatabaseName("EmailIndex"); - - b.HasIndex("NormalizedUserName") - .IsUnique() - .HasDatabaseName("UserNameIndex") - .HasFilter("[NormalizedUserName] IS NOT NULL"); - - b.ToTable("AspNetUsers", (string)null); - - b.HasData( - new - { - Id = "147f50b6-46bd-467e-811f-fa01ae984912", - AccessFailedCount = 0, - ConcurrencyStamp = "2aa333c4-54f1-4781-809f-d3d15e45e6b0", - EmailConfirmed = false, - GoogleEmail = "test01@gmail.com", - GoogleId = "test01", - GoogleName = "홍길동", - LockoutEnabled = false, - PhoneNumberConfirmed = false, - ProfileId = new Guid("a13ffaa2-c689-4d24-8f65-12df4b9d724c"), - SecurityStamp = "bdb064ce-a3a8-48a3-a021-b54ede8ea958", - TwoFactorEnabled = false - }, - new - { - Id = "539fb06a-f3fe-493c-98b6-4d64e6cd6d58", - AccessFailedCount = 0, - ConcurrencyStamp = "70b71192-b1ee-401f-b9a7-573342152bb5", - EmailConfirmed = false, - KakaoEmail = "test02@naver.com", - KakaoId = "test02", - KakaoName = "이순신", - LockoutEnabled = false, - PhoneNumberConfirmed = false, - ProfileId = new Guid("8b23a1d6-860a-4ff2-becd-d7c8a8c238a5"), - SecurityStamp = "fb615259-86f6-4c74-9ea4-8ea7cdbf87b2", - TwoFactorEnabled = false - }); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRole", b => - { - b.Property("Id") - .HasColumnType("nvarchar(450)"); - - b.Property("ConcurrencyStamp") - .IsConcurrencyToken() - .HasColumnType("nvarchar(max)"); - - b.Property("Name") - .HasMaxLength(256) - .HasColumnType("nvarchar(256)"); - - b.Property("NormalizedName") - .HasMaxLength(256) - .HasColumnType("nvarchar(256)"); - - b.HasKey("Id"); - - b.HasIndex("NormalizedName") - .IsUnique() - .HasDatabaseName("RoleNameIndex") - .HasFilter("[NormalizedName] IS NOT NULL"); - - b.ToTable("AspNetRoles", (string)null); - - b.HasData( - new - { - Id = "55d45176-c0bc-4a53-beb1-bc386aff26a8", - Name = "Manager", - NormalizedName = "MANAGER" - }, - new - { - Id = "8ce698c2-09f8-4f94-a04b-247c04582e04", - Name = "Administrator", - NormalizedName = "ADMINISTRATOR" - }); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("ClaimType") - .HasColumnType("nvarchar(max)"); - - b.Property("ClaimValue") - .HasColumnType("nvarchar(max)"); - - b.Property("RoleId") - .IsRequired() - .HasColumnType("nvarchar(450)"); - - b.HasKey("Id"); - - b.HasIndex("RoleId"); - - b.ToTable("AspNetRoleClaims", (string)null); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("ClaimType") - .HasColumnType("nvarchar(max)"); - - b.Property("ClaimValue") - .HasColumnType("nvarchar(max)"); - - b.Property("UserId") - .IsRequired() - .HasColumnType("nvarchar(450)"); - - b.HasKey("Id"); - - b.HasIndex("UserId"); - - b.ToTable("AspNetUserClaims", (string)null); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => - { - b.Property("LoginProvider") - .HasColumnType("nvarchar(450)"); - - b.Property("ProviderKey") - .HasColumnType("nvarchar(450)"); - - b.Property("ProviderDisplayName") - .HasColumnType("nvarchar(max)"); - - b.Property("UserId") - .IsRequired() - .HasColumnType("nvarchar(450)"); - - b.HasKey("LoginProvider", "ProviderKey"); - - b.HasIndex("UserId"); - - b.ToTable("AspNetUserLogins", (string)null); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => - { - b.Property("UserId") - .HasColumnType("nvarchar(450)"); - - b.Property("RoleId") - .HasColumnType("nvarchar(450)"); - - b.HasKey("UserId", "RoleId"); - - b.HasIndex("RoleId"); - - b.ToTable("AspNetUserRoles", (string)null); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => - { - b.Property("UserId") - .HasColumnType("nvarchar(450)"); - - b.Property("LoginProvider") - .HasColumnType("nvarchar(450)"); - - b.Property("Name") - .HasColumnType("nvarchar(450)"); - - b.Property("Value") - .HasColumnType("nvarchar(max)"); - - b.HasKey("UserId", "LoginProvider", "Name"); - - b.ToTable("AspNetUserTokens", (string)null); - }); - - modelBuilder.Entity("Entites.Models.Comment", b => - { - b.HasOne("Entites.Models.Post", null) - .WithMany("Comments") - .HasForeignKey("PostId"); - }); - - modelBuilder.Entity("Entites.Models.Like", b => - { - b.HasOne("Entites.Models.Post", null) - .WithMany("Likes") - .HasForeignKey("PostId"); - }); - - modelBuilder.Entity("Entites.Models.PostPhoto", b => - { - b.HasOne("Entites.Models.Post", null) - .WithMany("PostPhotos") - .HasForeignKey("PostId"); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => - { - b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null) - .WithMany() - .HasForeignKey("RoleId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => - { - b.HasOne("Entites.Models.User", null) - .WithMany() - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => - { - b.HasOne("Entites.Models.User", null) - .WithMany() - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => - { - b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null) - .WithMany() - .HasForeignKey("RoleId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("Entites.Models.User", null) - .WithMany() - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => - { - b.HasOne("Entites.Models.User", null) - .WithMany() - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("Entites.Models.Post", b => - { - b.Navigation("Comments"); - - b.Navigation("Likes"); - - b.Navigation("PostPhotos"); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/EveryPinApi/Migrations/20231230180933_CreatingIdentityTables.cs b/EveryPinApi/Migrations/20231230180933_CreatingIdentityTables.cs deleted file mode 100644 index 91299d1..0000000 --- a/EveryPinApi/Migrations/20231230180933_CreatingIdentityTables.cs +++ /dev/null @@ -1,377 +0,0 @@ -using System; -using Microsoft.EntityFrameworkCore.Migrations; - -#nullable disable - -#pragma warning disable CA1814 // Prefer jagged arrays over multidimensional - -namespace EveryPinApi.Migrations -{ - /// - public partial class CreatingIdentityTables : Migration - { - /// - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.CreateTable( - name: "AspNetRoles", - columns: table => new - { - Id = table.Column(type: "nvarchar(450)", nullable: false), - Name = table.Column(type: "nvarchar(256)", maxLength: 256, nullable: true), - NormalizedName = table.Column(type: "nvarchar(256)", maxLength: 256, nullable: true), - ConcurrencyStamp = table.Column(type: "nvarchar(max)", nullable: true) - }, - constraints: table => - { - table.PrimaryKey("PK_AspNetRoles", x => x.Id); - }); - - migrationBuilder.CreateTable( - name: "AspNetUsers", - columns: table => new - { - Id = table.Column(type: "nvarchar(450)", nullable: false), - GoogleId = table.Column(type: "nvarchar(max)", nullable: true), - GoogleName = table.Column(type: "nvarchar(max)", nullable: true), - GoogleEmail = table.Column(type: "nvarchar(max)", nullable: true), - KakaoId = table.Column(type: "nvarchar(max)", nullable: true), - KakaoName = table.Column(type: "nvarchar(max)", nullable: true), - KakaoEmail = table.Column(type: "nvarchar(max)", nullable: true), - ProfileId = table.Column(type: "uniqueidentifier", nullable: false), - UserName = table.Column(type: "nvarchar(256)", maxLength: 256, nullable: true), - NormalizedUserName = table.Column(type: "nvarchar(256)", maxLength: 256, nullable: true), - Email = table.Column(type: "nvarchar(256)", maxLength: 256, nullable: true), - NormalizedEmail = table.Column(type: "nvarchar(256)", maxLength: 256, nullable: true), - EmailConfirmed = table.Column(type: "bit", nullable: false), - PasswordHash = table.Column(type: "nvarchar(max)", nullable: true), - SecurityStamp = table.Column(type: "nvarchar(max)", nullable: true), - ConcurrencyStamp = table.Column(type: "nvarchar(max)", nullable: true), - PhoneNumber = table.Column(type: "nvarchar(max)", nullable: true), - PhoneNumberConfirmed = table.Column(type: "bit", nullable: false), - TwoFactorEnabled = table.Column(type: "bit", nullable: false), - LockoutEnd = table.Column(type: "datetimeoffset", nullable: true), - LockoutEnabled = table.Column(type: "bit", nullable: false), - AccessFailedCount = table.Column(type: "int", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_AspNetUsers", x => x.Id); - }); - - migrationBuilder.CreateTable( - name: "Posts", - columns: table => new - { - PostId = table.Column(type: "uniqueidentifier", nullable: false), - PostContent = table.Column(type: "nvarchar(max)", nullable: true), - UpdateDate = table.Column(type: "datetime2", nullable: true), - CreatedDate = table.Column(type: "datetime2", nullable: true) - }, - constraints: table => - { - table.PrimaryKey("PK_Posts", x => x.PostId); - }); - - migrationBuilder.CreateTable( - name: "Profiles", - columns: table => new - { - ProfileId = table.Column(type: "uniqueidentifier", nullable: false), - Name = table.Column(type: "nvarchar(max)", nullable: true), - SelfIntroduction = table.Column(type: "nvarchar(max)", nullable: true), - PhotoUrl = table.Column(type: "nvarchar(max)", nullable: true), - UserId = table.Column(type: "uniqueidentifier", nullable: false), - UpdatedDate = table.Column(type: "datetime2", nullable: true), - CreatedDate = table.Column(type: "datetime2", nullable: true) - }, - constraints: table => - { - table.PrimaryKey("PK_Profiles", x => x.ProfileId); - }); - - migrationBuilder.CreateTable( - name: "AspNetRoleClaims", - columns: table => new - { - Id = table.Column(type: "int", nullable: false) - .Annotation("SqlServer:Identity", "1, 1"), - RoleId = table.Column(type: "nvarchar(450)", nullable: false), - ClaimType = table.Column(type: "nvarchar(max)", nullable: true), - ClaimValue = table.Column(type: "nvarchar(max)", nullable: true) - }, - constraints: table => - { - table.PrimaryKey("PK_AspNetRoleClaims", x => x.Id); - table.ForeignKey( - name: "FK_AspNetRoleClaims_AspNetRoles_RoleId", - column: x => x.RoleId, - principalTable: "AspNetRoles", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateTable( - name: "AspNetUserClaims", - columns: table => new - { - Id = table.Column(type: "int", nullable: false) - .Annotation("SqlServer:Identity", "1, 1"), - UserId = table.Column(type: "nvarchar(450)", nullable: false), - ClaimType = table.Column(type: "nvarchar(max)", nullable: true), - ClaimValue = table.Column(type: "nvarchar(max)", nullable: true) - }, - constraints: table => - { - table.PrimaryKey("PK_AspNetUserClaims", x => x.Id); - table.ForeignKey( - name: "FK_AspNetUserClaims_AspNetUsers_UserId", - column: x => x.UserId, - principalTable: "AspNetUsers", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateTable( - name: "AspNetUserLogins", - columns: table => new - { - LoginProvider = table.Column(type: "nvarchar(450)", nullable: false), - ProviderKey = table.Column(type: "nvarchar(450)", nullable: false), - ProviderDisplayName = table.Column(type: "nvarchar(max)", nullable: true), - UserId = table.Column(type: "nvarchar(450)", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_AspNetUserLogins", x => new { x.LoginProvider, x.ProviderKey }); - table.ForeignKey( - name: "FK_AspNetUserLogins_AspNetUsers_UserId", - column: x => x.UserId, - principalTable: "AspNetUsers", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateTable( - name: "AspNetUserRoles", - columns: table => new - { - UserId = table.Column(type: "nvarchar(450)", nullable: false), - RoleId = table.Column(type: "nvarchar(450)", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_AspNetUserRoles", x => new { x.UserId, x.RoleId }); - table.ForeignKey( - name: "FK_AspNetUserRoles_AspNetRoles_RoleId", - column: x => x.RoleId, - principalTable: "AspNetRoles", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - table.ForeignKey( - name: "FK_AspNetUserRoles_AspNetUsers_UserId", - column: x => x.UserId, - principalTable: "AspNetUsers", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateTable( - name: "AspNetUserTokens", - columns: table => new - { - UserId = table.Column(type: "nvarchar(450)", nullable: false), - LoginProvider = table.Column(type: "nvarchar(450)", nullable: false), - Name = table.Column(type: "nvarchar(450)", nullable: false), - Value = table.Column(type: "nvarchar(max)", nullable: true) - }, - constraints: table => - { - table.PrimaryKey("PK_AspNetUserTokens", x => new { x.UserId, x.LoginProvider, x.Name }); - table.ForeignKey( - name: "FK_AspNetUserTokens_AspNetUsers_UserId", - column: x => x.UserId, - principalTable: "AspNetUsers", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateTable( - name: "Comments", - columns: table => new - { - CommentId = table.Column(type: "uniqueidentifier", nullable: false), - UserId = table.Column(type: "uniqueidentifier", nullable: false), - CommentMessage = table.Column(type: "nvarchar(max)", nullable: true), - CreatedDate = table.Column(type: "datetime2", nullable: true), - PostId = table.Column(type: "uniqueidentifier", nullable: true) - }, - constraints: table => - { - table.PrimaryKey("PK_Comments", x => x.CommentId); - table.ForeignKey( - name: "FK_Comments_Posts_PostId", - column: x => x.PostId, - principalTable: "Posts", - principalColumn: "PostId"); - }); - - migrationBuilder.CreateTable( - name: "Likes", - columns: table => new - { - LikeId = table.Column(type: "uniqueidentifier", nullable: false), - UserId = table.Column(type: "uniqueidentifier", nullable: false), - CreatedDate = table.Column(type: "datetime2", nullable: true), - PostId = table.Column(type: "uniqueidentifier", nullable: true) - }, - constraints: table => - { - table.PrimaryKey("PK_Likes", x => x.LikeId); - table.ForeignKey( - name: "FK_Likes_Posts_PostId", - column: x => x.PostId, - principalTable: "Posts", - principalColumn: "PostId"); - }); - - migrationBuilder.CreateTable( - name: "PostPhotos", - columns: table => new - { - PostPhotoId = table.Column(type: "uniqueidentifier", nullable: false), - PostId = table.Column(type: "uniqueidentifier", nullable: true) - }, - constraints: table => - { - table.PrimaryKey("PK_PostPhotos", x => x.PostPhotoId); - table.ForeignKey( - name: "FK_PostPhotos_Posts_PostId", - column: x => x.PostId, - principalTable: "Posts", - principalColumn: "PostId"); - }); - - migrationBuilder.InsertData( - table: "AspNetRoles", - columns: new[] { "Id", "ConcurrencyStamp", "Name", "NormalizedName" }, - values: new object[,] - { - { "55d45176-c0bc-4a53-beb1-bc386aff26a8", null, "Manager", "MANAGER" }, - { "8ce698c2-09f8-4f94-a04b-247c04582e04", null, "Administrator", "ADMINISTRATOR" } - }); - - migrationBuilder.InsertData( - table: "AspNetUsers", - columns: new[] { "Id", "AccessFailedCount", "ConcurrencyStamp", "Email", "EmailConfirmed", "GoogleEmail", "GoogleId", "GoogleName", "KakaoEmail", "KakaoId", "KakaoName", "LockoutEnabled", "LockoutEnd", "NormalizedEmail", "NormalizedUserName", "PasswordHash", "PhoneNumber", "PhoneNumberConfirmed", "ProfileId", "SecurityStamp", "TwoFactorEnabled", "UserName" }, - values: new object[,] - { - { "147f50b6-46bd-467e-811f-fa01ae984912", 0, "2aa333c4-54f1-4781-809f-d3d15e45e6b0", null, false, "test01@gmail.com", "test01", "홍길동", null, null, null, false, null, null, null, null, null, false, new Guid("a13ffaa2-c689-4d24-8f65-12df4b9d724c"), "bdb064ce-a3a8-48a3-a021-b54ede8ea958", false, null }, - { "539fb06a-f3fe-493c-98b6-4d64e6cd6d58", 0, "70b71192-b1ee-401f-b9a7-573342152bb5", null, false, null, null, null, "test02@naver.com", "test02", "이순신", false, null, null, null, null, null, false, new Guid("8b23a1d6-860a-4ff2-becd-d7c8a8c238a5"), "fb615259-86f6-4c74-9ea4-8ea7cdbf87b2", false, null } - }); - - migrationBuilder.InsertData( - table: "Profiles", - columns: new[] { "ProfileId", "CreatedDate", "Name", "PhotoUrl", "SelfIntroduction", "UpdatedDate", "UserId" }, - values: new object[,] - { - { new Guid("8b23a1d6-860a-4ff2-becd-d7c8a8c238a5"), new DateTime(2023, 12, 31, 3, 9, 33, 266, DateTimeKind.Local).AddTicks(4224), "Yi Sun-sin", null, "명량해전의 이순신 입니다.", null, new Guid("f3d72088-6d16-4b5b-9689-11d1f93bb212") }, - { new Guid("a13ffaa2-c689-4d24-8f65-12df4b9d724c"), new DateTime(2023, 12, 31, 3, 9, 33, 266, DateTimeKind.Local).AddTicks(4220), "홍홍홍", null, "안녕하세요, 홍길동입니다.", null, new Guid("b85489c1-2b74-4db9-89f0-234f926f5ea0") } - }); - - migrationBuilder.CreateIndex( - name: "IX_AspNetRoleClaims_RoleId", - table: "AspNetRoleClaims", - column: "RoleId"); - - migrationBuilder.CreateIndex( - name: "RoleNameIndex", - table: "AspNetRoles", - column: "NormalizedName", - unique: true, - filter: "[NormalizedName] IS NOT NULL"); - - migrationBuilder.CreateIndex( - name: "IX_AspNetUserClaims_UserId", - table: "AspNetUserClaims", - column: "UserId"); - - migrationBuilder.CreateIndex( - name: "IX_AspNetUserLogins_UserId", - table: "AspNetUserLogins", - column: "UserId"); - - migrationBuilder.CreateIndex( - name: "IX_AspNetUserRoles_RoleId", - table: "AspNetUserRoles", - column: "RoleId"); - - migrationBuilder.CreateIndex( - name: "EmailIndex", - table: "AspNetUsers", - column: "NormalizedEmail"); - - migrationBuilder.CreateIndex( - name: "UserNameIndex", - table: "AspNetUsers", - column: "NormalizedUserName", - unique: true, - filter: "[NormalizedUserName] IS NOT NULL"); - - migrationBuilder.CreateIndex( - name: "IX_Comments_PostId", - table: "Comments", - column: "PostId"); - - migrationBuilder.CreateIndex( - name: "IX_Likes_PostId", - table: "Likes", - column: "PostId"); - - migrationBuilder.CreateIndex( - name: "IX_PostPhotos_PostId", - table: "PostPhotos", - column: "PostId"); - } - - /// - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropTable( - name: "AspNetRoleClaims"); - - migrationBuilder.DropTable( - name: "AspNetUserClaims"); - - migrationBuilder.DropTable( - name: "AspNetUserLogins"); - - migrationBuilder.DropTable( - name: "AspNetUserRoles"); - - migrationBuilder.DropTable( - name: "AspNetUserTokens"); - - migrationBuilder.DropTable( - name: "Comments"); - - migrationBuilder.DropTable( - name: "Likes"); - - migrationBuilder.DropTable( - name: "PostPhotos"); - - migrationBuilder.DropTable( - name: "Profiles"); - - migrationBuilder.DropTable( - name: "AspNetRoles"); - - migrationBuilder.DropTable( - name: "AspNetUsers"); - - migrationBuilder.DropTable( - name: "Posts"); - } - } -} diff --git a/EveryPinApi/Migrations/20240109120726_edit-models.Designer.cs b/EveryPinApi/Migrations/20240109120726_edit-models.Designer.cs new file mode 100644 index 0000000..6a492ab --- /dev/null +++ b/EveryPinApi/Migrations/20240109120726_edit-models.Designer.cs @@ -0,0 +1,279 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Repository; + +#nullable disable + +namespace EveryPinApi.Migrations +{ + [DbContext(typeof(RepositoryContext))] + [Migration("20240109120726_edit-models")] + partial class editmodels + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.14") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("Entites.Models.CodeOAuthPlatform", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int") + .HasColumnName("PlatformCodeId"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("PlatformName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("CodeOAuthPlatforms"); + }); + + modelBuilder.Entity("Entites.Models.Comment", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int") + .HasColumnName("CommentId"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("CommentMessage") + .HasColumnType("nvarchar(max)"); + + b.Property("CreatedDate") + .HasColumnType("datetime2"); + + b.Property("PostId") + .HasColumnType("int"); + + b.Property("UserId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("PostId"); + + b.HasIndex("UserId"); + + b.ToTable("Comments"); + }); + + modelBuilder.Entity("Entites.Models.Like", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int") + .HasColumnName("LikeId"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("CreatedDate") + .HasColumnType("datetime2"); + + b.Property("PostId") + .HasColumnType("int"); + + b.Property("UserId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("PostId"); + + b.HasIndex("UserId"); + + b.ToTable("Likes"); + }); + + modelBuilder.Entity("Entites.Models.Post", b => + { + b.Property("PostId") + .ValueGeneratedOnAdd() + .HasColumnType("int") + .HasColumnName("PostId"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("PostId")); + + b.Property("CreatedDate") + .HasColumnType("datetime2"); + + b.Property("PostContent") + .HasColumnType("nvarchar(max)"); + + b.Property("UpdateDate") + .HasColumnType("datetime2"); + + b.HasKey("PostId"); + + b.ToTable("Posts"); + }); + + modelBuilder.Entity("Entites.Models.PostPhoto", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int") + .HasColumnName("PostPhotoId"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("PostId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("PostId"); + + b.ToTable("PostPhotos"); + }); + + modelBuilder.Entity("Entites.Models.Profile", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int") + .HasColumnName("ProfileId"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("CreatedDate") + .HasColumnType("datetime2"); + + b.Property("Name") + .HasColumnType("nvarchar(max)"); + + b.Property("PhotoUrl") + .HasColumnType("nvarchar(max)"); + + b.Property("SelfIntroduction") + .HasColumnType("nvarchar(max)"); + + b.Property("UpdatedDate") + .HasColumnType("datetime2"); + + b.Property("UserId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("UserId") + .IsUnique() + .HasFilter("[UserId] IS NOT NULL"); + + b.ToTable("Profiles"); + }); + + modelBuilder.Entity("Entites.Models.User", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int") + .HasColumnName("UserId"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("CreatedDate") + .HasColumnType("datetime2"); + + b.Property("DeleteCheck") + .HasColumnType("bit"); + + b.Property("Email") + .HasColumnType("nvarchar(max)"); + + b.Property("LastLoginDate") + .HasColumnType("datetime2"); + + b.Property("Name") + .HasColumnType("nvarchar(max)"); + + b.Property("PlatformCodeId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.ToTable("Users"); + }); + + modelBuilder.Entity("Entites.Models.Comment", b => + { + b.HasOne("Entites.Models.Post", "Post") + .WithMany("Comments") + .HasForeignKey("PostId"); + + b.HasOne("Entites.Models.User", "User") + .WithMany() + .HasForeignKey("UserId"); + + b.Navigation("Post"); + + b.Navigation("User"); + }); + + modelBuilder.Entity("Entites.Models.Like", b => + { + b.HasOne("Entites.Models.Post", "Post") + .WithMany("Likes") + .HasForeignKey("PostId"); + + b.HasOne("Entites.Models.User", "User") + .WithMany("Like") + .HasForeignKey("UserId"); + + b.Navigation("Post"); + + b.Navigation("User"); + }); + + modelBuilder.Entity("Entites.Models.PostPhoto", b => + { + b.HasOne("Entites.Models.Post", "Post") + .WithMany("PostPhotos") + .HasForeignKey("PostId"); + + b.Navigation("Post"); + }); + + modelBuilder.Entity("Entites.Models.Profile", b => + { + b.HasOne("Entites.Models.User", "User") + .WithOne("Profile") + .HasForeignKey("Entites.Models.Profile", "UserId"); + + b.Navigation("User"); + }); + + modelBuilder.Entity("Entites.Models.Post", b => + { + b.Navigation("Comments"); + + b.Navigation("Likes"); + + b.Navigation("PostPhotos"); + }); + + modelBuilder.Entity("Entites.Models.User", b => + { + b.Navigation("Like"); + + b.Navigation("Profile"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/EveryPinApi/Migrations/20240109120726_edit-models.cs b/EveryPinApi/Migrations/20240109120726_edit-models.cs new file mode 100644 index 0000000..2a9fe56 --- /dev/null +++ b/EveryPinApi/Migrations/20240109120726_edit-models.cs @@ -0,0 +1,210 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace EveryPinApi.Migrations +{ + /// + public partial class editmodels : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "CodeOAuthPlatforms", + columns: table => new + { + PlatformCodeId = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + PlatformName = table.Column(type: "nvarchar(max)", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_CodeOAuthPlatforms", x => x.PlatformCodeId); + }); + + migrationBuilder.CreateTable( + name: "Posts", + columns: table => new + { + PostId = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + PostContent = table.Column(type: "nvarchar(max)", nullable: true), + UpdateDate = table.Column(type: "datetime2", nullable: true), + CreatedDate = table.Column(type: "datetime2", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_Posts", x => x.PostId); + }); + + migrationBuilder.CreateTable( + name: "Users", + columns: table => new + { + UserId = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + PlatformCodeId = table.Column(type: "int", nullable: false), + Name = table.Column(type: "nvarchar(max)", nullable: true), + Email = table.Column(type: "nvarchar(max)", nullable: true), + CreatedDate = table.Column(type: "datetime2", nullable: false), + LastLoginDate = table.Column(type: "datetime2", nullable: false), + DeleteCheck = table.Column(type: "bit", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Users", x => x.UserId); + }); + + migrationBuilder.CreateTable( + name: "PostPhotos", + columns: table => new + { + PostPhotoId = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + PostId = table.Column(type: "int", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_PostPhotos", x => x.PostPhotoId); + table.ForeignKey( + name: "FK_PostPhotos_Posts_PostId", + column: x => x.PostId, + principalTable: "Posts", + principalColumn: "PostId"); + }); + + migrationBuilder.CreateTable( + name: "Comments", + columns: table => new + { + CommentId = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + PostId = table.Column(type: "int", nullable: true), + UserId = table.Column(type: "int", nullable: true), + CommentMessage = table.Column(type: "nvarchar(max)", nullable: true), + CreatedDate = table.Column(type: "datetime2", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_Comments", x => x.CommentId); + table.ForeignKey( + name: "FK_Comments_Posts_PostId", + column: x => x.PostId, + principalTable: "Posts", + principalColumn: "PostId"); + table.ForeignKey( + name: "FK_Comments_Users_UserId", + column: x => x.UserId, + principalTable: "Users", + principalColumn: "UserId"); + }); + + migrationBuilder.CreateTable( + name: "Likes", + columns: table => new + { + LikeId = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + PostId = table.Column(type: "int", nullable: true), + UserId = table.Column(type: "int", nullable: true), + CreatedDate = table.Column(type: "datetime2", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_Likes", x => x.LikeId); + table.ForeignKey( + name: "FK_Likes_Posts_PostId", + column: x => x.PostId, + principalTable: "Posts", + principalColumn: "PostId"); + table.ForeignKey( + name: "FK_Likes_Users_UserId", + column: x => x.UserId, + principalTable: "Users", + principalColumn: "UserId"); + }); + + migrationBuilder.CreateTable( + name: "Profiles", + columns: table => new + { + ProfileId = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + UserId = table.Column(type: "int", nullable: true), + Name = table.Column(type: "nvarchar(max)", nullable: true), + SelfIntroduction = table.Column(type: "nvarchar(max)", nullable: true), + PhotoUrl = table.Column(type: "nvarchar(max)", nullable: true), + UpdatedDate = table.Column(type: "datetime2", nullable: true), + CreatedDate = table.Column(type: "datetime2", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_Profiles", x => x.ProfileId); + table.ForeignKey( + name: "FK_Profiles_Users_UserId", + column: x => x.UserId, + principalTable: "Users", + principalColumn: "UserId"); + }); + + migrationBuilder.CreateIndex( + name: "IX_Comments_PostId", + table: "Comments", + column: "PostId"); + + migrationBuilder.CreateIndex( + name: "IX_Comments_UserId", + table: "Comments", + column: "UserId"); + + migrationBuilder.CreateIndex( + name: "IX_Likes_PostId", + table: "Likes", + column: "PostId"); + + migrationBuilder.CreateIndex( + name: "IX_Likes_UserId", + table: "Likes", + column: "UserId"); + + migrationBuilder.CreateIndex( + name: "IX_PostPhotos_PostId", + table: "PostPhotos", + column: "PostId"); + + migrationBuilder.CreateIndex( + name: "IX_Profiles_UserId", + table: "Profiles", + column: "UserId", + unique: true, + filter: "[UserId] IS NOT NULL"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "CodeOAuthPlatforms"); + + migrationBuilder.DropTable( + name: "Comments"); + + migrationBuilder.DropTable( + name: "Likes"); + + migrationBuilder.DropTable( + name: "PostPhotos"); + + migrationBuilder.DropTable( + name: "Profiles"); + + migrationBuilder.DropTable( + name: "Posts"); + + migrationBuilder.DropTable( + name: "Users"); + } + } +} diff --git a/EveryPinApi/Migrations/20240109121241_add-PostPhoto-url.Designer.cs b/EveryPinApi/Migrations/20240109121241_add-PostPhoto-url.Designer.cs new file mode 100644 index 0000000..7e3e687 --- /dev/null +++ b/EveryPinApi/Migrations/20240109121241_add-PostPhoto-url.Designer.cs @@ -0,0 +1,279 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Repository; + +#nullable disable + +namespace EveryPinApi.Migrations +{ + [DbContext(typeof(RepositoryContext))] + [Migration("20240109121241_add-PostPhoto-url")] + partial class addPostPhotourl + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.14") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("Entites.Models.CodeOAuthPlatform", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int") + .HasColumnName("PlatformCodeId"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("PlatformName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("CodeOAuthPlatforms"); + }); + + modelBuilder.Entity("Entites.Models.Comment", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int") + .HasColumnName("CommentId"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("CommentMessage") + .HasColumnType("nvarchar(max)"); + + b.Property("CreatedDate") + .HasColumnType("datetime2"); + + b.Property("PostId") + .HasColumnType("int"); + + b.Property("UserId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("PostId"); + + b.HasIndex("UserId"); + + b.ToTable("Comments"); + }); + + modelBuilder.Entity("Entites.Models.Like", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int") + .HasColumnName("LikeId"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("CreatedDate") + .HasColumnType("datetime2"); + + b.Property("PostId") + .HasColumnType("int"); + + b.Property("UserId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("PostId"); + + b.HasIndex("UserId"); + + b.ToTable("Likes"); + }); + + modelBuilder.Entity("Entites.Models.Post", b => + { + b.Property("PostId") + .ValueGeneratedOnAdd() + .HasColumnType("int") + .HasColumnName("PostId"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("PostId")); + + b.Property("CreatedDate") + .HasColumnType("datetime2"); + + b.Property("PostContent") + .HasColumnType("nvarchar(max)"); + + b.Property("UpdateDate") + .HasColumnType("datetime2"); + + b.HasKey("PostId"); + + b.ToTable("Posts"); + }); + + modelBuilder.Entity("Entites.Models.PostPhoto", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int") + .HasColumnName("PostPhotoId"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("PostId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("PostId"); + + b.ToTable("PostPhotos"); + }); + + modelBuilder.Entity("Entites.Models.Profile", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int") + .HasColumnName("ProfileId"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("CreatedDate") + .HasColumnType("datetime2"); + + b.Property("Name") + .HasColumnType("nvarchar(max)"); + + b.Property("PhotoUrl") + .HasColumnType("nvarchar(max)"); + + b.Property("SelfIntroduction") + .HasColumnType("nvarchar(max)"); + + b.Property("UpdatedDate") + .HasColumnType("datetime2"); + + b.Property("UserId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("UserId") + .IsUnique() + .HasFilter("[UserId] IS NOT NULL"); + + b.ToTable("Profiles"); + }); + + modelBuilder.Entity("Entites.Models.User", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int") + .HasColumnName("UserId"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("CreatedDate") + .HasColumnType("datetime2"); + + b.Property("DeleteCheck") + .HasColumnType("bit"); + + b.Property("Email") + .HasColumnType("nvarchar(max)"); + + b.Property("LastLoginDate") + .HasColumnType("datetime2"); + + b.Property("Name") + .HasColumnType("nvarchar(max)"); + + b.Property("PlatformCodeId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.ToTable("Users"); + }); + + modelBuilder.Entity("Entites.Models.Comment", b => + { + b.HasOne("Entites.Models.Post", "Post") + .WithMany("Comments") + .HasForeignKey("PostId"); + + b.HasOne("Entites.Models.User", "User") + .WithMany() + .HasForeignKey("UserId"); + + b.Navigation("Post"); + + b.Navigation("User"); + }); + + modelBuilder.Entity("Entites.Models.Like", b => + { + b.HasOne("Entites.Models.Post", "Post") + .WithMany("Likes") + .HasForeignKey("PostId"); + + b.HasOne("Entites.Models.User", "User") + .WithMany("Like") + .HasForeignKey("UserId"); + + b.Navigation("Post"); + + b.Navigation("User"); + }); + + modelBuilder.Entity("Entites.Models.PostPhoto", b => + { + b.HasOne("Entites.Models.Post", "Post") + .WithMany("PostPhotos") + .HasForeignKey("PostId"); + + b.Navigation("Post"); + }); + + modelBuilder.Entity("Entites.Models.Profile", b => + { + b.HasOne("Entites.Models.User", "User") + .WithOne("Profile") + .HasForeignKey("Entites.Models.Profile", "UserId"); + + b.Navigation("User"); + }); + + modelBuilder.Entity("Entites.Models.Post", b => + { + b.Navigation("Comments"); + + b.Navigation("Likes"); + + b.Navigation("PostPhotos"); + }); + + modelBuilder.Entity("Entites.Models.User", b => + { + b.Navigation("Like"); + + b.Navigation("Profile"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/EveryPinApi/Migrations/20240109121241_add-PostPhoto-url.cs b/EveryPinApi/Migrations/20240109121241_add-PostPhoto-url.cs new file mode 100644 index 0000000..da206af --- /dev/null +++ b/EveryPinApi/Migrations/20240109121241_add-PostPhoto-url.cs @@ -0,0 +1,22 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace EveryPinApi.Migrations +{ + /// + public partial class addPostPhotourl : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + + } + } +} diff --git a/EveryPinApi/Migrations/RepositoryContextModelSnapshot.cs b/EveryPinApi/Migrations/RepositoryContextModelSnapshot.cs index ab51b70..ec1ffb3 100644 --- a/EveryPinApi/Migrations/RepositoryContextModelSnapshot.cs +++ b/EveryPinApi/Migrations/RepositoryContextModelSnapshot.cs @@ -22,62 +22,90 @@ protected override void BuildModel(ModelBuilder modelBuilder) SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + modelBuilder.Entity("Entites.Models.CodeOAuthPlatform", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int") + .HasColumnName("PlatformCodeId"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("PlatformName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("CodeOAuthPlatforms"); + }); + modelBuilder.Entity("Entites.Models.Comment", b => { - b.Property("Id") + b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType("uniqueidentifier") + .HasColumnType("int") .HasColumnName("CommentId"); + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + b.Property("CommentMessage") .HasColumnType("nvarchar(max)"); b.Property("CreatedDate") .HasColumnType("datetime2"); - b.Property("PostId") - .HasColumnType("uniqueidentifier"); + b.Property("PostId") + .HasColumnType("int"); - b.Property("UserId") - .HasColumnType("uniqueidentifier"); + b.Property("UserId") + .HasColumnType("int"); b.HasKey("Id"); b.HasIndex("PostId"); + b.HasIndex("UserId"); + b.ToTable("Comments"); }); modelBuilder.Entity("Entites.Models.Like", b => { - b.Property("Id") + b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType("uniqueidentifier") + .HasColumnType("int") .HasColumnName("LikeId"); + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + b.Property("CreatedDate") .HasColumnType("datetime2"); - b.Property("PostId") - .HasColumnType("uniqueidentifier"); + b.Property("PostId") + .HasColumnType("int"); - b.Property("UserId") - .HasColumnType("uniqueidentifier"); + b.Property("UserId") + .HasColumnType("int"); b.HasKey("Id"); b.HasIndex("PostId"); + b.HasIndex("UserId"); + b.ToTable("Likes"); }); modelBuilder.Entity("Entites.Models.Post", b => { - b.Property("PostId") + b.Property("PostId") .ValueGeneratedOnAdd() - .HasColumnType("uniqueidentifier") + .HasColumnType("int") .HasColumnName("PostId"); + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("PostId")); + b.Property("CreatedDate") .HasColumnType("datetime2"); @@ -94,13 +122,15 @@ protected override void BuildModel(ModelBuilder modelBuilder) modelBuilder.Entity("Entites.Models.PostPhoto", b => { - b.Property("Id") + b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType("uniqueidentifier") + .HasColumnType("int") .HasColumnName("PostPhotoId"); - b.Property("PostId") - .HasColumnType("uniqueidentifier"); + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("PostId") + .HasColumnType("int"); b.HasKey("Id"); @@ -111,11 +141,13 @@ protected override void BuildModel(ModelBuilder modelBuilder) modelBuilder.Entity("Entites.Models.Profile", b => { - b.Property("Id") + b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType("uniqueidentifier") + .HasColumnType("int") .HasColumnName("ProfileId"); + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + b.Property("CreatedDate") .HasColumnType("datetime2"); @@ -131,367 +163,96 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.Property("UpdatedDate") .HasColumnType("datetime2"); - b.Property("UserId") - .HasColumnType("uniqueidentifier"); - - b.HasKey("Id"); - - b.ToTable("Profiles"); - - b.HasData( - new - { - Id = new Guid("a13ffaa2-c689-4d24-8f65-12df4b9d724c"), - CreatedDate = new DateTime(2023, 12, 31, 3, 9, 33, 266, DateTimeKind.Local).AddTicks(4220), - Name = "홍홍홍", - SelfIntroduction = "안녕하세요, 홍길동입니다.", - UserId = new Guid("b85489c1-2b74-4db9-89f0-234f926f5ea0") - }, - new - { - Id = new Guid("8b23a1d6-860a-4ff2-becd-d7c8a8c238a5"), - CreatedDate = new DateTime(2023, 12, 31, 3, 9, 33, 266, DateTimeKind.Local).AddTicks(4224), - Name = "Yi Sun-sin", - SelfIntroduction = "명량해전의 이순신 입니다.", - UserId = new Guid("f3d72088-6d16-4b5b-9689-11d1f93bb212") - }); - }); - - modelBuilder.Entity("Entites.Models.User", b => - { - b.Property("Id") - .HasColumnType("nvarchar(450)"); - - b.Property("AccessFailedCount") + b.Property("UserId") .HasColumnType("int"); - b.Property("ConcurrencyStamp") - .IsConcurrencyToken() - .HasColumnType("nvarchar(max)"); - - b.Property("Email") - .HasMaxLength(256) - .HasColumnType("nvarchar(256)"); - - b.Property("EmailConfirmed") - .HasColumnType("bit"); - - b.Property("GoogleEmail") - .HasColumnType("nvarchar(max)"); - - b.Property("GoogleId") - .HasColumnType("nvarchar(max)"); - - b.Property("GoogleName") - .HasColumnType("nvarchar(max)"); - - b.Property("KakaoEmail") - .HasColumnType("nvarchar(max)"); - - b.Property("KakaoId") - .HasColumnType("nvarchar(max)"); - - b.Property("KakaoName") - .HasColumnType("nvarchar(max)"); - - b.Property("LockoutEnabled") - .HasColumnType("bit"); - - b.Property("LockoutEnd") - .HasColumnType("datetimeoffset"); - - b.Property("NormalizedEmail") - .HasMaxLength(256) - .HasColumnType("nvarchar(256)"); - - b.Property("NormalizedUserName") - .HasMaxLength(256) - .HasColumnType("nvarchar(256)"); - - b.Property("PasswordHash") - .HasColumnType("nvarchar(max)"); - - b.Property("PhoneNumber") - .HasColumnType("nvarchar(max)"); - - b.Property("PhoneNumberConfirmed") - .HasColumnType("bit"); - - b.Property("ProfileId") - .HasColumnType("uniqueidentifier"); - - b.Property("SecurityStamp") - .HasColumnType("nvarchar(max)"); - - b.Property("TwoFactorEnabled") - .HasColumnType("bit"); - - b.Property("UserName") - .HasMaxLength(256) - .HasColumnType("nvarchar(256)"); - - b.HasKey("Id"); - - b.HasIndex("NormalizedEmail") - .HasDatabaseName("EmailIndex"); - - b.HasIndex("NormalizedUserName") - .IsUnique() - .HasDatabaseName("UserNameIndex") - .HasFilter("[NormalizedUserName] IS NOT NULL"); - - b.ToTable("AspNetUsers", (string)null); - - b.HasData( - new - { - Id = "147f50b6-46bd-467e-811f-fa01ae984912", - AccessFailedCount = 0, - ConcurrencyStamp = "2aa333c4-54f1-4781-809f-d3d15e45e6b0", - EmailConfirmed = false, - GoogleEmail = "test01@gmail.com", - GoogleId = "test01", - GoogleName = "홍길동", - LockoutEnabled = false, - PhoneNumberConfirmed = false, - ProfileId = new Guid("a13ffaa2-c689-4d24-8f65-12df4b9d724c"), - SecurityStamp = "bdb064ce-a3a8-48a3-a021-b54ede8ea958", - TwoFactorEnabled = false - }, - new - { - Id = "539fb06a-f3fe-493c-98b6-4d64e6cd6d58", - AccessFailedCount = 0, - ConcurrencyStamp = "70b71192-b1ee-401f-b9a7-573342152bb5", - EmailConfirmed = false, - KakaoEmail = "test02@naver.com", - KakaoId = "test02", - KakaoName = "이순신", - LockoutEnabled = false, - PhoneNumberConfirmed = false, - ProfileId = new Guid("8b23a1d6-860a-4ff2-becd-d7c8a8c238a5"), - SecurityStamp = "fb615259-86f6-4c74-9ea4-8ea7cdbf87b2", - TwoFactorEnabled = false - }); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRole", b => - { - b.Property("Id") - .HasColumnType("nvarchar(450)"); - - b.Property("ConcurrencyStamp") - .IsConcurrencyToken() - .HasColumnType("nvarchar(max)"); - - b.Property("Name") - .HasMaxLength(256) - .HasColumnType("nvarchar(256)"); - - b.Property("NormalizedName") - .HasMaxLength(256) - .HasColumnType("nvarchar(256)"); - b.HasKey("Id"); - b.HasIndex("NormalizedName") + b.HasIndex("UserId") .IsUnique() - .HasDatabaseName("RoleNameIndex") - .HasFilter("[NormalizedName] IS NOT NULL"); - - b.ToTable("AspNetRoles", (string)null); - - b.HasData( - new - { - Id = "55d45176-c0bc-4a53-beb1-bc386aff26a8", - Name = "Manager", - NormalizedName = "MANAGER" - }, - new - { - Id = "8ce698c2-09f8-4f94-a04b-247c04582e04", - Name = "Administrator", - NormalizedName = "ADMINISTRATOR" - }); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); + .HasFilter("[UserId] IS NOT NULL"); - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("ClaimType") - .HasColumnType("nvarchar(max)"); - - b.Property("ClaimValue") - .HasColumnType("nvarchar(max)"); - - b.Property("RoleId") - .IsRequired() - .HasColumnType("nvarchar(450)"); - - b.HasKey("Id"); - - b.HasIndex("RoleId"); - - b.ToTable("AspNetRoleClaims", (string)null); + b.ToTable("Profiles"); }); - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => + modelBuilder.Entity("Entites.Models.User", b => { b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType("int"); + .HasColumnType("int") + .HasColumnName("UserId"); SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - b.Property("ClaimType") - .HasColumnType("nvarchar(max)"); - - b.Property("ClaimValue") - .HasColumnType("nvarchar(max)"); - - b.Property("UserId") - .IsRequired() - .HasColumnType("nvarchar(450)"); - - b.HasKey("Id"); - - b.HasIndex("UserId"); - - b.ToTable("AspNetUserClaims", (string)null); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => - { - b.Property("LoginProvider") - .HasColumnType("nvarchar(450)"); + b.Property("CreatedDate") + .HasColumnType("datetime2"); - b.Property("ProviderKey") - .HasColumnType("nvarchar(450)"); + b.Property("DeleteCheck") + .HasColumnType("bit"); - b.Property("ProviderDisplayName") + b.Property("Email") .HasColumnType("nvarchar(max)"); - b.Property("UserId") - .IsRequired() - .HasColumnType("nvarchar(450)"); - - b.HasKey("LoginProvider", "ProviderKey"); - - b.HasIndex("UserId"); - - b.ToTable("AspNetUserLogins", (string)null); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => - { - b.Property("UserId") - .HasColumnType("nvarchar(450)"); - - b.Property("RoleId") - .HasColumnType("nvarchar(450)"); - - b.HasKey("UserId", "RoleId"); - - b.HasIndex("RoleId"); - - b.ToTable("AspNetUserRoles", (string)null); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => - { - b.Property("UserId") - .HasColumnType("nvarchar(450)"); - - b.Property("LoginProvider") - .HasColumnType("nvarchar(450)"); + b.Property("LastLoginDate") + .HasColumnType("datetime2"); b.Property("Name") - .HasColumnType("nvarchar(450)"); - - b.Property("Value") .HasColumnType("nvarchar(max)"); - b.HasKey("UserId", "LoginProvider", "Name"); + b.Property("PlatformCodeId") + .HasColumnType("int"); + + b.HasKey("Id"); - b.ToTable("AspNetUserTokens", (string)null); + b.ToTable("Users"); }); modelBuilder.Entity("Entites.Models.Comment", b => { - b.HasOne("Entites.Models.Post", null) + b.HasOne("Entites.Models.Post", "Post") .WithMany("Comments") .HasForeignKey("PostId"); + + b.HasOne("Entites.Models.User", "User") + .WithMany() + .HasForeignKey("UserId"); + + b.Navigation("Post"); + + b.Navigation("User"); }); modelBuilder.Entity("Entites.Models.Like", b => { - b.HasOne("Entites.Models.Post", null) + b.HasOne("Entites.Models.Post", "Post") .WithMany("Likes") .HasForeignKey("PostId"); + + b.HasOne("Entites.Models.User", "User") + .WithMany("Like") + .HasForeignKey("UserId"); + + b.Navigation("Post"); + + b.Navigation("User"); }); modelBuilder.Entity("Entites.Models.PostPhoto", b => { - b.HasOne("Entites.Models.Post", null) + b.HasOne("Entites.Models.Post", "Post") .WithMany("PostPhotos") .HasForeignKey("PostId"); - }); - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => - { - b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null) - .WithMany() - .HasForeignKey("RoleId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => - { - b.HasOne("Entites.Models.User", null) - .WithMany() - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); + b.Navigation("Post"); }); - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => - { - b.HasOne("Entites.Models.User", null) - .WithMany() - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => + modelBuilder.Entity("Entites.Models.Profile", b => { - b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null) - .WithMany() - .HasForeignKey("RoleId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("Entites.Models.User", null) - .WithMany() - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); + b.HasOne("Entites.Models.User", "User") + .WithOne("Profile") + .HasForeignKey("Entites.Models.Profile", "UserId"); - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => - { - b.HasOne("Entites.Models.User", null) - .WithMany() - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); + b.Navigation("User"); }); modelBuilder.Entity("Entites.Models.Post", b => @@ -502,6 +263,13 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.Navigation("PostPhotos"); }); + + modelBuilder.Entity("Entites.Models.User", b => + { + b.Navigation("Like"); + + b.Navigation("Profile"); + }); #pragma warning restore 612, 618 } } diff --git a/EveryPinApi/Program.cs b/EveryPinApi/Program.cs index 97b4faa..d3be766 100644 --- a/EveryPinApi/Program.cs +++ b/EveryPinApi/Program.cs @@ -32,7 +32,6 @@ builder.Services.AddAutoMapper(typeof(Program)); - var app = builder.Build(); // Configure the HTTP request pipeline. diff --git a/Repository/RepositoryContext.cs b/Repository/RepositoryContext.cs index d11a244..b2b6afb 100644 --- a/Repository/RepositoryContext.cs +++ b/Repository/RepositoryContext.cs @@ -4,7 +4,9 @@ using Repository.Configuration; using System; using System.Collections.Generic; +using System.Diagnostics.Metrics; using System.Linq; +using System.Reflection.Metadata; using System.Text; using System.Threading.Tasks; @@ -24,6 +26,34 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) //modelBuilder.ApplyConfiguration(new UserConfiguration()); //modelBuilder.ApplyConfiguration(new ProfileConfiguration()); //modelBuilder.ApplyConfiguration(new RoleConfiguration()); + + //// 선택적 1:1 + //modelBuilder.Entity() + // .HasOne(user => user.Profile) + // .WithOne(profile => profile.User) + // .HasForeignKey(profile => profile.UserId) + // .IsRequired(false); + // + //// 일대다 + //modelBuilder.Entity() + // .HasMany(post => post.Comments) + // .WithOne(comment => comment.Post) + // .HasForeignKey(comment => comment.PostId); + //modelBuilder.Entity() + // .HasMany(post => post.Likes) + // .WithOne(comment => comment.Post) + // .HasForeignKey(comment => comment.PostId); + //modelBuilder.Entity() + // .HasMany(post => post.PostPhotos) + // .WithOne(comment => comment.Post) + // .HasForeignKey(comment => comment.PostId); + // + //// 1:1 + //modelBuilder.Entity() + // .HasOne(like => like.User) + // .WithOne(user => user.) + // .HasForeignKey(profile => profile.UserId); + // } public DbSet? Users { get; set; } @@ -32,5 +62,6 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) public DbSet? PostPhotos { get; set; } public DbSet? Likes { get; set; } public DbSet? Comments { get; set; } + public DbSet? CodeOAuthPlatforms { get; set; } } } \ No newline at end of file From 0228fea94dfea190e7342395d57c2d30b95f7beb Mon Sep 17 00:00:00 2001 From: PC_KYJ Date: Mon, 15 Jan 2024 22:31:30 +0900 Subject: [PATCH 08/12] =?UTF-8?q?Refactor:=20Identity=20=EC=82=AC=EC=9A=A9?= =?UTF-8?q?=ED=95=98=EC=97=AC=20=EB=AA=A8=EB=8D=B8=EA=B4=80=EA=B3=84=20?= =?UTF-8?q?=EA=B0=9C=EC=84=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- EveryPinApi.Entites/Entites.csproj | 4 + EveryPinApi.Entites/Models/Comment.cs | 3 +- EveryPinApi.Entites/Models/Like.cs | 3 +- EveryPinApi.Entites/Models/Post.cs | 2 + EveryPinApi.Entites/Models/Profile.cs | 3 +- EveryPinApi.Entites/Models/User.cs | 13 +- EveryPinApi/EveryPinApi.csproj | 4 +- EveryPinApi/Extensions/ServiceExtensions.cs | 40 +- .../20240109120726_edit-models.Designer.cs | 279 ---------- .../Migrations/20240109120726_edit-models.cs | 210 ------- ...240109121241_add-PostPhoto-url.Designer.cs | 279 ---------- .../20240109121241_add-PostPhoto-url.cs | 22 - .../20240115132517_jwt-try-3.Designer.cs | 519 ++++++++++++++++++ .../Migrations/20240115132517_jwt-try-3.cs | 401 ++++++++++++++ .../RepositoryContextModelSnapshot.cs | 276 +++++++++- Repository/Repository.csproj | 2 +- Repository/RepositoryContext.cs | 4 +- 17 files changed, 1228 insertions(+), 836 deletions(-) delete mode 100644 EveryPinApi/Migrations/20240109120726_edit-models.Designer.cs delete mode 100644 EveryPinApi/Migrations/20240109120726_edit-models.cs delete mode 100644 EveryPinApi/Migrations/20240109121241_add-PostPhoto-url.Designer.cs delete mode 100644 EveryPinApi/Migrations/20240109121241_add-PostPhoto-url.cs create mode 100644 EveryPinApi/Migrations/20240115132517_jwt-try-3.Designer.cs create mode 100644 EveryPinApi/Migrations/20240115132517_jwt-try-3.cs diff --git a/EveryPinApi.Entites/Entites.csproj b/EveryPinApi.Entites/Entites.csproj index cfadb03..7bdefef 100644 --- a/EveryPinApi.Entites/Entites.csproj +++ b/EveryPinApi.Entites/Entites.csproj @@ -6,4 +6,8 @@ enable + + + + diff --git a/EveryPinApi.Entites/Models/Comment.cs b/EveryPinApi.Entites/Models/Comment.cs index d34ff4b..b11c2fc 100644 --- a/EveryPinApi.Entites/Models/Comment.cs +++ b/EveryPinApi.Entites/Models/Comment.cs @@ -15,7 +15,8 @@ public class Comment public int? PostId { get; set; } public Post? Post { get; set; } - public int? UserId { get; set; } + [ForeignKey("User")] + public required string UserId { get; set; } public User? User { get; set; } public string? CommentMessage { get; set; } diff --git a/EveryPinApi.Entites/Models/Like.cs b/EveryPinApi.Entites/Models/Like.cs index a7c2641..4fe42b1 100644 --- a/EveryPinApi.Entites/Models/Like.cs +++ b/EveryPinApi.Entites/Models/Like.cs @@ -15,7 +15,8 @@ public class Like public int? PostId { get; set; } public Post? Post { get; set; } - public int? UserId { get; set; } + [ForeignKey("User")] + public required string UserId { get; set; } public User? User { get; set; } public DateTime? CreatedDate { get; set; } = DateTime.Now; diff --git a/EveryPinApi.Entites/Models/Post.cs b/EveryPinApi.Entites/Models/Post.cs index ecc7fa8..a3229ed 100644 --- a/EveryPinApi.Entites/Models/Post.cs +++ b/EveryPinApi.Entites/Models/Post.cs @@ -12,6 +12,8 @@ public class Post [Column("PostId")] public int PostId { get; set; } public string? PostContent { get; set; } + [ForeignKey("User")] + public required string UserId { get; set; } public ICollection PostPhotos { get; } = new List(); public ICollection Likes { get; } = new List(); public ICollection Comments { get; } = new List(); diff --git a/EveryPinApi.Entites/Models/Profile.cs b/EveryPinApi.Entites/Models/Profile.cs index 300ba29..9da0a4c 100644 --- a/EveryPinApi.Entites/Models/Profile.cs +++ b/EveryPinApi.Entites/Models/Profile.cs @@ -12,7 +12,8 @@ public class Profile [Column("ProfileId")] public int Id { get; set; } - public int? UserId { get; set; } + [ForeignKey("User")] + public required string UserId { get; set; } public User? User { get; set; } public string? Name { get; set; } diff --git a/EveryPinApi.Entites/Models/User.cs b/EveryPinApi.Entites/Models/User.cs index 497a70c..3d19c7c 100644 --- a/EveryPinApi.Entites/Models/User.cs +++ b/EveryPinApi.Entites/Models/User.cs @@ -1,4 +1,5 @@ -using System; +using Microsoft.AspNetCore.Identity; +using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations.Schema; using System.Linq; @@ -7,15 +8,15 @@ namespace Entites.Models { - public class User + public class User : IdentityUser { - [Column("UserId")] - public int Id { get; set; } + //[Column("UserId")] + //public int Id { get; set; } public int PlatformCodeId { get; set; } public Profile? Profile { get; set; } public ICollection Like { get; set; } = new List(); - public string? Name { get; set; } - public string? Email { get; set; } + //public string? Name { get; set; } + //public string? Email { get; set; } public DateTime CreatedDate { get; set; } public DateTime LastLoginDate { get; set; } public bool DeleteCheck { get; set; } diff --git a/EveryPinApi/EveryPinApi.csproj b/EveryPinApi/EveryPinApi.csproj index caa6dd8..4376bb2 100644 --- a/EveryPinApi/EveryPinApi.csproj +++ b/EveryPinApi/EveryPinApi.csproj @@ -8,8 +8,8 @@ - - + + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/EveryPinApi/Extensions/ServiceExtensions.cs b/EveryPinApi/Extensions/ServiceExtensions.cs index 67d2615..4414bcd 100644 --- a/EveryPinApi/Extensions/ServiceExtensions.cs +++ b/EveryPinApi/Extensions/ServiceExtensions.cs @@ -7,6 +7,7 @@ using Service.Contracts; using Service; using Service.Contracts; +using Microsoft.Extensions.Options; namespace EveryPinApi.Extensions { @@ -56,19 +57,30 @@ public static void ConfigureServiceManager(this IServiceCollection services) => public static void ConfigureSqlContext(this IServiceCollection services, IConfiguration configuration) => services.AddSqlServer(configuration.GetConnectionString("everypindb")); - //public static void ConfigureIdentity(this IServiceCollection services) - //{ - // var builder = services.AddIdentity(o => - // { - // o.Password.RequireDigit = true; - // o.Password.RequireLowercase = false; - // o.Password.RequireUppercase = false; - // o.Password.RequireNonAlphanumeric = false; - // o.Password.RequiredLength = 10; - // o.User.RequireUniqueEmail = true; - // }) - // .AddEntityFrameworkStores() - // .AddDefaultTokenProviders(); - //} + public static void ConfigureIdentity(this IServiceCollection services) + { + var builder = services.AddIdentity(option => + { + // Password settings. + option.Password.RequireDigit = true; + option.Password.RequireLowercase = false; + option.Password.RequireUppercase = false; + option.Password.RequireNonAlphanumeric = false; + option.Password.RequiredLength = 10; + //option.Password.RequiredUniqueChars = 1; + + // Lockout settings. + //options.Lockout.DefaultLockoutTimeSpan = TimeSpan.FromMinutes(5); + //options.Lockout.MaxFailedAccessAttempts = 5; + //options.Lockout.AllowedForNewUsers = true; + + // User settings. + option.User.AllowedUserNameCharacters = + "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._@+"; + option.User.RequireUniqueEmail = true; + }) + .AddEntityFrameworkStores() + .AddDefaultTokenProviders(); + } } } diff --git a/EveryPinApi/Migrations/20240109120726_edit-models.Designer.cs b/EveryPinApi/Migrations/20240109120726_edit-models.Designer.cs deleted file mode 100644 index 6a492ab..0000000 --- a/EveryPinApi/Migrations/20240109120726_edit-models.Designer.cs +++ /dev/null @@ -1,279 +0,0 @@ -// -using System; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Metadata; -using Microsoft.EntityFrameworkCore.Migrations; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; -using Repository; - -#nullable disable - -namespace EveryPinApi.Migrations -{ - [DbContext(typeof(RepositoryContext))] - [Migration("20240109120726_edit-models")] - partial class editmodels - { - /// - protected override void BuildTargetModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder - .HasAnnotation("ProductVersion", "7.0.14") - .HasAnnotation("Relational:MaxIdentifierLength", 128); - - SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); - - modelBuilder.Entity("Entites.Models.CodeOAuthPlatform", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int") - .HasColumnName("PlatformCodeId"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("PlatformName") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.HasKey("Id"); - - b.ToTable("CodeOAuthPlatforms"); - }); - - modelBuilder.Entity("Entites.Models.Comment", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int") - .HasColumnName("CommentId"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("CommentMessage") - .HasColumnType("nvarchar(max)"); - - b.Property("CreatedDate") - .HasColumnType("datetime2"); - - b.Property("PostId") - .HasColumnType("int"); - - b.Property("UserId") - .HasColumnType("int"); - - b.HasKey("Id"); - - b.HasIndex("PostId"); - - b.HasIndex("UserId"); - - b.ToTable("Comments"); - }); - - modelBuilder.Entity("Entites.Models.Like", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int") - .HasColumnName("LikeId"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("CreatedDate") - .HasColumnType("datetime2"); - - b.Property("PostId") - .HasColumnType("int"); - - b.Property("UserId") - .HasColumnType("int"); - - b.HasKey("Id"); - - b.HasIndex("PostId"); - - b.HasIndex("UserId"); - - b.ToTable("Likes"); - }); - - modelBuilder.Entity("Entites.Models.Post", b => - { - b.Property("PostId") - .ValueGeneratedOnAdd() - .HasColumnType("int") - .HasColumnName("PostId"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("PostId")); - - b.Property("CreatedDate") - .HasColumnType("datetime2"); - - b.Property("PostContent") - .HasColumnType("nvarchar(max)"); - - b.Property("UpdateDate") - .HasColumnType("datetime2"); - - b.HasKey("PostId"); - - b.ToTable("Posts"); - }); - - modelBuilder.Entity("Entites.Models.PostPhoto", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int") - .HasColumnName("PostPhotoId"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("PostId") - .HasColumnType("int"); - - b.HasKey("Id"); - - b.HasIndex("PostId"); - - b.ToTable("PostPhotos"); - }); - - modelBuilder.Entity("Entites.Models.Profile", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int") - .HasColumnName("ProfileId"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("CreatedDate") - .HasColumnType("datetime2"); - - b.Property("Name") - .HasColumnType("nvarchar(max)"); - - b.Property("PhotoUrl") - .HasColumnType("nvarchar(max)"); - - b.Property("SelfIntroduction") - .HasColumnType("nvarchar(max)"); - - b.Property("UpdatedDate") - .HasColumnType("datetime2"); - - b.Property("UserId") - .HasColumnType("int"); - - b.HasKey("Id"); - - b.HasIndex("UserId") - .IsUnique() - .HasFilter("[UserId] IS NOT NULL"); - - b.ToTable("Profiles"); - }); - - modelBuilder.Entity("Entites.Models.User", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int") - .HasColumnName("UserId"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("CreatedDate") - .HasColumnType("datetime2"); - - b.Property("DeleteCheck") - .HasColumnType("bit"); - - b.Property("Email") - .HasColumnType("nvarchar(max)"); - - b.Property("LastLoginDate") - .HasColumnType("datetime2"); - - b.Property("Name") - .HasColumnType("nvarchar(max)"); - - b.Property("PlatformCodeId") - .HasColumnType("int"); - - b.HasKey("Id"); - - b.ToTable("Users"); - }); - - modelBuilder.Entity("Entites.Models.Comment", b => - { - b.HasOne("Entites.Models.Post", "Post") - .WithMany("Comments") - .HasForeignKey("PostId"); - - b.HasOne("Entites.Models.User", "User") - .WithMany() - .HasForeignKey("UserId"); - - b.Navigation("Post"); - - b.Navigation("User"); - }); - - modelBuilder.Entity("Entites.Models.Like", b => - { - b.HasOne("Entites.Models.Post", "Post") - .WithMany("Likes") - .HasForeignKey("PostId"); - - b.HasOne("Entites.Models.User", "User") - .WithMany("Like") - .HasForeignKey("UserId"); - - b.Navigation("Post"); - - b.Navigation("User"); - }); - - modelBuilder.Entity("Entites.Models.PostPhoto", b => - { - b.HasOne("Entites.Models.Post", "Post") - .WithMany("PostPhotos") - .HasForeignKey("PostId"); - - b.Navigation("Post"); - }); - - modelBuilder.Entity("Entites.Models.Profile", b => - { - b.HasOne("Entites.Models.User", "User") - .WithOne("Profile") - .HasForeignKey("Entites.Models.Profile", "UserId"); - - b.Navigation("User"); - }); - - modelBuilder.Entity("Entites.Models.Post", b => - { - b.Navigation("Comments"); - - b.Navigation("Likes"); - - b.Navigation("PostPhotos"); - }); - - modelBuilder.Entity("Entites.Models.User", b => - { - b.Navigation("Like"); - - b.Navigation("Profile"); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/EveryPinApi/Migrations/20240109120726_edit-models.cs b/EveryPinApi/Migrations/20240109120726_edit-models.cs deleted file mode 100644 index 2a9fe56..0000000 --- a/EveryPinApi/Migrations/20240109120726_edit-models.cs +++ /dev/null @@ -1,210 +0,0 @@ -using System; -using Microsoft.EntityFrameworkCore.Migrations; - -#nullable disable - -namespace EveryPinApi.Migrations -{ - /// - public partial class editmodels : Migration - { - /// - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.CreateTable( - name: "CodeOAuthPlatforms", - columns: table => new - { - PlatformCodeId = table.Column(type: "int", nullable: false) - .Annotation("SqlServer:Identity", "1, 1"), - PlatformName = table.Column(type: "nvarchar(max)", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_CodeOAuthPlatforms", x => x.PlatformCodeId); - }); - - migrationBuilder.CreateTable( - name: "Posts", - columns: table => new - { - PostId = table.Column(type: "int", nullable: false) - .Annotation("SqlServer:Identity", "1, 1"), - PostContent = table.Column(type: "nvarchar(max)", nullable: true), - UpdateDate = table.Column(type: "datetime2", nullable: true), - CreatedDate = table.Column(type: "datetime2", nullable: true) - }, - constraints: table => - { - table.PrimaryKey("PK_Posts", x => x.PostId); - }); - - migrationBuilder.CreateTable( - name: "Users", - columns: table => new - { - UserId = table.Column(type: "int", nullable: false) - .Annotation("SqlServer:Identity", "1, 1"), - PlatformCodeId = table.Column(type: "int", nullable: false), - Name = table.Column(type: "nvarchar(max)", nullable: true), - Email = table.Column(type: "nvarchar(max)", nullable: true), - CreatedDate = table.Column(type: "datetime2", nullable: false), - LastLoginDate = table.Column(type: "datetime2", nullable: false), - DeleteCheck = table.Column(type: "bit", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_Users", x => x.UserId); - }); - - migrationBuilder.CreateTable( - name: "PostPhotos", - columns: table => new - { - PostPhotoId = table.Column(type: "int", nullable: false) - .Annotation("SqlServer:Identity", "1, 1"), - PostId = table.Column(type: "int", nullable: true) - }, - constraints: table => - { - table.PrimaryKey("PK_PostPhotos", x => x.PostPhotoId); - table.ForeignKey( - name: "FK_PostPhotos_Posts_PostId", - column: x => x.PostId, - principalTable: "Posts", - principalColumn: "PostId"); - }); - - migrationBuilder.CreateTable( - name: "Comments", - columns: table => new - { - CommentId = table.Column(type: "int", nullable: false) - .Annotation("SqlServer:Identity", "1, 1"), - PostId = table.Column(type: "int", nullable: true), - UserId = table.Column(type: "int", nullable: true), - CommentMessage = table.Column(type: "nvarchar(max)", nullable: true), - CreatedDate = table.Column(type: "datetime2", nullable: true) - }, - constraints: table => - { - table.PrimaryKey("PK_Comments", x => x.CommentId); - table.ForeignKey( - name: "FK_Comments_Posts_PostId", - column: x => x.PostId, - principalTable: "Posts", - principalColumn: "PostId"); - table.ForeignKey( - name: "FK_Comments_Users_UserId", - column: x => x.UserId, - principalTable: "Users", - principalColumn: "UserId"); - }); - - migrationBuilder.CreateTable( - name: "Likes", - columns: table => new - { - LikeId = table.Column(type: "int", nullable: false) - .Annotation("SqlServer:Identity", "1, 1"), - PostId = table.Column(type: "int", nullable: true), - UserId = table.Column(type: "int", nullable: true), - CreatedDate = table.Column(type: "datetime2", nullable: true) - }, - constraints: table => - { - table.PrimaryKey("PK_Likes", x => x.LikeId); - table.ForeignKey( - name: "FK_Likes_Posts_PostId", - column: x => x.PostId, - principalTable: "Posts", - principalColumn: "PostId"); - table.ForeignKey( - name: "FK_Likes_Users_UserId", - column: x => x.UserId, - principalTable: "Users", - principalColumn: "UserId"); - }); - - migrationBuilder.CreateTable( - name: "Profiles", - columns: table => new - { - ProfileId = table.Column(type: "int", nullable: false) - .Annotation("SqlServer:Identity", "1, 1"), - UserId = table.Column(type: "int", nullable: true), - Name = table.Column(type: "nvarchar(max)", nullable: true), - SelfIntroduction = table.Column(type: "nvarchar(max)", nullable: true), - PhotoUrl = table.Column(type: "nvarchar(max)", nullable: true), - UpdatedDate = table.Column(type: "datetime2", nullable: true), - CreatedDate = table.Column(type: "datetime2", nullable: true) - }, - constraints: table => - { - table.PrimaryKey("PK_Profiles", x => x.ProfileId); - table.ForeignKey( - name: "FK_Profiles_Users_UserId", - column: x => x.UserId, - principalTable: "Users", - principalColumn: "UserId"); - }); - - migrationBuilder.CreateIndex( - name: "IX_Comments_PostId", - table: "Comments", - column: "PostId"); - - migrationBuilder.CreateIndex( - name: "IX_Comments_UserId", - table: "Comments", - column: "UserId"); - - migrationBuilder.CreateIndex( - name: "IX_Likes_PostId", - table: "Likes", - column: "PostId"); - - migrationBuilder.CreateIndex( - name: "IX_Likes_UserId", - table: "Likes", - column: "UserId"); - - migrationBuilder.CreateIndex( - name: "IX_PostPhotos_PostId", - table: "PostPhotos", - column: "PostId"); - - migrationBuilder.CreateIndex( - name: "IX_Profiles_UserId", - table: "Profiles", - column: "UserId", - unique: true, - filter: "[UserId] IS NOT NULL"); - } - - /// - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropTable( - name: "CodeOAuthPlatforms"); - - migrationBuilder.DropTable( - name: "Comments"); - - migrationBuilder.DropTable( - name: "Likes"); - - migrationBuilder.DropTable( - name: "PostPhotos"); - - migrationBuilder.DropTable( - name: "Profiles"); - - migrationBuilder.DropTable( - name: "Posts"); - - migrationBuilder.DropTable( - name: "Users"); - } - } -} diff --git a/EveryPinApi/Migrations/20240109121241_add-PostPhoto-url.Designer.cs b/EveryPinApi/Migrations/20240109121241_add-PostPhoto-url.Designer.cs deleted file mode 100644 index 7e3e687..0000000 --- a/EveryPinApi/Migrations/20240109121241_add-PostPhoto-url.Designer.cs +++ /dev/null @@ -1,279 +0,0 @@ -// -using System; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Metadata; -using Microsoft.EntityFrameworkCore.Migrations; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; -using Repository; - -#nullable disable - -namespace EveryPinApi.Migrations -{ - [DbContext(typeof(RepositoryContext))] - [Migration("20240109121241_add-PostPhoto-url")] - partial class addPostPhotourl - { - /// - protected override void BuildTargetModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder - .HasAnnotation("ProductVersion", "7.0.14") - .HasAnnotation("Relational:MaxIdentifierLength", 128); - - SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); - - modelBuilder.Entity("Entites.Models.CodeOAuthPlatform", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int") - .HasColumnName("PlatformCodeId"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("PlatformName") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.HasKey("Id"); - - b.ToTable("CodeOAuthPlatforms"); - }); - - modelBuilder.Entity("Entites.Models.Comment", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int") - .HasColumnName("CommentId"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("CommentMessage") - .HasColumnType("nvarchar(max)"); - - b.Property("CreatedDate") - .HasColumnType("datetime2"); - - b.Property("PostId") - .HasColumnType("int"); - - b.Property("UserId") - .HasColumnType("int"); - - b.HasKey("Id"); - - b.HasIndex("PostId"); - - b.HasIndex("UserId"); - - b.ToTable("Comments"); - }); - - modelBuilder.Entity("Entites.Models.Like", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int") - .HasColumnName("LikeId"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("CreatedDate") - .HasColumnType("datetime2"); - - b.Property("PostId") - .HasColumnType("int"); - - b.Property("UserId") - .HasColumnType("int"); - - b.HasKey("Id"); - - b.HasIndex("PostId"); - - b.HasIndex("UserId"); - - b.ToTable("Likes"); - }); - - modelBuilder.Entity("Entites.Models.Post", b => - { - b.Property("PostId") - .ValueGeneratedOnAdd() - .HasColumnType("int") - .HasColumnName("PostId"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("PostId")); - - b.Property("CreatedDate") - .HasColumnType("datetime2"); - - b.Property("PostContent") - .HasColumnType("nvarchar(max)"); - - b.Property("UpdateDate") - .HasColumnType("datetime2"); - - b.HasKey("PostId"); - - b.ToTable("Posts"); - }); - - modelBuilder.Entity("Entites.Models.PostPhoto", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int") - .HasColumnName("PostPhotoId"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("PostId") - .HasColumnType("int"); - - b.HasKey("Id"); - - b.HasIndex("PostId"); - - b.ToTable("PostPhotos"); - }); - - modelBuilder.Entity("Entites.Models.Profile", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int") - .HasColumnName("ProfileId"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("CreatedDate") - .HasColumnType("datetime2"); - - b.Property("Name") - .HasColumnType("nvarchar(max)"); - - b.Property("PhotoUrl") - .HasColumnType("nvarchar(max)"); - - b.Property("SelfIntroduction") - .HasColumnType("nvarchar(max)"); - - b.Property("UpdatedDate") - .HasColumnType("datetime2"); - - b.Property("UserId") - .HasColumnType("int"); - - b.HasKey("Id"); - - b.HasIndex("UserId") - .IsUnique() - .HasFilter("[UserId] IS NOT NULL"); - - b.ToTable("Profiles"); - }); - - modelBuilder.Entity("Entites.Models.User", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int") - .HasColumnName("UserId"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("CreatedDate") - .HasColumnType("datetime2"); - - b.Property("DeleteCheck") - .HasColumnType("bit"); - - b.Property("Email") - .HasColumnType("nvarchar(max)"); - - b.Property("LastLoginDate") - .HasColumnType("datetime2"); - - b.Property("Name") - .HasColumnType("nvarchar(max)"); - - b.Property("PlatformCodeId") - .HasColumnType("int"); - - b.HasKey("Id"); - - b.ToTable("Users"); - }); - - modelBuilder.Entity("Entites.Models.Comment", b => - { - b.HasOne("Entites.Models.Post", "Post") - .WithMany("Comments") - .HasForeignKey("PostId"); - - b.HasOne("Entites.Models.User", "User") - .WithMany() - .HasForeignKey("UserId"); - - b.Navigation("Post"); - - b.Navigation("User"); - }); - - modelBuilder.Entity("Entites.Models.Like", b => - { - b.HasOne("Entites.Models.Post", "Post") - .WithMany("Likes") - .HasForeignKey("PostId"); - - b.HasOne("Entites.Models.User", "User") - .WithMany("Like") - .HasForeignKey("UserId"); - - b.Navigation("Post"); - - b.Navigation("User"); - }); - - modelBuilder.Entity("Entites.Models.PostPhoto", b => - { - b.HasOne("Entites.Models.Post", "Post") - .WithMany("PostPhotos") - .HasForeignKey("PostId"); - - b.Navigation("Post"); - }); - - modelBuilder.Entity("Entites.Models.Profile", b => - { - b.HasOne("Entites.Models.User", "User") - .WithOne("Profile") - .HasForeignKey("Entites.Models.Profile", "UserId"); - - b.Navigation("User"); - }); - - modelBuilder.Entity("Entites.Models.Post", b => - { - b.Navigation("Comments"); - - b.Navigation("Likes"); - - b.Navigation("PostPhotos"); - }); - - modelBuilder.Entity("Entites.Models.User", b => - { - b.Navigation("Like"); - - b.Navigation("Profile"); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/EveryPinApi/Migrations/20240109121241_add-PostPhoto-url.cs b/EveryPinApi/Migrations/20240109121241_add-PostPhoto-url.cs deleted file mode 100644 index da206af..0000000 --- a/EveryPinApi/Migrations/20240109121241_add-PostPhoto-url.cs +++ /dev/null @@ -1,22 +0,0 @@ -using Microsoft.EntityFrameworkCore.Migrations; - -#nullable disable - -namespace EveryPinApi.Migrations -{ - /// - public partial class addPostPhotourl : Migration - { - /// - protected override void Up(MigrationBuilder migrationBuilder) - { - - } - - /// - protected override void Down(MigrationBuilder migrationBuilder) - { - - } - } -} diff --git a/EveryPinApi/Migrations/20240115132517_jwt-try-3.Designer.cs b/EveryPinApi/Migrations/20240115132517_jwt-try-3.Designer.cs new file mode 100644 index 0000000..5c16397 --- /dev/null +++ b/EveryPinApi/Migrations/20240115132517_jwt-try-3.Designer.cs @@ -0,0 +1,519 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Repository; + +#nullable disable + +namespace EveryPinApi.Migrations +{ + [DbContext(typeof(RepositoryContext))] + [Migration("20240115132517_jwt-try-3")] + partial class jwttry3 + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.15") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("Entites.Models.CodeOAuthPlatform", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int") + .HasColumnName("PlatformCodeId"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("PlatformName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("CodeOAuthPlatforms"); + }); + + modelBuilder.Entity("Entites.Models.Comment", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int") + .HasColumnName("CommentId"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("CommentMessage") + .HasColumnType("nvarchar(max)"); + + b.Property("CreatedDate") + .HasColumnType("datetime2"); + + b.Property("PostId") + .HasColumnType("int"); + + b.Property("UserId") + .HasColumnType("int"); + + b.Property("UserId1") + .HasColumnType("nvarchar(450)"); + + b.HasKey("Id"); + + b.HasIndex("PostId"); + + b.HasIndex("UserId1"); + + b.ToTable("Comments"); + }); + + modelBuilder.Entity("Entites.Models.Like", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int") + .HasColumnName("LikeId"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("CreatedDate") + .HasColumnType("datetime2"); + + b.Property("PostId") + .HasColumnType("int"); + + b.Property("UserId") + .HasColumnType("int"); + + b.Property("UserId1") + .HasColumnType("nvarchar(450)"); + + b.HasKey("Id"); + + b.HasIndex("PostId"); + + b.HasIndex("UserId1"); + + b.ToTable("Likes"); + }); + + modelBuilder.Entity("Entites.Models.Post", b => + { + b.Property("PostId") + .ValueGeneratedOnAdd() + .HasColumnType("int") + .HasColumnName("PostId"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("PostId")); + + b.Property("CreatedDate") + .HasColumnType("datetime2"); + + b.Property("PostContent") + .HasColumnType("nvarchar(max)"); + + b.Property("UpdateDate") + .HasColumnType("datetime2"); + + b.HasKey("PostId"); + + b.ToTable("Posts"); + }); + + modelBuilder.Entity("Entites.Models.PostPhoto", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int") + .HasColumnName("PostPhotoId"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("PostId") + .HasColumnType("int"); + + b.Property("photoUrl") + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.HasIndex("PostId"); + + b.ToTable("PostPhotos"); + }); + + modelBuilder.Entity("Entites.Models.Profile", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int") + .HasColumnName("ProfileId"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("CreatedDate") + .HasColumnType("datetime2"); + + b.Property("Name") + .HasColumnType("nvarchar(max)"); + + b.Property("PhotoUrl") + .HasColumnType("nvarchar(max)"); + + b.Property("SelfIntroduction") + .HasColumnType("nvarchar(max)"); + + b.Property("UpdatedDate") + .HasColumnType("datetime2"); + + b.Property("UserId") + .IsRequired() + .HasColumnType("nvarchar(450)"); + + b.HasKey("Id"); + + b.HasIndex("UserId") + .IsUnique(); + + b.ToTable("Profiles"); + }); + + modelBuilder.Entity("Entites.Models.User", b => + { + b.Property("Id") + .HasColumnType("nvarchar(450)"); + + b.Property("AccessFailedCount") + .HasColumnType("int"); + + b.Property("ConcurrencyStamp") + .IsConcurrencyToken() + .HasColumnType("nvarchar(max)"); + + b.Property("CreatedDate") + .HasColumnType("datetime2"); + + b.Property("DeleteCheck") + .HasColumnType("bit"); + + b.Property("Email") + .HasMaxLength(256) + .HasColumnType("nvarchar(256)"); + + b.Property("EmailConfirmed") + .HasColumnType("bit"); + + b.Property("LastLoginDate") + .HasColumnType("datetime2"); + + b.Property("LockoutEnabled") + .HasColumnType("bit"); + + b.Property("LockoutEnd") + .HasColumnType("datetimeoffset"); + + b.Property("NormalizedEmail") + .HasMaxLength(256) + .HasColumnType("nvarchar(256)"); + + b.Property("NormalizedUserName") + .HasMaxLength(256) + .HasColumnType("nvarchar(256)"); + + b.Property("PasswordHash") + .HasColumnType("nvarchar(max)"); + + b.Property("PhoneNumber") + .HasColumnType("nvarchar(max)"); + + b.Property("PhoneNumberConfirmed") + .HasColumnType("bit"); + + b.Property("PlatformCodeId") + .HasColumnType("int"); + + b.Property("SecurityStamp") + .HasColumnType("nvarchar(max)"); + + b.Property("TwoFactorEnabled") + .HasColumnType("bit"); + + b.Property("UserName") + .HasMaxLength(256) + .HasColumnType("nvarchar(256)"); + + b.HasKey("Id"); + + b.HasIndex("NormalizedEmail") + .HasDatabaseName("EmailIndex"); + + b.HasIndex("NormalizedUserName") + .IsUnique() + .HasDatabaseName("UserNameIndex") + .HasFilter("[NormalizedUserName] IS NOT NULL"); + + b.ToTable("AspNetUsers", (string)null); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRole", b => + { + b.Property("Id") + .HasColumnType("nvarchar(450)"); + + b.Property("ConcurrencyStamp") + .IsConcurrencyToken() + .HasColumnType("nvarchar(max)"); + + b.Property("Name") + .HasMaxLength(256) + .HasColumnType("nvarchar(256)"); + + b.Property("NormalizedName") + .HasMaxLength(256) + .HasColumnType("nvarchar(256)"); + + b.HasKey("Id"); + + b.HasIndex("NormalizedName") + .IsUnique() + .HasDatabaseName("RoleNameIndex") + .HasFilter("[NormalizedName] IS NOT NULL"); + + b.ToTable("AspNetRoles", (string)null); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ClaimType") + .HasColumnType("nvarchar(max)"); + + b.Property("ClaimValue") + .HasColumnType("nvarchar(max)"); + + b.Property("RoleId") + .IsRequired() + .HasColumnType("nvarchar(450)"); + + b.HasKey("Id"); + + b.HasIndex("RoleId"); + + b.ToTable("AspNetRoleClaims", (string)null); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ClaimType") + .HasColumnType("nvarchar(max)"); + + b.Property("ClaimValue") + .HasColumnType("nvarchar(max)"); + + b.Property("UserId") + .IsRequired() + .HasColumnType("nvarchar(450)"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("AspNetUserClaims", (string)null); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => + { + b.Property("LoginProvider") + .HasColumnType("nvarchar(450)"); + + b.Property("ProviderKey") + .HasColumnType("nvarchar(450)"); + + b.Property("ProviderDisplayName") + .HasColumnType("nvarchar(max)"); + + b.Property("UserId") + .IsRequired() + .HasColumnType("nvarchar(450)"); + + b.HasKey("LoginProvider", "ProviderKey"); + + b.HasIndex("UserId"); + + b.ToTable("AspNetUserLogins", (string)null); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => + { + b.Property("UserId") + .HasColumnType("nvarchar(450)"); + + b.Property("RoleId") + .HasColumnType("nvarchar(450)"); + + b.HasKey("UserId", "RoleId"); + + b.HasIndex("RoleId"); + + b.ToTable("AspNetUserRoles", (string)null); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => + { + b.Property("UserId") + .HasColumnType("nvarchar(450)"); + + b.Property("LoginProvider") + .HasColumnType("nvarchar(450)"); + + b.Property("Name") + .HasColumnType("nvarchar(450)"); + + b.Property("Value") + .HasColumnType("nvarchar(max)"); + + b.HasKey("UserId", "LoginProvider", "Name"); + + b.ToTable("AspNetUserTokens", (string)null); + }); + + modelBuilder.Entity("Entites.Models.Comment", b => + { + b.HasOne("Entites.Models.Post", "Post") + .WithMany("Comments") + .HasForeignKey("PostId"); + + b.HasOne("Entites.Models.User", "User") + .WithMany() + .HasForeignKey("UserId1"); + + b.Navigation("Post"); + + b.Navigation("User"); + }); + + modelBuilder.Entity("Entites.Models.Like", b => + { + b.HasOne("Entites.Models.Post", "Post") + .WithMany("Likes") + .HasForeignKey("PostId"); + + b.HasOne("Entites.Models.User", "User") + .WithMany("Like") + .HasForeignKey("UserId1"); + + b.Navigation("Post"); + + b.Navigation("User"); + }); + + modelBuilder.Entity("Entites.Models.PostPhoto", b => + { + b.HasOne("Entites.Models.Post", "Post") + .WithMany("PostPhotos") + .HasForeignKey("PostId"); + + b.Navigation("Post"); + }); + + modelBuilder.Entity("Entites.Models.Profile", b => + { + b.HasOne("Entites.Models.User", "User") + .WithOne("Profile") + .HasForeignKey("Entites.Models.Profile", "UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("User"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => + { + b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null) + .WithMany() + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => + { + b.HasOne("Entites.Models.User", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => + { + b.HasOne("Entites.Models.User", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => + { + b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null) + .WithMany() + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Entites.Models.User", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => + { + b.HasOne("Entites.Models.User", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Entites.Models.Post", b => + { + b.Navigation("Comments"); + + b.Navigation("Likes"); + + b.Navigation("PostPhotos"); + }); + + modelBuilder.Entity("Entites.Models.User", b => + { + b.Navigation("Like"); + + b.Navigation("Profile"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/EveryPinApi/Migrations/20240115132517_jwt-try-3.cs b/EveryPinApi/Migrations/20240115132517_jwt-try-3.cs new file mode 100644 index 0000000..5449569 --- /dev/null +++ b/EveryPinApi/Migrations/20240115132517_jwt-try-3.cs @@ -0,0 +1,401 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace EveryPinApi.Migrations +{ + /// + public partial class jwttry3 : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "AspNetRoles", + columns: table => new + { + Id = table.Column(type: "nvarchar(450)", nullable: false), + Name = table.Column(type: "nvarchar(256)", maxLength: 256, nullable: true), + NormalizedName = table.Column(type: "nvarchar(256)", maxLength: 256, nullable: true), + ConcurrencyStamp = table.Column(type: "nvarchar(max)", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_AspNetRoles", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "AspNetUsers", + columns: table => new + { + Id = table.Column(type: "nvarchar(450)", nullable: false), + PlatformCodeId = table.Column(type: "int", nullable: false), + CreatedDate = table.Column(type: "datetime2", nullable: false), + LastLoginDate = table.Column(type: "datetime2", nullable: false), + DeleteCheck = table.Column(type: "bit", nullable: false), + UserName = table.Column(type: "nvarchar(256)", maxLength: 256, nullable: true), + NormalizedUserName = table.Column(type: "nvarchar(256)", maxLength: 256, nullable: true), + Email = table.Column(type: "nvarchar(256)", maxLength: 256, nullable: true), + NormalizedEmail = table.Column(type: "nvarchar(256)", maxLength: 256, nullable: true), + EmailConfirmed = table.Column(type: "bit", nullable: false), + PasswordHash = table.Column(type: "nvarchar(max)", nullable: true), + SecurityStamp = table.Column(type: "nvarchar(max)", nullable: true), + ConcurrencyStamp = table.Column(type: "nvarchar(max)", nullable: true), + PhoneNumber = table.Column(type: "nvarchar(max)", nullable: true), + PhoneNumberConfirmed = table.Column(type: "bit", nullable: false), + TwoFactorEnabled = table.Column(type: "bit", nullable: false), + LockoutEnd = table.Column(type: "datetimeoffset", nullable: true), + LockoutEnabled = table.Column(type: "bit", nullable: false), + AccessFailedCount = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_AspNetUsers", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "CodeOAuthPlatforms", + columns: table => new + { + PlatformCodeId = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + PlatformName = table.Column(type: "nvarchar(max)", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_CodeOAuthPlatforms", x => x.PlatformCodeId); + }); + + migrationBuilder.CreateTable( + name: "Posts", + columns: table => new + { + PostId = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + PostContent = table.Column(type: "nvarchar(max)", nullable: true), + UpdateDate = table.Column(type: "datetime2", nullable: true), + CreatedDate = table.Column(type: "datetime2", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_Posts", x => x.PostId); + }); + + migrationBuilder.CreateTable( + name: "AspNetRoleClaims", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + RoleId = table.Column(type: "nvarchar(450)", nullable: false), + ClaimType = table.Column(type: "nvarchar(max)", nullable: true), + ClaimValue = table.Column(type: "nvarchar(max)", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_AspNetRoleClaims", x => x.Id); + table.ForeignKey( + name: "FK_AspNetRoleClaims_AspNetRoles_RoleId", + column: x => x.RoleId, + principalTable: "AspNetRoles", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "AspNetUserClaims", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + UserId = table.Column(type: "nvarchar(450)", nullable: false), + ClaimType = table.Column(type: "nvarchar(max)", nullable: true), + ClaimValue = table.Column(type: "nvarchar(max)", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_AspNetUserClaims", x => x.Id); + table.ForeignKey( + name: "FK_AspNetUserClaims_AspNetUsers_UserId", + column: x => x.UserId, + principalTable: "AspNetUsers", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "AspNetUserLogins", + columns: table => new + { + LoginProvider = table.Column(type: "nvarchar(450)", nullable: false), + ProviderKey = table.Column(type: "nvarchar(450)", nullable: false), + ProviderDisplayName = table.Column(type: "nvarchar(max)", nullable: true), + UserId = table.Column(type: "nvarchar(450)", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_AspNetUserLogins", x => new { x.LoginProvider, x.ProviderKey }); + table.ForeignKey( + name: "FK_AspNetUserLogins_AspNetUsers_UserId", + column: x => x.UserId, + principalTable: "AspNetUsers", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "AspNetUserRoles", + columns: table => new + { + UserId = table.Column(type: "nvarchar(450)", nullable: false), + RoleId = table.Column(type: "nvarchar(450)", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_AspNetUserRoles", x => new { x.UserId, x.RoleId }); + table.ForeignKey( + name: "FK_AspNetUserRoles_AspNetRoles_RoleId", + column: x => x.RoleId, + principalTable: "AspNetRoles", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_AspNetUserRoles_AspNetUsers_UserId", + column: x => x.UserId, + principalTable: "AspNetUsers", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "AspNetUserTokens", + columns: table => new + { + UserId = table.Column(type: "nvarchar(450)", nullable: false), + LoginProvider = table.Column(type: "nvarchar(450)", nullable: false), + Name = table.Column(type: "nvarchar(450)", nullable: false), + Value = table.Column(type: "nvarchar(max)", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_AspNetUserTokens", x => new { x.UserId, x.LoginProvider, x.Name }); + table.ForeignKey( + name: "FK_AspNetUserTokens_AspNetUsers_UserId", + column: x => x.UserId, + principalTable: "AspNetUsers", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "Profiles", + columns: table => new + { + ProfileId = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + UserId = table.Column(type: "nvarchar(450)", nullable: false), + Name = table.Column(type: "nvarchar(max)", nullable: true), + SelfIntroduction = table.Column(type: "nvarchar(max)", nullable: true), + PhotoUrl = table.Column(type: "nvarchar(max)", nullable: true), + UpdatedDate = table.Column(type: "datetime2", nullable: true), + CreatedDate = table.Column(type: "datetime2", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_Profiles", x => x.ProfileId); + table.ForeignKey( + name: "FK_Profiles_AspNetUsers_UserId", + column: x => x.UserId, + principalTable: "AspNetUsers", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "Comments", + columns: table => new + { + CommentId = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + PostId = table.Column(type: "int", nullable: true), + UserId = table.Column(type: "int", nullable: true), + UserId1 = table.Column(type: "nvarchar(450)", nullable: true), + CommentMessage = table.Column(type: "nvarchar(max)", nullable: true), + CreatedDate = table.Column(type: "datetime2", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_Comments", x => x.CommentId); + table.ForeignKey( + name: "FK_Comments_AspNetUsers_UserId1", + column: x => x.UserId1, + principalTable: "AspNetUsers", + principalColumn: "Id"); + table.ForeignKey( + name: "FK_Comments_Posts_PostId", + column: x => x.PostId, + principalTable: "Posts", + principalColumn: "PostId"); + }); + + migrationBuilder.CreateTable( + name: "Likes", + columns: table => new + { + LikeId = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + PostId = table.Column(type: "int", nullable: true), + UserId = table.Column(type: "int", nullable: true), + UserId1 = table.Column(type: "nvarchar(450)", nullable: true), + CreatedDate = table.Column(type: "datetime2", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_Likes", x => x.LikeId); + table.ForeignKey( + name: "FK_Likes_AspNetUsers_UserId1", + column: x => x.UserId1, + principalTable: "AspNetUsers", + principalColumn: "Id"); + table.ForeignKey( + name: "FK_Likes_Posts_PostId", + column: x => x.PostId, + principalTable: "Posts", + principalColumn: "PostId"); + }); + + migrationBuilder.CreateTable( + name: "PostPhotos", + columns: table => new + { + PostPhotoId = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + PostId = table.Column(type: "int", nullable: true), + photoUrl = table.Column(type: "nvarchar(max)", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_PostPhotos", x => x.PostPhotoId); + table.ForeignKey( + name: "FK_PostPhotos_Posts_PostId", + column: x => x.PostId, + principalTable: "Posts", + principalColumn: "PostId"); + }); + + migrationBuilder.CreateIndex( + name: "IX_AspNetRoleClaims_RoleId", + table: "AspNetRoleClaims", + column: "RoleId"); + + migrationBuilder.CreateIndex( + name: "RoleNameIndex", + table: "AspNetRoles", + column: "NormalizedName", + unique: true, + filter: "[NormalizedName] IS NOT NULL"); + + migrationBuilder.CreateIndex( + name: "IX_AspNetUserClaims_UserId", + table: "AspNetUserClaims", + column: "UserId"); + + migrationBuilder.CreateIndex( + name: "IX_AspNetUserLogins_UserId", + table: "AspNetUserLogins", + column: "UserId"); + + migrationBuilder.CreateIndex( + name: "IX_AspNetUserRoles_RoleId", + table: "AspNetUserRoles", + column: "RoleId"); + + migrationBuilder.CreateIndex( + name: "EmailIndex", + table: "AspNetUsers", + column: "NormalizedEmail"); + + migrationBuilder.CreateIndex( + name: "UserNameIndex", + table: "AspNetUsers", + column: "NormalizedUserName", + unique: true, + filter: "[NormalizedUserName] IS NOT NULL"); + + migrationBuilder.CreateIndex( + name: "IX_Comments_PostId", + table: "Comments", + column: "PostId"); + + migrationBuilder.CreateIndex( + name: "IX_Comments_UserId1", + table: "Comments", + column: "UserId1"); + + migrationBuilder.CreateIndex( + name: "IX_Likes_PostId", + table: "Likes", + column: "PostId"); + + migrationBuilder.CreateIndex( + name: "IX_Likes_UserId1", + table: "Likes", + column: "UserId1"); + + migrationBuilder.CreateIndex( + name: "IX_PostPhotos_PostId", + table: "PostPhotos", + column: "PostId"); + + migrationBuilder.CreateIndex( + name: "IX_Profiles_UserId", + table: "Profiles", + column: "UserId", + unique: true); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "AspNetRoleClaims"); + + migrationBuilder.DropTable( + name: "AspNetUserClaims"); + + migrationBuilder.DropTable( + name: "AspNetUserLogins"); + + migrationBuilder.DropTable( + name: "AspNetUserRoles"); + + migrationBuilder.DropTable( + name: "AspNetUserTokens"); + + migrationBuilder.DropTable( + name: "CodeOAuthPlatforms"); + + migrationBuilder.DropTable( + name: "Comments"); + + migrationBuilder.DropTable( + name: "Likes"); + + migrationBuilder.DropTable( + name: "PostPhotos"); + + migrationBuilder.DropTable( + name: "Profiles"); + + migrationBuilder.DropTable( + name: "AspNetRoles"); + + migrationBuilder.DropTable( + name: "Posts"); + + migrationBuilder.DropTable( + name: "AspNetUsers"); + } + } +} diff --git a/EveryPinApi/Migrations/RepositoryContextModelSnapshot.cs b/EveryPinApi/Migrations/RepositoryContextModelSnapshot.cs index ec1ffb3..b5773f9 100644 --- a/EveryPinApi/Migrations/RepositoryContextModelSnapshot.cs +++ b/EveryPinApi/Migrations/RepositoryContextModelSnapshot.cs @@ -17,7 +17,7 @@ protected override void BuildModel(ModelBuilder modelBuilder) { #pragma warning disable 612, 618 modelBuilder - .HasAnnotation("ProductVersion", "7.0.14") + .HasAnnotation("ProductVersion", "7.0.15") .HasAnnotation("Relational:MaxIdentifierLength", 128); SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); @@ -61,11 +61,14 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.Property("UserId") .HasColumnType("int"); + b.Property("UserId1") + .HasColumnType("nvarchar(450)"); + b.HasKey("Id"); b.HasIndex("PostId"); - b.HasIndex("UserId"); + b.HasIndex("UserId1"); b.ToTable("Comments"); }); @@ -88,11 +91,14 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.Property("UserId") .HasColumnType("int"); + b.Property("UserId1") + .HasColumnType("nvarchar(450)"); + b.HasKey("Id"); b.HasIndex("PostId"); - b.HasIndex("UserId"); + b.HasIndex("UserId1"); b.ToTable("Likes"); }); @@ -132,6 +138,9 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.Property("PostId") .HasColumnType("int"); + b.Property("photoUrl") + .HasColumnType("nvarchar(max)"); + b.HasKey("Id"); b.HasIndex("PostId"); @@ -163,26 +172,29 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.Property("UpdatedDate") .HasColumnType("datetime2"); - b.Property("UserId") - .HasColumnType("int"); + b.Property("UserId") + .IsRequired() + .HasColumnType("nvarchar(450)"); b.HasKey("Id"); b.HasIndex("UserId") - .IsUnique() - .HasFilter("[UserId] IS NOT NULL"); + .IsUnique(); b.ToTable("Profiles"); }); modelBuilder.Entity("Entites.Models.User", b => { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int") - .HasColumnName("UserId"); + b.Property("Id") + .HasColumnType("nvarchar(450)"); - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + b.Property("AccessFailedCount") + .HasColumnType("int"); + + b.Property("ConcurrencyStamp") + .IsConcurrencyToken() + .HasColumnType("nvarchar(max)"); b.Property("CreatedDate") .HasColumnType("datetime2"); @@ -191,20 +203,195 @@ protected override void BuildModel(ModelBuilder modelBuilder) .HasColumnType("bit"); b.Property("Email") - .HasColumnType("nvarchar(max)"); + .HasMaxLength(256) + .HasColumnType("nvarchar(256)"); + + b.Property("EmailConfirmed") + .HasColumnType("bit"); b.Property("LastLoginDate") .HasColumnType("datetime2"); - b.Property("Name") + b.Property("LockoutEnabled") + .HasColumnType("bit"); + + b.Property("LockoutEnd") + .HasColumnType("datetimeoffset"); + + b.Property("NormalizedEmail") + .HasMaxLength(256) + .HasColumnType("nvarchar(256)"); + + b.Property("NormalizedUserName") + .HasMaxLength(256) + .HasColumnType("nvarchar(256)"); + + b.Property("PasswordHash") .HasColumnType("nvarchar(max)"); + b.Property("PhoneNumber") + .HasColumnType("nvarchar(max)"); + + b.Property("PhoneNumberConfirmed") + .HasColumnType("bit"); + b.Property("PlatformCodeId") .HasColumnType("int"); + b.Property("SecurityStamp") + .HasColumnType("nvarchar(max)"); + + b.Property("TwoFactorEnabled") + .HasColumnType("bit"); + + b.Property("UserName") + .HasMaxLength(256) + .HasColumnType("nvarchar(256)"); + + b.HasKey("Id"); + + b.HasIndex("NormalizedEmail") + .HasDatabaseName("EmailIndex"); + + b.HasIndex("NormalizedUserName") + .IsUnique() + .HasDatabaseName("UserNameIndex") + .HasFilter("[NormalizedUserName] IS NOT NULL"); + + b.ToTable("AspNetUsers", (string)null); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRole", b => + { + b.Property("Id") + .HasColumnType("nvarchar(450)"); + + b.Property("ConcurrencyStamp") + .IsConcurrencyToken() + .HasColumnType("nvarchar(max)"); + + b.Property("Name") + .HasMaxLength(256) + .HasColumnType("nvarchar(256)"); + + b.Property("NormalizedName") + .HasMaxLength(256) + .HasColumnType("nvarchar(256)"); + + b.HasKey("Id"); + + b.HasIndex("NormalizedName") + .IsUnique() + .HasDatabaseName("RoleNameIndex") + .HasFilter("[NormalizedName] IS NOT NULL"); + + b.ToTable("AspNetRoles", (string)null); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ClaimType") + .HasColumnType("nvarchar(max)"); + + b.Property("ClaimValue") + .HasColumnType("nvarchar(max)"); + + b.Property("RoleId") + .IsRequired() + .HasColumnType("nvarchar(450)"); + b.HasKey("Id"); - b.ToTable("Users"); + b.HasIndex("RoleId"); + + b.ToTable("AspNetRoleClaims", (string)null); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ClaimType") + .HasColumnType("nvarchar(max)"); + + b.Property("ClaimValue") + .HasColumnType("nvarchar(max)"); + + b.Property("UserId") + .IsRequired() + .HasColumnType("nvarchar(450)"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("AspNetUserClaims", (string)null); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => + { + b.Property("LoginProvider") + .HasColumnType("nvarchar(450)"); + + b.Property("ProviderKey") + .HasColumnType("nvarchar(450)"); + + b.Property("ProviderDisplayName") + .HasColumnType("nvarchar(max)"); + + b.Property("UserId") + .IsRequired() + .HasColumnType("nvarchar(450)"); + + b.HasKey("LoginProvider", "ProviderKey"); + + b.HasIndex("UserId"); + + b.ToTable("AspNetUserLogins", (string)null); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => + { + b.Property("UserId") + .HasColumnType("nvarchar(450)"); + + b.Property("RoleId") + .HasColumnType("nvarchar(450)"); + + b.HasKey("UserId", "RoleId"); + + b.HasIndex("RoleId"); + + b.ToTable("AspNetUserRoles", (string)null); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => + { + b.Property("UserId") + .HasColumnType("nvarchar(450)"); + + b.Property("LoginProvider") + .HasColumnType("nvarchar(450)"); + + b.Property("Name") + .HasColumnType("nvarchar(450)"); + + b.Property("Value") + .HasColumnType("nvarchar(max)"); + + b.HasKey("UserId", "LoginProvider", "Name"); + + b.ToTable("AspNetUserTokens", (string)null); }); modelBuilder.Entity("Entites.Models.Comment", b => @@ -215,7 +402,7 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.HasOne("Entites.Models.User", "User") .WithMany() - .HasForeignKey("UserId"); + .HasForeignKey("UserId1"); b.Navigation("Post"); @@ -230,7 +417,7 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.HasOne("Entites.Models.User", "User") .WithMany("Like") - .HasForeignKey("UserId"); + .HasForeignKey("UserId1"); b.Navigation("Post"); @@ -250,11 +437,64 @@ protected override void BuildModel(ModelBuilder modelBuilder) { b.HasOne("Entites.Models.User", "User") .WithOne("Profile") - .HasForeignKey("Entites.Models.Profile", "UserId"); + .HasForeignKey("Entites.Models.Profile", "UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); b.Navigation("User"); }); + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => + { + b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null) + .WithMany() + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => + { + b.HasOne("Entites.Models.User", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => + { + b.HasOne("Entites.Models.User", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => + { + b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null) + .WithMany() + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Entites.Models.User", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => + { + b.HasOne("Entites.Models.User", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + modelBuilder.Entity("Entites.Models.Post", b => { b.Navigation("Comments"); diff --git a/Repository/Repository.csproj b/Repository/Repository.csproj index 4d55a42..ca2b6b6 100644 --- a/Repository/Repository.csproj +++ b/Repository/Repository.csproj @@ -7,7 +7,7 @@ - + diff --git a/Repository/RepositoryContext.cs b/Repository/RepositoryContext.cs index b2b6afb..0f8938b 100644 --- a/Repository/RepositoryContext.cs +++ b/Repository/RepositoryContext.cs @@ -1,4 +1,5 @@ using Entites.Models; +using Microsoft.AspNetCore.Identity.EntityFrameworkCore; using Microsoft.EntityFrameworkCore; using Repository.Configuration; @@ -12,7 +13,7 @@ namespace Repository { - public class RepositoryContext: DbContext + public class RepositoryContext : IdentityDbContext { public RepositoryContext(DbContextOptions options): base(options) { @@ -56,7 +57,6 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) // } - public DbSet? Users { get; set; } public DbSet? Profiles { get; set; } public DbSet? Posts { get; set; } public DbSet? PostPhotos { get; set; } From f69c148faa3ff98fc57eecb7c840ca02d1915687 Mon Sep 17 00:00:00 2001 From: PC_KYJ Date: Mon, 15 Jan 2024 23:57:26 +0900 Subject: [PATCH 09/12] =?UTF-8?q?Feat:=20=EC=97=AD=ED=95=A0=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80,=20DTO=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/AuthenticationController.cs | 18 +- EveryPinApi/MappingProfile.cs | 1 + .../20240115134905_AddedRolesToDb.Designer.cs | 537 ++++++++++++++++++ .../20240115134905_AddedRolesToDb.cs | 188 ++++++ .../RepositoryContextModelSnapshot.cs | 42 +- Repository/Configuration/RoleConfiguration.cs | 31 + Repository/RepositoryContext.cs | 1 + Shared/DataTransferObject/RegistUserDto.cs | 17 + 8 files changed, 815 insertions(+), 20 deletions(-) create mode 100644 EveryPinApi/Migrations/20240115134905_AddedRolesToDb.Designer.cs create mode 100644 EveryPinApi/Migrations/20240115134905_AddedRolesToDb.cs create mode 100644 Repository/Configuration/RoleConfiguration.cs create mode 100644 Shared/DataTransferObject/RegistUserDto.cs diff --git a/EveryPinApi.Presentation/Controllers/AuthenticationController.cs b/EveryPinApi.Presentation/Controllers/AuthenticationController.cs index 8a50a23..0951fcb 100644 --- a/EveryPinApi.Presentation/Controllers/AuthenticationController.cs +++ b/EveryPinApi.Presentation/Controllers/AuthenticationController.cs @@ -1,4 +1,6 @@ -using Service.Contracts; +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc; +using Service.Contracts; using System; using System.Collections.Generic; using System.Linq; @@ -8,11 +10,11 @@ namespace EveryPinApi.Presentation.Controllers { - //[Route("api/authentication")] - //[ApiController] - //public class AuthenticationController : ControllerBase - //{ - // private readonly IServiceManager _service; - // public AuthenticationController(IServiceManager service) => _service = service; - //} + [Route("api/authentication")] + [ApiController] + public class AuthenticationController : ControllerBase + { + private readonly IServiceManager _service; + public AuthenticationController(IServiceManager service) => _service = service; + } } diff --git a/EveryPinApi/MappingProfile.cs b/EveryPinApi/MappingProfile.cs index ad07173..422a0a6 100644 --- a/EveryPinApi/MappingProfile.cs +++ b/EveryPinApi/MappingProfile.cs @@ -17,6 +17,7 @@ public MappingProfile() .ForMember(dest => dest.Comments, opt => opt.MapFrom(m => m.Comments)); CreateMap(); CreateMap(); + CreateMap(); } } } diff --git a/EveryPinApi/Migrations/20240115134905_AddedRolesToDb.Designer.cs b/EveryPinApi/Migrations/20240115134905_AddedRolesToDb.Designer.cs new file mode 100644 index 0000000..e135cc8 --- /dev/null +++ b/EveryPinApi/Migrations/20240115134905_AddedRolesToDb.Designer.cs @@ -0,0 +1,537 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Repository; + +#nullable disable + +namespace EveryPinApi.Migrations +{ + [DbContext(typeof(RepositoryContext))] + [Migration("20240115134905_AddedRolesToDb")] + partial class AddedRolesToDb + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.15") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("Entites.Models.CodeOAuthPlatform", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int") + .HasColumnName("PlatformCodeId"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("PlatformName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("CodeOAuthPlatforms"); + }); + + modelBuilder.Entity("Entites.Models.Comment", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int") + .HasColumnName("CommentId"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("CommentMessage") + .HasColumnType("nvarchar(max)"); + + b.Property("CreatedDate") + .HasColumnType("datetime2"); + + b.Property("PostId") + .HasColumnType("int"); + + b.Property("UserId") + .IsRequired() + .HasColumnType("nvarchar(450)"); + + b.HasKey("Id"); + + b.HasIndex("PostId"); + + b.HasIndex("UserId"); + + b.ToTable("Comments"); + }); + + modelBuilder.Entity("Entites.Models.Like", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int") + .HasColumnName("LikeId"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("CreatedDate") + .HasColumnType("datetime2"); + + b.Property("PostId") + .HasColumnType("int"); + + b.Property("UserId") + .IsRequired() + .HasColumnType("nvarchar(450)"); + + b.HasKey("Id"); + + b.HasIndex("PostId"); + + b.HasIndex("UserId"); + + b.ToTable("Likes"); + }); + + modelBuilder.Entity("Entites.Models.Post", b => + { + b.Property("PostId") + .ValueGeneratedOnAdd() + .HasColumnType("int") + .HasColumnName("PostId"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("PostId")); + + b.Property("CreatedDate") + .HasColumnType("datetime2"); + + b.Property("PostContent") + .HasColumnType("nvarchar(max)"); + + b.Property("UpdateDate") + .HasColumnType("datetime2"); + + b.Property("UserId") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("PostId"); + + b.ToTable("Posts"); + }); + + modelBuilder.Entity("Entites.Models.PostPhoto", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int") + .HasColumnName("PostPhotoId"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("PostId") + .HasColumnType("int"); + + b.Property("photoUrl") + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.HasIndex("PostId"); + + b.ToTable("PostPhotos"); + }); + + modelBuilder.Entity("Entites.Models.Profile", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int") + .HasColumnName("ProfileId"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("CreatedDate") + .HasColumnType("datetime2"); + + b.Property("Name") + .HasColumnType("nvarchar(max)"); + + b.Property("PhotoUrl") + .HasColumnType("nvarchar(max)"); + + b.Property("SelfIntroduction") + .HasColumnType("nvarchar(max)"); + + b.Property("UpdatedDate") + .HasColumnType("datetime2"); + + b.Property("UserId") + .IsRequired() + .HasColumnType("nvarchar(450)"); + + b.HasKey("Id"); + + b.HasIndex("UserId") + .IsUnique(); + + b.ToTable("Profiles"); + }); + + modelBuilder.Entity("Entites.Models.User", b => + { + b.Property("Id") + .HasColumnType("nvarchar(450)"); + + b.Property("AccessFailedCount") + .HasColumnType("int"); + + b.Property("ConcurrencyStamp") + .IsConcurrencyToken() + .HasColumnType("nvarchar(max)"); + + b.Property("CreatedDate") + .HasColumnType("datetime2"); + + b.Property("DeleteCheck") + .HasColumnType("bit"); + + b.Property("Email") + .HasMaxLength(256) + .HasColumnType("nvarchar(256)"); + + b.Property("EmailConfirmed") + .HasColumnType("bit"); + + b.Property("LastLoginDate") + .HasColumnType("datetime2"); + + b.Property("LockoutEnabled") + .HasColumnType("bit"); + + b.Property("LockoutEnd") + .HasColumnType("datetimeoffset"); + + b.Property("NormalizedEmail") + .HasMaxLength(256) + .HasColumnType("nvarchar(256)"); + + b.Property("NormalizedUserName") + .HasMaxLength(256) + .HasColumnType("nvarchar(256)"); + + b.Property("PasswordHash") + .HasColumnType("nvarchar(max)"); + + b.Property("PhoneNumber") + .HasColumnType("nvarchar(max)"); + + b.Property("PhoneNumberConfirmed") + .HasColumnType("bit"); + + b.Property("PlatformCodeId") + .HasColumnType("int"); + + b.Property("SecurityStamp") + .HasColumnType("nvarchar(max)"); + + b.Property("TwoFactorEnabled") + .HasColumnType("bit"); + + b.Property("UserName") + .HasMaxLength(256) + .HasColumnType("nvarchar(256)"); + + b.HasKey("Id"); + + b.HasIndex("NormalizedEmail") + .HasDatabaseName("EmailIndex"); + + b.HasIndex("NormalizedUserName") + .IsUnique() + .HasDatabaseName("UserNameIndex") + .HasFilter("[NormalizedUserName] IS NOT NULL"); + + b.ToTable("AspNetUsers", (string)null); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRole", b => + { + b.Property("Id") + .HasColumnType("nvarchar(450)"); + + b.Property("ConcurrencyStamp") + .IsConcurrencyToken() + .HasColumnType("nvarchar(max)"); + + b.Property("Name") + .HasMaxLength(256) + .HasColumnType("nvarchar(256)"); + + b.Property("NormalizedName") + .HasMaxLength(256) + .HasColumnType("nvarchar(256)"); + + b.HasKey("Id"); + + b.HasIndex("NormalizedName") + .IsUnique() + .HasDatabaseName("RoleNameIndex") + .HasFilter("[NormalizedName] IS NOT NULL"); + + b.ToTable("AspNetRoles", (string)null); + + b.HasData( + new + { + Id = "2e40618a-157e-49c0-baa4-a21365dad9c2", + Name = "NormalUser", + NormalizedName = "NORMALUSER" + }, + new + { + Id = "c2e99813-2533-4073-bbfe-d327d0b74546", + Name = "Administrator", + NormalizedName = "ADMINISTRATOR" + }); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ClaimType") + .HasColumnType("nvarchar(max)"); + + b.Property("ClaimValue") + .HasColumnType("nvarchar(max)"); + + b.Property("RoleId") + .IsRequired() + .HasColumnType("nvarchar(450)"); + + b.HasKey("Id"); + + b.HasIndex("RoleId"); + + b.ToTable("AspNetRoleClaims", (string)null); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ClaimType") + .HasColumnType("nvarchar(max)"); + + b.Property("ClaimValue") + .HasColumnType("nvarchar(max)"); + + b.Property("UserId") + .IsRequired() + .HasColumnType("nvarchar(450)"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("AspNetUserClaims", (string)null); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => + { + b.Property("LoginProvider") + .HasColumnType("nvarchar(450)"); + + b.Property("ProviderKey") + .HasColumnType("nvarchar(450)"); + + b.Property("ProviderDisplayName") + .HasColumnType("nvarchar(max)"); + + b.Property("UserId") + .IsRequired() + .HasColumnType("nvarchar(450)"); + + b.HasKey("LoginProvider", "ProviderKey"); + + b.HasIndex("UserId"); + + b.ToTable("AspNetUserLogins", (string)null); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => + { + b.Property("UserId") + .HasColumnType("nvarchar(450)"); + + b.Property("RoleId") + .HasColumnType("nvarchar(450)"); + + b.HasKey("UserId", "RoleId"); + + b.HasIndex("RoleId"); + + b.ToTable("AspNetUserRoles", (string)null); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => + { + b.Property("UserId") + .HasColumnType("nvarchar(450)"); + + b.Property("LoginProvider") + .HasColumnType("nvarchar(450)"); + + b.Property("Name") + .HasColumnType("nvarchar(450)"); + + b.Property("Value") + .HasColumnType("nvarchar(max)"); + + b.HasKey("UserId", "LoginProvider", "Name"); + + b.ToTable("AspNetUserTokens", (string)null); + }); + + modelBuilder.Entity("Entites.Models.Comment", b => + { + b.HasOne("Entites.Models.Post", "Post") + .WithMany("Comments") + .HasForeignKey("PostId"); + + b.HasOne("Entites.Models.User", "User") + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Post"); + + b.Navigation("User"); + }); + + modelBuilder.Entity("Entites.Models.Like", b => + { + b.HasOne("Entites.Models.Post", "Post") + .WithMany("Likes") + .HasForeignKey("PostId"); + + b.HasOne("Entites.Models.User", "User") + .WithMany("Like") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Post"); + + b.Navigation("User"); + }); + + modelBuilder.Entity("Entites.Models.PostPhoto", b => + { + b.HasOne("Entites.Models.Post", "Post") + .WithMany("PostPhotos") + .HasForeignKey("PostId"); + + b.Navigation("Post"); + }); + + modelBuilder.Entity("Entites.Models.Profile", b => + { + b.HasOne("Entites.Models.User", "User") + .WithOne("Profile") + .HasForeignKey("Entites.Models.Profile", "UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("User"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => + { + b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null) + .WithMany() + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => + { + b.HasOne("Entites.Models.User", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => + { + b.HasOne("Entites.Models.User", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => + { + b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null) + .WithMany() + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Entites.Models.User", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => + { + b.HasOne("Entites.Models.User", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Entites.Models.Post", b => + { + b.Navigation("Comments"); + + b.Navigation("Likes"); + + b.Navigation("PostPhotos"); + }); + + modelBuilder.Entity("Entites.Models.User", b => + { + b.Navigation("Like"); + + b.Navigation("Profile"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/EveryPinApi/Migrations/20240115134905_AddedRolesToDb.cs b/EveryPinApi/Migrations/20240115134905_AddedRolesToDb.cs new file mode 100644 index 0000000..08a29c0 --- /dev/null +++ b/EveryPinApi/Migrations/20240115134905_AddedRolesToDb.cs @@ -0,0 +1,188 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +#pragma warning disable CA1814 // Prefer jagged arrays over multidimensional + +namespace EveryPinApi.Migrations +{ + /// + public partial class AddedRolesToDb : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropForeignKey( + name: "FK_Comments_AspNetUsers_UserId1", + table: "Comments"); + + migrationBuilder.DropForeignKey( + name: "FK_Likes_AspNetUsers_UserId1", + table: "Likes"); + + migrationBuilder.DropIndex( + name: "IX_Likes_UserId1", + table: "Likes"); + + migrationBuilder.DropIndex( + name: "IX_Comments_UserId1", + table: "Comments"); + + migrationBuilder.DropColumn( + name: "UserId1", + table: "Likes"); + + migrationBuilder.DropColumn( + name: "UserId1", + table: "Comments"); + + migrationBuilder.AddColumn( + name: "UserId", + table: "Posts", + type: "nvarchar(max)", + nullable: false, + defaultValue: ""); + + migrationBuilder.AlterColumn( + name: "UserId", + table: "Likes", + type: "nvarchar(450)", + nullable: false, + defaultValue: "", + oldClrType: typeof(int), + oldType: "int", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "UserId", + table: "Comments", + type: "nvarchar(450)", + nullable: false, + defaultValue: "", + oldClrType: typeof(int), + oldType: "int", + oldNullable: true); + + migrationBuilder.InsertData( + table: "AspNetRoles", + columns: new[] { "Id", "ConcurrencyStamp", "Name", "NormalizedName" }, + values: new object[,] + { + { "2e40618a-157e-49c0-baa4-a21365dad9c2", null, "NormalUser", "NORMALUSER" }, + { "c2e99813-2533-4073-bbfe-d327d0b74546", null, "Administrator", "ADMINISTRATOR" } + }); + + migrationBuilder.CreateIndex( + name: "IX_Likes_UserId", + table: "Likes", + column: "UserId"); + + migrationBuilder.CreateIndex( + name: "IX_Comments_UserId", + table: "Comments", + column: "UserId"); + + migrationBuilder.AddForeignKey( + name: "FK_Comments_AspNetUsers_UserId", + table: "Comments", + column: "UserId", + principalTable: "AspNetUsers", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + + migrationBuilder.AddForeignKey( + name: "FK_Likes_AspNetUsers_UserId", + table: "Likes", + column: "UserId", + principalTable: "AspNetUsers", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropForeignKey( + name: "FK_Comments_AspNetUsers_UserId", + table: "Comments"); + + migrationBuilder.DropForeignKey( + name: "FK_Likes_AspNetUsers_UserId", + table: "Likes"); + + migrationBuilder.DropIndex( + name: "IX_Likes_UserId", + table: "Likes"); + + migrationBuilder.DropIndex( + name: "IX_Comments_UserId", + table: "Comments"); + + migrationBuilder.DeleteData( + table: "AspNetRoles", + keyColumn: "Id", + keyValue: "2e40618a-157e-49c0-baa4-a21365dad9c2"); + + migrationBuilder.DeleteData( + table: "AspNetRoles", + keyColumn: "Id", + keyValue: "c2e99813-2533-4073-bbfe-d327d0b74546"); + + migrationBuilder.DropColumn( + name: "UserId", + table: "Posts"); + + migrationBuilder.AlterColumn( + name: "UserId", + table: "Likes", + type: "int", + nullable: true, + oldClrType: typeof(string), + oldType: "nvarchar(450)"); + + migrationBuilder.AddColumn( + name: "UserId1", + table: "Likes", + type: "nvarchar(450)", + nullable: true); + + migrationBuilder.AlterColumn( + name: "UserId", + table: "Comments", + type: "int", + nullable: true, + oldClrType: typeof(string), + oldType: "nvarchar(450)"); + + migrationBuilder.AddColumn( + name: "UserId1", + table: "Comments", + type: "nvarchar(450)", + nullable: true); + + migrationBuilder.CreateIndex( + name: "IX_Likes_UserId1", + table: "Likes", + column: "UserId1"); + + migrationBuilder.CreateIndex( + name: "IX_Comments_UserId1", + table: "Comments", + column: "UserId1"); + + migrationBuilder.AddForeignKey( + name: "FK_Comments_AspNetUsers_UserId1", + table: "Comments", + column: "UserId1", + principalTable: "AspNetUsers", + principalColumn: "Id"); + + migrationBuilder.AddForeignKey( + name: "FK_Likes_AspNetUsers_UserId1", + table: "Likes", + column: "UserId1", + principalTable: "AspNetUsers", + principalColumn: "Id"); + } + } +} diff --git a/EveryPinApi/Migrations/RepositoryContextModelSnapshot.cs b/EveryPinApi/Migrations/RepositoryContextModelSnapshot.cs index b5773f9..3ad33ba 100644 --- a/EveryPinApi/Migrations/RepositoryContextModelSnapshot.cs +++ b/EveryPinApi/Migrations/RepositoryContextModelSnapshot.cs @@ -58,17 +58,15 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.Property("PostId") .HasColumnType("int"); - b.Property("UserId") - .HasColumnType("int"); - - b.Property("UserId1") + b.Property("UserId") + .IsRequired() .HasColumnType("nvarchar(450)"); b.HasKey("Id"); b.HasIndex("PostId"); - b.HasIndex("UserId1"); + b.HasIndex("UserId"); b.ToTable("Comments"); }); @@ -88,17 +86,15 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.Property("PostId") .HasColumnType("int"); - b.Property("UserId") - .HasColumnType("int"); - - b.Property("UserId1") + b.Property("UserId") + .IsRequired() .HasColumnType("nvarchar(450)"); b.HasKey("Id"); b.HasIndex("PostId"); - b.HasIndex("UserId1"); + b.HasIndex("UserId"); b.ToTable("Likes"); }); @@ -121,6 +117,10 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.Property("UpdateDate") .HasColumnType("datetime2"); + b.Property("UserId") + .IsRequired() + .HasColumnType("nvarchar(max)"); + b.HasKey("PostId"); b.ToTable("Posts"); @@ -286,6 +286,20 @@ protected override void BuildModel(ModelBuilder modelBuilder) .HasFilter("[NormalizedName] IS NOT NULL"); b.ToTable("AspNetRoles", (string)null); + + b.HasData( + new + { + Id = "2e40618a-157e-49c0-baa4-a21365dad9c2", + Name = "NormalUser", + NormalizedName = "NORMALUSER" + }, + new + { + Id = "c2e99813-2533-4073-bbfe-d327d0b74546", + Name = "Administrator", + NormalizedName = "ADMINISTRATOR" + }); }); modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => @@ -402,7 +416,9 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.HasOne("Entites.Models.User", "User") .WithMany() - .HasForeignKey("UserId1"); + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); b.Navigation("Post"); @@ -417,7 +433,9 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.HasOne("Entites.Models.User", "User") .WithMany("Like") - .HasForeignKey("UserId1"); + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); b.Navigation("Post"); diff --git a/Repository/Configuration/RoleConfiguration.cs b/Repository/Configuration/RoleConfiguration.cs new file mode 100644 index 0000000..0f18143 --- /dev/null +++ b/Repository/Configuration/RoleConfiguration.cs @@ -0,0 +1,31 @@ +using Microsoft.AspNetCore.Identity; +using Microsoft.EntityFrameworkCore.Metadata.Builders; +using Microsoft.EntityFrameworkCore; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Repository.Configuration +{ + public class RoleConfiguration : IEntityTypeConfiguration + { + public void Configure(EntityTypeBuilder builder) + { + builder.HasData( + new IdentityRole + { + Name = "NormalUser", + NormalizedName = "NORMALUSER" + }, + new IdentityRole + { + Name = "Administrator", + NormalizedName = "ADMINISTRATOR" + } + ); + } + } + +} diff --git a/Repository/RepositoryContext.cs b/Repository/RepositoryContext.cs index 0f8938b..f12e599 100644 --- a/Repository/RepositoryContext.cs +++ b/Repository/RepositoryContext.cs @@ -27,6 +27,7 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) //modelBuilder.ApplyConfiguration(new UserConfiguration()); //modelBuilder.ApplyConfiguration(new ProfileConfiguration()); //modelBuilder.ApplyConfiguration(new RoleConfiguration()); + modelBuilder.ApplyConfiguration(new RoleConfiguration()); //// 선택적 1:1 //modelBuilder.Entity() diff --git a/Shared/DataTransferObject/RegistUserDto.cs b/Shared/DataTransferObject/RegistUserDto.cs new file mode 100644 index 0000000..43b0608 --- /dev/null +++ b/Shared/DataTransferObject/RegistUserDto.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Shared.DataTransferObject +{ + public record RegistUserDto + { + public string? UserName { get; init; } + public string? Password { get; init; } + public string? Email { get; init; } + public string? PhoneNumber { get; init; } + public ICollection? Roles { get; init; } + } +} From b3bfc117ed6e93f8f96216b967ab82ec6fd3eed7 Mon Sep 17 00:00:00 2001 From: PC_KYJ Date: Tue, 16 Jan 2024 23:14:43 +0900 Subject: [PATCH 10/12] =?UTF-8?q?Feat:=20Model=20=EC=88=98=EC=A0=95,=20JWT?= =?UTF-8?q?=20Ioc=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- EveryPinApi.Entites/Models/User.cs | 2 +- .../Controllers/AuthenticationController.cs | 22 +- EveryPinApi/EveryPinApi.csproj | 1 + EveryPinApi/Extensions/ServiceExtensions.cs | 28 + .../20240116141216_refactor-model.Designer.cs | 540 ++++++++++++++++++ .../20240116141216_refactor-model.cs | 68 +++ .../RepositoryContextModelSnapshot.cs | 7 +- EveryPinApi/Program.cs | 3 +- Service.Contracts/IServiceManager.cs | 2 +- .../Models/IAuthenticationService.cs | 16 + Service/Models/AuthenticationService.cs | 41 ++ Service/ServiceManager.cs | 13 +- Shared/DataTransferObject/RegistUserDto.cs | 1 + 13 files changed, 734 insertions(+), 10 deletions(-) create mode 100644 EveryPinApi/Migrations/20240116141216_refactor-model.Designer.cs create mode 100644 EveryPinApi/Migrations/20240116141216_refactor-model.cs create mode 100644 Service.Contracts/Models/IAuthenticationService.cs create mode 100644 Service/Models/AuthenticationService.cs diff --git a/EveryPinApi.Entites/Models/User.cs b/EveryPinApi.Entites/Models/User.cs index 3d19c7c..3da2003 100644 --- a/EveryPinApi.Entites/Models/User.cs +++ b/EveryPinApi.Entites/Models/User.cs @@ -15,7 +15,7 @@ public class User : IdentityUser public int PlatformCodeId { get; set; } public Profile? Profile { get; set; } public ICollection Like { get; set; } = new List(); - //public string? Name { get; set; } + public string? Name { get; set; } //public string? Email { get; set; } public DateTime CreatedDate { get; set; } public DateTime LastLoginDate { get; set; } diff --git a/EveryPinApi.Presentation/Controllers/AuthenticationController.cs b/EveryPinApi.Presentation/Controllers/AuthenticationController.cs index 0951fcb..0bd7e53 100644 --- a/EveryPinApi.Presentation/Controllers/AuthenticationController.cs +++ b/EveryPinApi.Presentation/Controllers/AuthenticationController.cs @@ -1,6 +1,6 @@ using Microsoft.AspNetCore.Mvc; -using Microsoft.AspNetCore.Mvc; using Service.Contracts; +using Shared.DataTransferObject; using System; using System.Collections.Generic; using System.Linq; @@ -16,5 +16,25 @@ public class AuthenticationController : ControllerBase { private readonly IServiceManager _service; public AuthenticationController(IServiceManager service) => _service = service; + + [HttpPost] + //[ServiceFilter(typeof(ValidationFilterAttribute))] + public async Task RegisterUser([FromBody] RegistUserDto registUserDto) + { + var result = await + _service.AuthenticationService.RegisterUser(registUserDto); + + if (!result.Succeeded) + { + foreach (var error in result.Errors) + { + ModelState.TryAddModelError(error.Code, error.Description); + } + return BadRequest(ModelState); + } + + return StatusCode(201); + } } + } diff --git a/EveryPinApi/EveryPinApi.csproj b/EveryPinApi/EveryPinApi.csproj index 4376bb2..5d23e01 100644 --- a/EveryPinApi/EveryPinApi.csproj +++ b/EveryPinApi/EveryPinApi.csproj @@ -8,6 +8,7 @@ + all diff --git a/EveryPinApi/Extensions/ServiceExtensions.cs b/EveryPinApi/Extensions/ServiceExtensions.cs index 4414bcd..9ae75c1 100644 --- a/EveryPinApi/Extensions/ServiceExtensions.cs +++ b/EveryPinApi/Extensions/ServiceExtensions.cs @@ -8,6 +8,9 @@ using Service; using Service.Contracts; using Microsoft.Extensions.Options; +using Microsoft.AspNetCore.Authentication.JwtBearer; +using Microsoft.IdentityModel.Tokens; +using System.Text; namespace EveryPinApi.Extensions { @@ -82,5 +85,30 @@ public static void ConfigureIdentity(this IServiceCollection services) .AddEntityFrameworkStores() .AddDefaultTokenProviders(); } + + public static void ConfigureJWT(this IServiceCollection services, IConfiguration configuration) + { + var jwtSettings = configuration.GetSection("JwtSettings"); + var secretKey = jwtSettings["jwtSecret"]; + services.AddAuthentication(opt => + { + opt.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme; + opt.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme; + }) + .AddJwtBearer(options => + { + options.TokenValidationParameters = new TokenValidationParameters + { + ValidateIssuer = true, + ValidateAudience = true, + ValidateLifetime = true, + ValidateIssuerSigningKey = true, + ValidIssuer = jwtSettings["validIssuer"], + ValidAudience = jwtSettings["validAudience"], + IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(secretKey)) + }; + }); + } + } } diff --git a/EveryPinApi/Migrations/20240116141216_refactor-model.Designer.cs b/EveryPinApi/Migrations/20240116141216_refactor-model.Designer.cs new file mode 100644 index 0000000..eed8218 --- /dev/null +++ b/EveryPinApi/Migrations/20240116141216_refactor-model.Designer.cs @@ -0,0 +1,540 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Repository; + +#nullable disable + +namespace EveryPinApi.Migrations +{ + [DbContext(typeof(RepositoryContext))] + [Migration("20240116141216_refactor-model")] + partial class refactormodel + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.15") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("Entites.Models.CodeOAuthPlatform", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int") + .HasColumnName("PlatformCodeId"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("PlatformName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("CodeOAuthPlatforms"); + }); + + modelBuilder.Entity("Entites.Models.Comment", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int") + .HasColumnName("CommentId"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("CommentMessage") + .HasColumnType("nvarchar(max)"); + + b.Property("CreatedDate") + .HasColumnType("datetime2"); + + b.Property("PostId") + .HasColumnType("int"); + + b.Property("UserId") + .IsRequired() + .HasColumnType("nvarchar(450)"); + + b.HasKey("Id"); + + b.HasIndex("PostId"); + + b.HasIndex("UserId"); + + b.ToTable("Comments"); + }); + + modelBuilder.Entity("Entites.Models.Like", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int") + .HasColumnName("LikeId"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("CreatedDate") + .HasColumnType("datetime2"); + + b.Property("PostId") + .HasColumnType("int"); + + b.Property("UserId") + .IsRequired() + .HasColumnType("nvarchar(450)"); + + b.HasKey("Id"); + + b.HasIndex("PostId"); + + b.HasIndex("UserId"); + + b.ToTable("Likes"); + }); + + modelBuilder.Entity("Entites.Models.Post", b => + { + b.Property("PostId") + .ValueGeneratedOnAdd() + .HasColumnType("int") + .HasColumnName("PostId"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("PostId")); + + b.Property("CreatedDate") + .HasColumnType("datetime2"); + + b.Property("PostContent") + .HasColumnType("nvarchar(max)"); + + b.Property("UpdateDate") + .HasColumnType("datetime2"); + + b.Property("UserId") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("PostId"); + + b.ToTable("Posts"); + }); + + modelBuilder.Entity("Entites.Models.PostPhoto", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int") + .HasColumnName("PostPhotoId"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("PostId") + .HasColumnType("int"); + + b.Property("photoUrl") + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.HasIndex("PostId"); + + b.ToTable("PostPhotos"); + }); + + modelBuilder.Entity("Entites.Models.Profile", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int") + .HasColumnName("ProfileId"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("CreatedDate") + .HasColumnType("datetime2"); + + b.Property("Name") + .HasColumnType("nvarchar(max)"); + + b.Property("PhotoUrl") + .HasColumnType("nvarchar(max)"); + + b.Property("SelfIntroduction") + .HasColumnType("nvarchar(max)"); + + b.Property("UpdatedDate") + .HasColumnType("datetime2"); + + b.Property("UserId") + .IsRequired() + .HasColumnType("nvarchar(450)"); + + b.HasKey("Id"); + + b.HasIndex("UserId") + .IsUnique(); + + b.ToTable("Profiles"); + }); + + modelBuilder.Entity("Entites.Models.User", b => + { + b.Property("Id") + .HasColumnType("nvarchar(450)"); + + b.Property("AccessFailedCount") + .HasColumnType("int"); + + b.Property("ConcurrencyStamp") + .IsConcurrencyToken() + .HasColumnType("nvarchar(max)"); + + b.Property("CreatedDate") + .HasColumnType("datetime2"); + + b.Property("DeleteCheck") + .HasColumnType("bit"); + + b.Property("Email") + .HasMaxLength(256) + .HasColumnType("nvarchar(256)"); + + b.Property("EmailConfirmed") + .HasColumnType("bit"); + + b.Property("LastLoginDate") + .HasColumnType("datetime2"); + + b.Property("LockoutEnabled") + .HasColumnType("bit"); + + b.Property("LockoutEnd") + .HasColumnType("datetimeoffset"); + + b.Property("Name") + .HasColumnType("nvarchar(max)"); + + b.Property("NormalizedEmail") + .HasMaxLength(256) + .HasColumnType("nvarchar(256)"); + + b.Property("NormalizedUserName") + .HasMaxLength(256) + .HasColumnType("nvarchar(256)"); + + b.Property("PasswordHash") + .HasColumnType("nvarchar(max)"); + + b.Property("PhoneNumber") + .HasColumnType("nvarchar(max)"); + + b.Property("PhoneNumberConfirmed") + .HasColumnType("bit"); + + b.Property("PlatformCodeId") + .HasColumnType("int"); + + b.Property("SecurityStamp") + .HasColumnType("nvarchar(max)"); + + b.Property("TwoFactorEnabled") + .HasColumnType("bit"); + + b.Property("UserName") + .HasMaxLength(256) + .HasColumnType("nvarchar(256)"); + + b.HasKey("Id"); + + b.HasIndex("NormalizedEmail") + .HasDatabaseName("EmailIndex"); + + b.HasIndex("NormalizedUserName") + .IsUnique() + .HasDatabaseName("UserNameIndex") + .HasFilter("[NormalizedUserName] IS NOT NULL"); + + b.ToTable("AspNetUsers", (string)null); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRole", b => + { + b.Property("Id") + .HasColumnType("nvarchar(450)"); + + b.Property("ConcurrencyStamp") + .IsConcurrencyToken() + .HasColumnType("nvarchar(max)"); + + b.Property("Name") + .HasMaxLength(256) + .HasColumnType("nvarchar(256)"); + + b.Property("NormalizedName") + .HasMaxLength(256) + .HasColumnType("nvarchar(256)"); + + b.HasKey("Id"); + + b.HasIndex("NormalizedName") + .IsUnique() + .HasDatabaseName("RoleNameIndex") + .HasFilter("[NormalizedName] IS NOT NULL"); + + b.ToTable("AspNetRoles", (string)null); + + b.HasData( + new + { + Id = "7936c632-4ef6-4ff9-9417-555941ceadd4", + Name = "NormalUser", + NormalizedName = "NORMALUSER" + }, + new + { + Id = "c5127bc6-4ae3-40e2-b9c9-8c297f6810b1", + Name = "Administrator", + NormalizedName = "ADMINISTRATOR" + }); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ClaimType") + .HasColumnType("nvarchar(max)"); + + b.Property("ClaimValue") + .HasColumnType("nvarchar(max)"); + + b.Property("RoleId") + .IsRequired() + .HasColumnType("nvarchar(450)"); + + b.HasKey("Id"); + + b.HasIndex("RoleId"); + + b.ToTable("AspNetRoleClaims", (string)null); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ClaimType") + .HasColumnType("nvarchar(max)"); + + b.Property("ClaimValue") + .HasColumnType("nvarchar(max)"); + + b.Property("UserId") + .IsRequired() + .HasColumnType("nvarchar(450)"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("AspNetUserClaims", (string)null); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => + { + b.Property("LoginProvider") + .HasColumnType("nvarchar(450)"); + + b.Property("ProviderKey") + .HasColumnType("nvarchar(450)"); + + b.Property("ProviderDisplayName") + .HasColumnType("nvarchar(max)"); + + b.Property("UserId") + .IsRequired() + .HasColumnType("nvarchar(450)"); + + b.HasKey("LoginProvider", "ProviderKey"); + + b.HasIndex("UserId"); + + b.ToTable("AspNetUserLogins", (string)null); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => + { + b.Property("UserId") + .HasColumnType("nvarchar(450)"); + + b.Property("RoleId") + .HasColumnType("nvarchar(450)"); + + b.HasKey("UserId", "RoleId"); + + b.HasIndex("RoleId"); + + b.ToTable("AspNetUserRoles", (string)null); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => + { + b.Property("UserId") + .HasColumnType("nvarchar(450)"); + + b.Property("LoginProvider") + .HasColumnType("nvarchar(450)"); + + b.Property("Name") + .HasColumnType("nvarchar(450)"); + + b.Property("Value") + .HasColumnType("nvarchar(max)"); + + b.HasKey("UserId", "LoginProvider", "Name"); + + b.ToTable("AspNetUserTokens", (string)null); + }); + + modelBuilder.Entity("Entites.Models.Comment", b => + { + b.HasOne("Entites.Models.Post", "Post") + .WithMany("Comments") + .HasForeignKey("PostId"); + + b.HasOne("Entites.Models.User", "User") + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Post"); + + b.Navigation("User"); + }); + + modelBuilder.Entity("Entites.Models.Like", b => + { + b.HasOne("Entites.Models.Post", "Post") + .WithMany("Likes") + .HasForeignKey("PostId"); + + b.HasOne("Entites.Models.User", "User") + .WithMany("Like") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Post"); + + b.Navigation("User"); + }); + + modelBuilder.Entity("Entites.Models.PostPhoto", b => + { + b.HasOne("Entites.Models.Post", "Post") + .WithMany("PostPhotos") + .HasForeignKey("PostId"); + + b.Navigation("Post"); + }); + + modelBuilder.Entity("Entites.Models.Profile", b => + { + b.HasOne("Entites.Models.User", "User") + .WithOne("Profile") + .HasForeignKey("Entites.Models.Profile", "UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("User"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => + { + b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null) + .WithMany() + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => + { + b.HasOne("Entites.Models.User", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => + { + b.HasOne("Entites.Models.User", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => + { + b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null) + .WithMany() + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Entites.Models.User", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => + { + b.HasOne("Entites.Models.User", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Entites.Models.Post", b => + { + b.Navigation("Comments"); + + b.Navigation("Likes"); + + b.Navigation("PostPhotos"); + }); + + modelBuilder.Entity("Entites.Models.User", b => + { + b.Navigation("Like"); + + b.Navigation("Profile"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/EveryPinApi/Migrations/20240116141216_refactor-model.cs b/EveryPinApi/Migrations/20240116141216_refactor-model.cs new file mode 100644 index 0000000..ba484e5 --- /dev/null +++ b/EveryPinApi/Migrations/20240116141216_refactor-model.cs @@ -0,0 +1,68 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +#pragma warning disable CA1814 // Prefer jagged arrays over multidimensional + +namespace EveryPinApi.Migrations +{ + /// + public partial class refactormodel : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.DeleteData( + table: "AspNetRoles", + keyColumn: "Id", + keyValue: "2e40618a-157e-49c0-baa4-a21365dad9c2"); + + migrationBuilder.DeleteData( + table: "AspNetRoles", + keyColumn: "Id", + keyValue: "c2e99813-2533-4073-bbfe-d327d0b74546"); + + migrationBuilder.AddColumn( + name: "Name", + table: "AspNetUsers", + type: "nvarchar(max)", + nullable: true); + + migrationBuilder.InsertData( + table: "AspNetRoles", + columns: new[] { "Id", "ConcurrencyStamp", "Name", "NormalizedName" }, + values: new object[,] + { + { "7936c632-4ef6-4ff9-9417-555941ceadd4", null, "NormalUser", "NORMALUSER" }, + { "c5127bc6-4ae3-40e2-b9c9-8c297f6810b1", null, "Administrator", "ADMINISTRATOR" } + }); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DeleteData( + table: "AspNetRoles", + keyColumn: "Id", + keyValue: "7936c632-4ef6-4ff9-9417-555941ceadd4"); + + migrationBuilder.DeleteData( + table: "AspNetRoles", + keyColumn: "Id", + keyValue: "c5127bc6-4ae3-40e2-b9c9-8c297f6810b1"); + + migrationBuilder.DropColumn( + name: "Name", + table: "AspNetUsers"); + + migrationBuilder.InsertData( + table: "AspNetRoles", + columns: new[] { "Id", "ConcurrencyStamp", "Name", "NormalizedName" }, + values: new object[,] + { + { "2e40618a-157e-49c0-baa4-a21365dad9c2", null, "NormalUser", "NORMALUSER" }, + { "c2e99813-2533-4073-bbfe-d327d0b74546", null, "Administrator", "ADMINISTRATOR" } + }); + } + } +} diff --git a/EveryPinApi/Migrations/RepositoryContextModelSnapshot.cs b/EveryPinApi/Migrations/RepositoryContextModelSnapshot.cs index 3ad33ba..f3bad17 100644 --- a/EveryPinApi/Migrations/RepositoryContextModelSnapshot.cs +++ b/EveryPinApi/Migrations/RepositoryContextModelSnapshot.cs @@ -218,6 +218,9 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.Property("LockoutEnd") .HasColumnType("datetimeoffset"); + b.Property("Name") + .HasColumnType("nvarchar(max)"); + b.Property("NormalizedEmail") .HasMaxLength(256) .HasColumnType("nvarchar(256)"); @@ -290,13 +293,13 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.HasData( new { - Id = "2e40618a-157e-49c0-baa4-a21365dad9c2", + Id = "7936c632-4ef6-4ff9-9417-555941ceadd4", Name = "NormalUser", NormalizedName = "NORMALUSER" }, new { - Id = "c2e99813-2533-4073-bbfe-d327d0b74546", + Id = "c5127bc6-4ae3-40e2-b9c9-8c297f6810b1", Name = "Administrator", NormalizedName = "ADMINISTRATOR" }); diff --git a/EveryPinApi/Program.cs b/EveryPinApi/Program.cs index d3be766..384d09e 100644 --- a/EveryPinApi/Program.cs +++ b/EveryPinApi/Program.cs @@ -26,7 +26,8 @@ // Auth builder.Services.AddAuthentication(); -//builder.Services.ConfigureIdentity(); +builder.Services.ConfigureIdentity(); +builder.Services.ConfigureJWT(builder.Configuration); // AutoMapper builder.Services.AddAutoMapper(typeof(Program)); diff --git a/Service.Contracts/IServiceManager.cs b/Service.Contracts/IServiceManager.cs index 8513e87..bb7e004 100644 --- a/Service.Contracts/IServiceManager.cs +++ b/Service.Contracts/IServiceManager.cs @@ -14,7 +14,7 @@ public interface IServiceManager IPostPhotoService PostPhotoService { get; } IPostService PostService { get; } IProfileService ProfileService { get; } - //IUserService UserService { get; } + IAuthenticationService AuthenticationService { get; } } } diff --git a/Service.Contracts/Models/IAuthenticationService.cs b/Service.Contracts/Models/IAuthenticationService.cs new file mode 100644 index 0000000..96b6551 --- /dev/null +++ b/Service.Contracts/Models/IAuthenticationService.cs @@ -0,0 +1,16 @@ +using Microsoft.AspNetCore.Identity; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Shared.DataTransferObject; + +namespace Service.Contracts.Models +{ + public interface IAuthenticationService + { + Task RegisterUser(RegistUserDto registUserDto); + } + +} diff --git a/Service/Models/AuthenticationService.cs b/Service/Models/AuthenticationService.cs new file mode 100644 index 0000000..9863a86 --- /dev/null +++ b/Service/Models/AuthenticationService.cs @@ -0,0 +1,41 @@ +using AutoMapper; +using Entites.Models; +using Microsoft.AspNetCore.Identity; +using Microsoft.Extensions.Configuration; +using Service.Contracts.Models; +using Shared.DataTransferObject; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Service.Models +{ + internal sealed class AuthenticationService : IAuthenticationService + { + //private readonly ILoggerManager _logger; + private readonly IMapper _mapper; + private readonly UserManager _userManager; + private readonly IConfiguration _configuration; + + public AuthenticationService(IMapper mapper, + UserManager userManager, IConfiguration configuration) + { + //_logger = logger; + _mapper = mapper; + _userManager = userManager; + _configuration = configuration; + } + + public async Task RegisterUser(RegistUserDto registUserDto) + { + var user = _mapper.Map(registUserDto); + var result = await _userManager.CreateAsync(user, registUserDto.Password); + if (result.Succeeded) + await _userManager.AddToRolesAsync(user, registUserDto.Roles); + return result; + } + } + +} diff --git a/Service/ServiceManager.cs b/Service/ServiceManager.cs index 75274fc..9fe40e6 100644 --- a/Service/ServiceManager.cs +++ b/Service/ServiceManager.cs @@ -1,5 +1,9 @@ using AutoMapper; using Contracts.Repository; +using Entites.Models; +using Microsoft.AspNetCore.Identity; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.Logging; using Service.Contracts; using Service.Contracts.Models; using Service.Models; @@ -18,16 +22,17 @@ public sealed class ServiceManager : IServiceManager private readonly Lazy _postPhotoService; private readonly Lazy _postService; private readonly Lazy _profileService; - //private readonly Lazy _userService; + private readonly Lazy _authenticationService; - public ServiceManager(IRepositoryManager repositoryManager, IMapper mapper) + public ServiceManager(IRepositoryManager repositoryManager, IMapper mapper, UserManager userManager, IConfiguration configuration) { _commentService = new Lazy(() => new CommentService(repositoryManager, mapper)); _likeService = new Lazy(() => new LikeService(repositoryManager, mapper)); _postPhotoService = new Lazy(() => new PostPhotoService(repositoryManager, mapper)); _postService = new Lazy(() => new PostService(repositoryManager, mapper)); _profileService = new Lazy(() => new ProfileService(repositoryManager, mapper)); - //_userService = new Lazy(() => new UserService(repositoryManager)); + //_authenticationService = new Lazy(() => new AuthenticationService(logger, mapper, userManager, configuration)); + _authenticationService = new Lazy(() => new AuthenticationService(mapper, userManager, configuration)); } public ICommentService CommentService => _commentService.Value; @@ -35,6 +40,6 @@ public ServiceManager(IRepositoryManager repositoryManager, IMapper mapper) public IPostPhotoService PostPhotoService => _postPhotoService.Value; public IPostService PostService => _postService.Value; public IProfileService ProfileService => _profileService.Value; - //public IUserService UserService => _userService.Value; + public IAuthenticationService AuthenticationService => _authenticationService.Value; } } diff --git a/Shared/DataTransferObject/RegistUserDto.cs b/Shared/DataTransferObject/RegistUserDto.cs index 43b0608..0adfe7b 100644 --- a/Shared/DataTransferObject/RegistUserDto.cs +++ b/Shared/DataTransferObject/RegistUserDto.cs @@ -8,6 +8,7 @@ namespace Shared.DataTransferObject { public record RegistUserDto { + public string? Name { get; init; } public string? UserName { get; init; } public string? Password { get; init; } public string? Email { get; init; } From b461e1ff0be1e2384c09322435e9c232601e8fa6 Mon Sep 17 00:00:00 2001 From: PC_KYJ Date: Wed, 17 Jan 2024 23:21:57 +0900 Subject: [PATCH 11/12] =?UTF-8?q?Feat:=20Ilogger=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/AuthenticationController.cs | 9 ++++++++- .../Controllers/CommentController.cs | 9 ++++++++- .../Controllers/LikeController.cs | 9 ++++++++- .../Controllers/PostController.cs | 9 ++++++++- .../Controllers/PostPhotoController.cs | 9 ++++++++- .../Controllers/ProfileController.cs | 9 ++++++++- EveryPinApi/Extensions/ServiceExtensions.cs | 11 ++++++----- 7 files changed, 54 insertions(+), 11 deletions(-) diff --git a/EveryPinApi.Presentation/Controllers/AuthenticationController.cs b/EveryPinApi.Presentation/Controllers/AuthenticationController.cs index 0bd7e53..0d9c229 100644 --- a/EveryPinApi.Presentation/Controllers/AuthenticationController.cs +++ b/EveryPinApi.Presentation/Controllers/AuthenticationController.cs @@ -1,4 +1,5 @@ using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.Logging; using Service.Contracts; using Shared.DataTransferObject; using System; @@ -14,8 +15,14 @@ namespace EveryPinApi.Presentation.Controllers [ApiController] public class AuthenticationController : ControllerBase { + private readonly ILogger _logger; private readonly IServiceManager _service; - public AuthenticationController(IServiceManager service) => _service = service; + + public AuthenticationController(ILogger logger, IServiceManager service) + { + _logger = logger; + _service = service; + } [HttpPost] //[ServiceFilter(typeof(ValidationFilterAttribute))] diff --git a/EveryPinApi.Presentation/Controllers/CommentController.cs b/EveryPinApi.Presentation/Controllers/CommentController.cs index c09d92a..b3e6342 100644 --- a/EveryPinApi.Presentation/Controllers/CommentController.cs +++ b/EveryPinApi.Presentation/Controllers/CommentController.cs @@ -7,6 +7,7 @@ using System.Runtime.InteropServices; using System.Text; using System.Threading.Tasks; +using Microsoft.Extensions.Logging; namespace EveryPinApi.Presentation.Controllers { @@ -14,8 +15,14 @@ namespace EveryPinApi.Presentation.Controllers [ApiController] public class CommentController : ControllerBase { + private readonly ILogger _logger; private readonly IServiceManager _service; - public CommentController(IServiceManager service) => _service = service; + + public CommentController(ILogger logger, IServiceManager service) + { + _logger = logger; + _service = service; + } [HttpGet] public IActionResult GetAllComment() diff --git a/EveryPinApi.Presentation/Controllers/LikeController.cs b/EveryPinApi.Presentation/Controllers/LikeController.cs index a514e2b..ad7de6b 100644 --- a/EveryPinApi.Presentation/Controllers/LikeController.cs +++ b/EveryPinApi.Presentation/Controllers/LikeController.cs @@ -1,4 +1,5 @@ using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.Logging; using Service.Contracts; using System; using System.Collections.Generic; @@ -12,8 +13,14 @@ namespace EveryPinApi.Presentation.Controllers [ApiController] public class LikeController : ControllerBase { + private readonly ILogger _logger; private readonly IServiceManager _service; - public LikeController(IServiceManager service) => _service = service; + + public LikeController(ILogger logger, IServiceManager service) + { + _logger = logger; + _service = service; + } [HttpGet] public IActionResult GetAllLike() diff --git a/EveryPinApi.Presentation/Controllers/PostController.cs b/EveryPinApi.Presentation/Controllers/PostController.cs index 84cd58a..68548b9 100644 --- a/EveryPinApi.Presentation/Controllers/PostController.cs +++ b/EveryPinApi.Presentation/Controllers/PostController.cs @@ -1,4 +1,5 @@ using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.Logging; using Service.Contracts; using System; using System.Collections.Generic; @@ -12,8 +13,14 @@ namespace EveryPinApi.Presentation.Controllers [ApiController] public class PostController : ControllerBase { + private readonly ILogger _logger; private readonly IServiceManager _service; - public PostController(IServiceManager service) => _service = service; + + public PostController(ILogger logger, IServiceManager service) + { + _logger = logger; + _service = service; + } [HttpGet] public IActionResult GetAllPost() diff --git a/EveryPinApi.Presentation/Controllers/PostPhotoController.cs b/EveryPinApi.Presentation/Controllers/PostPhotoController.cs index 102d021..9da4e1a 100644 --- a/EveryPinApi.Presentation/Controllers/PostPhotoController.cs +++ b/EveryPinApi.Presentation/Controllers/PostPhotoController.cs @@ -1,4 +1,5 @@ using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.Logging; using Service.Contracts; using System; using System.Collections.Generic; @@ -12,8 +13,14 @@ namespace EveryPinApi.Presentation.Controllers [ApiController] public class PostPhotoController : ControllerBase { + private readonly ILogger _logger; private readonly IServiceManager _service; - public PostPhotoController(IServiceManager service) => _service = service; + + public PostPhotoController(ILogger logger, IServiceManager service) + { + _logger = logger; + _service = service; + } [HttpGet] public IActionResult GetAllPostPhoto() diff --git a/EveryPinApi.Presentation/Controllers/ProfileController.cs b/EveryPinApi.Presentation/Controllers/ProfileController.cs index c372044..9591bab 100644 --- a/EveryPinApi.Presentation/Controllers/ProfileController.cs +++ b/EveryPinApi.Presentation/Controllers/ProfileController.cs @@ -1,4 +1,5 @@ using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.Logging; using Service.Contracts; using System; using System.Collections.Generic; @@ -12,8 +13,14 @@ namespace EveryPinApi.Presentation.Controllers [ApiController] public class ProfileController : ControllerBase { + private readonly ILogger _logger; private readonly IServiceManager _service; - public ProfileController(IServiceManager service) => _service = service; + + public ProfileController(ILogger logger, IServiceManager service) + { + _logger = logger; + _service = service; + } [HttpGet] public IActionResult GetAllProfile() diff --git a/EveryPinApi/Extensions/ServiceExtensions.cs b/EveryPinApi/Extensions/ServiceExtensions.cs index 9ae75c1..e6c9e0b 100644 --- a/EveryPinApi/Extensions/ServiceExtensions.cs +++ b/EveryPinApi/Extensions/ServiceExtensions.cs @@ -88,8 +88,9 @@ public static void ConfigureIdentity(this IServiceCollection services) public static void ConfigureJWT(this IServiceCollection services, IConfiguration configuration) { - var jwtSettings = configuration.GetSection("JwtSettings"); - var secretKey = jwtSettings["jwtSecret"]; + var validIssuer = configuration.GetSection("JwtSettings-validIssuer"); + var validAudience = configuration.GetSection("JwtSettings-validAudience"); + var secretKey = configuration.GetSection("JwtSettings-SECRET"); services.AddAuthentication(opt => { opt.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme; @@ -103,9 +104,9 @@ public static void ConfigureJWT(this IServiceCollection services, IConfiguration ValidateAudience = true, ValidateLifetime = true, ValidateIssuerSigningKey = true, - ValidIssuer = jwtSettings["validIssuer"], - ValidAudience = jwtSettings["validAudience"], - IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(secretKey)) + ValidIssuer = validIssuer.Value, + ValidAudience = validAudience.Value, + IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(secretKey.Value)) }; }); } From 54bfd8e7d09fb29298e6b4627fb2b5176c2565c6 Mon Sep 17 00:00:00 2001 From: PC_KYJ Date: Wed, 17 Jan 2024 23:49:55 +0900 Subject: [PATCH 12/12] =?UTF-8?q?Refactor:=20=EC=97=B0=EA=B2=B0=EB=AC=B8?= =?UTF-8?q?=EC=9E=90=EC=97=B4=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- EveryPinApi/Extensions/ServiceExtensions.cs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/EveryPinApi/Extensions/ServiceExtensions.cs b/EveryPinApi/Extensions/ServiceExtensions.cs index e6c9e0b..dfaa002 100644 --- a/EveryPinApi/Extensions/ServiceExtensions.cs +++ b/EveryPinApi/Extensions/ServiceExtensions.cs @@ -88,9 +88,9 @@ public static void ConfigureIdentity(this IServiceCollection services) public static void ConfigureJWT(this IServiceCollection services, IConfiguration configuration) { - var validIssuer = configuration.GetSection("JwtSettings-validIssuer"); - var validAudience = configuration.GetSection("JwtSettings-validAudience"); - var secretKey = configuration.GetSection("JwtSettings-SECRET"); + var validIssuer = configuration.GetConnectionString("JwtSettings-validIssuer"); + var validAudience = configuration.GetConnectionString("JwtSettings-validAudience"); + var secretKey = configuration.GetConnectionString("JwtSettings-SECRET"); services.AddAuthentication(opt => { opt.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme; @@ -104,9 +104,9 @@ public static void ConfigureJWT(this IServiceCollection services, IConfiguration ValidateAudience = true, ValidateLifetime = true, ValidateIssuerSigningKey = true, - ValidIssuer = validIssuer.Value, - ValidAudience = validAudience.Value, - IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(secretKey.Value)) + ValidIssuer = validIssuer.ToString(), + ValidAudience = validAudience.ToString(), + IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(secretKey.ToString())) }; }); }