Skip to content

Commit 9d3818f

Browse files
committed
Add map view
1 parent c951118 commit 9d3818f

File tree

12 files changed

+627
-15
lines changed

12 files changed

+627
-15
lines changed

CLAUDE.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@ Read backend/API_DOC.md to understand the backend API.
77

88
Use `uv` for dependencies management.
99
Always update backend/API_DOC.md whenever you change the API.
10+
Always add or update backend tests when you work on the API.
1011
DO NOT INSTALL django-rest-framework, keep it simple base Django only.

backend/API_DOC.md

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,32 @@ Response:
4747
}
4848
```
4949

50-
### Update User Profile
50+
### User Profile
51+
**GET** `/api/auth/profile/` - Get current user profile information
52+
**PUT** `/api/auth/profile/` - Update user profile information
53+
54+
Both endpoints require authentication token.
55+
56+
#### Get User Profile
57+
**GET** `/api/auth/profile/`
58+
59+
Response:
60+
```json
61+
{
62+
"id": 1,
63+
"username": "current_user",
64+
"email": "user@example.com",
65+
"first_name": "Current",
66+
"last_name": "User",
67+
"company_id": 1,
68+
"company_name": "ACME Logistics"
69+
}
70+
```
71+
72+
#### Update User Profile
5173
**PUT** `/api/auth/profile/`
5274

53-
Updates the current user's profile information. Requires authentication token.
75+
Updates the current user's profile information.
5476

5577
Request:
5678
```json

backend/accounts/tests.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,3 +371,51 @@ def test_register_password_hashing(self):
371371
user = User.objects.get(username='newuser')
372372
self.assertNotEqual(user.password, 'newpass123') # Should be hashed
373373
self.assertTrue(user.check_password('newpass123')) # But should validate
374+
375+
class UserProfileViewTestCase(TestCase):
376+
def setUp(self):
377+
self.company = Company.objects.create(
378+
name='Test Company',
379+
address='123 Test St',
380+
phone='555-1234',
381+
email='test@company.com'
382+
)
383+
384+
self.user = User.objects.create_user(
385+
username='testuser',
386+
password='testpass123',
387+
email='test@user.com',
388+
first_name='Test',
389+
last_name='User'
390+
)
391+
392+
self.profile = UserProfile.objects.create(
393+
user=self.user,
394+
company=self.company
395+
)
396+
397+
self.token = AuthToken.objects.create(user=self.user)
398+
399+
def test_get_profile(self):
400+
"""Test GET /api/auth/profile/ returns user profile data"""
401+
response = self.client.get('/api/auth/profile/',
402+
headers={'Authorization': f'Token {self.token.key}'}
403+
)
404+
405+
self.assertEqual(response.status_code, 200)
406+
data = response.json()
407+
408+
self.assertEqual(data['id'], self.user.id)
409+
self.assertEqual(data['username'], 'testuser')
410+
self.assertEqual(data['email'], 'test@user.com')
411+
self.assertEqual(data['first_name'], 'Test')
412+
self.assertEqual(data['last_name'], 'User')
413+
self.assertEqual(data['company_id'], self.company.id)
414+
self.assertEqual(data['company_name'], 'Test Company')
415+
416+
def test_get_profile_no_auth(self):
417+
"""Test GET /api/auth/profile/ without authentication returns 401"""
418+
response = self.client.get('/api/auth/profile/')
419+
self.assertEqual(response.status_code, 401)
420+
data = response.json()
421+
self.assertEqual(data['error'], 'Authentication required')

backend/accounts/views.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,32 @@ def get_user_from_token(request):
144144

145145
@method_decorator(csrf_exempt, name='dispatch')
146146
class UserProfileUpdateView(View):
147+
def get(self, request):
148+
user = get_user_from_token(request)
149+
if not user:
150+
return JsonResponse({'error': 'Authentication required'}, status=401)
151+
152+
# Return current user data
153+
response_data = {
154+
'id': user.id,
155+
'username': user.username,
156+
'email': user.email,
157+
'first_name': user.first_name,
158+
'last_name': user.last_name
159+
}
160+
161+
# Add company info if user has profile
162+
try:
163+
profile = user.profile
164+
response_data.update({
165+
'company_id': profile.company.id,
166+
'company_name': profile.company.name
167+
})
168+
except:
169+
pass
170+
171+
return JsonResponse(response_data)
172+
147173
def put(self, request):
148174
user = get_user_from_token(request)
149175
if not user:

frontend/.env

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Mapbox Configuration
2+
VITE_MAPBOX_ACCESS_TOKEN=pk.eyJ1IjoiY29yZW50aW5zbWl0aCIsImEiOiJjang0YnYyamswN2Q0NDhudGRkbTYyczY5In0.VTGpl803vYym7mQNAk9QdQ
3+
4+
# Backend API Configuration
5+
VITE_API_BASE_URL=http://localhost:8000/api

0 commit comments

Comments
 (0)