Skip to content

Commit 9954edf

Browse files
committed
feat: Init Project
1 parent 82deafd commit 9954edf

21 files changed

+692
-118
lines changed

App.tsx

+18-112
Original file line numberDiff line numberDiff line change
@@ -1,118 +1,24 @@
1-
/**
2-
* Sample React Native App
3-
* https://github.com/facebook/react-native
4-
*
5-
* @format
6-
*/
7-
1+
import {createNativeStackNavigator} from '@react-navigation/native-stack';
82
import React from 'react';
9-
import type {PropsWithChildren} from 'react';
10-
import {
11-
SafeAreaView,
12-
ScrollView,
13-
StatusBar,
14-
StyleSheet,
15-
Text,
16-
useColorScheme,
17-
View,
18-
} from 'react-native';
19-
20-
import {
21-
Colors,
22-
DebugInstructions,
23-
Header,
24-
LearnMoreLinks,
25-
ReloadInstructions,
26-
} from 'react-native/Libraries/NewAppScreen';
27-
28-
type SectionProps = PropsWithChildren<{
29-
title: string;
30-
}>;
31-
32-
function Section({children, title}: SectionProps): React.JSX.Element {
33-
const isDarkMode = useColorScheme() === 'dark';
34-
return (
35-
<View style={styles.sectionContainer}>
36-
<Text
37-
style={[
38-
styles.sectionTitle,
39-
{
40-
color: isDarkMode ? Colors.white : Colors.black,
41-
},
42-
]}>
43-
{title}
44-
</Text>
45-
<Text
46-
style={[
47-
styles.sectionDescription,
48-
{
49-
color: isDarkMode ? Colors.light : Colors.dark,
50-
},
51-
]}>
52-
{children}
53-
</Text>
54-
</View>
55-
);
56-
}
57-
58-
function App(): React.JSX.Element {
59-
const isDarkMode = useColorScheme() === 'dark';
3+
import UserScreen from './src/presentation/pages/UserScreen';
4+
import {NavigationContainer} from '@react-navigation/native';
5+
import UserDetailScreen from './src/presentation/pages/UserDetailScreen';
6+
import CharacterScreen from './src/presentation/pages/CharacterScreen';
7+
import {QueryClient, QueryClientProvider} from 'react-query';
608

61-
const backgroundStyle = {
62-
backgroundColor: isDarkMode ? Colors.darker : Colors.lighter,
63-
};
9+
const Stack = createNativeStackNavigator();
10+
const queryClient = new QueryClient();
6411

12+
export default function MyStack() {
6513
return (
66-
<SafeAreaView style={backgroundStyle}>
67-
<StatusBar
68-
barStyle={isDarkMode ? 'light-content' : 'dark-content'}
69-
backgroundColor={backgroundStyle.backgroundColor}
70-
/>
71-
<ScrollView
72-
contentInsetAdjustmentBehavior="automatic"
73-
style={backgroundStyle}>
74-
<Header />
75-
<View
76-
style={{
77-
backgroundColor: isDarkMode ? Colors.black : Colors.white,
78-
}}>
79-
<Section title="Step One">
80-
Edit <Text style={styles.highlight}>App.tsx</Text> to change this
81-
screen and then come back to see your edits.
82-
</Section>
83-
<Section title="See Your Changes">
84-
<ReloadInstructions />
85-
</Section>
86-
<Section title="Debug">
87-
<DebugInstructions />
88-
</Section>
89-
<Section title="Learn More">
90-
Read the docs to discover what to do next:
91-
</Section>
92-
<LearnMoreLinks />
93-
</View>
94-
</ScrollView>
95-
</SafeAreaView>
14+
<QueryClientProvider client={queryClient}>
15+
<NavigationContainer>
16+
<Stack.Navigator initialRouteName="Characters">
17+
<Stack.Screen name="Characters" component={CharacterScreen} />
18+
<Stack.Screen name="User" component={UserScreen} />
19+
<Stack.Screen name="UserDetail" component={UserDetailScreen} />
20+
</Stack.Navigator>
21+
</NavigationContainer>
22+
</QueryClientProvider>
9623
);
9724
}
98-
99-
const styles = StyleSheet.create({
100-
sectionContainer: {
101-
marginTop: 32,
102-
paddingHorizontal: 24,
103-
},
104-
sectionTitle: {
105-
fontSize: 24,
106-
fontWeight: '600',
107-
},
108-
sectionDescription: {
109-
marginTop: 8,
110-
fontSize: 18,
111-
fontWeight: '400',
112-
},
113-
highlight: {
114-
fontWeight: '700',
115-
},
116-
});
117-
118-
export default App;

ios/Podfile.lock

+33-1
Original file line numberDiff line numberDiff line change
@@ -935,6 +935,8 @@ PODS:
935935
- React-Mapbuffer (0.74.3):
936936
- glog
937937
- React-debug
938+
- react-native-safe-area-context (4.10.8):
939+
- React-Core
938940
- React-nativeconfig (0.74.3)
939941
- React-NativeModulesApple (0.74.3):
940942
- glog
@@ -1164,6 +1166,28 @@ PODS:
11641166
- React-logger (= 0.74.3)
11651167
- React-perflogger (= 0.74.3)
11661168
- React-utils (= 0.74.3)
1169+
- RNScreens (3.32.0):
1170+
- DoubleConversion
1171+
- glog
1172+
- hermes-engine
1173+
- RCT-Folly (= 2024.01.01.00)
1174+
- RCTRequired
1175+
- RCTTypeSafety
1176+
- React-Codegen
1177+
- React-Core
1178+
- React-debug
1179+
- React-Fabric
1180+
- React-featureflags
1181+
- React-graphics
1182+
- React-ImageManager
1183+
- React-NativeModulesApple
1184+
- React-RCTFabric
1185+
- React-RCTImage
1186+
- React-rendererdebug
1187+
- React-utils
1188+
- ReactCommon/turbomodule/bridging
1189+
- ReactCommon/turbomodule/core
1190+
- Yoga
11671191
- SocketRocket (0.7.0)
11681192
- Yoga (0.0.0)
11691193

@@ -1200,6 +1224,7 @@ DEPENDENCIES:
12001224
- React-jsitracing (from `../node_modules/react-native/ReactCommon/hermes/executor/`)
12011225
- React-logger (from `../node_modules/react-native/ReactCommon/logger`)
12021226
- React-Mapbuffer (from `../node_modules/react-native/ReactCommon`)
1227+
- react-native-safe-area-context (from `../node_modules/react-native-safe-area-context`)
12031228
- React-nativeconfig (from `../node_modules/react-native/ReactCommon`)
12041229
- React-NativeModulesApple (from `../node_modules/react-native/ReactCommon/react/nativemodule/core/platform/ios`)
12051230
- React-perflogger (from `../node_modules/react-native/ReactCommon/reactperflogger`)
@@ -1223,6 +1248,7 @@ DEPENDENCIES:
12231248
- React-runtimescheduler (from `../node_modules/react-native/ReactCommon/react/renderer/runtimescheduler`)
12241249
- React-utils (from `../node_modules/react-native/ReactCommon/react/utils`)
12251250
- ReactCommon/turbomodule/core (from `../node_modules/react-native/ReactCommon`)
1251+
- RNScreens (from `../node_modules/react-native-screens`)
12261252
- Yoga (from `../node_modules/react-native/ReactCommon/yoga`)
12271253

12281254
SPEC REPOS:
@@ -1291,6 +1317,8 @@ EXTERNAL SOURCES:
12911317
:path: "../node_modules/react-native/ReactCommon/logger"
12921318
React-Mapbuffer:
12931319
:path: "../node_modules/react-native/ReactCommon"
1320+
react-native-safe-area-context:
1321+
:path: "../node_modules/react-native-safe-area-context"
12941322
React-nativeconfig:
12951323
:path: "../node_modules/react-native/ReactCommon"
12961324
React-NativeModulesApple:
@@ -1337,6 +1365,8 @@ EXTERNAL SOURCES:
13371365
:path: "../node_modules/react-native/ReactCommon/react/utils"
13381366
ReactCommon:
13391367
:path: "../node_modules/react-native/ReactCommon"
1368+
RNScreens:
1369+
:path: "../node_modules/react-native-screens"
13401370
Yoga:
13411371
:path: "../node_modules/react-native/ReactCommon/yoga"
13421372

@@ -1371,6 +1401,7 @@ SPEC CHECKSUMS:
13711401
React-jsitracing: 6b3c8c98313642140530f93c46f5a6ca4530b446
13721402
React-logger: fa92ba4d3a5d39ac450f59be2a3cec7b099f0304
13731403
React-Mapbuffer: 9f68550e7c6839d01411ac8896aea5c868eff63a
1404+
react-native-safe-area-context: b7daa1a8df36095a032dff095a1ea8963cb48371
13741405
React-nativeconfig: fa5de9d8f4dbd5917358f8ad3ad1e08762f01dcb
13751406
React-NativeModulesApple: 585d1b78e0597de364d259cb56007052d0bda5e5
13761407
React-perflogger: 7bb9ba49435ff66b666e7966ee10082508a203e8
@@ -1394,9 +1425,10 @@ SPEC CHECKSUMS:
13941425
React-runtimescheduler: 0c80752bceb80924cb8a4babc2a8e3ed70d41e87
13951426
React-utils: a06061b3887c702235d2dac92dacbd93e1ea079e
13961427
ReactCommon: f00e436b3925a7ae44dfa294b43ef360fbd8ccc4
1428+
RNScreens: 5aeecbb09aa7285379b6e9f3c8a3c859bb16401c
13971429
SocketRocket: abac6f5de4d4d62d24e11868d7a2f427e0ef940d
13981430
Yoga: 88480008ccacea6301ff7bf58726e27a72931c8d
13991431

14001432
PODFILE CHECKSUM: baf45152e05de6e137288a2c7e40b5979da97295
14011433

1402-
COCOAPODS: 1.14.3
1434+
COCOAPODS: 1.15.2

package.json

+7-1
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,14 @@
1010
"test": "jest"
1111
},
1212
"dependencies": {
13+
"@react-navigation/native": "^6.1.17",
14+
"@react-navigation/native-stack": "^6.10.0",
15+
"axios": "^1.7.2",
1316
"react": "18.2.0",
14-
"react-native": "0.74.3"
17+
"react-native": "0.74.3",
18+
"react-native-safe-area-context": "^4.10.8",
19+
"react-native-screens": "^3.32.0",
20+
"react-query": "^3.39.3"
1521
},
1622
"devDependencies": {
1723
"@babel/core": "^7.20.0",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import {Character} from '../../domain/entities/Character';
2+
3+
export interface ICharacterRepository {
4+
getAllCharacters(page: number): Promise<Character[]>;
5+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import User from '../../domain/entities/User';
2+
3+
export interface IUserRepository {
4+
getUsers(): Promise<User[]>;
5+
getByUserId(userId: number): Promise<User>;
6+
// N data logically
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import {Character} from '../../domain/entities/Character';
2+
import {ICharacterRepository} from '../models/ICharacterRepository';
3+
4+
export class CharacterRepository implements ICharacterRepository {
5+
async getAllCharacters(page: number): Promise<Character[]> {
6+
const response = await fetch(
7+
`https://rickandmortyapi.com/api/character?page=${page}`,
8+
);
9+
const data = await response.json();
10+
return data.results.map(
11+
(char: any) =>
12+
new Character(
13+
char.id,
14+
char.name,
15+
char.status,
16+
char.species,
17+
char.gender,
18+
char.image,
19+
),
20+
);
21+
}
22+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import {User} from '../../domain/entities/User';
2+
import {UserEntity} from '../../domain/entities/UserEntity';
3+
import {IUserRepository} from '../models/IUserRepository';
4+
5+
export class UserRepository implements IUserRepository {
6+
async getUsers(): Promise<User[]> {
7+
const response = await fetch('https://jsonplaceholder.typicode.com/users');
8+
9+
const data = await response.json();
10+
11+
return data.map(
12+
(user: UserEntity) => new User(user.id, user.name, user.email),
13+
);
14+
}
15+
async getByUserId(userId: number): Promise<User> {
16+
const response = await fetch(
17+
`https://jsonplaceholder.typicode.com/users/${userId}`,
18+
);
19+
20+
const data = await response.json();
21+
22+
return new User(data.id, data.name, data.email);
23+
}
24+
}

src/domain/entities/Character.ts

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
export class Character {
2+
constructor(
3+
public id: number,
4+
public name: string,
5+
public status: string,
6+
public species: string,
7+
public gender: string,
8+
public image: string,
9+
) {}
10+
}

src/domain/entities/User.ts

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// import {useState} from 'react';
2+
3+
export class User {
4+
constructor(public id: number, public name: string, public email: string) {}
5+
}
6+
7+
// interface UserProps {
8+
// initialId: string;
9+
// initialName: string;
10+
// initialEmail: string;
11+
// }
12+
13+
// const UserFunc = ({initialId, initialName, initialEmail}: UserProps): any => {
14+
// const [id, setId] = useState<string>(initialId);
15+
// const [name, setName] = useState<string>(initialName);
16+
// const [email, setEmail] = useState<string>(initialEmail);
17+
18+
// return {id, setId, name, setName, email, setEmail};
19+
// };
20+
21+
export default User;

src/domain/entities/UserEntity.ts

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
export interface UserEntity {
2+
id: number;
3+
name: string;
4+
username: string;
5+
email: string;
6+
address: Address;
7+
phone: string;
8+
website: string;
9+
company: Company;
10+
}
11+
12+
export interface Address {
13+
street: string;
14+
suite: string;
15+
city: string;
16+
zipcode: string;
17+
geo: Geo;
18+
}
19+
20+
export interface Geo {
21+
lat: string;
22+
lng: string;
23+
}
24+
25+
export interface Company {
26+
name: string;
27+
catchPhrase: string;
28+
bs: string;
29+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import {ICharacterRepository} from '../../application/models/ICharacterRepository';
2+
import {Character} from '../entities/Character';
3+
4+
export class GetCharactersUseCase {
5+
constructor(private characterRepository: ICharacterRepository) {}
6+
7+
async execute(page: number): Promise<Character[]> {
8+
return await this.characterRepository.getAllCharacters(page);
9+
}
10+
}

src/domain/usecases/GetUserUseCase.ts

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import {IUserRepository} from '../../application/models/IUserRepository';
2+
import {User} from '../entities/User';
3+
4+
export class GetUserUseCase {
5+
constructor(private userRepository: IUserRepository) {}
6+
7+
async execute(): Promise<User[]> {
8+
return await this.userRepository.getUsers();
9+
}
10+
11+
async executeById(id: number): Promise<User> {
12+
return await this.userRepository.getByUserId(id);
13+
}
14+
}

0 commit comments

Comments
 (0)