Skip to content

Commit 0e5f064

Browse files
committed
Fourth frontend part
1 parent afb1d69 commit 0e5f064

File tree

24 files changed

+856
-606
lines changed

24 files changed

+856
-606
lines changed

backend/foundation/src/main/kotlin/ru/ifmo/se/dating/spring/api/CorsFilter.kt

+5-4
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,13 @@ class CorsFilter : WebFilter {
1313
// FIXME
1414
override fun filter(ctx: ServerWebExchange, chain: WebFilterChain): Mono<Void> {
1515
ctx.response.headers.add("Access-Control-Allow-Origin", "*")
16-
ctx.response.headers.add("Access-Control-Allow-Methods", "GET, PUT, POST, DELETE, OPTIONS")
16+
ctx.response.headers.add("Access-Control-Allow-Methods", "GET, PUT, POST, PATCH, DELETE, OPTIONS")
1717
ctx.response.headers.add(
1818
"Access-Control-Allow-Headers",
19-
"DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With," +
20-
"If-Modified-Since,Cache-Control,Content-Type,Content-Range,Range"
21-
)
19+
// "DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With," +
20+
// "If-Modified-Since,Cache-Control,Content-Type,Content-Range,Range,Authorization"
21+
"*"
22+
)
2223
if (ctx.request.method == HttpMethod.OPTIONS) {
2324
ctx.response.headers.add("Access-Control-Max-Age", "1728000")
2425
ctx.response.statusCode = HttpStatus.NO_CONTENT

backend/matchmaker/src/main/kotlin/ru/ifmo/se/dating/matchmaker/security/MatchmakerSecuredPaths.kt

+1
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,6 @@ class MatchmakerSecuredPaths : SpringSecuredPaths {
1414
Path("/api/**"),
1515
Not(Path("/api/people/{person_id}", HttpMethod.PUT)),
1616
Not(Path("/api/monitoring/healthcheck", HttpMethod.GET)),
17+
Not(Path("/api/suggestions", HttpMethod.OPTIONS)),
1718
)
1819
}

frontend/Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ COPY package*.json ./
66

77
RUN npm install
88

9-
# COPY .cert ./.cert
9+
COPY .cert ./.cert
1010

1111
COPY dist ./dist
1212

frontend/src/app/routes/ui/index.tsx

+8-7
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import { Route } from 'atomic-router-react'
22
import { routes } from '../api'
3-
import { Registration, Home, Main } from '@/pages'
3+
import { Registration, Main } from '@/pages'
4+
import { Welcome } from '@/pages/welcome/ui/Welcome.tsx'
45

56
export const Routes = () => (
6-
<>
7-
<Route route={routes.home} view={Home} />
8-
<Route route={routes.registration} view={Registration} />
9-
<Route route={routes.main} view={Main} />
10-
</>
11-
)
7+
<>
8+
<Route route={routes.home} view={Welcome}/>
9+
<Route route={routes.registration} view={Registration}/>
10+
<Route route={routes.main} view={Main}/>
11+
</>
12+
);
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
export interface PersonPatch {
2-
status: string
3-
firstName: string
4-
lastName: string
5-
interests: Topic[]
6-
height: number
7-
birthday: string
8-
facultyId: number
9-
locationId: number
2+
status: string | null,
3+
firstName: string | null,
4+
lastName: string | null,
5+
interests: Topic[] | null,
6+
height: number | null,
7+
birthday: string | null,
8+
facultyId: number | null,
9+
locationId: number | null
1010
}
1111

1212
export interface Topic {
13-
topicId: number
14-
level: number
13+
topicId: number,
14+
level: number
1515
}

frontend/src/entities/person/model/Person.ts

