Skip to content

Commit 15bc91e

Browse files
authored
Merge pull request #71 from boolean-uk/59-backend---create-posts-and-comments-model
Created models for post and postcomment, and some DTOs
2 parents 3a79fe8 + cc16f17 commit 15bc91e

File tree

5 files changed

+104
-0
lines changed

5 files changed

+104
-0
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
namespace exercise.wwwapi.DTOs.GetUsers
2+
{
3+
public class UserBasicDTO
4+
{
5+
public int Id { get; set; }
6+
public string? FirstName { get; set; }
7+
public string? LastName { get; set; }
8+
public string? Photo { get; set; }
9+
}
10+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using exercise.wwwapi.DTOs.GetUsers;
2+
using exercise.wwwapi.Models;
3+
using System.ComponentModel.DataAnnotations;
4+
using System.ComponentModel.DataAnnotations.Schema;
5+
6+
namespace exercise.wwwapi.DTOs.Posts
7+
{
8+
public class PostCommentDTO
9+
{
10+
public int Id { get; set; }
11+
public UserBasicDTO? User { get; set; }
12+
public required string Content { get; set; }
13+
public DateTime CreatedAt { get; set; }
14+
public DateTime? UpdatedAt { get; set; }
15+
}
16+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using exercise.wwwapi.DTOs.GetUsers;
2+
using exercise.wwwapi.Models;
3+
using System.ComponentModel.DataAnnotations;
4+
using System.ComponentModel.DataAnnotations.Schema;
5+
6+
namespace exercise.wwwapi.DTOs.Posts
7+
{
8+
public class PostDTO
9+
{
10+
public required int Id { get; set; }
11+
public UserBasicDTO? User { get; set; }
12+
public required string Content { get; set; }
13+
public required DateTime CreatedAt { get; set; }
14+
public DateTime? UpdatedAt { get; set; }
15+
public required int NumLikes { get; set; }
16+
17+
public ICollection<PostCommentDTO> Comments { get; set; } = new List<PostCommentDTO>();
18+
}
19+
}

exercise.wwwapi/Models/Post.cs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
using System.ComponentModel.DataAnnotations;
2+
using System.ComponentModel.DataAnnotations.Schema;
3+
4+
namespace exercise.wwwapi.Models
5+
{
6+
[Table("posts")]
7+
public class Post
8+
{
9+
[Key, Column("id")]
10+
public required int Id { get; set; }
11+
[Column("userid")]
12+
public required int UserId { get; set; }
13+
[ForeignKey("UserId")]
14+
public User? User { get; set; }
15+
[Column("content")]
16+
public string Content { get; set; } = string.Empty;
17+
[Column("createdat")]
18+
public required DateTime CreatedAt { get; set; }
19+
[Column("updatedat")]
20+
public DateTime? UpdatedAt { get; set; }
21+
[Column("numlikes")]
22+
public required int NumLikes { get; set; } = 0;
23+
24+
public ICollection<PostComment> Comments { get; set; } = new List<PostComment>();
25+
}
26+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
using System.ComponentModel.DataAnnotations;
2+
using System.ComponentModel.DataAnnotations.Schema;
3+
4+
namespace exercise.wwwapi.Models
5+
{
6+
[Table("comments")]
7+
public class PostComment
8+
{
9+
[Key, Column("id")]
10+
public int Id { get; set; }
11+
12+
[Column("postid")]
13+
public int PostId { get; set; }
14+
15+
[ForeignKey("PostId")]
16+
public Post? Post { get; set; }
17+
18+
[Column("userid")]
19+
public int UserId { get; set; }
20+
21+
[ForeignKey("UserId")]
22+
public User? User { get; set; }
23+
24+
[Column("content")]
25+
public string Content { get; set; } = string.Empty;
26+
27+
[Column("createdat")]
28+
public DateTime CreatedAt { get; set; }
29+
30+
[Column("updatedat")]
31+
public DateTime? UpdatedAt { get; set; }
32+
}
33+
}

0 commit comments

Comments
 (0)