feat: add organization REST endpoints
This commit is contained in:
1 parent
7b3bdd4075
commit
2f63a9a4fd
3 files changed
+65
No files matched your search
@@ -0,0 +1,41 @@
|
||||
package com.slotline.organization;
|
||||
|
||||
import com.slotline.organization.dto.OrganizationRequest;
|
||||
import com.slotline.organization.dto.OrganizationResponse;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.validation.Valid;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.ResponseStatus;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api/organizations")
|
||||
@Tag(name = "Organizations")
|
||||
public class OrganizationController {
|
||||
|
||||
private final OrganizationService organizationService;
|
||||
|
||||
public OrganizationController(OrganizationService organizationService) {
|
||||
this.organizationService = organizationService;
|
||||
}
|
||||
|
||||
@GetMapping
|
||||
@Operation(summary = "List tenants (ADMIN only)")
|
||||
public List<OrganizationResponse> list() {
|
||||
return organizationService.findAll();
|
||||
}
|
||||
|
||||
@PostMapping
|
||||
@ResponseStatus(HttpStatus.CREATED)
|
||||
@Operation(summary = "Provision a new tenant (ADMIN only)")
|
||||
public OrganizationResponse create(@Valid @RequestBody OrganizationRequest request) {
|
||||
return organizationService.create(request);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package com.slotline.organization.dto;
|
||||
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import jakarta.validation.constraints.Pattern;
|
||||
import jakarta.validation.constraints.Size;
|
||||
|
||||
public record OrganizationRequest(
|
||||
@NotBlank @Size(max = 128) String name,
|
||||
@NotBlank @Size(min = 2, max = 64) @Pattern(regexp = "[a-z0-9-]+",
|
||||
message = "slug must be lowercase letters, digits or hyphens") String slug) {
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.slotline.organization.dto;
|
||||
|
||||
import com.slotline.organization.Organization;
|
||||
|
||||
import java.time.Instant;
|
||||
|
||||
public record OrganizationResponse(Long id, String name, String slug, Instant createdAt) {
|
||||
|
||||
public static OrganizationResponse from(Organization organization) {
|
||||
return new OrganizationResponse(organization.getId(), organization.getName(), organization.getSlug(),
|
||||
organization.getCreatedAt());
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user