- Prerequisites
- Setup Instructions
- API Documentation
- User CRUD API
- Project Management API
- Attributes Management API
- Timesheet Management API
Ensure you have the following installed before setting up the project:
- PHP 8.2+
- Composer
- MySQL or PostgreSQL
- Laravel 11 (installed globally via Composer)
- Node.js & NPM (for frontend assets, if applicable)
git https://github.com/DevAthul-88/timesheet_api.git
cd timesheet_apicomposer installCopy the example environment file and update the necessary credentials:
cp .env.example .envUpdate database connection details in .env:
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=timesheet_api
DB_USERNAME=root
DB_PASSWORD=php artisan key:generatephp artisan migrate --seedphp artisan servehttp://127.0.0.1:8000/
The Markdown-based documentation will be displayed.
Run:
php artisan cache:clear && php artisan view:clearEndpoint: POST /api/register
Request:
{
"name": "John Doe",
"email": "johndoe@example.com",
"password": "password",
"password_confirmation": "password"
}Response:
{
"message": "User registered successfully",
"token": "<JWT_TOKEN>"
}Endpoint: POST /api/login
Request:
{
"email": "johndoe@example.com",
"password": "password"
}Response:
{
"message": "Login successful",
"token": "<JWT_TOKEN>"
}Endpoint: GET /api/user
Headers:
{
"Authorization": "Bearer <JWT_TOKEN>"
}Response:
{
"id": 1,
"name": "John Doe",
"email": "johndoe@example.com"
}Use the following test credentials to authenticate API requests:
{
"email": "test@example.com",
"password": "password"
}Endpoint: GET /api/users
Query Parameters:
search(optional): Filter users by first name, last name, or email.per_page(optional, default: 15): Number of results per page.
Response:
{
"data": [
{
"id": 1,
"first_name": "John",
"last_name": "Doe",
"email": "johndoe@example.com"
}
],
"links": {...},
"meta": {...}
}Endpoint: GET /api/users/{id}
Response:
{
"data": {
"id": 1,
"first_name": "John",
"last_name": "Doe",
"email": "johndoe@example.com"
}
}Endpoint: PUT /api/users/{id}
Request Body:
{
"first_name": "Updated Name",
"last_name": "Updated Last",
"email": "updated@example.com"
}Response:
{
"data": {
"id": 1,
"first_name": "Updated Name",
"last_name": "Updated Last",
"email": "updated@example.com"
}
}Endpoint: DELETE /api/users/{id}
Response:
{
"message": "User deleted successfully"
}Endpoint: POST /api/users/{id}/restore
Response:
{
"data": {
"id": 1,
"first_name": "John",
"last_name": "Doe",
"email": "johndoe@example.com"
}
}This API provides comprehensive CRUD operations for Projects with advanced filtering and attribute management.
- Endpoint:
GET /api/projects - Query Parameters:
per_page: Number of projects per page (default: 10)filter[status]: Filter by project statusfilter[eav]: Filter by extended attributes
Example Request:
GET /api/projects?per_page=20&filter[status]=pendingResponse Example:
{
"data": [
{
"id": 1,
"name": "Marketing Campaign",
"status": "pending",
"users": [
{
"id": 1,
"name": "John Doe"
}
],
"attributeValues": [
{
"name": "Department",
"value": "Marketing"
}
]
}
],
"meta": {
"current_page": 1,
"total": 15
}
}- Endpoint:
POST /api/projects - Request Body:
{
"name": "Marketing Campaign",
"status": "pending",
"attributes": {
"Department": "Marketing",
"Start Date": "2024-02-01",
"Priority": "Medium",
"Budget": 25000,
"Client": "XYZ Company"
}
}- Endpoint:
GET /api/projects/{project_id} - Returns: Full project details including users, timesheets, and attributes
- Endpoint:
PUT/PATCH /api/projects/{project_id} - Request Body: Same as create project
- Supports: Updating project details and attributes
- Endpoint:
DELETE /api/projects/{project_id} - Note: Soft deletes project and associated timesheets
- Endpoint:
POST /api/projects/{project_id}/assign-user - Request Body:
{
"user_id": 1,
"role": "member"
}- Endpoint:
POST /api/projects/{project_id}/remove-user - Request Body:
{
"user_id": 1
}-
Marketing Project
- ID: 1
- Name: "Marketing Campaign"
- Status: "pending"
-
Development Project
- ID: 2
- Name: "Product Development"
- Status: "active"
-
Project Manager
- ID: 1
- Name: "John Doe"
- Email: "john.doe@example.com"
-
Team Member
- ID: 2
- Name: "Jane Smith"
- Email: "jane.smith@example.com"
- 404: Project not found
- 400: Invalid attribute
- 422: Validation errors
- 500: Server errors
# Filter projects by department and priority
GET /api/projects?filter[eav][Department]=Marketing&filter[eav][Priority]=Medium- Supports extended (EAV) attributes
- Soft delete implementation
- Transactional operations for data integrity
- Comprehensive logging for tracking operations
This API provides CRUD operations for managing dynamic attributes across different entity types.
- Endpoint:
GET /api/attributes - Description: Retrieve all defined attributes
Response Example:
{
"data": [
{
"id": 1,
"name": "Priority",
"type": "select",
"description": "Project priority level",
"options": ["Low", "Medium", "High", "Critical"],
"is_required": true,
"meta": {
"created_at": "2024-02-15T10:00:00Z",
"updated_at": "2024-02-15T10:00:00Z",
"options_count": 4
}
}
]
}- Endpoint:
POST /api/attributes - Request Body:
{
"name": "Department",
"type": "select",
"description": "Project department",
"options": ["Marketing", "Sales", "Engineering", "Support"],
"is_required": false,
"entity_type": "App\\Models\\Project"
}Response:
- Success: Returns created attribute details
- Status Code: 201 Created
- Endpoint:
GET /api/attributes/{attribute_id} - Description: Retrieve specific attribute details
Response Example:
{
"data": {
"id": 1,
"name": "Priority",
"type": "select",
"description": "Project priority level",
"options": ["Low", "Medium", "High", "Critical"],
"is_required": true,
"meta": {
"created_at": "2024-02-15T10:00:00Z",
"updated_at": "2024-02-15T10:00:00Z",
"options_count": 4
}
}
}- Endpoint:
PUT/PATCH /api/attributes/{attribute_id} - Request Body: Same as create attribute
- Description: Update existing attribute details
- Endpoint:
DELETE /api/attributes/{attribute_id} - Description: Remove an attribute
text: Single-line text inputtextarea: Multi-line text inputselect: Dropdown selectionmultiselect: Multiple selectionnumber: Numeric inputdate: Date selectionboolean: True/False toggle
{
"name": "Priority",
"type": "select",
"description": "Project priority level",
"options": ["Low", "Medium", "High", "Critical"],
"is_required": true,
"entity_type": "App\\Models\\Project"
}{
"name": "Budget",
"type": "number",
"description": "Project budget allocation",
"is_required": false,
"entity_type": "App\\Models\\Project"
}- 400: Bad Request
- 404: Attribute Not Found
- 422: Validation Error
- 500: Server Error
name: Required, unique, max 255 characterstype: Required, must be one of predefined typesdescription: Optional, max 500 charactersoptions: Optional, must be valid JSON array for select typesis_required: Booleanentity_type: Must be a valid PHP class namespace
-
Project Priority
- ID: 1
- Name: "Priority"
- Type: "select"
-
Project Department
- ID: 2
- Name: "Department"
- Type: "select"
- Supports dynamic attribute creation
- Attributes can be associated with specific entity types
- Comprehensive error logging
- Transactional database operations
This API provides comprehensive CRUD operations for managing timesheets, with advanced filtering and sorting capabilities.
- Endpoint:
GET /api/timesheets - Query Parameters:
per_page: Number of results per page (default: 10)sort_by: Column to sort by (default: 'created_at')sort_direction: Sort order ('asc' or 'desc')task_name: Filter by task nameproject_id: Filter by projectuser_id: Filter by userdate_from: Start date filterdate_to: End date filter
Example Request:
GET /api/timesheets?per_page=15&project_id=1&date_from=2024-01-01&date_to=2024-01-31Response Example:
{
"data": [
{
"id": 1,
"user_id": 1,
"project_id": 1,
"task_name": "Design",
"date": "2024-01-15",
"hours": 8.5,
"description": "Worked on the initial design",
"user": {
"id": 1,
"name": "John Doe"
},
"project": {
"id": 1,
"name": "Marketing Campaign"
}
}
],
"meta": {
"current_page": 1,
"total_pages": 3,
"total_items": 30,
"sort_by": "created_at",
"sort_direction": "desc"
}
}- Endpoint:
POST /api/timesheets - Request Body:
{
"user_id": 1,
"project_id": 1,
"task_name": "Design",
"date": "2024-01-15",
"hours": 8.5,
"description": "Worked on the initial design"
}- Endpoint:
GET /api/timesheets/{timesheet_id} - Returns: Detailed timesheet information
- Endpoint:
PUT/PATCH /api/timesheets/{timesheet_id} - Request Body: Same as create timesheet
- Endpoint:
DELETE /api/timesheets/{timesheet_id}
- Endpoint:
GET /api/my-timesheets - Description: Retrieves timesheets for the authenticated user
- Supported columns:
idtask_namedatehourscreated_atupdated_at
- Filter by task name (partial match)
- Filter by project
- Filter by user
- Date range filtering
user_id: Required, must exist in users tableproject_id: Required, must exist in projects tabletask_name: Required, max 255 charactersdate: Required, valid datehours: Required, numeric, min 0, max 24description: Optional, max 1000 characters
{
"user_id": 1,
"project_id": 2,
"task_name": "Feature Development",
"date": "2024-02-15",
"hours": 8,
"description": "Implemented new user authentication module"
}- Endpoint:
POST /api/timesheets/bulk - Request Body:
{
"timesheets": [
{
"user_id": 1,
"project_id": 1,
"task_name": "Design",
"date": "2024-02-15",
"hours": 4,
"description": "UI/UX design review"
},
{
"user_id": 1,
"project_id": 2,
"task_name": "Development",
"date": "2024-02-15",
"hours": 4,
"description": "Backend API implementation"
}
]
}- Endpoint:
PUT /api/timesheets/bulk - Request Body:
{
"timesheets": [
{
"id": 1,
"task_name": "Updated Task Name",
"hours": 6,
"description": "Updated description"
},
{
"id": 2,
"task_name": "Another Updated Task",
"hours": 5,
"description": "Another updated description"
}
]
}- Endpoint:
GET /api/timesheets/summary - Query Parameters:
date_from: Start date for summarydate_to: End date for summaryuser_id: (Optional) Filter by specific userproject_id: (Optional) Filter by specific project
Response Example:
{
"total_hours": 280.5,
"average_daily_hours": 7.2,
"projects_breakdown": [
{
"project_id": 1,
"project_name": "Marketing Campaign",
"total_hours": 120.5
},
{
"project_id": 2,
"project_name": "Product Development",
"total_hours": 160
}
],
"user_breakdown": [
{
"user_id": 1,
"user_name": "John Doe",
"total_hours": 180.5
},
{
"user_id": 2,
"user_name": "Jane Smith",
"total_hours": 100
}
]
}- Endpoint:
GET /api/timesheets/export - Query Parameters:
format: Export format (csv, xlsx, pdf)date_from: Start date for exportdate_to: End date for exportuser_id: (Optional) Filter by specific userproject_id: (Optional) Filter by specific project
- Pagination implemented to manage large datasets
- Indexing on frequently queried columns
- Caching mechanisms for frequently accessed reports
- Efficient query optimization
- Authentication required for all endpoints
- Data privacy and scope restrictions
- Audit logging for all timesheet modifications
- Seamless integration with Project Management API
- User authentication and authorization
- Reporting and invoicing systems
- Performance management tools
This comprehensive Timesheet Management API provides robust, flexible, and secure methods for tracking, managing, and analyzing work hours across projects and users. With advanced filtering, reporting, and export capabilities, it serves as a powerful tool for project management and resource allocation.