11package dev.snipme.snipmeapp.domain.snippets
22
33import dev.snipme.snipmeapp.domain.repository.snippet.SnippetRepository
4- import dev.snipme.snipmeapp.util.extension.titleCase
54import io.reactivex.Completable
65import io.reactivex.Single
76
@@ -13,7 +12,9 @@ class SetupDemoSnippetsUseCase(
1312 val demoSetup = snippetRepository.getDemoSetupStatus()
1413
1514 return if (! demoSetup) {
16- setupDemoSnippets()
15+ setupDemoSnippets().andThen(
16+ snippetRepository.setDemoSetupStatus(true )
17+ )
1718 } else {
1819 Completable .complete()
1920 }
@@ -24,24 +25,36 @@ class SetupDemoSnippetsUseCase(
2425 snippetRepository.create(
2526 title = " Your first snippet" ,
2627 code = KOTLIN_SAMPLE ,
27- language = SnippetLanguageType .KOTLIN .name.titleCase() ,
28+ language = SnippetLanguageType .KOTLIN .name,
2829 visibility = SnippetVisibility .VISIBLE ,
29- userId = 1 ,
3030 favorite = false
3131 ),
3232 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,
3636 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 ,
3844 favorite = false
3945 ),
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+ )
4053 ),
4154 )
4255}
4356
44- const val KOTLIN_SAMPLE = """
57+ private const val KOTLIN_SAMPLE = """
4558// Data class
4659data class User(val id: Int, val name: String, val email: String)
4760
@@ -109,4 +122,77 @@ suspend fun fetchUserData(): Result<List<User>> {
109122 }
110123 }
111124}
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', 'alice@example.com'),
135+ new User(2, 'Bob', 'bobexample.com'), // Invalid email
136+ new User(3, 'Charlie', 'charlie@example.com')
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+ }
112198"""
0 commit comments