~jpgleeson/caint

6f3be0f7da2c8dd98496502b86b5c40592f7ae25 — jpgleeson 1 year, 5 months ago 9a6a9c6
OwnerId added to models

To allow for good tenant management. The Comment model itself only needs to have the ownerid as a convenience function for the dashboard, but I could refactor it out to only use thread ownerIds if that seemed better at some point.
5 files changed, 17 insertions(+), 2 deletions(-)

M Controllers/ThreadsController.cs
M Models/Comment.cs
M Models/Tenant.cs
M Models/Thread.cs
M caintDB.db
M Controllers/ThreadsController.cs => Controllers/ThreadsController.cs +11 -2
@@ 25,7 25,6 @@ namespace caint.Controllers
        [HttpOptions]
        public IActionResult PreflightRoute()
        {
            Console.WriteLine("preflight");
            return NoContent();
        }



@@ 71,7 70,8 @@ namespace caint.Controllers

            var thread = new Thread{
                hostname = newThread.hostname,
                path = newThread.path
                path = newThread.path,
                ownerId = getOwner(newThread.hostname)
            };
            
            _context.threads.Add(thread);


@@ 80,6 80,15 @@ namespace caint.Controllers
            return (ItemToDTO(thread).id);
        }

        private string getOwner(string tenant)
        {
            var tenantOwner = _context.tenants.Where(x => x.tenantName == tenant).FirstOrDefault();

            Console.WriteLine(tenantOwner.ownerId);

            return tenantOwner.ownerId;
        }

        private static ThreadDTO ItemToDTO(Thread thread) =>
        new ThreadDTO 
        {

M Models/Comment.cs => Models/Comment.cs +2 -0
@@ 12,6 12,8 @@ namespace caint.Models

        public bool approved {  get; set;   }

        public string ownerId { get; set; }

    }

    public class CommentDTO

M Models/Tenant.cs => Models/Tenant.cs +2 -0
@@ 7,5 7,7 @@ namespace caint.Models
        public string tenantName { get; set; }

        public bool active { get; set; }

        public string ownerId { get; set; }
    }
}
\ No newline at end of file

M Models/Thread.cs => Models/Thread.cs +2 -0
@@ 7,6 7,8 @@ namespace caint.Models
        public string hostname { get; set; }

        public string path { get; set; }

        public string ownerId { get; set; }
    }

    public class ThreadDTO

M caintDB.db => caintDB.db +0 -0