Browse Source

commit: First db op

码农 6 years ago
parent
commit
e51b2f8996

+ 93 - 26
MyTrelloWeb/App/AppServices/KanbanService.cs

@@ -1,124 +1,191 @@
-using MyTrelloWeb.App.AppServices.Common;
+using System;
+using System.Linq;
+using System.Web.UI.WebControls;
+using MyTrelloWeb.App.AppServices.Common;
 using MyTrelloWeb.App.Dto;
+using MyTrelloWeb.App.Entity;
 
 namespace MyTrelloWeb.App.AppServices
 {
     public interface IKanbanService
     {
         // kanban level
-        KanbanSummaryOutput GetKanbanSummary();
+
+        ListSummaryOutput[] KanbanSummary();
 
         // list level
 
-        void ListCreate(CreateWithNameInput input);
+        ListSummaryOutput ListSummary(QueryByIdInput input);
+
+        KanbanEntryCreateOutput ListCreate(CreateWithTitleInput input);
 
-        void ListRename(ReameInput input);
+        void ListRename(ContentInput input);
 
         void ListDelete(DeleteByIdInput input);
 
-        //TODO: get list summary
+        void ListMove(ListMoveInput input);
 
         // card level
 
-        void CardCreate(CreateWithNameAndParentIdInput input);
+        CardDetailOutput CardDetail(QueryByIdInput input);
+
+        KanbanEntryCreateOutput CardCreate(CreateWithTitleAndParentIdInput input);
 
-        void CardRename(ReameInput input);
+        void CardRename(ContentInput input);
+
+        void CardEditSummary(ContentInput input);
 
         void CardMove(MoveInput input);
 
         void CardDelete(DeleteByIdInput input);
 
-        //TODO: edit summary
-        //TODO: get Card detail
-
         // manifest level
 
-        void ManifestCreate(CreateWithNameAndParentIdInput input);
+        KanbanEntryCreateOutput ManifestCreate(CreateWithTitleAndParentIdInput input);
 
         void ManifestMove(MoveInput input);
 
-        void ManifestRename(ReameInput input);
+        void ManifestRename(ContentInput input);
 
         void ManifestDelete(DeleteByIdInput input);
 
         // item level
 
-        void ItemCreate(CreateWithNameAndParentIdInput input);
+        KanbanEntryCreateOutput ItemCreate(CreateWithTitleAndParentIdInput input);
 
         void ItemMove(MoveInput input);
 
-        void ItemRename(ReameInput input);
+        void ItemRename(ContentInput input);
 
         void ItemDelete(DeleteByIdInput input);
 
-        //TODO: item check
+        void ItemCheck(CheckInput input);
     }
 
-    internal class KanbanService : AppServiceBase, IKanbanService
+    internal class KanbanService : AppServiceBase<KanbanEntity>, IKanbanService
     {
-        public KanbanSummaryOutput GetKanbanSummary()
+        ListSummaryOutput[] IKanbanService.KanbanSummary()
         {
-            return new KanbanSummaryOutput();
+            throw new NotImplementedException();
         }
 
-        void IKanbanService.ListCreate(CreateWithNameInput input)
+        ListSummaryOutput IKanbanService.ListSummary(QueryByIdInput input)
         {
+            throw new NotImplementedException();
         }
 
-        void IKanbanService.ListRename(ReameInput input)
+        KanbanEntryCreateOutput IKanbanService.ListCreate(CreateWithTitleInput input)
         {
+            var newEntity = new KanbanEntity
+            {
+                //TODO: Kanban ID
+                Type = KanbanEntryType.List,
+                Title = input.Title,
+            };
+
+            using (var repo = GetRepository())
+            {
+                var existedCount = repo.Query(p => p.Type == KanbanEntryType.List).Count();
+                newEntity.Sort = existedCount + 1;
+                repo.Add(newEntity);
+                repo.SaveChanges();
+            }
+
+            return new KanbanEntryCreateOutput
+            {
+                Id = newEntity.Id,
+                Sort = newEntity.Sort
+            };
+        }
+
+        void IKanbanService.ListRename(ContentInput input)
+        {
+            throw new NotImplementedException();
         }
 
         void IKanbanService.ListDelete(DeleteByIdInput input)
         {
+            throw new NotImplementedException();
+        }
+
+        void IKanbanService.ListMove(ListMoveInput input)
+        {
+            throw new NotImplementedException();
+        }
+
+        CardDetailOutput IKanbanService.CardDetail(QueryByIdInput input)
+        {
+            throw new NotImplementedException();
         }
 
-        void IKanbanService.CardCreate(CreateWithNameAndParentIdInput input)
+        KanbanEntryCreateOutput IKanbanService.CardCreate(CreateWithTitleAndParentIdInput input)
         {
+            throw new NotImplementedException();
         }
 
-        void IKanbanService.CardRename(ReameInput input)
+        void IKanbanService.CardRename(ContentInput input)
         {
+            throw new NotImplementedException();
+        }
+
+        void IKanbanService.CardEditSummary(ContentInput input)
+        {
+            throw new NotImplementedException();
         }
 
         void IKanbanService.CardMove(MoveInput input)
         {
+            throw new NotImplementedException();
         }
 
         void IKanbanService.CardDelete(DeleteByIdInput input)
         {
+            throw new NotImplementedException();
         }
 
-        void IKanbanService.ManifestCreate(CreateWithNameAndParentIdInput input)
+        KanbanEntryCreateOutput IKanbanService.ManifestCreate(CreateWithTitleAndParentIdInput input)
         {
+            throw new NotImplementedException();
         }
 
         void IKanbanService.ManifestMove(MoveInput input)
         {
+            throw new NotImplementedException();
         }
 
-        void IKanbanService.ManifestRename(ReameInput input)
+        void IKanbanService.ManifestRename(ContentInput input)
         {
+            throw new NotImplementedException();
         }
 
         void IKanbanService.ManifestDelete(DeleteByIdInput input)
         {
+            throw new NotImplementedException();
         }
 
-        void IKanbanService.ItemCreate(CreateWithNameAndParentIdInput input)
+        KanbanEntryCreateOutput IKanbanService.ItemCreate(CreateWithTitleAndParentIdInput input)
         {
+            throw new NotImplementedException();
         }
 
         void IKanbanService.ItemMove(MoveInput input)
         {
+            throw new NotImplementedException();
         }
 
-        void IKanbanService.ItemRename(ReameInput input)
+        void IKanbanService.ItemRename(ContentInput input)
         {
+            throw new NotImplementedException();
         }
 
         void IKanbanService.ItemDelete(DeleteByIdInput input)
         {
+            throw new NotImplementedException();
+        }
+
+        void IKanbanService.ItemCheck(CheckInput input)
+        {
+            throw new NotImplementedException();
         }
     }
 }

