Skip to content

Commit 9c77efc

Browse files
committed
Task 15 : Add OpenApi for endpoints in CryptoConvertController
1 parent 05eb8d0 commit 9c77efc

File tree

1 file changed

+140
-0
lines changed

1 file changed

+140
-0
lines changed

src/main/java/com/casestudy/cryptoexchangeapi/exchange/controller/CryptoConvertController.java

Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@
99
import com.casestudy.cryptoexchangeapi.exchange.model.dto.response.CryptoConvertResponse;
1010
import com.casestudy.cryptoexchangeapi.exchange.model.mapper.CustomPageCryptoConvertToCustomPagingCryptoConvertResponseMapper;
1111
import com.casestudy.cryptoexchangeapi.exchange.service.CryptoConvertService;
12+
import io.swagger.v3.oas.annotations.Operation;
13+
import io.swagger.v3.oas.annotations.media.Content;
14+
import io.swagger.v3.oas.annotations.media.ExampleObject;
15+
import io.swagger.v3.oas.annotations.media.Schema;
16+
import io.swagger.v3.oas.annotations.responses.ApiResponse;
1217
import io.swagger.v3.oas.annotations.tags.Tag;
1318
import jakarta.annotation.PostConstruct;
1419
import jakarta.validation.Valid;
@@ -37,6 +42,66 @@ public class CryptoConvertController {
3742
private static final CustomPageCryptoConvertToCustomPagingCryptoConvertResponseMapper PAGE_MAPPER =
3843
CustomPageCryptoConvertToCustomPagingCryptoConvertResponseMapper.initialize();
3944

45+
@Operation(
46+
operationId = "convert",
47+
summary = "Convert an amount from one crypto to another and persist the result",
48+
requestBody = @io.swagger.v3.oas.annotations.parameters.RequestBody(
49+
required = true,
50+
description = "Conversion request",
51+
content = @Content(
52+
schema = @Schema(implementation = ConvertRequest.class),
53+
examples = @ExampleObject(
54+
name = "BTC to ARB",
55+
value = """
56+
{
57+
"from": "BTC",
58+
"to": "ARB",
59+
"amount": 100
60+
}
61+
"""
62+
)
63+
)
64+
),
65+
responses = {
66+
@ApiResponse(
67+
responseCode = "201",
68+
description = "Conversion created",
69+
content = @Content(
70+
schema = @Schema(implementation = CustomResponse.class),
71+
examples = @ExampleObject(
72+
name = "Created",
73+
value = """
74+
{
75+
"time": "2025-10-01T18:04:33.282",
76+
"httpStatus": "CREATED",
77+
"isSuccess": true,
78+
"response": {
79+
"createdAt": "2025-10-01T18:04:33.282",
80+
"transactionId": "6c7de41f-71e5-4d63-984d-8dcb60ba6265",
81+
"amount": 100,
82+
"from": "BTC",
83+
"to": "ARB",
84+
"convertedAmount": 2711598539.488985400
85+
}
86+
}
87+
"""
88+
)
89+
)
90+
),
91+
@ApiResponse(
92+
responseCode = "400",
93+
description = "Validation error",
94+
content = @Content(
95+
mediaType = "application/json"
96+
)
97+
),
98+
@ApiResponse(
99+
responseCode = "502",
100+
description = "Upstream conversion unavailable (CMC error)",
101+
content = @Content(mediaType = "application/json")
102+
)
103+
}
104+
)
40105
@PostMapping
41106
@ResponseStatus(HttpStatus.CREATED)
42107
public CustomResponse<CryptoConvert> convert(@Valid @RequestBody ConvertRequest req) {
@@ -46,6 +111,81 @@ public CustomResponse<CryptoConvert> convert(@Valid @RequestBody ConvertRequest
46111

47112
}
48113

114+
@Operation(
115+
operationId = "getHistory",
116+
summary = "Search conversion history with filters, pagination and sorting",
117+
requestBody = @io.swagger.v3.oas.annotations.parameters.RequestBody(
118+
required = true,
119+
description = "Filter, pagination and sorting",
120+
content = @Content(
121+
schema = @Schema(implementation = FilterServicePagingRequest.class),
122+
examples = @ExampleObject(
123+
name = "Filter & page",
124+
value = """
125+
{
126+
"filterRequest": {
127+
"filter": {
128+
"from": "BTC",
129+
"to": "ARB",
130+
"minAmount": 50,
131+
"maxAmount": 5000,
132+
"minConvertedAmount": 1000000,
133+
"maxConvertedAmount": 3000000000,
134+
"createdAtFrom": "2025-09-29T00:00:00",
135+
"createdAtTo": "2025-10-02T23:59:59",
136+
"transactionIdContains": "6c7de4"
137+
}
138+
},
139+
"pagingRequest": {
140+
"pagination": { "pageNumber": 1, "pageSize": 20 },
141+
"sorting": { "sortBy": "createdAt", "sortDirection": "DESC" }
142+
}
143+
}
144+
"""
145+
)
146+
)
147+
),
148+
responses = {
149+
@ApiResponse(
150+
responseCode = "200",
151+
description = "Paged result",
152+
content = @Content(
153+
schema = @Schema(implementation = CustomPagingResponse.class),
154+
examples = @ExampleObject(
155+
name = "OK",
156+
value = """
157+
{
158+
"time": "2025-10-01T19:27:24.2492919",
159+
"httpStatus": "OK",
160+
"isSuccess": true,
161+
"response": {
162+
"content": [
163+
{
164+
"transactionId": "6c7de41f-71e5-4d63-984d-8dcb60ba6265",
165+
"amount": 100,
166+
"from": "BTC",
167+
"to": "ARB",
168+
"convertedAmount": 2711598539.488985400,
169+
"createdAt": "2025-10-01T18:04:33.282"
170+
}
171+
],
172+
"pageNumber": 1,
173+
"pageSize": 20,
174+
"totalElementCount": 1,
175+
"totalPageCount": 1
176+
}
177+
}
178+
"""
179+
)
180+
)
181+
),
182+
@ApiResponse(
183+
responseCode = "400",
184+
description = "Validation error",
185+
content = @Content(mediaType = "application/json")
186+
)
187+
}
188+
)
49189
@PostMapping("/history")
50190
public CustomResponse<CustomPagingResponse<CryptoConvertResponse>> getHistory(
51191
@Valid @RequestBody FilterServicePagingRequest filterServicePagingRequest) {

0 commit comments

Comments
 (0)