Skip to content

Conversation

Copilot
Copy link

@Copilot Copilot AI commented Sep 2, 2025

This PR implements a complete Java REST API for user management based on the requirements specification. The API allows administrators to retrieve user information by ID with proper authentication and error handling.

Key Features Implemented

REST API Endpoint

  • GET /api/users/{id} - Retrieves user information by ID
  • Returns user details including name, email, phone, and department
  • Proper HTTP status codes (200, 404, 401, 403)

Security & Authentication

  • Spring Security with Basic Authentication
  • Admin role required for API access
  • Default admin credentials: admin / admin123
  • Unauthorized requests return 401, insufficient privileges return 403

Data Layer

  • JPA User entity with fields: id, name, email, phone, department
  • H2 in-memory database for development
  • Pre-loaded with 5 sample Japanese users
  • Proper error handling for non-existent users (404 response)

Testing

  • Comprehensive unit tests covering all scenarios:
    • Successful user retrieval with admin credentials
    • 404 error for non-existent users
    • 401 error for unauthenticated requests
    • 403 error for non-admin users

Usage Example

# Get user information (successful case)
curl -u admin:admin123 http://localhost:8080/api/users/1

# Response:
{
  "id": 1,
  "name": "田中太郎",
  "email": "tanaka@example.com",
  "phone": "090-1234-5678",
  "department": "開発部"
}

# Non-existent user (404 error)
curl -u admin:admin123 http://localhost:8080/api/users/999

# Unauthenticated request (401 error)
curl http://localhost:8080/api/users/1

Technical Stack

  • Java 17 with Spring Boot 3.1.5
  • Spring Security for authentication
  • Spring Data JPA for data access
  • H2 database for development
  • Maven for build management
  • Comprehensive test suite

The implementation follows Spring Boot best practices with proper separation of concerns across controller, service, and repository layers. All requirements from the specification have been fulfilled with additional documentation and testing.

Fixes #1.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

@Copilot Copilot AI assigned Copilot and yus04 Sep 2, 2025
Copy link
Author

Copilot AI commented Sep 2, 2025

@yus04 👋 This repository doesn't have Copilot instructions. With Copilot instructions, I can understand the repository better, work faster and produce higher quality PRs.

I can generate a .github/copilot-instructions.md file for you automatically. Click here to open a pre-filled issue and assign it to me. I'll write the instructions, and then tag you for review.

Co-authored-by: yus04 <49590084+yus04@users.noreply.github.com>
@Copilot Copilot AI changed the title [WIP] 要件定義書に基づいた REST API の実装 Implement REST API for user management with admin authentication Sep 2, 2025
@Copilot Copilot AI requested a review from yus04 September 2, 2025 06:48
Copilot finished work on behalf of yus04 September 2, 2025 06:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

要件定義書に基づいた REST API の実装
2 participants