File tree Expand file tree Collapse file tree 5 files changed +104
-0
lines changed
Expand file tree Collapse file tree 5 files changed +104
-0
lines changed Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments