📨
SlackClone
  • Introduction
  • Server
    • Server Introduction
    • Getting Started
      • Install .NET Core 3
      • Create a Project
      • Install Dependencies - Mongo
      • Install Dependencies - PostgreSQL
        • PostgreSQL Install - Windows
        • Connect to PostgreSQL DB - pgAdmin
    • API
      • Setup HotChocolate Server
      • Add Playground
      • Data Model - PostgreSQL
        • PostgreSQL Entities
        • Database Context
        • Queries
          • Filtering
          • Sorting
        • Mutations
        • Subscriptions
      • Data Model - Mongo
        • Mongo Entities
        • Queries
  • Authorization
  • Authentication
  • Error Handling
  • Testing
  • Backend Summary
  • Client
    • Client Introduction
    • Getting Started
      • Install Dependencies
      • Create Project
    • App
      • Routing
      • Queries
        • Pagination
        • Sorting
        • Filtering
      • Mutations
      • Subscriptions
      • Authentication
    • Frontend Summary
Powered by GitBook
On this page
  1. Server
  2. API
  3. Data Model - PostgreSQL

PostgreSQL Entities

Create the following classes for the entities that will exist in the API based on the diagram above.

.\Entities\User.cs
using System;



namespace SlackClone.Entities
{
    public class User
    {
        public Guid Id { get; set; }
        public string FirstName { get; set; }
        public string LastName { get; set; }
        public string FullName { get => $"{FirstName} {LastName}"; }
        public string Email { get; set; }
        public string Username { get; set; }
        public string Password { get; set; }
        public UserStatus Status { get; set; }
    }
}
.\Entities\UserStatus.cs
using System;



namespace SlackClone.Entities
{
    public class UserStatus
    {
        public Guid Id { get; set; }
        public string Status { get; set; }
        public string Description { get; set; }
        public int Rank { get; set; }
    }
}
.\Entities\DirectMessage.cs
using System;

namespace SlackClone.Entities
{
    public class DirectMessage
    {
        public Guid Id { get; set; }
        public string Content { get; set; }
        public User CreatedBy { get; set; }
        public User SentTo { get; set; }
        public DateTime CreatedAt { get; set; }
    }
}
.\Entities\Channel.cs
using System;

using System.Collections.Generic;



namespace SlackClone.Entities
{
    public class Channel
    {
        public Guid Id { get; set; }
        public string Name { get; set; }
        public ICollection<ChannelChannelMessage> 
            ChannelsChannelMessages { get; set; }
    }
}
.\Entities\ChannelMessage.cs
using System;

using System.Collections.Generic;



namespace SlackClone.Entities
{
    public class ChannelMessage
    {
        public Guid Id { get; set; }
        public string Content { get; set; }
        public User CreatedBy { get; set; }
        public DateTime CreatedAt { get; set; }
        public int Likes { get; set; }
        public ICollection<ChannelChannelMessage> 
            ChannelsChannelMessages { get; set; }
    }
}
.\Entities\ChannelChannelMessage.cs
using System;



namespace SlackClone.Entities
{
    public class ChannelChannelMessage
    {
        public Guid ChannelId { get; set; }
        public Channel Channel { get; set; }
        public Guid MessageId { get; set; }
        public ChannelMessage ChannelMessage { get; set; }
    }
}
PreviousData Model - PostgreSQLNextDatabase Context

Last updated 5 years ago