Skip to content

Question answer #34

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions VNH.Application/DTOs/Catalog/Forum/Answer/AnswerFpkDto.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace VNH.Application.DTOs.Catalog.Forum.Answer
{
public class AnswerFpkDto
{
public string AnswerId { get; set; } = string.Empty;
public string UserId { get; set; } = string.Empty;
}
}
44 changes: 44 additions & 0 deletions VNH.Application/DTOs/Catalog/Forum/Answer/AnswerQuestionDto.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using VNH.Application.DTOs.Catalog.Users;

namespace VNH.Application.DTOs.Catalog.Forum.Answer
{
public class AnswerQuestionDto
{

public Guid Id { get; set; } = Guid.NewGuid();
public Guid? AuthorId { get; set; }

public string QuestionId { get; set; } = string.Empty;
public UserShortDto? UserShort { get; set; }
public string Content { get; set; } = String.Empty;
public DateTime PubDate { get; set; }
public DateTime? UpdateAt { get; set; }
public bool Confirm { get; set; } = false;
public bool MostConfirm { get; set; } = false;
public List<SubAnswerQuestionDto>? SubAnswer { get; set; }

}

public class SubAnswerQuestionDto
{
public Guid Id { get; set; } = Guid.NewGuid();
public Guid PreAnswerId { get; set; }
public Guid AuthorId { get; set; }
public string Content { get; set; } = string.Empty;
[Column(TypeName = "datetime")]
public DateTime? PubDate { get; set; }
[Column(TypeName = "datetime")]
public DateTime? UpdateAt { get; set; }

public UserShortDto? UserShort { get; set; }


}

}
40 changes: 40 additions & 0 deletions VNH.Application/DTOs/Catalog/Forum/Answer/AnswerResponseDto.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using VNH.Application.DTOs.Catalog.Users;

namespace VNH.Application.DTOs.Catalog.Forum.Answer
{
public class AnswerResponseDto
{

public string Id { get; set; } = string.Empty;
public string Content { get; set; } = string.Empty;

public string QuestionId { get; set; } = string.Empty;

[Column(TypeName = "datetime")]
public DateTime? PubDate { get; set; }
public UserShortDto UserShort { get; set; } = new UserShortDto();
public bool Confirm { get; set; }
public bool MostConfirm { get; set; }
public List<SubAnswerResponseDto>? SubAnserwer { get; set; }

}

public class SubAnswerResponseDto
{
public Guid Id { get; set; }
public Guid PreAnswerId { get; set; }
public string Content { get; set; } = string.Empty;
[Column(TypeName = "datetime")]
public DateTime? PubDate { get; set; }

public UserShortDto? UserShort { get; set; }

}

}
30 changes: 30 additions & 0 deletions VNH.Application/DTOs/Catalog/Forum/Answer/CreateAnswerDto.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using VNH.Application.DTOs.Catalog.Users;

namespace VNH.Application.DTOs.Catalog.Forum.Answer
{
public class CreateAnswerDto
{
public Guid Id { get; set; } = Guid.NewGuid();
public Guid? AuthorId { get; set; }
public string QuestionId { get; set; } = string.Empty;
public string Content { get; set; } = string.Empty;

}

public class SubAnswerDto
{
public Guid Id { get; set; } = Guid.NewGuid();
public Guid PreAnswerId { get; set; }

public string Content { get; set; } = string.Empty;

public Guid AuthorId { get; set; }


}
}
18 changes: 18 additions & 0 deletions VNH.Application/DTOs/Catalog/Forum/Question/CreateQuestionDto.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace VNH.Application.DTOs.Catalog.Forum.Question
{
public class CreateQuestionDto
{
public Guid? Id { get; set; } = Guid.NewGuid();

public string? Title { get; set; } = string.Empty;
public string? Content { get; set; } = string.Empty;
public List<string>? Tag { get; set; }

}
}
14 changes: 14 additions & 0 deletions VNH.Application/DTOs/Catalog/Forum/Question/QuestionFpkDto.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace VNH.Application.DTOs.Catalog.Forum.Question
{
public class QuestionFpkDto
{
public string QuestionId { get; set; } = string.Empty;
public string UserId { get; set; } = string.Empty;
}
}
21 changes: 21 additions & 0 deletions VNH.Application/DTOs/Catalog/Forum/Question/QuestionResponseDto.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@

