Skip to content

Commit be52d49

Browse files
committed
Added Questions and Answers below User Profile
1 parent 487a1e7 commit be52d49

22 files changed

+599
-88
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
namespace LetsDisc.Posts.Dto
2+
{
3+
public class AnswerWithQuestion
4+
{
5+
public PostDto Question { get; set; }
6+
public PostDto Answer { get; set; }
7+
}
8+
}

src/LetsDisc.Application/Tags/TagAppService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public TagAppService(IRepository<Tag> tagRepository)
2121
_tagRepository = tagRepository;
2222
}
2323

24-
// Getting all questions on the Home Page
24+
// Getting all tags on the Home Page
2525
public async Task<PagedResultDto<TagDto>> GetTags(PagedResultRequestDto input)
2626
{
2727
var tagCount = await _tagRepository.CountAsync();

src/LetsDisc.Application/Users/UserAppService.cs

Lines changed: 54 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
using System.IO;
2525
using Abp.UI;
2626
using Microsoft.AspNetCore.Mvc;
27+
using LetsDisc.Posts.Dto;
28+
using LetsDisc.Tags;
2729

2830
namespace LetsDisc.Users
2931
{
@@ -35,6 +37,7 @@ public class UserAppService : AsyncCrudAppService<User, UserDto, long, PagedResu
3537
private readonly IPasswordHasher<User> _passwordHasher;
3638
private readonly IRepository<UserDetails, long> _userDetailsRepository;
3739
private readonly IRepository<Post> _postRepository;
40+
private readonly IRepository<PostTag> _tagRepository;
3841

3942
public UserAppService(
4043
IRepository<User, long> repository,
@@ -43,7 +46,8 @@ public UserAppService(
4346
IRepository<Role> roleRepository,
4447
IPasswordHasher<User> passwordHasher,
4548
IRepository<UserDetails, long> userDetailsRepository,
46-
IRepository<Post> postRepository)
49+
IRepository<Post> postRepository,
50+
IRepository<PostTag> tagRepository)
4751
: base(repository)
4852
{
4953
_userManager = userManager;
@@ -52,6 +56,7 @@ public UserAppService(
5256
_passwordHasher = passwordHasher;
5357
_userDetailsRepository = userDetailsRepository;
5458
_postRepository = postRepository;
59+
_tagRepository = tagRepository;
5560
}
5661

5762
public override async Task<UserDto> Create(CreateUserDto input)
@@ -177,19 +182,19 @@ public async Task<UserInfo> GetUser(long id)
177182
});
178183
}
179184

180-
var questionsCount = await _postRepository.CountAsync(p => p.PostTypeId == (int)PostTypes.Question && p.CreatorUserId == id);
181-
var answersCount = await _postRepository.CountAsync(p => p.PostTypeId == (int)PostTypes.Answer && p.CreatorUserId == id);
182-
183185
userDetails.Views++;
184186
var userDto = base.MapToEntityDto(user);
185187
var userDetailsDto = ObjectMapper.Map<UserDetailsDto>(userDetails);
186188

189+
var questionCount = await _postRepository.CountAsync(p => p.PostTypeId == (int)PostTypes.Question && p.CreatorUserId == id);
190+
var answerCount = await _postRepository.CountAsync(p => p.PostTypeId == (int)PostTypes.Answer && p.CreatorUserId == id);
191+
187192
return new UserInfo
188193
{
189194
User = userDto,
190195
UserDetails = userDetailsDto,
191-
questionsCount = questionsCount,
192-
answersCount = answersCount
196+
questionsCount = questionCount,
197+
answersCount = answerCount
193198
};
194199
}
195200

@@ -260,5 +265,48 @@ protected virtual void CheckErrors(IdentityResult identityResult)
260265
{
261266
identityResult.CheckErrors(LocalizationManager);
262267
}
268+
269+
public async Task<PagedResultDto<PostDto>> GetUserQuestions(PagedResultRequestDto input, long userId)
270+
{
271+
var questionCount = await _postRepository.CountAsync(p => p.PostTypeId == (int)PostTypes.Question && p.CreatorUserId == userId);
272+
var questions = await _postRepository.GetAll()
273+
.Where(p => p.PostTypeId == (int)PostTypes.Question && p.CreatorUserId == userId)
274+
.Skip(input.SkipCount)
275+
.Take(input.MaxResultCount)
276+
.ToListAsync();
277+
278+
return new PagedResultDto<PostDto>
279+
{
280+
TotalCount = questionCount,
281+
Items = questions.MapTo<List<PostDto>>()
282+
};
283+
}
284+
285+
public async Task<PagedResultDto<AnswerWithQuestion>> GetUserAnswers(PagedResultRequestDto input, long userId)
286+
{
287+
var answerCount = await _postRepository.CountAsync(p => p.PostTypeId == (int)PostTypes.Answer && p.CreatorUserId == userId);
288+
var answers = await _postRepository.GetAll()
289+
.Where(p => p.PostTypeId == (int)PostTypes.Answer && p.CreatorUserId == userId)
290+
.Skip(input.SkipCount)
291+
.Take(input.MaxResultCount)
292+
.ToListAsync();
293+
List<AnswerWithQuestion> answerWithQuestionList = new List<AnswerWithQuestion>();
294+
foreach (var answer in answers)
295+
{
296+
var question = await _postRepository.FirstOrDefaultAsync(p => p.PostTypeId == (int)PostTypes.Question && p.Id == answer.ParentId);
297+
var answerWithQuestion = new AnswerWithQuestion
298+
{
299+
Question = question.MapTo<PostDto>(),
300+
Answer = answer.MapTo<PostDto>()
301+
};
302+
answerWithQuestionList.Add(answerWithQuestion);
303+
}
304+
305+
return new PagedResultDto<AnswerWithQuestion>
306+
{
307+
TotalCount = answerCount,
308+
Items = answerWithQuestionList
309+
};
310+
}
263311
}
264312
}

