1
1
package dev.snipme.snipmeapp.domain.snippets
2
2
3
3
import dev.snipme.snipmeapp.domain.repository.snippet.SnippetRepository
4
- import dev.snipme.snipmeapp.util.extension.titleCase
5
4
import io.reactivex.Completable
6
5
import io.reactivex.Single
7
6
@@ -13,7 +12,9 @@ class SetupDemoSnippetsUseCase(
13
12
val demoSetup = snippetRepository.getDemoSetupStatus()
14
13
15
14
return if (! demoSetup) {
16
- setupDemoSnippets()
15
+ setupDemoSnippets().andThen(
16
+ snippetRepository.setDemoSetupStatus(true )
17
+ )
17
18
} else {
18
19
Completable .complete()
19
20
}
@@ -24,24 +25,36 @@ class SetupDemoSnippetsUseCase(
24
25
snippetRepository.create(
25
26
title = " Your first snippet" ,
26
27
code = KOTLIN_SAMPLE ,
27
- language = SnippetLanguageType .KOTLIN .name.titleCase() ,
28
+ language = SnippetLanguageType .KOTLIN .name,
28
29
visibility = SnippetVisibility .VISIBLE ,
29
- userId = 1 ,
30
30
favorite = false
31
31
),
32
32
snippetRepository.create(
33
- title = " Hello World " ,
34
- code = " console.log('Hello, World!') " ,
35
- language = SnippetLanguageType .JAVASCRIPT .name.titleCase() ,
33
+ title = " Your favorite code " ,
34
+ code = JAVASCRIPT_SAMPLE ,
35
+ language = SnippetLanguageType .JAVASCRIPT .name,
36
36
visibility = SnippetVisibility .VISIBLE ,
37
- userId = 1 ,
37
+ favorite = true
38
+ ),
39
+ snippetRepository.create(
40
+ title = " Hidden one" ,
41
+ code = PYTHON_SAMPLE ,
42
+ language = SnippetLanguageType .PYTHON .name,
43
+ visibility = SnippetVisibility .HIDDEN ,
38
44
favorite = false
39
45
),
46
+ snippetRepository.create(
47
+ title = " Popular Java code" ,
48
+ code = JAVA_SAMPLE ,
49
+ language = SnippetLanguageType .JAVA .name,
50
+ visibility = SnippetVisibility .VISIBLE ,
51
+ favorite = false
52
+ )
40
53
),
41
54
)
42
55
}
43
56
44
- const val KOTLIN_SAMPLE = """
57
+ private const val KOTLIN_SAMPLE = """
45
58
// Data class
46
59
data class User(val id: Int, val name: String, val email: String)
47
60
@@ -109,4 +122,77 @@ suspend fun fetchUserData(): Result<List<User>> {
109
122
}
110
123
}
111
124
}
125
+ """
126
+
127
+ const val JAVASCRIPT_SAMPLE = """
128
+ // Async function with Promise
129
+ async function fetchUserData() {
130
+ return new Promise((resolve, reject) => {
131
+ setTimeout(() => {
132
+ try {
133
+ const data = [
134
+ new User(1, 'Alice', '[email protected] '),
135
+ new User(2, 'Bob', 'bobexample.com'), // Invalid email
136
+ new User(3, 'Charlie', '[email protected] ')
137
+ ];
138
+ resolve(data);
139
+ } catch (error) {
140
+ reject(error);
141
+ }
142
+ }, 1000); // Simulate network delay
143
+ });
144
+ }
145
+ """
146
+
147
+ const val PYTHON_SAMPLE = """
148
+ # Class definition
149
+ class User:
150
+ def __init__(self, id, name, email):
151
+ self.id = id
152
+ self.name = name
153
+ self.email = email
154
+
155
+ def __str__(self):
156
+ return f'User(id={self.id}, name={self.name}, email={self.email})'
157
+
158
+ # Function with list comprehension
159
+ def is_valid_email(email):
160
+ return '@' in email and '.' in email
161
+
162
+ # Function with generator expression
163
+
164
+ def custom_filter(predicate, items):
165
+ return [item for item in items if predicate(item)]
166
+ """
167
+
168
+ const val JAVA_SAMPLE = """
169
+ // Class definition
170
+ public class User {
171
+ private final int id;
172
+ private final String name;
173
+ private final String email;
174
+
175
+ public User(int id, String name, String email) {
176
+ this.id = id;
177
+ this.name = name;
178
+ this.email = email;
179
+ }
180
+
181
+ @Override
182
+ public String toString() {
183
+ return String.format("User(id=%d, name=%s, email=%s)", id, name, email);
184
+ }
185
+
186
+ // Function with lambda expression
187
+ public static boolean isValidEmail(String email) {
188
+ return email.contains("@") && email.contains(".");
189
+ }
190
+
191
+ // Function with method reference
192
+ public static List<User> customFilter(Predicate<User> predicate, List<User> items) {
193
+ return items.stream()
194
+ .filter(predicate)
195
+ .collect(Collectors.toList());
196
+ }
197
+ }
112
198
"""
0 commit comments