+ 13 - 10
MyTrelloWeb/App/DbMigration/20190413235130_InitDatabase.cs

@@ -1,5 +1,6 @@
 using FluentMigrator;
 using MyTrelloWeb.VCommon.Logging;
+using MyTrelloWeb.VCommon.VEntity;
 
 namespace MyTrelloWeb.App.DbMigration
 {
@@ -10,25 +11,27 @@ namespace MyTrelloWeb.App.DbMigration
 
         public override void Up()
         {
-            Logger.Info($"Exec Migration UP {Version}_{this.GetType().Name}");
+            Logger.Info($"Exec Migration UP {Version}_{GetType().Name}");
 
             Create.Table("Kanban")
-                .WithColumn("ListId").AsGuid().PrimaryKey()
-                .WithColumn("CardId").AsGuid().PrimaryKey()
-                .WithColumn("ManifestId").AsGuid().PrimaryKey()
-                .WithColumn("ItemId").AsGuid().PrimaryKey()
+                .WithColumn("Id").AsGuid().PrimaryKey()
+                .WithColumn(nameof(ISoftDelete.IsAbolish)).AsBoolean().Indexed()
+                .WithColumn("Type").AsByte().Indexed()
+                .WithColumn("ListId").AsGuid().Indexed()
+                .WithColumn("CardId").AsGuid().Indexed()
+                .WithColumn("ManifestId").AsGuid().Indexed()
                 .WithColumn("Sort").AsInt32()
-                .WithColumn("Title").AsString()
-                .WithColumn("Summary").AsString().Nullable()
+                .WithColumn("Title").AsString(128)
+                .WithColumn("Summary").AsString(4096).Nullable()
                 .WithColumn("Checked").AsBoolean()
-                .WithColumn("CreationTime").AsDateTime()
-                .WithColumn("LastModificationTime").AsDateTime().Nullable()
+                .WithColumn(nameof(IHaveCreationTime.CreationTime)).AsDateTime()
+                .WithColumn(nameof(IHaveLastModificationTime.LastModificationTime)).AsDateTime().Nullable()
                 ;
         }
 
         public override void Down()
         {
-            Logger.Info($"Exec Migration DOWN {Version}_{this.GetType().Name}");
+            Logger.Info($"Exec Migration DOWN {Version}_{GetType().Name}");
 
             Delete.Table("Kanban");
         }

+ 6 - 0
MyTrelloWeb/App/Dto/CardDetailOutput.cs

@@ -0,0 +1,6 @@
+namespace MyTrelloWeb.App.Dto
+{
+    public class CardDetailOutput
+    {
+    }
+}

+ 3 - 1
MyTrelloWeb/App/Dto/ReameInput.cs

@@ -3,9 +3,11 @@ using MyTrelloWeb.VCommon.DataAnnotations.ExtraValidation;
 
 namespace MyTrelloWeb.App.Dto
 {
-    public class ReameInput : CreateWithNameInput
+    public class CheckInput
     {
         [NoEmptyGuid]
         public Guid Id { get; set; }
+
+        public bool Check { get; set; }
     }
 }

+ 15 - 0
MyTrelloWeb/App/Dto/ContentInput.cs

@@ -0,0 +1,15 @@
+using MyTrelloWeb.VCommon.DataAnnotations.ExtraValidation;
+using System;
+using System.ComponentModel.DataAnnotations;
+
+namespace MyTrelloWeb.App.Dto
+{
+    public class ContentInput
+    {
+        [NoEmptyGuid]
+        public Guid Id { get; set; }
+
+        [Required]
+        public string Content { get; set; }
+    }
+}

+ 1 - 1
MyTrelloWeb/App/Dto/CreateWithNameAndParentIdInput.cs

@@ -3,7 +3,7 @@ using MyTrelloWeb.VCommon.DataAnnotations.ExtraValidation;
 
 namespace MyTrelloWeb.App.Dto
 {
-    public class CreateWithNameAndParentIdInput : CreateWithNameInput
+    public class CreateWithTitleAndParentIdInput : CreateWithTitleInput
     {
         [NoEmptyGuid]
         public Guid ParentId { get; set; }

+ 2 - 2
MyTrelloWeb/App/Dto/CreateWithNameInput.cs

@@ -2,9 +2,9 @@
 
 namespace MyTrelloWeb.App.Dto
 {
-    public class CreateWithNameInput
+    public class CreateWithTitleInput
     {
         [Required]
-        public string Name { get; set; }
+        public string Title { get; set; }
     }
 }

+ 13 - 0
MyTrelloWeb/App/Dto/KanbanEntryCreateOutput.cs

@@ -0,0 +1,13 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Web;
+
+namespace MyTrelloWeb.App.Dto
+{
+    public class KanbanEntryCreateOutput
+    {
+        public Guid Id { get; set; }
+        public int Sort { get; set; }
+    }
+}

+ 13 - 0
MyTrelloWeb/App/Dto/ListMoveInput.cs

@@ -0,0 +1,13 @@
+using System;
+using MyTrelloWeb.VCommon.DataAnnotations.ExtraValidation;
+
+namespace MyTrelloWeb.App.Dto
+{
+    public class ListMoveInput
+    {
+        [NoEmptyGuid]
+        public Guid Id { get; set; }
+
+        public int Sort { get; set; }
+    }
+}

+ 1 - 1
MyTrelloWeb/App/Dto/KanbanSummaryOutput.cs

@@ -5,7 +5,7 @@ using System.Web;
 
 namespace MyTrelloWeb.App.Dto
 {
-    public class KanbanSummaryOutput
+    public class ListSummaryOutput
     {
     }
 }

+ 3 - 3
MyTrelloWeb/App/Dto/MoveInput.cs

@@ -1,5 +1,5 @@
-using System;
-using MyTrelloWeb.VCommon.DataAnnotations.ExtraValidation;
+using MyTrelloWeb.VCommon.DataAnnotations.ExtraValidation;
+using System;
 
 namespace MyTrelloWeb.App.Dto
 {
@@ -13,4 +13,4 @@ namespace MyTrelloWeb.App.Dto
 
         public int Sort { get; set; }
     }
-}
+}

+ 11 - 0
MyTrelloWeb/App/Dto/QueryByIdInput.cs

@@ -0,0 +1,11 @@
+using System;
+using MyTrelloWeb.VCommon.DataAnnotations.ExtraValidation;
+
+namespace MyTrelloWeb.App.Dto
+{
+    public class QueryByIdInput
+    {
+        [NoEmptyGuid]
+        public Guid Guid { get; set; }
+    }
+}

+ 6 - 3
MyTrelloWeb/App/Entity/KanbanEntity.cs

@@ -1,19 +1,21 @@
 using MyTrelloWeb.VCommon.VEntity;
 using System;
 using System.ComponentModel.DataAnnotations;
+using System.ComponentModel.DataAnnotations.Schema;
 
 namespace MyTrelloWeb.App.Entity
 {
-    public class KanbanEntity : IHaveCreationTime, IHaveLastModificationTime
+    [Table("Kanban")]
+    public class KanbanEntity : VEntityBase, ISoftDelete, IHaveCreationTime, IHaveLastModificationTime
     {
+        public KanbanEntryType Type { get; set; }
+
         public Guid ListId { get; set; }
 
         public Guid CardId { get; set; }
 
         public Guid ManifestId { get; set; }
 
-        public Guid ItemId { get; set; }
-
         public int Sort { get; set; }
 
         [Required]
@@ -25,5 +27,6 @@ namespace MyTrelloWeb.App.Entity
 
         public DateTime CreationTime { get; set; }
         public DateTime? LastModificationTime { get; set; }
+        public bool IsAbolish { get; set; }
     }
 }

+ 12 - 0
MyTrelloWeb/App/Entity/KanbanEntryType.cs

@@ -0,0 +1,12 @@
+namespace MyTrelloWeb.App.Entity
+{
+    public enum KanbanEntryType
+    {
+        //0 is invalid
+
+        List = 10,
+        Card = 20,
+        Manifest = 30,
+        Item = 40,
+    }
+}

+ 3 - 1
MyTrelloWeb/App/MyTrelloDbMigrator.cs

@@ -23,7 +23,9 @@ namespace MyTrelloWeb.App
                 {
                     cmd.CommandText = "SHOW DATABASES LIKE @" + nameof(dbName);
                     cmd.Parameters.Add(new MySqlParameter(nameof(dbName), dbName));
-                    var dbCheckResult = cmd.ExecuteScalar() as string;
+
+                    var dbCheckResult = (string)cmd.ExecuteScalar();
+
                     cmd.Parameters.Clear();
                     if (null == dbCheckResult || dbCheckResult.ToLower() != dbName.ToLower())
                     {

+ 4 - 0
MyTrelloWeb/App_Start/LoggerActivator.cs

@@ -14,6 +14,10 @@ namespace MyTrelloWeb
         {
             Logger.Init(new VJsonFileLogger(logTo: ConfigurationManager.AppSettings["LogPath"], enableAll: true)); //TODO: 稳定之后把ALL日志关闭?
             Logger.Info("Logger Init");
+#if DEBUG
+            Logger.EnableDebugLevel = true;
+            Logger.Info("Enable debug level");
+#endif
             AppDomain.CurrentDomain.UnhandledException += (sender, e) => { Logger.Fatal("AppDomain.CurrentDomain.UnhandledException", e.ExceptionObject); };
         }
 

+ 12 - 0
MyTrelloWeb/Index.html

@@ -0,0 +1,12 @@
+<!DOCTYPE html>
+<html>
+<head>
+    <meta charset="utf-8" />
+    <title>MyTrello</title>
+</head>
+<body>
+    <h1>MyTrello</h1>
+    <a href="/swagger1/?api/">Swagger1</a>
+    <a href="/swagger2/?api/">Swagger2</a>
+</body>
+</html>

+ 11 - 4
MyTrelloWeb/MyTrelloWeb.csproj

@@ -219,6 +219,7 @@
     <EmbeddedResource Include="VCommon\VSwaggerUI\Version2\swagger-ui-standalone-preset.js" />
     <EmbeddedResource Include="VCommon\VSwaggerUI\Version2\swagger-ui.css" />
     <EmbeddedResource Include="VCommon\VSwaggerUI\Version2\swagger-ui.js" />
+    <Content Include="Index.html" />
     <Content Include="Web.config">
       <SubType>Designer</SubType>
     </Content>
@@ -229,14 +230,20 @@
     <Compile Include="App\AppServices\KanbanService.cs" />
     <Compile Include="App\Auditing\ServiceAuditInterceptor.cs" />
     <Compile Include="App\DbMigration\20190413235130_InitDatabase.cs" />
-    <Compile Include="App\Dto\CreateWithNameAndParentIdInput.cs" />
-    <Compile Include="App\Dto\CreateWithNameInput.cs" />
+    <Compile Include="App\Dto\CardDetailOutput.cs" />
+    <Compile Include="App\Dto\CheckInput.cs" />
+    <Compile Include="App\Dto\CreateWithTitleAndParentIdInput.cs" />
+    <Compile Include="App\Dto\CreateWithTitleInput.cs" />
     <Compile Include="App\Dto\DeleteByIdInput.cs" />
-    <Compile Include="App\Dto\KanbanSummaryOutput.cs" />
+    <Compile Include="App\Dto\KanbanEntryCreateOutput.cs" />
+    <Compile Include="App\Dto\ListMoveInput.cs" />
+    <Compile Include="App\Dto\ListSummaryOutput.cs" />
     <Compile Include="App\Dto\MoveInput.cs" />
-    <Compile Include="App\Dto\ReameInput.cs" />
+    <Compile Include="App\Dto\ContentInput.cs" />
+    <Compile Include="App\Dto\QueryByIdInput.cs" />
     <Compile Include="App\EntityFramework\MyTrelloDataContext.cs" />
     <Compile Include="App\Entity\KanbanEntity.cs" />
+    <Compile Include="App\Entity\KanbanEntryType.cs" />
     <Compile Include="App\MyTrelloDbMigrator.cs" />
     <Compile Include="App\Swagger2UiModule.cs" />
     <Compile Include="App\Swagger1UiModule.cs" />