The Activity Log Service is a microservice responsible for logging user activities in the Recipe Sharing Platform. It receives event-based logs from the main application via a Feign client and stores them in a separate database.
-
Exposes REST API endpoints to store and retrieve activity logs
-
Uses a dedicated database for logging
-
Spring Boot (REST API)
-
Spring Data JPA (Persistence layer)
-
MySQL (Database)
-
Lombok (Code simplification)
-
JUnit (Testing)
- Log Activity
Endpoint: POST /api/v1/activity-log
Response:
{
"userId": "123e4567-e89b-12d3-a456-426614174000",
"action": "User registered with username: johndoe",
"createdOn": "2007-12-03T10:15:30:55.000000"
}
- Get All Logs For User
Endpoint: GET /api/v1/activity-log
Query Parameter: userId (UUID of the user)
Example Request:
GET /api/activity-log?userId=123e4567-e89b-12d3-a456-426614174000
Response:
[{
"userId": "123e4567-e89b-12d3-a456-426614174000",
"action": "User registered",
"createdOn": "2007-12-03T10:15:30:55.000000."
}]
- Delete Activity Log by User ID
Endpoint: DELETE /api/v1/activity-log
Query Parameter: userId (UUID of the user)
Example Request:
DELETE /api/activity-log?userId=123e4567-e89b-12d3-a456-426614174000
Response:
200 OK - Activity logs deleted successfully
404 Not Found - No logs found for the given user
- Clone the repository:
git clone https://github.com/tsekovTriesCoding/activity-log-service.git
cd activity-log-service
Configure the database: Update application.yml:
spring:
datasource:
url: jdbc:mysql://localhost:3306/activity_log_db
username: root
password: yourpassword
Build and run the application:
mvn clean install
mvn spring-boot:run
Access the API at http://localhost:8081/api/v1/activity-log
- Set up environment variables Create a .env file in the root of the project with the following content:
MYSQL_ROOT_PASSWORD=yourpass
MYSQL_DATABASE=db_name
MYSQL_USER=activityuser
MYSQL_PASSWORD=activitypass
- Feel free to adjust the values to match your needs.
- Build and run the containers
From the root of the project directory, run:
docker-compose up --build
This will:
- Start a MySQL database container on port 3308.
- Build and run the Activity Log Service container on port 8081.
- Access the API Once the services are up, the Activity Log API will be available at:
http://localhost:8081/api/v1/activity-log