-
Notifications
You must be signed in to change notification settings - Fork 0
/
ReservationResource.java
209 lines (193 loc) · 16 KB
/
ReservationResource.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
package io.extact.msa.rms.reservation.webapi;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotNull;
import jakarta.ws.rs.Consumes;
import jakarta.ws.rs.DELETE;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.POST;
import jakarta.ws.rs.PUT;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.PathParam;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.QueryParam;
import jakarta.ws.rs.core.MediaType;
import org.eclipse.microprofile.openapi.annotations.Operation;
import org.eclipse.microprofile.openapi.annotations.enums.ParameterIn;
import org.eclipse.microprofile.openapi.annotations.enums.SchemaType;
import org.eclipse.microprofile.openapi.annotations.media.Content;
import org.eclipse.microprofile.openapi.annotations.media.Schema;
import org.eclipse.microprofile.openapi.annotations.parameters.Parameter;
import org.eclipse.microprofile.openapi.annotations.responses.APIResponse;
import org.eclipse.microprofile.openapi.annotations.security.SecurityRequirement;
import org.eclipse.microprofile.openapi.annotations.security.SecurityRequirements;
import io.extact.msa.rms.platform.fw.domain.constraint.RmsId;
import io.extact.msa.rms.platform.fw.exception.BusinessFlowException;
import io.extact.msa.rms.reservation.webapi.dto.AddReservationEventDto;
import io.extact.msa.rms.reservation.webapi.dto.ReservationResourceDto;
public interface ReservationResource {
/*
* NOTE:
* @SecurityRequirementSetで本来はRmsHeaderAuthn and RmsHeaderAuthzにすべきだがsmallrye-open-apiがバグ?で未サポートのため
* @SecurityRequirementsで定義している。MicroProfile OpenAPI 3.1.0では対応されるハズ
* see: https://github.com/smallrye/smallrye-open-api/pull/1097
*/
@GET
@Produces(MediaType.APPLICATION_JSON)
//--- for OpenAPI
@Operation(operationId = "getAll", summary = "予約の全件を取得する", description = "登録されているすべての予約を取得する")
@SecurityRequirements({@SecurityRequirement(name = "RmsHeaderAuthn"), @SecurityRequirement(name = "RmsHeaderAuthz")})
@APIResponse(responseCode = "200", description = "検索結果", content = @Content(mediaType = "application/json", schema = @Schema(type = SchemaType.ARRAY, implementation = ReservationResourceDto.class)))
@APIResponse(responseCode = "500", ref = "#/components/responses/ServerError")
@APIResponse(responseCode = "503", ref = "#/components/responses/ServiceUnavailable")
List<ReservationResourceDto> getAll();
@GET
@Path("/item/{itemId}/startdate/{startDate}")
@Produces(MediaType.APPLICATION_JSON)
//--- for OpenAPI
@Operation(operationId = "findByRentalItemAndStartDate", summary = "指定されたレンタル品と利用開始日で予約を検索する", description = "指定されたレンタル品と利用開始日に一致する予約を検索する")
@SecurityRequirements({@SecurityRequirement(name = "RmsHeaderAuthn"), @SecurityRequirement(name = "RmsHeaderAuthz")})
@Parameter(name = "itemId", description = "レンタル品ID", in = ParameterIn.PATH, required = true)
@Parameter(name = "startDate", description = "利用開始日", in = ParameterIn.PATH, required = true, schema = @Schema(implementation = String.class, example = "20201230", format = "yyyyMMdd"))
@APIResponse(responseCode = "200", description = "検索結果", content = @Content(mediaType = "application/json", schema = @Schema(type = SchemaType.ARRAY, implementation = ReservationResourceDto.class)))
@APIResponse(responseCode = "400", ref = "#/components/responses/ParameterError")
@APIResponse(responseCode = "500", ref = "#/components/responses/ServerError")
@APIResponse(responseCode = "503", ref = "#/components/responses/ServiceUnavailable")
List<ReservationResourceDto> findByRentalItemAndStartDate(@RmsId @PathParam("itemId") Integer itemId, @NotNull @PathParam("startDate") LocalDate startDate);
@GET
@Path("/reserver/{reserverId}")
@Produces(MediaType.APPLICATION_JSON)
//--- for OpenAPI
@Operation(operationId = "findByReserverId", summary = "指定されたユーザが予約者の予約を検索する", description = "指定されたユーザが予約者の予約を検索する")
@SecurityRequirements({@SecurityRequirement(name = "RmsHeaderAuthn"), @SecurityRequirement(name = "RmsHeaderAuthz")})
@Parameter(name = "reserverId", description = "ユーザID", in = ParameterIn.PATH, required = true)
@APIResponse(responseCode = "200", description = "検索結果", content = @Content(mediaType = "application/json", schema = @Schema(type = SchemaType.ARRAY, implementation = ReservationResourceDto.class)))
@APIResponse(responseCode = "400", ref = "#/components/responses/ParameterError")
@APIResponse(responseCode = "500", ref = "#/components/responses/ServerError")
@APIResponse(responseCode = "503", ref = "#/components/responses/ServiceUnavailable")
List<ReservationResourceDto> findByReserverId(@RmsId @PathParam("reserverId") Integer reserverId);
@GET
@Path("/item/{itemId}")
@Produces(MediaType.APPLICATION_JSON)
//--- for OpenAPI
@Operation(operationId = "findByRentalItemId", summary = "指定されたレンタル品に対する予約を検索する", description = "指定されたレンタル品に対する予約を検索する")
@SecurityRequirements({@SecurityRequirement(name = "RmsHeaderAuthn"), @SecurityRequirement(name = "RmsHeaderAuthz")})
@Parameter(name = "rentalItemId", description = "レンタル品ID", in = ParameterIn.PATH, required = true)
@APIResponse(responseCode = "200", description = "検索結果", content = @Content(mediaType = "application/json", schema = @Schema(type = SchemaType.ARRAY, implementation = ReservationResourceDto.class)))
@APIResponse(responseCode = "400", ref = "#/components/responses/ParameterError")
@APIResponse(responseCode = "500", ref = "#/components/responses/ServerError")
@APIResponse(responseCode = "503", ref = "#/components/responses/ServiceUnavailable")
List<ReservationResourceDto> findByRentalItemId(@RmsId @PathParam("itemId") Integer itemId);
@GET
@Path("/item/overlapped")
@Produces(MediaType.APPLICATION_JSON)
//--- for OpenAPI
@Operation(operationId = "findOverlappedReservations", summary = "指定された期間と被る予約を検索する", description = "指定された期間と予約されている期間が被っているものを対象にする")
@SecurityRequirements({@SecurityRequirement(name = "RmsHeaderAuthn"), @SecurityRequirement(name = "RmsHeaderAuthz")})
@Parameter(name = "from", description = "利用開始日", in = ParameterIn.PATH, required = true, schema = @Schema(implementation = String.class, example = "20201230", format = "yyyyMMdd"))
@Parameter(name = "to", description = "利用終了日", in = ParameterIn.PATH, required = true, schema = @Schema(implementation = String.class, example = "20201230", format = "yyyyMMdd"))
@APIResponse(responseCode = "200", description = "検索結果", content = @Content(mediaType = "application/json", schema = @Schema(type = SchemaType.ARRAY, implementation = ReservationResourceDto.class)))
@APIResponse(responseCode = "400", ref = "#/components/responses/ParameterError")
@APIResponse(responseCode = "500", ref = "#/components/responses/ServerError")
@APIResponse(responseCode = "503", ref = "#/components/responses/ServiceUnavailable")
List<ReservationResourceDto> findOverlappedReservations(@NotNull @QueryParam("from") LocalDateTime from,
@NotNull @QueryParam("to") LocalDateTime to);
@GET
@Path("/item/{itemId}/overlapped")
@Produces(MediaType.APPLICATION_JSON)
//--- for OpenAPI
@Operation(operationId = "findOverlappedReservation", summary = "指定された期間で予約されているレンタル品の予約を取得する", description = "指定された期間と予約されている期間が被っているものを対象にする。なお、該当なしはnullに相当する204(NoContent)を返す")
@SecurityRequirements({@SecurityRequirement(name = "RmsHeaderAuthn"), @SecurityRequirement(name = "RmsHeaderAuthz")})
@Parameter(name = "itemId", description = "レンタル品ID", in = ParameterIn.PATH, required = true)
@Parameter(name = "from", description = "利用開始日", in = ParameterIn.PATH, required = true, schema = @Schema(implementation = String.class, example = "20201230", format = "yyyyMMdd"))
@Parameter(name = "to", description = "利用終了日", in = ParameterIn.PATH, required = true, schema = @Schema(implementation = String.class, example = "20201230", format = "yyyyMMdd"))
@APIResponse(responseCode = "200", description = "検索結果", content = @Content(mediaType = "application/json", schema = @Schema(type = SchemaType.ARRAY, implementation = ReservationResourceDto.class)))
@APIResponse(responseCode = "204", ref = "#/components/responses/NoContent")
@APIResponse(responseCode = "400", ref = "#/components/responses/ParameterError")
@APIResponse(responseCode = "500", ref = "#/components/responses/ServerError")
@APIResponse(responseCode = "503", ref = "#/components/responses/ServiceUnavailable")
ReservationResourceDto findOverlappedReservation(@RmsId @PathParam("itemId") Integer itemId,
@NotNull @QueryParam("from") LocalDateTime from,
@NotNull @QueryParam("to") LocalDateTime to);
@GET
@Path("/has-item/{itemId}")
@Produces(MediaType.APPLICATION_JSON)
//--- for OpenAPI
@Operation(operationId = "hasRentalItemWith", summary = "指定されたレンタル品に対する予約があるかを返す")
@SecurityRequirement(name = "RmsJwtAuth")
@SecurityRequirements({@SecurityRequirement(name = "RmsHeaderAuthn"), @SecurityRequirement(name = "RmsHeaderAuthz")})
@APIResponse(responseCode = "200", description = "ある場合はtrueを返す", content = @Content(mediaType = "application/json", schema = @Schema(type = SchemaType.BOOLEAN, implementation = Boolean.class)))
@APIResponse(responseCode = "400", ref = "#/components/responses/ParameterError")
@APIResponse(responseCode = "500", ref = "#/components/responses/ServerError")
@APIResponse(responseCode = "503", ref = "#/components/responses/ServiceUnavailable")
boolean hasRentalItemWith(@RmsId @PathParam("itemId") Integer itemId);
@GET
@Path("/has-user/{userId}")
@Produces(MediaType.APPLICATION_JSON)
//--- for OpenAPI
@Operation(operationId = "hasUserAccountWith", summary = "指定されたユーザの予約があるかを返す")
@SecurityRequirements({@SecurityRequirement(name = "RmsHeaderAuthn"), @SecurityRequirement(name = "RmsHeaderAuthz")})
@Parameter(name = "userId", description = "ユーザID", in = ParameterIn.PATH, required = true)
@APIResponse(responseCode = "200", description = "ある場合はtrueを返す", content = @Content(mediaType = "application/json", schema = @Schema(type = SchemaType.BOOLEAN, implementation = Boolean.class)))
@APIResponse(responseCode = "400", ref = "#/components/responses/ParameterError")
@APIResponse(responseCode = "500", ref = "#/components/responses/ServerError")
@APIResponse(responseCode = "503", ref = "#/components/responses/ServiceUnavailable")
boolean hasUserAccountWith(@RmsId @PathParam("userId") Integer userId);
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
//--- for OpenAPI
@Operation(operationId = "add", summary = "レンタル品を予約する", description = "予約対象のレンタル品が存在しない場合は404を予定期間に別の予約が既に入っている場合は409を返す")
@SecurityRequirements({@SecurityRequirement(name = "RmsHeaderAuthn"), @SecurityRequirement(name = "RmsHeaderAuthz")})
@Parameter(name = "dto", description = "登録内容", required = true, content = @Content(mediaType = "application/json", schema = @Schema(implementation = AddReservationEventDto.class)))
@APIResponse(responseCode = "200", description = "登録成功", content = @Content(mediaType = "application/json", schema = @Schema(implementation = ReservationResourceDto.class)))
@APIResponse(responseCode = "400", ref = "#/components/responses/ParameterError")
@APIResponse(responseCode = "404", ref = "#/components/responses/UnknownData")
@APIResponse(responseCode = "409", ref = "#/components/responses/DataDupricate")
@APIResponse(responseCode = "500", ref = "#/components/responses/ServerError")
@APIResponse(responseCode = "503", ref = "#/components/responses/ServiceUnavailable")
ReservationResourceDto add(@Valid AddReservationEventDto dto) throws BusinessFlowException;
@PUT
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
//--- for OpenAPI
@Operation(operationId = "update", summary = "予約を更新する", description = "依頼された予約を更新する")
@SecurityRequirements({@SecurityRequirement(name = "RmsHeaderAuthn"), @SecurityRequirement(name = "RmsHeaderAuthz")})
@Parameter(name = "dto", description = "更新内容", required = true, content = @Content(mediaType = "application/json", schema = @Schema(implementation = ReservationResourceDto.class)))
@APIResponse(responseCode = "200", description = "登録成功", content = @Content(mediaType = "application/json", schema = @Schema(implementation = ReservationResourceDto.class)))
@APIResponse(responseCode = "400", ref = "#/components/responses/ParameterError")
@APIResponse(responseCode = "404", ref = "#/components/responses/UnknownData")
@APIResponse(responseCode = "500", ref = "#/components/responses/ServerError")
@APIResponse(responseCode = "503", ref = "#/components/responses/ServiceUnavailable")
ReservationResourceDto update(@Valid ReservationResourceDto dto);
@DELETE
@Path("/{reservationId}")
//--- for OpenAPI
@Operation(operationId = "delete", summary = "予約を削除する", description = "予約を削除する")
@SecurityRequirements({@SecurityRequirement(name = "RmsHeaderAuthn"), @SecurityRequirement(name = "RmsHeaderAuthz")})
@Parameter(name = "reservationId", description = "予約ID", in = ParameterIn.PATH, required = true)
@APIResponse(responseCode = "200", description = "登録成功")
@APIResponse(responseCode = "400", ref = "#/components/responses/ParameterError")
@APIResponse(responseCode = "404", ref = "#/components/responses/UnknownData")
@APIResponse(responseCode = "500", ref = "#/components/responses/ServerError")
@APIResponse(responseCode = "503", ref = "#/components/responses/ServiceUnavailable")
void delete(@RmsId @PathParam("reservationId") Integer reservationId) throws BusinessFlowException;
@DELETE
@Path("cancel")
//--- for OpenAPI
@Operation(operationId = "cancel", summary = "予約をキャンセルする", description = "依頼された予約IDに対する予約をキャンセルする。予約のキャンセルは予約した人しか行えない。"
+ "他の人が予約キャンセルを行った場合は禁止操作としてエラーにする")
@SecurityRequirements({@SecurityRequirement(name = "RmsHeaderAuthn"), @SecurityRequirement(name = "RmsHeaderAuthz")})
@Parameter(name = "reservationId", description = "予約ID", in = ParameterIn.QUERY, required = true)
@Parameter(name = "reserverId", description = "予約者ID", in = ParameterIn.QUERY, required = true)
@APIResponse(responseCode = "200", description = "登録成功")
@APIResponse(responseCode = "400", ref = "#/components/responses/ParameterError")
@APIResponse(responseCode = "403", ref = "#/components/responses/Forbidden")
@APIResponse(responseCode = "404", ref = "#/components/responses/UnknownData")
@APIResponse(responseCode = "500", ref = "#/components/responses/ServerError")
@APIResponse(responseCode = "503", ref = "#/components/responses/ServiceUnavailable")
void cancel(@RmsId @QueryParam("reservationId") Integer reservationId,
@RmsId @QueryParam("reserverId") Integer reserverId) throws BusinessFlowException;
}