forked from ServiceStackApps/RedisStackOverflow
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathResetService.cs
More file actions
69 lines (56 loc) · 5.4 KB
/
Copy pathResetService.cs
File metadata and controls
69 lines (56 loc) · 5.4 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
using System.Collections.Generic;
using RedisStackOverflow.ServiceModel;
using ServiceStack;
using ServiceStack.Redis;
namespace RedisStackOverflow.ServiceInterface
{
/// <summary>
/// Create your ServiceStack rest-ful web service implementation.
/// </summary>
public class ResetService : Service
{
/// <summary>
/// Gets or sets the Redis Manager. The built-in IoC used with ServiceStack autowires this property.
/// </summary>
public IRedisClientsManager RedisManager { get; set; }
/// <summary>
/// Gets or sets the repository. The built-in IoC used with ServiceStack autowires this property.
/// </summary>
public IRedisRepository Repository { get; set; }
private static readonly Dictionary<string, string> JavascriptQuestions = new() {
{"a javascript string problem?","i have this script, but i the result.bgimage is not showing up, i think JS thinks its a string rather than variable!!! how can i solve this problem? thanks"},
{"Control events of Object (HTML) by JavaScript","Is it possible to control an object that contains a swf that streams music, I want to be able to pause it by JS, but I don't know if that's possible or not."},
{"Javascript function not working with an array","i have this function which loops through an array of check boxes checking if the boxes value is equal to something in a text box, i dont know whats wrong."},
{"Prototypal programming in Python","Javascript uses a prototype-based model for its objects. Nevertheless, the language is very flexible, and it is easy to write in a few lines functions which replace other kind on constructs. For instance, one can make a class function, emulating the standard class behaviour, including inheritance or private members. Or one can mimcìic functional tools by writing, for instance, a curry function which will take a function and some of its arguments and return the partially applied function."},
};
static readonly Dictionary<string, string> RestQuestions = new() {
{"How do I implement login in a RESTful web service?","I am building a web application with a services layer. The services layer is going to be built using a RESTful design. The thinking is that some time in the future we may build other applications (iPhone, Android, etc.) that use the same services layer as the web application. My question is this - how do I implement login? I think I am having trouble moving from a more traditional verb based design to a resource based design. If I was building this with SOAP I would probably have a method called Login. In REST I should have a resource."},
{"Framework for providing API access to website?","We have a website that we want to provide web based API access to to other sites. It may end up being a REST based API, but I'm not sure yet. It needs to be accessible from a Drupal module, but we want to built the API to be scalable so that we can access the site's data and functionality from other environments such as joomla, wordpress, other non-php languages, etc. I am looking for a robust/stable PHP based framework that allows me to create such APIs - can folks suggest something that meets the criteria?"},
{"Does HATEOAS imply query strings are not RESTful?","Does the HATEOAS (hypermedia as the engine of app state) recommendation imply that query strings are not RESTful?"},
{"Drupal as backend for RESTful API?","Are there any good write-ups on creating RESTful APIs with Drupal? I see the services API, which I guess is how it's done. What I'm looking for, I suppose is a comparison of drupal vs. other frameworks for that particular purpose."},
};
public Question ToQuestion(string title, string body, List<string> tags)
{
return new Question
{
Title = title,
Content = body,
Tags = tags,
};
}
public object Get(Reset request)
{
var restQuestions = new Dictionary<string, string>(RestQuestions);
JavascriptQuestions.ForEach(restQuestions.Add);
var questions = new List<Question>();
questions.AddRange(RestQuestions.Map(kvp => ToQuestion(kvp.Key, kvp.Value, new List<string> { "rest", "http" })));
questions.AddRange(JavascriptQuestions.Map(kvp => ToQuestion(kvp.Key, kvp.Value, new List<string> { "javascript", "jquery" })));
RedisManager.Exec(r => r.FlushAll());
var mythz = Repository.GetOrCreateUser(new User { DisplayName = "mythz" });
questions.ForEach(q => q.UserId = mythz.Id);
questions.ForEach(q => Repository.StoreQuestion(q));
AuthRepository.CreateUsers();
return HttpResult.Redirect("/");
}
}
}