# cossmosdb **Repository Path**: cesul/cossmosdb ## Basic Information - **Project Name**: cossmosdb - **Description**: cossmosdb - **Primary Language**: Java - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2025-03-14 - **Last Updated**: 2025-04-10 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # Spring Boot with Azure Cosmos DB for MongoDB API This project demonstrates how to integrate Spring Boot with Azure Cosmos DB using the MongoDB API. ## Prerequisites - Java 17 or later - Maven 3.6 or later - An Azure account with an active subscription - Azure Cosmos DB account with MongoDB API ## Configuration Before running the application, you need to set up the following environment variables: - `COSMOSDB_ACCOUNT_NAME`: Your Azure Cosmos DB account name - `COSMOSDB_ACCOUNT_KEY`: Your Azure Cosmos DB primary key - `COSMOSDB_DATABASE_NAME`: The name of your database You can set these environment variables in your development environment or create a `application-local.properties` file with the following content: ```properties spring.data.mongodb.uri=mongodb://your-account-name:your-account-key@your-account-name.mongo.cosmos.azure.com:10255/?ssl=true&replicaSet=globaldb&retrywrites=false&maxIdleTimeMS=120000&appName=@your-account-name@ spring.data.mongodb.database=your-database-name ``` ## Creating an Azure Cosmos DB Account 1. Sign in to the [Azure Portal](https://portal.azure.com/) 2. Create a new Azure Cosmos DB account - Select API: Azure Cosmos DB for MongoDB - Create a new database and collection 3. Get the connection information from the "Connection String" section in the Azure Portal ## Running the Application ```bash # Set environment variables (example for Linux/macOS) export COSMOSDB_ACCOUNT_NAME=your-account-name export COSMOSDB_ACCOUNT_KEY=your-account-key export COSMOSDB_DATABASE_NAME=your-database-name # Run the application ./mvnw spring-boot:run ``` ## API Endpoints ### User Endpoints The application provides the following REST endpoints for User operations: - `GET /api/users`: Get all users - `GET /api/users/{id}`: Get a user by ID - `GET /api/users/name/{name}`: Get users by name - `GET /api/users/email/{email}`: Get users by email - `GET /api/users/age/{age}`: Get users older than the specified age - `POST /api/users`: Create a new user - `PUT /api/users/{id}`: Update an existing user - `DELETE /api/users/{id}`: Delete a user ### Story Endpoints The application provides the following REST endpoints for Story operations: - `GET /api/stories`: Get all stories - `GET /api/stories/{id}`: Get a story by ID - `GET /api/stories/title/{title}`: Get stories by title - `GET /api/stories/search?keyword=value`: Search stories by title keyword - `GET /api/stories/category/{category}`: Get stories by category - `GET /api/stories/status/{status}`: Get stories by status - `GET /api/stories/author/{authorId}`: Get stories by author - `GET /api/stories/date-range?start=datetime&end=datetime`: Get stories created between dates - `GET /api/stories/tag/{tagName}`: Get stories by tag - `GET /api/stories/most-viewed`: Get most viewed stories - `GET /api/stories/most-liked`: Get most liked stories - `GET /api/stories/latest`: Get latest stories - `POST /api/stories`: Create a new story - `PUT /api/stories/{id}`: Update an existing story - `DELETE /api/stories/{id}`: Delete a story - `PUT /api/stories/{id}/publish`: Publish a story - `PUT /api/stories/{id}/archive`: Archive a story ## Example JSON Payloads ### User JSON ```json { "name": "John Doe", "email": "john.doe@example.com", "age": 30 } ``` ### Story JSON ```json { "title": "My First Story", "content": "This is the content of my first story...", "category": "FICTION", "author": { "id": "user-id-here" }, "tags": [ { "name": "fiction", "color": "#FF5733" }, { "name": "adventure", "color": "#33FF57" } ], "metadata": { "language": "English", "readTimeMinutes": 5, "coverImageUrl": "https://example.com/cover.jpg" } } ```