Skip to content

Commit 447113b

Browse files
authored
Merge pull request #59 from supplyDevelopment/response_entities
Response entities
2 parents 6fff62f + e99adda commit 447113b

20 files changed

Lines changed: 480 additions & 62 deletions

supply-backend/src/main/java/supply/server/controller/end_point/AuthorisationController.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package supply.server.controller.end_point;
22

3+
import io.swagger.v3.oas.annotations.responses.ApiResponse;
4+
import io.swagger.v3.oas.annotations.responses.ApiResponses;
35
import io.swagger.v3.oas.annotations.tags.Tag;
6+
import jakarta.servlet.http.Cookie;
47
import jakarta.servlet.http.HttpServletRequest;
58
import jakarta.servlet.http.HttpServletResponse;
69
import jakarta.validation.Valid;
@@ -26,6 +29,11 @@ public class AuthorisationController {
2629
private final AuthenticationService authenticationService;
2730

2831

32+
@ApiResponses(value = {
33+
@ApiResponse(responseCode = "200", description = "Success, cookie set"),
34+
@ApiResponse(responseCode = "400", description = "Bad request"),
35+
@ApiResponse(responseCode = "500", description = "Internal server error")
36+
})
2937
@PostMapping("/register_company")
3038
public ResponseEntity<?> registerCompany(@RequestBody @Valid @NotNull EmailRequest email, HttpServletResponse response) {
3139
String jwt = companyService.createCompany(email.toEmail());
@@ -34,6 +42,11 @@ public ResponseEntity<?> registerCompany(@RequestBody @Valid @NotNull EmailReque
3442
return ResponseEntity.ok().build();
3543
}
3644

45+
@ApiResponses(value = {
46+
@ApiResponse(responseCode = "200", description = "Success, cookie set"),
47+
@ApiResponse(responseCode = "400", description = "Bad request"),
48+
@ApiResponse(responseCode = "500", description = "Internal server error")
49+
})
3750
@PostMapping("/authorize")
3851
public ResponseEntity<?> authorize(@RequestBody @Valid @NotNull EmailPasswordRequest emailPassword, HttpServletResponse response) {
3952
Optional<String> jwtOptional = authenticationService.authenticate(emailPassword.toEmail(), emailPassword.password());
@@ -44,6 +57,10 @@ public ResponseEntity<?> authorize(@RequestBody @Valid @NotNull EmailPasswordReq
4457
return ResponseEntity.status(HttpStatus.BAD_REQUEST).build();
4558
}
4659

60+
@ApiResponses(value = {
61+
@ApiResponse(responseCode = "200", description = "Success, cookie deleted"),
62+
@ApiResponse(responseCode = "500", description = "Internal server error")
63+
})
4764
@GetMapping("/logout")
4865
public ResponseEntity<?> logout(HttpServletRequest request, HttpServletResponse response) {
4966
authenticationService.resetAuthenticationCookie(request, response);

supply-backend/src/main/java/supply/server/controller/end_point/EmployeeController.java

Lines changed: 38 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package supply.server.controller.end_point;
22

3+
import io.swagger.v3.oas.annotations.responses.ApiResponse;
4+
import io.swagger.v3.oas.annotations.responses.ApiResponses;
35
import io.swagger.v3.oas.annotations.tags.Tag;
46
import jakarta.validation.Valid;
57
import jakarta.validation.constraints.NotNull;
@@ -9,9 +11,9 @@
911
import supply.server.controller.entity.request.CreateUserRequest;
1012
import supply.server.controller.entity.request.EmailPasswordRequest;
1113
import supply.server.controller.entity.request.PaginationRequest;
12-
import supply.server.controller.entity.response.UserProfileResponse;
14+
import supply.server.controller.entity.response.UserFullInfoResponse;
15+
import supply.server.controller.entity.response.UserPartialInfoResponse;
1316
import supply.server.data.PaginatedList;
14-
import supply.server.data.company.Company;
1517
import supply.server.data.user.User;
1618
import supply.server.service.dataService.CreationService;
1719
import supply.server.service.dataService.FetchService;
@@ -31,30 +33,54 @@ public class EmployeeController {
3133
private final CreationService creationService;
3234
private final FetchService fetchService;
3335

36+
@ApiResponses(value = {
37+
@ApiResponse(responseCode = "200", description = "Success", useReturnTypeSchema = true),
38+
@ApiResponse(responseCode = "400", description = "Bad request"),
39+
@ApiResponse(responseCode = "500", description = "Internal server error")
40+
})
3441
@GetMapping("/employees")
35-
public ResponseEntity<?> getEmployees(
42+
public ResponseEntity<PaginatedList<UserPartialInfoResponse>> getEmployees(
3643
@RequestParam @Valid @NotNull String prefix,
3744
@Valid @NotNull PaginationRequest paginationRequest
3845
) {
3946
PaginatedList<User> users = searchService.getUsers(prefix, paginationRequest.toPagination());
4047

41-
return ResponseEntity.ok(users);
48+
return ResponseEntity.ok(
49+
new PaginatedList<>(
50+
users.total(),
51+
users.items().stream().map(UserPartialInfoResponse::new).toList()
52+
)
53+
);
4254
}
4355

56+
@ApiResponses(value = {
57+
@ApiResponse(responseCode = "200", description = "Success", useReturnTypeSchema = true),
58+
@ApiResponse(responseCode = "400", description = "Bad request"),
59+
@ApiResponse(responseCode = "500", description = "Internal server error")
60+
})
4461
@GetMapping("/employees/{id}")
45-
public ResponseEntity<?> getEmployee(@PathVariable String id) {
62+
public ResponseEntity<UserFullInfoResponse> getEmployee(@PathVariable String id) {
4663
User user = fetchService.getUser(UUID.fromString(id));
47-
Company company = fetchService.getCompany();
4864

49-
return ResponseEntity.ok(new UserProfileResponse(user, company));
65+
return ResponseEntity.ok(new UserFullInfoResponse(user));
5066
}
5167

68+
@ApiResponses(value = {
69+
@ApiResponse(responseCode = "200", description = "Success"),
70+
@ApiResponse(responseCode = "400", description = "Bad request"),
71+
@ApiResponse(responseCode = "500", description = "Internal server error")
72+
})
5273
@PostMapping("/add")
5374
public ResponseEntity<?> addEmployee(@RequestBody @Valid @NotNull CreateUserRequest createUser) {
5475
creationService.createUser(createUser.toCreateUser());
5576
return ResponseEntity.ok().build();
5677
}
5778

79+
@ApiResponses(value = {
80+
@ApiResponse(responseCode = "200", description = "Success"),
81+
@ApiResponse(responseCode = "400", description = "Bad request"),
82+
@ApiResponse(responseCode = "500", description = "Internal server error")
83+
})
5884
@PostMapping("/update")
5985
public ResponseEntity<?> updateEmployee(@RequestBody @Valid @NotNull EmailPasswordRequest emailPassword, @Valid @NotNull String id) {
6086
if (emailPassword.password() != null) {
@@ -66,6 +92,11 @@ public ResponseEntity<?> updateEmployee(@RequestBody @Valid @NotNull EmailPasswo
6692
return ResponseEntity.ok().build();
6793
}
6894

95+
@ApiResponses(value = {
96+
@ApiResponse(responseCode = "200", description = "Success"),
97+
@ApiResponse(responseCode = "400", description = "Bad request"),
98+
@ApiResponse(responseCode = "500", description = "Internal server error")
99+
})
69100
@PostMapping("/remove")
70101
public ResponseEntity<?> removeEmployee(@RequestBody @Valid @NotNull UUID id) {
71102
updateService.removeUser(id);

supply-backend/src/main/java/supply/server/controller/end_point/HistoryController.java

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package supply.server.controller.end_point;
22

3+
import io.swagger.v3.oas.annotations.responses.ApiResponse;
4+
import io.swagger.v3.oas.annotations.responses.ApiResponses;
35
import io.swagger.v3.oas.annotations.tags.Tag;
46
import jakarta.validation.Valid;
57
import jakarta.validation.constraints.NotNull;
@@ -10,6 +12,7 @@
1012
import org.springframework.web.bind.annotation.RequestParam;
1113
import org.springframework.web.bind.annotation.RestController;
1214
import supply.server.controller.entity.request.PaginationRequest;
15+
import supply.server.controller.entity.response.ResourceHistoryResponse;
1316
import supply.server.data.PaginatedList;
1417
import supply.server.data.resource.history.ResourceHistory;
1518
import supply.server.service.dataService.SearchService;
@@ -22,13 +25,23 @@ public class HistoryController {
2225

2326
private final SearchService searchService;
2427

28+
@ApiResponses(value = {
29+
@ApiResponse(responseCode = "200", description = "Success", useReturnTypeSchema = true),
30+
@ApiResponse(responseCode = "400", description = "Bad request"),
31+
@ApiResponse(responseCode = "500", description = "Internal server error")
32+
})
2533
@GetMapping("/get")
26-
public ResponseEntity<?> getHistory(
34+
public ResponseEntity<PaginatedList<ResourceHistoryResponse>> getHistory(
2735
@Valid @NotNull PaginationRequest paginationRequest
2836
) {
2937
PaginatedList<ResourceHistory> resources = searchService.getResourceHistory(paginationRequest.toPagination());
3038

31-
return ResponseEntity.ok(resources);
39+
return ResponseEntity.ok(
40+
new PaginatedList<>(
41+
resources.total(),
42+
resources.items().stream().map(ResourceHistoryResponse::new).toList()
43+
)
44+
);
3245
}
3346

3447

supply-backend/src/main/java/supply/server/controller/end_point/ProfileController.java

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package supply.server.controller.end_point;
22

3+
import io.swagger.v3.oas.annotations.responses.ApiResponse;
4+
import io.swagger.v3.oas.annotations.responses.ApiResponses;
35
import io.swagger.v3.oas.annotations.tags.Tag;
46
import jakarta.validation.Valid;
57
import jakarta.validation.constraints.NotEmpty;
@@ -9,15 +11,13 @@
911
import org.springframework.web.bind.annotation.*;
1012
import supply.server.controller.entity.request.EmailPasswordRequest;
1113
import supply.server.controller.entity.request.EmailRequest;
12-
import supply.server.controller.entity.response.UserInfoResponse;
13-
import supply.server.controller.entity.response.UserProfileResponse;
14-
import supply.server.data.company.Company;
14+
import supply.server.controller.entity.response.UserFullInfoResponse;
15+
import supply.server.controller.entity.response.UserPartialInfoResponse;
1516
import supply.server.data.user.User;
1617
import supply.server.service.dataService.FetchService;
1718
import supply.server.service.dataService.UpdateService;
1819

1920
import java.util.List;
20-
import java.util.UUID;
2121

2222
@RestController
2323
@RequestMapping("/profile")
@@ -28,23 +28,33 @@ public class ProfileController {
2828
private final FetchService fetchService;
2929
private final UpdateService updateService;
3030

31-
31+
@ApiResponses(value = {
32+
@ApiResponse(responseCode = "200", description = "Success", useReturnTypeSchema = true),
33+
@ApiResponse(responseCode = "500", description = "Internal server error")
34+
})
3235
@GetMapping("/info")
33-
public ResponseEntity<?> getInfo() {
36+
public ResponseEntity<UserFullInfoResponse> getInfo() {
3437
User user = fetchService.getUser();
35-
Company company = fetchService.getCompany();
3638

37-
return ResponseEntity.ok(new UserProfileResponse(user, company));
39+
return ResponseEntity.ok(new UserFullInfoResponse(user));
3840
}
3941

42+
@ApiResponses(value = {
43+
@ApiResponse(responseCode = "200", description = "Success", useReturnTypeSchema = true),
44+
@ApiResponse(responseCode = "500", description = "Internal server error")
45+
})
4046
@GetMapping("/user_info")
41-
public ResponseEntity<?> getUserInfo() {
47+
public ResponseEntity<UserPartialInfoResponse> getUserInfo() {
4248
User user = fetchService.getUser();
43-
Company company = fetchService.getCompany();
4449

45-
return ResponseEntity.ok(new UserInfoResponse(user, company));
50+
return ResponseEntity.ok(new UserPartialInfoResponse(user));
4651
}
4752

53+
@ApiResponses(value = {
54+
@ApiResponse(responseCode = "200", description = "Success"),
55+
@ApiResponse(responseCode = "400", description = "Bad request"),
56+
@ApiResponse(responseCode = "500", description = "Internal server error")
57+
})
4858
@PostMapping("/company/update")
4959
public ResponseEntity<?> updateCompany(
5060
@RequestBody @Valid @NotNull @NotEmpty List<EmailRequest> emails
@@ -53,6 +63,11 @@ public ResponseEntity<?> updateCompany(
5363
return ResponseEntity.ok().build();
5464
}
5565

66+
@ApiResponses(value = {
67+
@ApiResponse(responseCode = "200", description = "Success"),
68+
@ApiResponse(responseCode = "400", description = "Bad request"),
69+
@ApiResponse(responseCode = "500", description = "Internal server error")
70+
})
5671
@PostMapping("/user/update")
5772
public ResponseEntity<?> updateUser(@RequestBody @Valid @NotNull EmailPasswordRequest emailPassword) {
5873
if (emailPassword.password() != null) {

supply-backend/src/main/java/supply/server/controller/end_point/ProjectController.java

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package supply.server.controller.end_point;
22

3+
import io.swagger.v3.oas.annotations.responses.ApiResponse;
4+
import io.swagger.v3.oas.annotations.responses.ApiResponses;
35
import io.swagger.v3.oas.annotations.tags.Tag;
46
import jakarta.validation.Valid;
57
import jakarta.validation.constraints.NotNull;
@@ -8,6 +10,7 @@
810
import org.springframework.web.bind.annotation.*;
911
import supply.server.controller.entity.request.CreateProjectRequest;
1012
import supply.server.controller.entity.request.PaginationRequest;
13+
import supply.server.controller.entity.response.ProjectResponse;
1114
import supply.server.data.PaginatedList;
1215
import supply.server.data.project.Project;
1316
import supply.server.service.dataService.CreationService;
@@ -26,27 +29,47 @@ public class ProjectController {
2629
private final SearchService searchService;
2730
private final FetchService fetchService;
2831

32+
@ApiResponses(value = {
33+
@ApiResponse(responseCode = "200", description = "Success"),
34+
@ApiResponse(responseCode = "400", description = "Bad request"),
35+
@ApiResponse(responseCode = "500", description = "Internal server error")
36+
})
2937
@PostMapping("/add")
3038
public ResponseEntity<?> addProject(@RequestBody @Valid @NotNull CreateProjectRequest createProject) {
3139
creationService.createProject(createProject.name(), createProject.description());
3240
return ResponseEntity.ok().build();
3341
}
3442

43+
@ApiResponses(value = {
44+
@ApiResponse(responseCode = "200", description = "Success", useReturnTypeSchema = true),
45+
@ApiResponse(responseCode = "400", description = "Bad request"),
46+
@ApiResponse(responseCode = "500", description = "Internal server error")
47+
})
3548
@GetMapping("/projects")
36-
public ResponseEntity<?> getProjects(
49+
public ResponseEntity<PaginatedList<ProjectResponse>> getProjects(
3750
@RequestParam @NotNull String prefix,
3851
@Valid @NotNull PaginationRequest paginationRequest
3952
) {
4053
PaginatedList<Project> projects = searchService.getProjects(prefix, paginationRequest.toPagination());
4154

42-
return ResponseEntity.ok(projects);
55+
return ResponseEntity.ok(
56+
new PaginatedList<>(
57+
projects.total(),
58+
projects.items().stream().map(ProjectResponse::new).toList()
59+
)
60+
);
4361
}
4462

63+
@ApiResponses(value = {
64+
@ApiResponse(responseCode = "200", description = "Success", useReturnTypeSchema = true),
65+
@ApiResponse(responseCode = "400", description = "Bad request"),
66+
@ApiResponse(responseCode = "500", description = "Internal server error")
67+
})
4568
@GetMapping("/projects/{id}")
46-
public ResponseEntity<?> getProject(@PathVariable String id) {
69+
public ResponseEntity<ProjectResponse> getProject(@PathVariable String id) {
4770
Project project = fetchService.getProject(UUID.fromString(id));
4871

49-
return ResponseEntity.ok(project);
72+
return ResponseEntity.ok(new ProjectResponse(project));
5073
}
5174

5275
}

0 commit comments

Comments
 (0)