add get user route

This commit is contained in:
b1ek 2023-05-16 20:07:50 +10:00
parent 7525b2d56b
commit 54c276d972
Signed by: blek
GPG Key ID: 14546221E3595D0C
4 changed files with 38 additions and 7 deletions

View File

@ -10,8 +10,12 @@ urlpatterns = format_suffix_patterns([
path("apartaments/comparison/", views.ApartamentGetManyViewSet.as_view({'get': 'retrieve'})), # пример: apartaments/comparison/?user_id=1 user_id - id пользователя path("apartaments/comparison/", views.ApartamentGetManyViewSet.as_view({'get': 'retrieve'})), # пример: apartaments/comparison/?user_id=1 user_id - id пользователя
path("apartaments/favorite/", views.ApartamentGetManyViewSet.as_view({'get': 'list'})), # пример: apartaments/favorite/?user_id=1 user_id - id пользователя path("apartaments/favorite/", views.ApartamentGetManyViewSet.as_view({'get': 'list'})), # пример: apartaments/favorite/?user_id=1 user_id - id пользователя
path("apartaments/filters/", views.ApartmentFilter.as_view({'post': 'list'})), path("apartaments/filters/", views.ApartmentFilter.as_view({'post': 'list'})),
path("psych_test/add_result/<int:pk>", views.PsychTestAddResultViewSet.as_view({'post': 'create'})), # пример: psych_test/add_result/1/?result=50 result - результат псих теста пользователя
path("users/get_compatible", views.CompatibleUsersView.as_view({'post': 'list'})), # user
path("user/get_compatible", views.CompatibleUsersView.as_view({'post': 'list'})),
# пример: psych_test/add_result/1/?result=50 result - результат псих теста пользователя
path("psych_test/add_result/<int:pk>", views.PsychTestAddResultViewSet.as_view({'post': 'create'})),
path('user/get', views.UserGet.as_view()),
# auth # auth
re_path(r'^auth/vvsu/', views.VVSUAuthProxy), re_path(r'^auth/vvsu/', views.VVSUAuthProxy),

View File

@ -211,3 +211,28 @@ class UserLogin(APIView):
resp.headers['Content-Type'] = cb.headers['Content-Type']; resp.headers['Content-Type'] = cb.headers['Content-Type'];
return resp; return resp;
class UserGet(APIView):
def get(self, req: HttpRequest):
if not ('id' in req.GET.keys() or 'login' in req.GET.keys()):
res = JsonResponse({'error': 'no id or login'});
res.status_code = 400;
return res;
id_type = 'id' if 'id' in req.GET.keys() else 'login';
id = req.GET.get(id_type);
if (id_type == 'login'):
if not id.endswith('@vvsu.ru'):
id += '@vvsu.ru';
id_type = 'openid_addr';
user = None;
try:
user = User.objects.get(**{id_type: id});
except User.DoesNotExist:
res = JsonResponse({'error': 'not found'});
res.status_code = 404;
return res;
return JsonResponse(PublicUserSerializer(user).data);

View File

@ -4,4 +4,3 @@ djangorestframework
django-cors-headers django-cors-headers
Pillow Pillow
requests requests
oic

View File

@ -25,9 +25,12 @@ class User {
} }
/** @param {string} id */ /**
* @param {string} id
* @returns {User}
*/
static async getById(id) { static async getById(id) {
const data = await axios.post(API_ROOT + '/users/get', { id }); const data = await axios.get(API_ROOT + '/api/user/get', { params: { id } });
if (data.data['error']) if (data.data['error'])
throw new Error(data.data['error']); throw new Error(data.data['error']);
return new User(data.data); return new User(data.data);