package com.xuqm.tenant.controller; import com.xuqm.common.model.ApiResponse; import com.xuqm.tenant.dto.CreateAppRequest; import com.xuqm.tenant.entity.AppEntity; import com.xuqm.tenant.service.AppService; import jakarta.validation.Valid; import org.springframework.http.ResponseEntity; import org.springframework.security.core.annotation.AuthenticationPrincipal; import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PutMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import java.util.List; @RestController @RequestMapping("/api/apps") public class AppController { private final AppService appService; public AppController(AppService appService) { this.appService = appService; } @GetMapping public ResponseEntity>> list(@AuthenticationPrincipal String tenantId) { return ResponseEntity.ok(ApiResponse.success(appService.listByTenant(tenantId))); } @GetMapping("/{id}") public ResponseEntity> get(@PathVariable String id, @AuthenticationPrincipal String tenantId) { return ResponseEntity.ok(ApiResponse.success(appService.getById(id, tenantId))); } @PostMapping public ResponseEntity> create(@Valid @RequestBody CreateAppRequest req, @AuthenticationPrincipal String tenantId) { return ResponseEntity.ok(ApiResponse.success(appService.create(tenantId, req))); } @PutMapping("/{id}") public ResponseEntity> update(@PathVariable String id, @Valid @RequestBody CreateAppRequest req, @AuthenticationPrincipal String tenantId) { return ResponseEntity.ok(ApiResponse.success(appService.update(id, tenantId, req))); } @DeleteMapping("/{id}") public ResponseEntity> delete(@PathVariable String id, @AuthenticationPrincipal String tenantId) { appService.delete(id, tenantId); return ResponseEntity.ok(ApiResponse.ok()); } }