src/LetsDisc.Web.Host/src/app/about/about.component.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ <h2>
88
</div>
99
<div class="body">
1010
<div class="about-body" style="font-size: 18px; line-height: 18px;">
11-
<p>LetsDisc is a place where programmers around the world can share ideas and help each other grow. </p>
12-
<p>We can think of it as an online community for sharing and discovering great ideas, great questions and great answers.</p>
13-
<p>Anyone can share articles, questions, discussions, etc. as long as they are of their own.</p>
11+
<p>LetsDiscuss is a place where programmers around the world can share ideas and help each other grow by sharing knowledg, experience and wisdom. </p>
12+
<p>We can think of it as an online community for sharing and discovering great ideas, great questions and great answers. Any registered user can ask questions, can also answer questions asked by other users</p>
13+
<p>This website has been founded by Gopesh Sharma, Full Stack Developer and the code being open source can be found at <a href="https://github.com/codingdefined/LetsDisc">Github</a>.</p>
1414
</div>
1515
</div>
1616
</div>

src/LetsDisc.Web.Host/src/app/app-routing.module.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import { PageNotFoundComponent } from '@app/page-not-found/page-not-found.compon
1212
import { TagsComponent } from '@app/tags/tags.component';
1313
import { UserDetailComponent } from '@app/users/user-detail/user-detail.component';
1414
import { EditUserComponent } from '@app/users/edit-user/edit-user.component';
15+
import { ContactComponent } from '@app/contact/contact.component';
16+
import { PrivacyComponent } from '@app/privacy/privacy.component';
1517

1618
@NgModule({
1719
imports: [
@@ -40,6 +42,8 @@ import { EditUserComponent } from '@app/users/edit-user/edit-user.component';
4042
]
4143
},
4244
{ path: 'about', component: AboutComponent },
45+
{ path: 'contact', component: ContactComponent },
46+
{ path: 'privacy', component: PrivacyComponent },
4347
{ path: 'tags', component: TagsComponent },
4448
{ path: '', redirectTo: '/questions', pathMatch: 'full' },
4549
{ path: '**', component: PageNotFoundComponent }

src/LetsDisc.Web.Host/src/app/app.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export class AppComponent extends AppComponentBase implements OnInit, AfterViewI
1717
}
1818

1919
ngOnInit(): void {
20-
20+
2121
SignalRAspNetCoreHelper.initSignalR();
2222

2323
abp.event.on('abp.notifications.received', userNotification => {

src/LetsDisc.Web.Host/src/app/app.module.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ import { PageNotFoundComponent } from './page-not-found/page-not-found.component
4343
import { TagsComponent } from './tags/tags.component';
4444
import { SocialLoginModule } from "angularx-social-login";
4545
import { UserDetailComponent } from './users/user-detail/user-detail.component';
46+
import { PrivacyComponent } from './privacy/privacy.component';
47+
import { ContactComponent } from './contact/contact.component';
4648

4749
@NgModule({
4850
declarations: [
@@ -72,6 +74,8 @@ import { UserDetailComponent } from './users/user-detail/user-detail.component';
7274
PageNotFoundComponent,
7375
TagsComponent,
7476
UserDetailComponent,
77+
PrivacyComponent,
78+
ContactComponent,
7579
],
7680
imports: [
7781
CommonModule,
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<div class="row clearfix">
2+
<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
3+
<div class="card">
4+
<div class="header">
5+
<h2>
6+
Contact
7+
</h2>
8+
</div>
9+
<div class="body">
10+
<div class="about-body" style="font-size: 18px; line-height: 18px;">
11+
<p>You may contact us with your feedback and suggestions at our email address: info AT letsdiscuss DOT com.</p>
12+
</div>
13+
</div>
14+
</div>
15+
</div>
16+
</div>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { Component, OnInit } from '@angular/core';
2+
3+
@Component({
4+
selector: 'app-contact',
5+
templateUrl: './contact.component.html'
6+
})
7+
export class ContactComponent implements OnInit {
8+
9+
constructor() { }
10+
11+
ngOnInit() {
12+
}
13+
14+
}

src/LetsDisc.Web.Host/src/app/layout/sidebar-nav.component.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ export class SideBarNavComponent extends AppComponentBase {
1313
new MenuItem(this.l("Tags"), "", "local_offer", "/tags"),
1414
new MenuItem(this.l("Users"), "", "people", "/users"),
1515
new MenuItem(this.l("About"), "", "info", "/about"),
16+
new MenuItem(this.l("Contact"), "", "contact_mail", "/contact"),
17+
new MenuItem(this.l("Privacy"), "", "security", "/privacy")
1618
];
1719

1820
constructor(

0 commit comments

Comments
 (0)