Action Memo API Module
Prompt
Create a Java Spring Boot module for managing action memos with the following components: 1. **Entity Class**: Define an entity `ActionMemo` representing the `PORTAL_ACTION_MEMOS` table with fields: `memoId`, `controlCode`, `claimId`, `healthFacility`, `physician`, `batchNumber`, `patientName`, `accountName`, `approvalNumber`, `availmentDate`, `memoType`, `action`, `dateCreated`, `createdBy`, `serviceType`, `status`, `providerUserId`, `createdTs`, `createdByField`, `updatedTs`, `updatedBy`, `message`, `type`, `providerCode`. Use JPA annotations: `@Entity`, `@Table`, primary key annotations like `@Id`, `@GeneratedValue`, column mappings with `@Column`, relationships with `@ManyToOne`, `@JoinColumn`, and specify `insertable=false, updatable=false` where necessary. Include Lombok annotations `@Data` and `@NoArgsConstructor`. 2. **Request Class**: Create a `PendingMemoRequest` with fields `page`, `size`, `search`, `status`, `memoType`, `fromDate`, and `toDate`. Add validation annotations such as `@NotNull`, `@NotBlank` and use `@Data` to generate boilerplate code. 3. **Response Class**: Define `PendingMemoResponse` containing: - A list of `MemoResponse` objects each having fields: `memoId`, `controlCode`, `healthFacility`, `physician`, `batchNumber`, `patientName`, `accountName`, `approvalNumber`, `availmentDate`, `submissionDate`, `memoType`, `status`, `documentId`. - Pagination info: `currentPage`, `pageSize`, `totalPages`, `totalRecords`. 4. **API Response Wrapper**: Use the provided generic `ApiResponse<T>` class to standardize all API responses with `responseCode`, `message`, `errorDetails`, `data`, and ISO 8601 `timestamp`. 5. **Repository Layer**: Implement `ClaimsRepository` as a Spring Data JPA repository for the `ActionMemo` entity. 6. **Service Layer**: - Define the interface `MemoService` with method `PendingMemoResponse getMemoListByStatus(PendingMemoRequest request);`. - Implement this interface in `MemoServiceImpl`: - Handle pagination, normalize filters (convert date ranges to IST, clean filters). - Query `actionMemosRepository` applying filters; if all filters are empty, fetch all memos. - Map queried data to a list of `MemoResponse`. - Construct and return `PendingMemoResponse` with data and pagination metadata. - Use SLF4J for logging throughout the service. 7. **Controller Layer**: Create `ClaimsServiceController` with a single endpoint: - `@PostMapping("/memoListByStatus")` accepting a `@Valid` `@RequestBody` `PendingMemoRequest`. - Calls `MemoService.getMemoListByStatus()` and returns an `ApiResponse<PendingMemoResponse>`. 8. **Global Exception Handler**: Use the provided class that: - Handles `SQLException`, `DataAccessException`, `RuntimeException`, general `Exception`, and `MethodArgumentNotValidException`. - Logs exceptions appropriately. - Returns standardized `ApiResponse` failures with descriptive messages. **Additional requirements:** - Apply validation annotations properly in request classes. - Use Lombok annotations for cleaner model classes. - Add detailed SLF4J logs in service implementation. - Follow best Spring Boot practices for layered architecture. # Steps 1. Design the `ActionMemo` entity mapping to database structure. 2. Create `PendingMemoRequest` and apply validation constraints. 3. Define `PendingMemoResponse` and `MemoResponse` DTOs. 4. Implement `ClaimsRepository` using Spring Data JPA. 5. Define `MemoService` interface and implement it in `MemoServiceImpl` with filtering, paging, and logging. 6. Create `ClaimsServiceController` with POST endpoint. 7. Integrate and configure the global exception handler. # Output Format Provide full Java class implementation snippets with proper package declarations and import statements for each component: - Entity class - Request and response DTO classes - Repository interface - Service interface and implementation - Controller class - Global exception handler Use annotations and Lombok where specified. Each class should be properly documented and structured for use in a Spring Boot project. # Notes - Dates should be handled and converted correctly to IST time zone where needed. - Ensure validation error messages are meaningful. - Logging statements must include method entry, parameters, and exception details if any. - Pagination defaults can be assumed but expose pagination fields to clients for flexibility. - The controller method should return `ApiResponse.success()` wrapping the `PendingMemoResponse` on success.
Related Coding Prompts
Write Code
As a seasoned programmer, your task is to write code in [programming language] to [perform action]. The code should be efficient, well-structured, and optimized for performance. Make sure to follow best practices and industry standards while implementing the necessary algorithms and logic to achieve the desired functionality. Test the code thoroughly to ensure it functions as intended and meets all requirements. Additionally, document the code properly for future reference and maintenance.
Debug Code
Act as a seasoned programmer with over 20 years of commercial experience. Analyze the provided [piece of code] that is causing a specific [error]. Your task involves diagnosing the root cause of the error, understanding the context and functionality intended by the code, and proposing a solution to fix the issue. Your analysis should include a step-by-step walkthrough of the code, identification of any bugs or logical mistakes, and a detailed explanation of how to resolve them. Additionally, suggest any improvements or optimizations to enhance the performance, readability, or maintainability of the code based on your extensive experience. Ensure that your solution adheres to best practices in software development and is compatible with the current development environment where the code is being executed.
Do Code Review
As a seasoned programmer with over 20 years of commercial experience, your task is to perform a comprehensive code review on the provided [piece of code]. Your review should meticulously evaluate the code's efficiency, readability, and maintainability. You are expected to identify any potential bugs, security vulnerabilities, or performance issues and suggest specific improvements or optimizations. Additionally, assess the code's adherence to industry standards and best practices. Your feedback should be constructive and detailed, offering clear explanations and recommendations for changes. Where applicable, provide examples or references to support your suggestions. Your goal is to ensure that the code not only functions as intended but also meets high standards of quality and can be easily managed and scaled in the future. This review is an opportunity to mentor and guide less experienced developers, so your insights should be both educational and actionable.