using VNH.Application.DTOs.Catalog.HashTags;
using VNH.Application.DTOs.Catalog.Users;

namespace VNH.Application.DTOs.Catalog.Forum.Question
{
public class QuestionResponseDto
{
public string Id { get; set; } =string.Empty;
public string Title { get; set; } = string.Empty;
public string Content { get; set; } = string.Empty;
public DateTime? CreateAt { get; set; }
public DateTime? UpdateAt { get; set; }
public List<TagDto> Tags { get; set; } = new List<TagDto>();
public UserShortDto UserShort { get; set; } = new UserShortDto();
public int ViewNumber { get; set; } = 0;
public int CommentNumber { get; set; } = 0;
public int SaveNumber { get; set; } = 0;

}
}
3 changes: 1 addition & 2 deletions VNH.Application/DTOs/Catalog/Posts/CreatePostDto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@ public class CreatePostDto
public string? Id { get; set; } = Guid.NewGuid().ToString();
public string Title { get; set; } = string.Empty;
public string Content { get; set; } = string.Empty;
public IFormFile? Image { get; set; }
public IFormFile? Image { get; set; }
public Guid TopicId { get; set; }
public List<string>? Tag { get; set; }
}
}

25 changes: 25 additions & 0 deletions VNH.Application/Interfaces/Catalog/Forum/IAnswerService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using VNH.Application.DTOs.Catalog.Forum.Answer;
using VNH.Application.DTOs.Common.ResponseNotification;
using VNH.Domain;

namespace VNH.Application.Interfaces.Catalog.Forum
{
public interface IAnswerService
{

Task<ApiResult<List<AnswerQuestionDto>>> GetAnswer(string questionId);
Task<ApiResult<List<AnswerQuestionDto>>> CreateAnswer(AnswerQuestionDto answer);
Task<ApiResult<List<AnswerQuestionDto>>> UpdateAnswer(AnswerQuestionDto answer);
Task<ApiResult<string>> DeteleAnswer(string id);


Task<ApiResult<string>> CreateSubAnswer(SubAnswerQuestionDto subAnswer);

Task<ApiResult<SubAnswerQuestionDto>> UpdateSubAnswer(SubAnswerQuestionDto answer);
Task<ApiResult<string>> DeteleSubAnswer(string id);

Task<ApiResult<int>> ConfirmOrNoConfirm(AnswerFpkDto answerFpk);


}
}
27 changes: 27 additions & 0 deletions VNH.Application/Interfaces/Catalog/Forum/IQuestionService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@


using VNH.Application.DTOs.Catalog.Forum.Question;
using VNH.Application.DTOs.Catalog.HashTags;
using VNH.Application.DTOs.Catalog.Posts;
using VNH.Application.DTOs.Common.ResponseNotification;

namespace VNH.Application.Interfaces.Catalog.Forum
{
public interface IQuestionService
{
Task<ApiResult<QuestionResponseDto>> Create(CreateQuestionDto requestDto, string name);
Task<ApiResult<QuestionResponseDto>> Update(CreateQuestionDto requestDto, string name);

Task<ApiResult<QuestionResponseDto>> Detail(string Id);
Task<ApiResult<List<QuestionResponseDto>>> GetAll();
Task<ApiResult<string>> Delete(string id, string email);
Task<ApiResult<int>> AddOrRemoveSaveQuestion(QuestionFpkDto questionFpk);

Task<ApiResult<bool>> GetSave(QuestionFpkDto questionFpk);

Task<ApiResult<List<string>>> GetAllTag(int numberTag);
Task<ApiResult<List<QuestionResponseDto>>> GetQuestionByTag(string tag);


}
}
23 changes: 23 additions & 0 deletions VNH.Application/Mappers/AnswerMapper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using AutoMapper;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using VNH.Application.DTOs.Catalog.Forum.Answer;
using VNH.Domain;

