This repository was archived by the owner on Dec 24, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathStackOverflowQuery.cs
More file actions
138 lines (120 loc) · 3.96 KB
/
Copy pathStackOverflowQuery.cs
File metadata and controls
138 lines (120 loc) · 3.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
using System.Collections.Generic;
using ServiceStack.DataAnnotations;
using ServiceStack.OrmLite;
namespace ServiceStack.Admin.Web
{
[Route("/questions")]
[AutoQueryViewer(
Title = "Explore StackOverflow Questions", Description = "Find ServiceStack Questions on StackOverflow",
IconUrl = "material-icons:cast", DefaultSearchField = "Title", DefaultSearchType = "Contains", DefaultSearchText = "ServiceStack")]
public class StackOverflowQuery : QueryDb<Question>
{
public int? ScoreGreaterThan { get; set; }
}
[Route("/questions/search")]
public class SearchQuestions : IReturn<SearchQuestionsResponse>
{
public List<string> Tags { get; set; }
public string UserId { get; set; }
}
[Description("Get a list of Answers for a Question")]
[Route("/answers/{QuestionId}")]
public class GetAnswers : IReturn<GetAnswersResponse>
{
public int QuestionId { get; set; }
}
public class StackOverflowServices : Service
{
public object Get(SearchQuestions request)
{
var query = Db.From<Question>();
if (request.Tags != null && request.Tags.Count > 0)
{
query.Join<QuestionTag>((q, t) => q.QuestionId == t.QuestionId)
.Where<QuestionTag>(x => Sql.In(x.Tag, request.Tags));
}
var response = new SearchQuestionsResponse
{
Results = Db.Select(query)
};
return response;
}
public object Get(GetAnswers request)
{
return new GetAnswersResponse
{
Ansnwer = Db.Single<Answer>(x => x.QuestionId == request.QuestionId)
};
}
}
public class SearchQuestionsResponse
{
public List<Question> Results { get; set; }
}
public class GetAnswersResponse
{
public Answer Ansnwer { get; set; }
}
public class AnswersResponse
{
public List<Answer> Items { get; set; }
public bool HasMore { get; set; }
public int QuotaMax { get; set; }
public int QuotaRemaining { get; set; }
}
public class QuestionsResponse
{
public List<Question> Items { get; set; }
public bool HasMore { get; set; }
public int QuotaMax { get; set; }
public int QuotaRemaining { get; set; }
}
public class User
{
public int Reputation { get; set; }
public int Userid { get; set; }
public string UserType { get; set; }
public int AcceptRate { get; set; }
public string ProfileImage { get; set; }
public string DisplayName { get; set; }
public string Link { get; set; }
}
public class Question
{
[PrimaryKey]
[Alias("Id")]
public int QuestionId { get; set; }
public string Title { get; set; }
public int Score { get; set; }
public int ViewCount { get; set; }
public bool IsAnswered { get; set; }
public int AnswerCount { get; set; }
public string Link { get; set; }
public string[] Tags { get; set; }
public User Owner { get; set; }
public int LastActivityDate { get; set; }
public int CreationDate { get; set; }
public int LastEditDate { get; set; }
public int? AcceptedAnswerId { get; set; }
}
public class QuestionTag
{
[AutoIncrement]
public int Id { get; set; }
public int QuestionId { get; set; }
public string Tag { get; set; }
}
public class Answer
{
[PrimaryKey]
[Alias("Id")]
public int AnswerId { get; set; }
public User Owner { get; set; }
public bool IsAccepted { get; set; }
public int Score { get; set; }
public int LastActivityDate { get; set; }
public int LastEditDate { get; set; }
public int CreationDate { get; set; }
public int QuestionId { get; set; }
}
}