add get user route
This commit is contained in:
parent
7525b2d56b
commit
54c276d972
|
@ -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/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("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
|
||||
re_path(r'^auth/vvsu/', views.VVSUAuthProxy),
|
||||
|
|
|
@ -211,3 +211,28 @@ class UserLogin(APIView):
|
|||
resp.headers['Content-Type'] = cb.headers['Content-Type'];
|
||||
|
||||
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);
|
|
@ -4,4 +4,3 @@ djangorestframework
|
|||
django-cors-headers
|
||||
Pillow
|
||||
requests
|
||||
oic
|
|
@ -25,9 +25,12 @@ class User {
|
|||
|
||||
}
|
||||
|
||||
/** @param {string} id */
|
||||
/**
|
||||
* @param {string} id
|
||||
* @returns {User}
|
||||
*/
|
||||
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'])
|
||||
throw new Error(data.data['error']);
|
||||
return new User(data.data);
|
||||
|
|
Loading…
Reference in New Issue