namespace VNH.Application.Mappers
{
public class AnswerMapper : Profile
{

public AnswerMapper() {
CreateMap<AnswerQuestionDto,Answer>().ReverseMap();

CreateMap<SubAnswerQuestionDto, SubAnswer>().ReverseMap();


}
}
}
21 changes: 21 additions & 0 deletions VNH.Application/Mappers/QuestionMapper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using AutoMapper;

using VNH.Application.DTOs.Catalog.Forum.Question;
using VNH.Domain;

namespace VNH.Application.Mappers
{
public class QuestionMapper : Profile

{
public QuestionMapper()
{

CreateMap<CreateQuestionDto, Question>().ReverseMap();

CreateMap<QuestionResponseDto, Question>().ReverseMap();


}
}
}
3 changes: 3 additions & 0 deletions VNH.Domain/Entities/Answer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ public Answer()
public Guid? AuthorId { get; set; }
[Column(TypeName = "datetime")]
public DateTime? PubDate { get; set; }

[Column(TypeName = "datetime")]
public DateTime? UpdateAt { get; set; }
public bool? Confirm { get; set; }
public bool? MostConfirm { get; set; }

Expand Down
11 changes: 7 additions & 4 deletions VNH.Domain/Entities/Question.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,17 @@ public Question()
public int? ViewNumber { get; set; }
public Guid? AuthorId { get; set; }
[Column(TypeName = "datetime")]
public DateTime? PubDate { get; set; }
public Guid? QuestionTagId { get; set; }
public DateTime? UpdateAt { get; set; }

[Column(TypeName = "datetime")]
public DateTime CreateAt { get; set; }


[ForeignKey("AuthorId")]
[InverseProperty("Questions")]
public virtual User Author { get; set; }
[InverseProperty("IdNavigation")]
public virtual QuestionTag QuestionTag { get; set; }
[InverseProperty("Question")]
public virtual ICollection<QuestionTag> QuestionTag { get; set; }
[InverseProperty("Question")]
public virtual ICollection<QuestionLike> QuestionLikes { get; set; }
[InverseProperty("Question")]
Expand Down
6 changes: 4 additions & 2 deletions VNH.Domain/Entities/QuestionTag.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@ public partial class QuestionTag
public Guid Id { get; set; }
public Guid? TagId { get; set; }

[ForeignKey("Id")]
public Guid? QuestionId { get; set; }

[ForeignKey("QuestionId")]
[InverseProperty("QuestionTag")]
public virtual Question IdNavigation { get; set; }
public virtual Question Question { get; set; }
[ForeignKey("TagId")]
[InverseProperty("QuestionTags")]
public virtual Tag Tag { get; set; }
Expand Down
3 changes: 3 additions & 0 deletions VNH.Domain/Entities/SubAnswer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ public partial class SubAnswer
[Column(TypeName = "datetime")]
public DateTime? PubDate { get; set; }

[Column(TypeName = "datetime")]
public DateTime? UpdateAt { get; set; }

[ForeignKey("AuthorId")]
[InverseProperty("SubAnswers")]
public virtual User Author { get; set; }
Expand Down
4 changes: 4 additions & 0 deletions VNH.Infrastructure/DependencyInjectionInfrastructure.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
using VNH.Infrastructure.Implement.Catalog.Reports;
using VNH.Application.Interfaces.Documents;
using VNH.Infrastructure.Implement.Catalog.Documents;
using VNH.Application.Interfaces.Catalog.Forum;
using VNH.Infrastructure.Implement.Catalog.Forum;

namespace VNH.Infrastructure
{
Expand Down Expand Up @@ -131,6 +133,8 @@ public static IServiceCollection AddInfrastructure(this IServiceCollection servi
services.AddScoped<IReportService, ReportService>();
services.AddScoped<IDocumentService, DocumentService>();
services.AddScoped<IFileService, FileService>();
services.AddScoped<IQuestionService, QuestionService>();
services.AddScoped<IAnswerService, AnswerService>();
services.AddSignalR();


Expand Down
Loading