+13
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,16 @@ export interface Person {
1515
faculty: string
1616
location: Location
1717
}
18+
19+
export interface PersonLegacy {
20+
status: string,
21+
userId: number,
22+
firstName: string,
23+
zodiac: string,
24+
lastName: string,
25+
interests: Interest[],
26+
height: number,
27+
birthday: Date,
28+
facultyId: number,
29+
locationId: number
30+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export interface Coordinates {
2+
latitude: number,
3+
longitude: number
4+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { Coordinates } from './Coordinates.ts'
2+
3+
export interface Location {
4+
id: number,
5+
name: string,
6+
coordinates: Coordinates
7+
8+
}

frontend/src/entities/registration-data/model/RegistartionData.ts

+10-9
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@ import { Interest } from './interest.ts'
22
import { Picture } from './picture.ts'
33

44
export type RegistrationData = {
5-
tgId: string
6-
name: string
7-
surname: string
8-
height: number
9-
faculty: string
10-
birthday: Date
11-
pictures: Picture[]
12-
interests: Interest[]
13-
}
5+
tgId: string | null;
6+
name: string | null;
7+
surname: string | null;
8+
height: number | null;
9+
facultyId: number | null;
10+
birthday: Date | null;
11+
pictures: Picture[] | null;
12+
interests: Interest[] | null;
13+
locationId: number | null;
14+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export interface Faculty {
2+
id: number,
3+
longName: string
4+
}
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,80 @@
1-
import { createEffect, createStore } from 'effector'
2-
import { persist } from 'effector-storage/session'
3-
import { AuthRequest } from '../model/AuthRequest.ts'
4-
import { AuthResponse } from '../model/AuthResponse.ts'
1+
import {createEffect, createStore} from 'effector'
2+
import {persist} from 'effector-storage/session'
3+
import {AuthRequest} from '../model/AuthRequest.ts'
4+
import {AuthResponse} from '../model/AuthResponse.ts'
55
import axios from 'axios'
6-
import { AuthState, initialAuthState } from '@/entities'
7-
import { backendAuthikUrl } from '@/shared/api'
6+
import {AuthState, initialAuthState} from '@/entities'
7+
import {backendAuthikUrl} from '@/shared/api'
88

99
export const $authStore = createStore<AuthState>(initialAuthState)
10+
export const $userIdStore = createStore<number | null>(null);
1011

11-
persist({ store: $authStore, key: 'authStore' })
12+
export const $userRegisteredStore = createStore<boolean>(false);
13+
14+
15+
persist({store: $authStore, key: 'authStore'})
16+
persist({store: $userIdStore, key: 'userIdStore'})
17+
persist({store: $userRegisteredStore, key: 'userRegisteredStore'})
1218

1319
export const authFx = createEffect<AuthRequest, AuthState, Error>({
14-
handler: async (authReq) => {
15-
try {
16-
const response = await axios.put<AuthResponse>(
17-
`${backendAuthikUrl}/api/auth/telegram/web-app`,
18-
JSON.stringify(authReq),
19-
{
20-
method: 'PUT',
21-
headers: {
22-
'Content-Type': 'application/json',
23-
},
24-
},
25-
)
26-
return fillAuthState(response.data)
27-
} catch (error) {
28-
console.error(error)
29-
throw new Error('Auth failed')
30-
}
31-
},
20+
handler: async (authReq) => {
21+
try {
22+
const response = await axios.put<AuthResponse>(
23+
`${backendAuthikUrl}/api/auth/telegram/web-app`,
24+
JSON.stringify(authReq),
25+
{
26+
method: 'PUT',
27+
headers: {
28+
'Content-Type': 'application/json',
29+
},
30+
},
31+
)
32+
return fillAuthState(response.data)
33+
} catch (error) {
34+
console.error(error)
35+
throw new Error('Auth failed')
36+
}
37+
},
3238
})
3339

3440
const fillAuthState = (response: AuthResponse): AuthState => {
35-
return {
36-
token: response.access,
37-
loading: false,
38-
tgId: '-1',
39-
isAuthenticated: true,
40-
error: null,
41-
}
41+
return {
42+
token: response.access,
43+
loading: false,
44+
tgId: '-1',
45+
isAuthenticated: true,
46+
error: null
47+
};
4248
}
4349

44-
export const $isAuthenticated = $authStore.map((state) => state.isAuthenticated)
50+
export const $isAuthenticated = $authStore.map(state => state.isAuthenticated)
51+
52+
$authStore.on(authFx.doneData, (_, result) => result);
53+
$authStore.on(authFx.failData, (_, error) => ({...initialAuthState, loading: false, error: error.message}));
54+
55+
export const userIdFx = createEffect<number | null, number | null, Error>({
56+
handler: async (x) => {
57+
if (x == null)
58+
throw Error("x is null")
59+
return x
60+
}
61+
}
62+
)
63+
64+
export const userRegisteredFx = createEffect<boolean, boolean, Error>({
65+
handler: async (x) => {
66+
if (!x)
67+
throw Error("user not registered")
68+
return x
69+
}
70+
}
71+
)
4572

46-
$authStore.on(authFx.doneData, (_, result) => result)
47-
$authStore.on(authFx.failData, (_, error) => ({
48-
...initialAuthState,
49-
loading: false,
50-
error: error.message,
51-
}))
73+
$userIdStore.on(userIdFx.doneData, (_, result) => result)
74+
$userIdStore.on(userIdFx.failData, (_, __) => {
75+
return null
76+
})
77+
$userRegisteredStore.on(userRegisteredFx.doneData, (_, result) => result)
78+
$userRegisteredStore.on(userRegisteredFx.failData, (_, __) => {
79+
return false
80+
})

frontend/src/features/edit-profile/api/editProfile.ts

+29-29
Original file line numberDiff line numberDiff line change
@@ -6,33 +6,33 @@ import { PersonPatch } from '@/entities/person-patch/model/PersonPatch.ts'
66
export function editProfile(profile: Person) {
77
const url = `${backendPeopleUrl}/api/people/${profile.id}`
88

9-
// FIXME jwt token
10-
const basicAuth = 'test basic auth'
11-
const config = {
12-
method: 'POST',
13-
headers: {
14-
'Content-Type': 'application/json',
15-
Authorization: +basicAuth,
16-
},
17-
}
18-
const profilePatch: PersonPatch = {
19-
status: 'ready',
20-
firstName: profile.firstName,
21-
lastName: profile.lastName,
22-
interests: profile.interests.map((interest) => {
23-
return { topicId: interest.topic.id, level: interest.level }
24-
}),
25-
height: profile.height,
26-
birthday: `${profile.birthday.getFullYear()}-${profile.birthday.getMonth()}-${profile.birthday.getDay()}`,
27-
facultyId: 1,
28-
locationId: 1,
29-
}
30-
axios
31-
.post(url, profilePatch, config)
32-
.then((response) => {
33-
console.log(response.data)
34-
})
35-
.catch((error) => {
36-
console.error('Error patching: ', error)
37-
})
9+
// FIXME jwt token
10+
const basicAuth = 'test basic auth'
11+
const config = {
12+
method: 'POST',
13+
headers: {
14+
'Content-Type': 'application/json',
15+
'Authorization': +basicAuth,
16+
},
17+
}
18+
const profilePatch: PersonPatch = {
19+
status: 'ready',
20+
firstName: profile.firstName,
21+
lastName: profile.lastName,
22+
interests: profile.interests.map((interest) => {
23+
return { topicId: interest.topic.id, level: interest.level }
24+
}),
25+
height: profile.height,
26+
birthday: `${profile.birthday.getFullYear()}-${profile.birthday.getMonth()}-${profile.birthday.getDay()}`,
27+
facultyId: 1,
28+
locationId: 1,
29+
}
30+
axios
31+
.post(url, profilePatch, config)
32+
.then((response) => {
33+
console.log(response.data);
34+
})
35+
.catch((error) => {
36+
console.error('Error patching: ', error)
37+
})
3838
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import axios from "axios";
2+
import React from "react";
3+
import {backendPeopleUrl} from "@/shared/api";
4+
import {Faculty} from "@/entities/registration-data/model/faculty.ts";
5+
6+
export function getFaculties(setFaculties: React.Dispatch<React.SetStateAction<Array<Faculty>>>) {
7+
const url = `${backendPeopleUrl}/api/faculties`;
8+
9+
axios.get(url)
10+
.then((response) => {
11+
console.log(response.data);
12+
//FIXME after integration with backend
13+
setFaculties(response.data)
14+
})
15+
.catch((error) => {
16+
console.error("Error getting faculties: ", error);
17+
//TODO remove after integration with backend
18+
setFaculties([
19+
{id: 1, longName: "piict"}
20+
])
21+
})
22+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import axios from 'axios'
2+
import React from 'react'
3+
import { backendPeopleUrl } from '@/shared/api'
4+
import { Location } from '@/entities/registration-data/model/Location.ts'
5+
6+
export function getLocations(setLocations: React.Dispatch<React.SetStateAction<Array<Location>>>) {
7+
const url = `${backendPeopleUrl}/api/locations`;
8+
9+
axios.get(url)
10+
.then((response) => {
11+
console.log(response.data);
12+
//FIXME after integration with backend
13+
setLocations(response.data)
14+
})
15+
.catch((error) => {
16+
console.error("Error getting locations: ", error);
17+
//TODO remove after integration with backend
18+
setLocations([
19+
{
20+
"id": 1,
21+
"name": "ITMO University, Kronverkskiy Avenue",
22+
"coordinates": {
23+
"latitude": 59.957478,
24+
"longitude": 30.308014
25+
}
26+
}
27+
])
28+
})
29+
}

0 commit comments

Comments
 (0)