Skip to content

Commit 3560308

Browse files
authored
Merge pull request #45 from Jalen-Stephens/35-chore---write-javadoc-comments-for-all-non-trivial-code
35 chore write javadoc comments for all non trivial code
2 parents c96997e + ea1d63f commit 3560308

31 files changed

+2098
-606
lines changed

citations.md

Lines changed: 413 additions & 0 deletions
Large diffs are not rendered by default.

src/main/java/dev/coms4156/project/metadetect/MetaDetectApplication.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77

88
/**
99
* Entry point for the MetaDetect AI Image Detection Service.
10-
* This class starts the Spring Boot application.
10+
* Bootstraps the Spring Boot application and exposes shared infrastructure
11+
* beans (such as {@link Clock}) used across the service for deterministic and
12+
* testable timestamps.
1113
*/
1214
@SpringBootApplication
1315
public class MetaDetectApplication {
@@ -16,6 +18,10 @@ public static void main(String[] args) {
1618
SpringApplication.run(MetaDetectApplication.class, args);
1719
}
1820

21+
/**
22+
* System UTC clock used for consistent timestamp generation across
23+
* services (injection-friendly for tests).
24+
*/
1925
@Bean
2026
public Clock clock() {
2127
return Clock.systemUTC();

src/main/java/dev/coms4156/project/metadetect/config/AppConfig.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import org.springframework.context.annotation.Configuration;
66

77
/** Configuation class to provide constants to other processes. */
8-
98
@Configuration
109
public class AppConfig {
1110

@@ -16,7 +15,6 @@ public class AppConfig {
1615
*
1716
* @return a C2paToolInvoker instance configured with the tool path.
1817
*/
19-
2018
@Bean
2119
public C2paToolInvoker c2paToolInvoker() {
2220
// Path to the C2PA tool binary

src/main/java/dev/coms4156/project/metadetect/controller/AnalyzeController.java

Lines changed: 66 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -12,69 +12,115 @@
1212
import org.springframework.web.bind.annotation.RequestParam;
1313
import org.springframework.web.bind.annotation.RestController;
1414

15-
1615
/**
17-
* REST controller for image analysis operations.
18-
* Endpoints:
19-
* - POST /api/analyze/{imageId} -> start an analysis (202 Accepted)
20-
* - GET /api/analyze/{analysisId} -> status/score (polling)
21-
* - GET /api/analyze/{analysisId}/manifest -> manifest JSON
22-
* - GET /api/analyze/compare -> stubbed compare (left & right image IDs)
23-
* Notes:
24-
* - Ownership and RLS checks are enforced in AnalyzeService/ImageService.
25-
* - Exceptions (Forbidden/NotFound/etc.)
26-
* are expected to be mapped by global @RestControllerAdvice.
16+
* HTTP API for starting and querying image analyses.
17+
* Responsibilities
18+
* - Accepts requests to start analysis on an already-uploaded image.
19+
* - Exposes polling endpoints to retrieve analysis status, confidence scores, and stored manifests.
20+
* - Delegates ownership/RLS checks and business logic to {@link AnalyzeService}.
21+
* Contract
22+
* - POST /api/analyze/{imageId} returns 202 Accepted with an analysis identifier.
23+
* - GET /api/analyze/{analysisId} returns current status and (optionally) a confidence score.
24+
* - GET /api/analyze/{analysisId}/manifest returns a captured C2PA manifest (if available).
25+
* - GET /api/analyze/compare?left=...&right=...
26+
* returns a lightweight comparison (Iteration 1 stub).
27+
* Error Handling
28+
* - Authorization, ownership, and not-found conditions are surfaced as exceptions from the service
29+
* layer and mapped by a global {@code @RestControllerAdvice}.
30+
* Thread-safety
31+
* - Controller is stateless; relies on Spring-managed, thread-safe collaborators.
2732
*/
2833
@RestController
2934
@RequestMapping("/api/analyze")
3035
public class AnalyzeController {
3136

3237
private final AnalyzeService analyzeService;
3338

39+
/**
40+
* Constructs the controller with required collaborators.
41+
*
42+
* @param analyzeService domain service coordinating analysis lifecycle and access checks
43+
*/
3444
public AnalyzeController(AnalyzeService analyzeService) {
3545
this.analyzeService = analyzeService;
3646
}
3747

3848
/**
39-
* Starts analysis for an existing image that is already uploaded to Supabase Storage.
40-
* Returns 202 with a body containing the new analysisId.
49+
* Starts analysis for an existing image that is already persisted
50+
* and stored (e.g., in Supabase Storage).
51+
* The service enqueues or triggers downstream processing and
52+
* returns an identifier used for polling.
53+
* Response semantics
54+
* - Returns HTTP 202 Accepted to indicate asynchronous processing has begun.
55+
*
56+
* @param imageId unique identifier of the previously uploaded image
57+
* @return 202 Accepted with a body containing
58+
* {@link Dtos.AnalyzeStartResponse} and a new analysisId
59+
* @throws org.springframework.web.server.ResponseStatusException if the image does not exist or
60+
* the caller is not authorized to analyze it (propagated from the service layer)
4161
*/
4262
@PostMapping("/{imageId}")
4363
public ResponseEntity<Dtos.AnalyzeStartResponse> submit(@PathVariable UUID imageId) {
64+
// Delegate to service: performs ownership checks, persists analysis row, and schedules work.
4465
Dtos.AnalyzeStartResponse resp = analyzeService.submitAnalysis(imageId);
45-
// As per ticket: 202 Accepted with { analysisId }
66+
67+
// Per API contract, asynchronous start returns 202 Accepted rather than 200 OK.
4668
return ResponseEntity.status(HttpStatus.ACCEPTED).body(resp);
4769
}
4870

4971
/**
50-
* Returns current status (PENDING/COMPLETED/FAILED) and an optional score (stubbed).
51-
* Suitable for client-side polling.
72+
* Retrieves the current analysis status and (optionally) a confidence score suitable for polling.
73+
* Typical states include PENDING, COMPLETED, and FAILED.
74+
*
75+
* @param analysisId unique identifier returned by {@link #submit(UUID)}
76+
* @return 200 OK with {@link Dtos.AnalyzeConfidenceResponse}
77+
* @throws org.springframework.web.server.ResponseStatusException
78+
* if the analysis does not exist or the
79+
* caller lacks access (propagated from the service layer)
5280
*/
5381
@GetMapping("/{analysisId}")
5482
public ResponseEntity<Dtos.AnalyzeConfidenceResponse> getStatus(@PathVariable UUID analysisId) {
83+
// Service encapsulates lookup and authorization; controller simply returns the DTO.
5584
Dtos.AnalyzeConfidenceResponse resp = analyzeService.getConfidence(analysisId);
5685
return ResponseEntity.ok(resp);
5786
}
5887

5988
/**
60-
* Returns the stored C2PA manifest JSON for a completed analysis.
89+
* Returns the stored C2PA manifest for a completed analysis, when available.
90+
* Clients should check analysis status before calling this endpoint
91+
* to avoid unnecessary requests.
92+
*
93+
* @param analysisId unique identifier of the analysis
94+
* @return 200 OK with {@link Dtos.AnalysisManifestResponse};
95+
* may be 404/403 via advice if not accessible
6196
*/
6297
@GetMapping("/{analysisId}/manifest")
6398
public ResponseEntity<Dtos.AnalysisManifestResponse> getManifest(@PathVariable UUID analysisId) {
99+
// The service is responsible for ensuring the analysis is complete and manifest exists or
100+
// raising a mapped exception if it does not.
64101
Dtos.AnalysisManifestResponse resp = analyzeService.getMetadata(analysisId);
65102
return ResponseEntity.ok(resp);
66103
}
67104

68105
/**
69-
* Stubbed comparison endpoint (Iteration 1).
70-
* Ownership of both images is validated by the service layer.
71-
* Example: /api/analyze/compare?left={imageId}&right={imageId}
106+
* Lightweight comparison endpoint (Iteration 1 stub) that
107+
* compares two images owned by the caller.
108+
* The service validates ownership of both resources and returns a basic comparison DTO.
109+
* Example
110+
* GET /api/analyze/compare?left={imageId}&right={imageId}
111+
*
112+
* @param leftImageId identifier of the left image to compare
113+
* @param rightImageId identifier of the right image to compare
114+
* @return 200 OK with {@link Dtos.AnalyzeCompareResponse}
115+
* @throws org.springframework.web.server.ResponseStatusException
116+
* if either image is missing or unauthorized
72117
*/
73118
@GetMapping("/compare")
74119
public ResponseEntity<Dtos.AnalyzeCompareResponse> compare(
75120
@RequestParam("left") UUID leftImageId,
76121
@RequestParam("right") UUID rightImageId) {
77122

123+
// Delegate comparison to the domain service; controller remains a thin transport layer.
78124
Dtos.AnalyzeCompareResponse resp = analyzeService.compare(leftImageId, rightImageId);
79125
return ResponseEntity.ok(resp);
80126
}

src/main/java/dev/coms4156/project/metadetect/controller/AuthController.java

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,20 +25,53 @@ public class AuthController {
2525
private final UserService userService;
2626
private final AuthProxyService authProxy;
2727

28+
/**
29+
* Constructs the controller with required collaborators.
30+
*
31+
* @param userService local user domain service
32+
* @param authProxy adaptor that calls Supabase Auth endpoints
33+
*/
2834
public AuthController(UserService userService, AuthProxyService authProxy) {
2935
this.userService = userService;
3036
this.authProxy = authProxy;
3137
}
3238

33-
// --- Proxy endpoints (raw Supabase JSON passthrough) ---
39+
// === Proxy endpoints (raw Supabase JSON passthrough) ========================
3440

41+
/**
42+
* Proxies a sign-up request to Supabase Auth.
43+
* Returns Supabase's JSON (e.g., user, session, error) as-is to the caller.
44+
* Validation
45+
* - Basic shape validation is provided by the DTO; deeper
46+
* validation and error shaping are
47+
* delegated to Supabase.
48+
* Side effects
49+
* - Supabase may create the user and return a session
50+
* depending on project config
51+
* (email confirmation, etc.).
52+
*
53+
* @param req register payload containing email and password
54+
* @return upstream Supabase JSON wrapped in a {@link ResponseEntity}
55+
*/
3556
@PostMapping("/signup")
3657
public ResponseEntity<String> signup(@RequestBody Dtos.RegisterRequest req) {
58+
// Pass-through: do not log raw passwords; the proxy handles HTTP and error codes.
3759
return authProxy.signup(req.email(), req.password());
3860
}
3961

62+
/**
63+
* Proxies a login request to Supabase Auth.
64+
* Returns Supabase's JSON (e.g., session/access token) as-is.
65+
* Error handling
66+
* - Incorrect credentials and account state errors are surfaced from Supabase and returned
67+
* unchanged so clients can rely on standard Supabase error formats.
68+
*
69+
* @param req login payload containing email and password
70+
* @return upstream Supabase JSON wrapped in a {@link ResponseEntity}
71+
*/
4072
@PostMapping("/login")
4173
public ResponseEntity<String> login(@RequestBody Dtos.LoginRequest req) {
74+
// Pass-through: credentials are forwarded to Supabase; no local auth happens here.
4275
return authProxy.login(req.email(), req.password());
4376
}
4477

src/main/java/dev/coms4156/project/metadetect/controller/HealthController.java

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,33 +5,51 @@
55
import org.springframework.jdbc.core.JdbcTemplate;
66
import org.springframework.web.bind.annotation.GetMapping;
77
import org.springframework.web.bind.annotation.RestController;
8+
89
/**
9-
* Basic health/version for Iteration 1.
10+
* Health and metadata endpoints for Iteration 1 readiness.
11+
* Responsibilities:
12+
* - Verifies DB connectivity with a minimal round-trip.
13+
* - Exposes a static version endpoint for diagnostics.
14+
* These endpoints are intentionally unauthenticated so platform probes (Kubernetes, Render,
15+
* Fly.io, etc.) can detect whether the service is healthy at startup and runtime.
1016
*/
11-
1217
@RestController
1318
public class HealthController {
1419

1520
private final JdbcTemplate jdbc;
1621

22+
/**
23+
* Constructs the controller used for basic health checks.
24+
*
25+
* @param jdbc JDBC template used to verify DB connectivity.
26+
*/
1727
public HealthController(JdbcTemplate jdbc) {
1828
this.jdbc = jdbc;
1929
}
2030

2131
/**
22-
* Simple liveness endpoint for health checks.
32+
* Performs a minimal DB liveness check using a simple `select 1`.
33+
* Returns "UP" when the DB is reachable, otherwise "DOWN".
2334
*
24-
* @return static JSON confirming the service is reachable
35+
* @return a simple "UP" or "DOWN" status string
2536
*/
2637
@GetMapping("/db/health")
2738
public String dbHealth() {
39+
// No table lookup required: trivial round-trip ensures database is responsive.
2840
Integer one = jdbc.queryForObject("select 1", Integer.class);
2941
return one != null && one == 1 ? "UP" : "DOWN";
30-
3142
}
3243

44+
/**
45+
* Returns static version/service metadata for smoke tests or rollout tracing.
46+
*
47+
* @return JSON map containing service name and version
48+
*/
3349
@GetMapping("/db/version")
3450
public ResponseEntity<Map<String, String>> version() {
35-
return ResponseEntity.ok(Map.of("service", "metadetect-service", "version", "0.1.0"));
51+
return ResponseEntity.ok(
52+
Map.of("service", "metadetect-service", "version", "0.1.0")
53+
);
3654
}
3755
}

0 commit comments

Comments
 (0)