File size: 7,032 Bytes
1c8e50c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
# Task Service - Quick Start Guide

This guide will help you get the Task Service up and running in under 5 minutes.

---

## Prerequisites Checklist

Before starting, ensure you have:

- [ ] Java 17 or higher installed
- [ ] MongoDB installed and running
- [ ] Eureka Server running on port 8085
- [ ] User Service running on port 8081 (for full functionality)

---

## Quick Setup (3 Steps)

### Step 1: Start MongoDB
```bash
# Start MongoDB service
sudo systemctl start mongod

# Verify MongoDB is running
sudo systemctl status mongod

# Or if using Docker
docker run -d -p 27017:27017 --name mongodb mongo:latest
```

### Step 2: Navigate to TaskService Directory
```bash
cd /path/to/Task-Management-System-using-microservices/TaskService
```

### Step 3: Run the Service
```bash
# Build and run
./gradlew clean bootRun

# Or build JAR and run
./gradlew clean build
java -jar build/libs/TaskService-0.0.1-SNAPSHOT.jar
```

---

## Verify Installation

### Test 1: Check Service Health
```bash
curl http://localhost:8082/tasks
```
**Expected Output:** `"Welcome to Task Service"`

### Test 2: Check Eureka Registration
Open browser: `http://localhost:8085`

Look for `TASK-SERVICE` in the registered instances.

### Test 3: Check Actuator Health
```bash
curl http://localhost:8082/actuator/health
```

---

## Quick Test with Sample Data

### 1. Get JWT Token from User Service
First, login via User Service to get a JWT token.

### 2. Create a Task (Admin Only)
```bash
curl -X POST http://localhost:8082/api/tasks \
  -H "Authorization: Bearer YOUR_JWT_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "title": "My First Task",
    "description": "Testing task creation",
    "deadline": "2024-12-31T23:59:59",
    "tags": ["test", "demo"]
  }'
```

### 3. Get All Tasks
```bash
curl -X GET http://localhost:8082/api/tasks \
  -H "Authorization: Bearer YOUR_JWT_TOKEN"
```

### 4. Get Tasks by Status
```bash
curl -X GET "http://localhost:8082/api/tasks?status=PENDING&sortByDeadline=asc" \
  -H "Authorization: Bearer YOUR_JWT_TOKEN"
```

---

## Common Issues & Quick Fixes

### Issue 1: Port 8082 Already in Use
```bash
# Find the process
lsof -i :8082

# Kill it
kill -9 <PID>

# Or change port in application.properties
echo "server.port=8083" >> src/main/resources/application.properties
```

### Issue 2: MongoDB Connection Error
```bash
# Check if MongoDB is running
sudo systemctl status mongod

# If not, start it
sudo systemctl start mongod

# Check connection
mongo --eval "db.version()"
```

### Issue 3: Eureka Connection Error
```bash
# Check if Eureka is running on 8085
curl http://localhost:8085

# If not, start Eureka Server first
cd ../EurekaServerConfiguration
./gradlew bootRun
```

### Issue 4: User Service Connection Error
```bash
# Check if User Service is running on 8081
curl http://localhost:8081

# If not, start User Service
cd ../TaskUserService
./gradlew bootRun
```

---

## Development Mode

### Enable Hot Reload
```bash
# Run with DevTools for automatic restart
./gradlew bootRun --continuous
```

### Check Logs
```bash
# View application logs
tail -f logs/task-service.log

# Or if running in terminal, logs appear in console
```

### Debug Mode
```bash
# Run with debug enabled
./gradlew bootRun --debug-jvm
```

Then attach your IDE debugger to port 5005.

---

## Docker Quick Start

### Build Docker Image
```bash
# Build the application first
./gradlew clean build

# Build Docker image
docker build -t task-service:latest .
```

### Run Docker Container
```bash
docker run -d \
  -p 8082:8082 \
  -e SPRING_DATA_MONGODB_URI=mongodb://host.docker.internal:27017/tasks \
  -e EUREKA_CLIENT_SERVICE_URL_DEFAULTZONE=http://host.docker.internal:8085/eureka \
  --name task-service \
  task-service:latest
```

### Check Container Logs
```bash
docker logs -f task-service
```

---

## Using Docker Compose (Recommended)

### Start All Services
```bash
# From the root directory
docker-compose up task-service

# Or start all services
docker-compose up
```

### Stop Services
```bash
docker-compose down
```

---

## Environment Configuration

### Development (Default)
```properties
# Uses localhost for all services
server.port=8082
spring.data.mongodb.uri=mongodb://localhost:27017/tasks
eureka.client.service-url.defaultZone=http://localhost:8085/eureka
```

### Docker
```properties
# Uses container names for service discovery
spring.data.mongodb.uri=mongodb://mongodb:27017/tasks
eureka.client.service-url.defaultZone=http://eureka-server:8085/eureka
```

---

## Testing the API

### Using cURL
See examples above or check `API_REFERENCE.md`

### Using Postman
1. Import the API endpoints from `API_REFERENCE.md`
2. Set up environment variables:
   - `BASE_URL`: http://localhost:8082
   - `JWT_TOKEN`: Your token from User Service
3. Set Authorization header: `Bearer {{JWT_TOKEN}}`

### Using HTTPie
```bash
# Install HTTPie
pip install httpie

# Test endpoint
http GET localhost:8082/tasks

# Create task
http POST localhost:8082/api/tasks \
  Authorization:"Bearer YOUR_TOKEN" \
  title="Test Task" \
  description="Testing with HTTPie" \
  deadline="2024-12-31T23:59:59"
```

---

## Next Steps

1. βœ… **Read the README**: Full documentation in `README.md`
2. βœ… **Check API Reference**: Complete API docs in `API_REFERENCE.md`
3. βœ… **Review Changes**: See what was improved in `CHANGELOG.md`
4. βœ… **Explore Code**: All classes have comprehensive JavaDoc

---

## Useful Commands

### Gradle Commands
```bash
# Clean build
./gradlew clean build

# Run tests
./gradlew test

# Run application
./gradlew bootRun

# Build without tests
./gradlew build -x test

# Show dependencies
./gradlew dependencies
```

### MongoDB Commands
```bash
# Connect to MongoDB
mongo

# Use tasks database
use tasks

# Show all tasks
db.Tasks.find().pretty()

# Count tasks
db.Tasks.count()

# Clear all tasks (careful!)
db.Tasks.deleteMany({})
```

### Service Commands
```bash
# Check if service is running
curl http://localhost:8082/tasks

# Check Eureka registration
curl http://localhost:8085/eureka/apps/TASK-SERVICE

# Check actuator health
curl http://localhost:8082/actuator/health

# Check actuator metrics
curl http://localhost:8082/actuator/metrics
```

---

## Getting Help

### Documentation
- **README.md** - Complete service documentation
- **API_REFERENCE.md** - API endpoint reference
- **CHANGELOG.md** - Version history
- **SUMMARY.md** - Code review summary

### Logs
Check logs for detailed error information:
```bash
# Application logs
tail -f logs/task-service.log

# Docker logs
docker logs -f task-service

# Gradle output
./gradlew bootRun --info
```

### Common Endpoints
- Health: http://localhost:8082/tasks
- Actuator: http://localhost:8082/actuator
- Eureka Dashboard: http://localhost:8085

---

## Ready to Go! πŸš€

Your Task Service should now be running on **http://localhost:8082**

Try the health check:
```bash
curl http://localhost:8082/tasks
```

If you see `"Welcome to Task Service"`, you're all set! πŸŽ‰

---

**Happy Coding!** πŸ’»