StakeKeyReportController.java

1
package org.cardanofoundation.explorer.api.controller;
2
3
import jakarta.validation.Valid;
4
5
import lombok.RequiredArgsConstructor;
6
7
import org.springframework.core.io.InputStreamResource;
8
import org.springframework.core.io.Resource;
9
import org.springframework.data.domain.Sort;
10
import org.springframework.http.HttpHeaders;
11
import org.springframework.http.MediaType;
12
import org.springframework.http.ResponseEntity;
13
import org.springframework.validation.annotation.Validated;
14
import org.springframework.web.bind.annotation.GetMapping;
15
import org.springframework.web.bind.annotation.PathVariable;
16
import org.springframework.web.bind.annotation.PostMapping;
17
import org.springframework.web.bind.annotation.RequestAttribute;
18
import org.springframework.web.bind.annotation.RequestBody;
19
import org.springframework.web.bind.annotation.RequestMapping;
20
import org.springframework.web.bind.annotation.RequestParam;
21
import org.springframework.web.bind.annotation.RestController;
22
23
import io.swagger.v3.oas.annotations.Operation;
24
import io.swagger.v3.oas.annotations.Parameter;
25
import io.swagger.v3.oas.annotations.tags.Tag;
26
import org.springdoc.core.annotations.ParameterObject;
27
28
import org.cardanofoundation.explorer.api.common.constant.CommonConstant;
29
import org.cardanofoundation.explorer.api.common.enumeration.ExportType;
30
import org.cardanofoundation.explorer.api.config.LogMessage;
31
import org.cardanofoundation.explorer.api.controller.validation.StakeKeyLengthValid;
32
import org.cardanofoundation.explorer.api.interceptor.auth.UserPrincipal;
33
import org.cardanofoundation.explorer.api.model.request.stake.report.ReportHistoryFilterRequest;
34
import org.cardanofoundation.explorer.api.model.request.stake.report.StakeKeyReportRequest;
35
import org.cardanofoundation.explorer.api.model.response.BaseFilterResponse;
36
import org.cardanofoundation.explorer.api.model.response.ReportLimitResponse;
37
import org.cardanofoundation.explorer.api.model.response.stake.lifecycle.StakeDelegationFilterResponse;
38
import org.cardanofoundation.explorer.api.model.response.stake.lifecycle.StakeRegistrationFilterResponse;
39
import org.cardanofoundation.explorer.api.model.response.stake.lifecycle.StakeRewardResponse;
40
import org.cardanofoundation.explorer.api.model.response.stake.lifecycle.StakeWalletActivityResponse;
41
import org.cardanofoundation.explorer.api.model.response.stake.lifecycle.StakeWithdrawalFilterResponse;
42
import org.cardanofoundation.explorer.api.model.response.stake.report.ReportHistoryResponse;
43
import org.cardanofoundation.explorer.api.model.response.stake.report.StakeKeyReportHistoryResponse;
44
import org.cardanofoundation.explorer.api.model.response.stake.report.StakeKeyReportResponse;
45
import org.cardanofoundation.explorer.api.service.ReportHistoryService;
46
import org.cardanofoundation.explorer.api.service.StakeKeyReportService;
47
import org.cardanofoundation.explorer.common.validation.pagination.Pagination;
48
import org.cardanofoundation.explorer.common.validation.pagination.PaginationDefault;
49
import org.cardanofoundation.explorer.common.validation.pagination.PaginationValid;
50
import org.cardanofoundation.explorer.common.validation.prefixed.PrefixedValid;
51
52
@RestController
53
@RequestMapping("/api/v1/staking-lifecycle/report")
54
@RequiredArgsConstructor
55
@Validated
56
@Tag(name = "stake-key-lifecycle-report", description = "The stake key lifecycle report APIs")
57
public class StakeKeyReportController {
58
59
  private final StakeKeyReportService stakeKeyReportService;
60
  private final ReportHistoryService reportHistoryService;
61
62
  @PostMapping(value = "/stake-key")
63
  @LogMessage
64
  @Operation(summary = "Generate stake key report")
65
  public ResponseEntity<StakeKeyReportHistoryResponse> generateStakeKeyReport(
66
      @RequestAttribute("user") UserPrincipal userPrincipal,
67
      @RequestBody StakeKeyReportRequest stakeKeyReportRequest) {
68 1 1. generateStakeKeyReport : replaced return value with null for org/cardanofoundation/explorer/api/controller/StakeKeyReportController::generateStakeKeyReport → KILLED
    return ResponseEntity.ok()
69
        .body(stakeKeyReportService.generateStakeKeyReport(stakeKeyReportRequest, userPrincipal));
70
  }
71
72
  @GetMapping(value = "/stake-key/{reportId}/export")
73
  @LogMessage
74
  @Operation(summary = "Export stake key report by id")
75
  public ResponseEntity<Resource> exportStakeKeyReportByStorageKey(
76
      @RequestAttribute("user") UserPrincipal userPrincipal,
77
      @PathVariable @Parameter(description = "The identifier of report") Long reportId,
78
      @RequestParam(required = false) @Parameter(description = "Type for export")
79
          ExportType exportType) {
80
    StakeKeyReportResponse response =
81
        stakeKeyReportService.exportStakeKeyReport(
82
            reportId, userPrincipal.getUsername(), exportType);
83 1 1. exportStakeKeyReportByStorageKey : replaced return value with null for org/cardanofoundation/explorer/api/controller/StakeKeyReportController::exportStakeKeyReportByStorageKey → KILLED
    return ResponseEntity.ok()
84
        .contentLength(response.getByteArrayInputStream().available())
85
        .header(
86
            HttpHeaders.CONTENT_DISPOSITION,
87
            "attachment; filename=\"" + response.getFileName() + "\"")
88
        .contentType(MediaType.APPLICATION_OCTET_STREAM)
89
        .body(new InputStreamResource(response.getByteArrayInputStream()));
90
  }
91
92
  @GetMapping(value = "/stake-key/{stakeKey}/history")
93
  @LogMessage
94
  @Operation(summary = "Get stake key report history by stake key")
95
  public ResponseEntity<BaseFilterResponse<StakeKeyReportHistoryResponse>>
96
      getStakeReportHistoryByStakeKey(
97
          @RequestAttribute("user") UserPrincipal userPrincipal,
98
          @PathVariable
99
              @PrefixedValid(CommonConstant.PREFIXED_STAKE_KEY)
100
              @StakeKeyLengthValid
101
              @Parameter(description = "The Bech32 encoded version of the stake address.")
102
              String stakeKey,
103
          @ParameterObject @PaginationValid @Valid Pagination pagination) {
104 1 1. getStakeReportHistoryByStakeKey : replaced return value with null for org/cardanofoundation/explorer/api/controller/StakeKeyReportController::getStakeReportHistoryByStakeKey → KILLED
    return ResponseEntity.ok(
105
        stakeKeyReportService.getStakeKeyReportHistoryByStakeKey(
106
            stakeKey, userPrincipal.getUsername(), pagination.toPageable()));
107
  }
108
109
  @GetMapping(value = "/stake-key/{reportId}/detail")
110
  @LogMessage
111
  @Operation(summary = "Get stake key report detail by report id")
112
  public ResponseEntity<StakeKeyReportHistoryResponse> getStakeReportDetail(
113
      @RequestAttribute("user") UserPrincipal userPrincipal,
114
      @PathVariable @Parameter(description = "The identifier of report") Long reportId) {
115 1 1. getStakeReportDetail : replaced return value with null for org/cardanofoundation/explorer/api/controller/StakeKeyReportController::getStakeReportDetail → KILLED
    return ResponseEntity.ok(
116
        stakeKeyReportService.getStakeKeyReportHistoryByReportId(
117
            reportId, userPrincipal.getUsername()));
118
  }
119
120
  @GetMapping(value = "/stake-key/history")
121
  @LogMessage
122
  @Operation(summary = "Get all stake key report history")
123
  public ResponseEntity<BaseFilterResponse<StakeKeyReportHistoryResponse>> getStakeReportHistory(
124
      @RequestAttribute("user") UserPrincipal userPrincipal,
125
      @ParameterObject @Parameter(description = "filter condition")
126
          ReportHistoryFilterRequest filterRequest,
127
      @ParameterObject
128
          @PaginationValid
129
          @PaginationDefault(
130
              size = 20,
131
              sort = {"id"},
132
              direction = Sort.Direction.DESC)
133
          @Valid
134
          Pagination pagination) {
135 1 1. getStakeReportHistory : replaced return value with null for org/cardanofoundation/explorer/api/controller/StakeKeyReportController::getStakeReportHistory → KILLED
    return ResponseEntity.ok(
136
        stakeKeyReportService.getStakeKeyReportHistory(
137
            userPrincipal.getUsername(), filterRequest, pagination.toPageable()));
138
  }
139
140
  @GetMapping(value = "/dashboard")
141
  @LogMessage
142
  @Operation(summary = "Get report history of stake key and pool id")
143
  public ResponseEntity<BaseFilterResponse<ReportHistoryResponse>> getReportHistory(
144
      @RequestAttribute("user") UserPrincipal userPrincipal,
145
      @ParameterObject @Parameter(description = "filter condition")
146
          ReportHistoryFilterRequest filterRequest,
147
      @ParameterObject
148
          @PaginationValid
149
          @PaginationDefault(
150
              size = 20,
151
              sort = {"createdAt"},
152
              direction = Sort.Direction.DESC)
153
          @Valid
154
          Pagination pagination) {
155 1 1. getReportHistory : replaced return value with null for org/cardanofoundation/explorer/api/controller/StakeKeyReportController::getReportHistory → KILLED
    return ResponseEntity.ok(
156
        reportHistoryService.getReportHistory(
157
            filterRequest, userPrincipal.getUsername(), pagination.toPageable()));
158
  }
159
160
  @GetMapping(value = "/stake-key/{reportId}/registrations")
161
  @LogMessage
162
  @Operation(summary = "Get stake registrations by report id")
163
  public ResponseEntity<BaseFilterResponse<StakeRegistrationFilterResponse>>
164
      getStakeKeyRegistrationsByReportId(
165
          @RequestAttribute("user") UserPrincipal userPrincipal,
166
          @PathVariable @Parameter(description = "The identifier of report") Long reportId,
167
          @ParameterObject
168
              @PaginationValid
169
              @PaginationDefault(
170
                  size = 20,
171
                  sort = {"time"},
172
                  direction = Sort.Direction.DESC)
173
              @Valid
174
              Pagination pagination) {
175 1 1. getStakeKeyRegistrationsByReportId : replaced return value with null for org/cardanofoundation/explorer/api/controller/StakeKeyReportController::getStakeKeyRegistrationsByReportId → KILLED
    return ResponseEntity.ok(
176
        stakeKeyReportService.getStakeRegistrationsByReportId(
177
            reportId, userPrincipal.getUsername(), pagination.toPageable()));
178
  }
179
180
  @GetMapping(value = "/stake-key/{reportId}/de-registrations")
181
  @LogMessage
182
  @Operation(summary = "Get stake deregistrations by report id")
183
  public ResponseEntity<BaseFilterResponse<StakeRegistrationFilterResponse>>
184
      getStakeKeyDeregistrationsByReportId(
185
          @RequestAttribute("user") UserPrincipal userPrincipal,
186
          @PathVariable @Parameter(description = "The identifier of report") Long reportId,
187
          @ParameterObject
188
              @PaginationValid
189
              @PaginationDefault(
190
                  size = 20,
191
                  sort = {"time"},
192
                  direction = Sort.Direction.DESC)
193
              @Valid
194
              Pagination pagination) {
195 1 1. getStakeKeyDeregistrationsByReportId : replaced return value with null for org/cardanofoundation/explorer/api/controller/StakeKeyReportController::getStakeKeyDeregistrationsByReportId → KILLED
    return ResponseEntity.ok(
196
        stakeKeyReportService.getStakeDeRegistrationsByReportId(
197
            reportId, userPrincipal.getUsername(), pagination.toPageable()));
198
  }
199
200
  @GetMapping(value = "/stake-key/{reportId}/delegations")
201
  @LogMessage
202
  @Operation(summary = "Get stake delegations by report id")
203
  public ResponseEntity<BaseFilterResponse<StakeDelegationFilterResponse>>
204
      getStakeKeyDelegationsByReportId(
205
          @RequestAttribute("user") UserPrincipal userPrincipal,
206
          @PathVariable @Parameter(description = "The identifier of report") Long reportId,
207
          @ParameterObject
208
              @PaginationValid
209
              @PaginationDefault(
210
                  size = 20,
211
                  sort = {"time"},
212
                  direction = Sort.Direction.DESC)
213
              @Valid
214
              Pagination pagination) {
215 1 1. getStakeKeyDelegationsByReportId : replaced return value with null for org/cardanofoundation/explorer/api/controller/StakeKeyReportController::getStakeKeyDelegationsByReportId → KILLED
    return ResponseEntity.ok(
216
        stakeKeyReportService.getStakeDelegationsByReportId(
217
            reportId, userPrincipal.getUsername(), pagination.toPageable()));
218
  }
219
220
  @GetMapping(value = "/stake-key/{reportId}/rewards")
221
  @LogMessage
222
  @Operation(summary = "Get stake rewards by report id")
223
  public ResponseEntity<BaseFilterResponse<StakeRewardResponse>> getStakeKeyRewardsByReportId(
224
      @RequestAttribute("user") UserPrincipal userPrincipal,
225
      @PathVariable @Parameter(description = "The identifier of report") Long reportId,
226
      @ParameterObject
227
          @PaginationValid
228
          @PaginationDefault(
229
              size = 20,
230
              sort = {"id"},
231
              direction = Sort.Direction.DESC)
232
          @Valid
233
          Pagination pagination) {
234 1 1. getStakeKeyRewardsByReportId : replaced return value with null for org/cardanofoundation/explorer/api/controller/StakeKeyReportController::getStakeKeyRewardsByReportId → KILLED
    return ResponseEntity.ok(
235
        stakeKeyReportService.getStakeRewardsByReportId(
236
            reportId, userPrincipal.getUsername(), pagination.toPageable()));
237
  }
238
239
  @GetMapping(value = "/stake-key/{reportId}/withdrawals")
240
  @LogMessage
241
  @Operation(summary = "Get stake withdrawals by report id")
242
  public ResponseEntity<BaseFilterResponse<StakeWithdrawalFilterResponse>>
243
      getStakeKeyWithdrawalsByReportId(
244
          @RequestAttribute("user") UserPrincipal userPrincipal,
245
          @PathVariable @Parameter(description = "The identifier of report") Long reportId,
246
          @ParameterObject
247
              @PaginationValid
248
              @PaginationDefault(
249
                  size = 20,
250
                  sort = {"time"},
251
                  direction = Sort.Direction.DESC)
252
              @Valid
253
              Pagination pagination) {
254 1 1. getStakeKeyWithdrawalsByReportId : replaced return value with null for org/cardanofoundation/explorer/api/controller/StakeKeyReportController::getStakeKeyWithdrawalsByReportId → KILLED
    return ResponseEntity.ok(
255
        stakeKeyReportService.getStakeWithdrawalsByReportId(
256
            reportId, userPrincipal.getUsername(), pagination.toPageable()));
257
  }
258
259
  @GetMapping(value = "/stake-key/{reportId}/wallet-activity")
260
  @LogMessage
261
  @Operation(summary = "Get wallet activity by report id")
262
  public ResponseEntity<BaseFilterResponse<StakeWalletActivityResponse>>
263
      getWalletActivityByReportId(
264
          @RequestAttribute("user") UserPrincipal userPrincipal,
265
          @PathVariable @Parameter(description = "The identifier of report") Long reportId,
266
          @ParameterObject
267
              @PaginationValid
268
              @PaginationDefault(
269
                  size = 20,
270
                  sort = {"time"},
271
                  direction = Sort.Direction.DESC)
272
              @Valid
273
              Pagination pagination) {
274 1 1. getWalletActivityByReportId : replaced return value with null for org/cardanofoundation/explorer/api/controller/StakeKeyReportController::getWalletActivityByReportId → KILLED
    return ResponseEntity.ok(
275
        stakeKeyReportService.getWalletActivitiesByReportId(
276
            reportId, userPrincipal.getUsername(), pagination.toPageable()));
277
  }
278
279
  @GetMapping(value = "/report-limit")
280
  @LogMessage
281
  @Operation(summary = "Get report limit information")
282
  public ResponseEntity<ReportLimitResponse> getReportLimit(
283
      @RequestAttribute("user") UserPrincipal userPrincipal) {
284 1 1. getReportLimit : replaced return value with null for org/cardanofoundation/explorer/api/controller/StakeKeyReportController::getReportLimit → KILLED
    return ResponseEntity.ok(reportHistoryService.getReportLimit(userPrincipal));
285
  }
286
}

Mutations

68

1.1
Location : generateStakeKeyReport
Killed by : org.cardanofoundation.explorer.api.controller.StakeKeyReportControllerTest.[engine:junit-jupiter]/[class:org.cardanofoundation.explorer.api.controller.StakeKeyReportControllerTest]/[method:shouldGenerateStakeKeyReport()]
replaced return value with null for org/cardanofoundation/explorer/api/controller/StakeKeyReportController::generateStakeKeyReport → KILLED

83

1.1
Location : exportStakeKeyReportByStorageKey
Killed by : org.cardanofoundation.explorer.api.controller.StakeKeyReportControllerTest.[engine:junit-jupiter]/[class:org.cardanofoundation.explorer.api.controller.StakeKeyReportControllerTest]/[method:shouldExportStakeKeyReportByStorageKey()]
replaced return value with null for org/cardanofoundation/explorer/api/controller/StakeKeyReportController::exportStakeKeyReportByStorageKey → KILLED

104

1.1
Location : getStakeReportHistoryByStakeKey
Killed by : org.cardanofoundation.explorer.api.controller.StakeKeyReportControllerTest.[engine:junit-jupiter]/[class:org.cardanofoundation.explorer.api.controller.StakeKeyReportControllerTest]/[method:shouldGetStakeKeyReportHistoriesByStakeKey()]
replaced return value with null for org/cardanofoundation/explorer/api/controller/StakeKeyReportController::getStakeReportHistoryByStakeKey → KILLED

115

1.1
Location : getStakeReportDetail
Killed by : org.cardanofoundation.explorer.api.controller.StakeKeyReportControllerTest.[engine:junit-jupiter]/[class:org.cardanofoundation.explorer.api.controller.StakeKeyReportControllerTest]/[method:shouldGetStakeKeyReportDetail()]
replaced return value with null for org/cardanofoundation/explorer/api/controller/StakeKeyReportController::getStakeReportDetail → KILLED

135

1.1
Location : getStakeReportHistory
Killed by : org.cardanofoundation.explorer.api.controller.StakeKeyReportControllerTest.[engine:junit-jupiter]/[class:org.cardanofoundation.explorer.api.controller.StakeKeyReportControllerTest]/[method:shouldGetAllStakeKeyReportHistories()]
replaced return value with null for org/cardanofoundation/explorer/api/controller/StakeKeyReportController::getStakeReportHistory → KILLED

155

1.1
Location : getReportHistory
Killed by : org.cardanofoundation.explorer.api.controller.StakeKeyReportControllerTest.[engine:junit-jupiter]/[class:org.cardanofoundation.explorer.api.controller.StakeKeyReportControllerTest]/[method:shouldGetReportHistoryDashBoard()]
replaced return value with null for org/cardanofoundation/explorer/api/controller/StakeKeyReportController::getReportHistory → KILLED

175

1.1
Location : getStakeKeyRegistrationsByReportId
Killed by : org.cardanofoundation.explorer.api.controller.StakeKeyReportControllerTest.[engine:junit-jupiter]/[class:org.cardanofoundation.explorer.api.controller.StakeKeyReportControllerTest]/[method:shouldGetRegistrations()]
replaced return value with null for org/cardanofoundation/explorer/api/controller/StakeKeyReportController::getStakeKeyRegistrationsByReportId → KILLED

195

1.1
Location : getStakeKeyDeregistrationsByReportId
Killed by : org.cardanofoundation.explorer.api.controller.StakeKeyReportControllerTest.[engine:junit-jupiter]/[class:org.cardanofoundation.explorer.api.controller.StakeKeyReportControllerTest]/[method:shouldGetDeRegistrations()]
replaced return value with null for org/cardanofoundation/explorer/api/controller/StakeKeyReportController::getStakeKeyDeregistrationsByReportId → KILLED

215

1.1
Location : getStakeKeyDelegationsByReportId
Killed by : org.cardanofoundation.explorer.api.controller.StakeKeyReportControllerTest.[engine:junit-jupiter]/[class:org.cardanofoundation.explorer.api.controller.StakeKeyReportControllerTest]/[method:shouldGetDelegations()]
replaced return value with null for org/cardanofoundation/explorer/api/controller/StakeKeyReportController::getStakeKeyDelegationsByReportId → KILLED

234

1.1
Location : getStakeKeyRewardsByReportId
Killed by : org.cardanofoundation.explorer.api.controller.StakeKeyReportControllerTest.[engine:junit-jupiter]/[class:org.cardanofoundation.explorer.api.controller.StakeKeyReportControllerTest]/[method:shouldGetRewards()]
replaced return value with null for org/cardanofoundation/explorer/api/controller/StakeKeyReportController::getStakeKeyRewardsByReportId → KILLED

254

1.1
Location : getStakeKeyWithdrawalsByReportId
Killed by : org.cardanofoundation.explorer.api.controller.StakeKeyReportControllerTest.[engine:junit-jupiter]/[class:org.cardanofoundation.explorer.api.controller.StakeKeyReportControllerTest]/[method:shouldGetWithdrawals()]
replaced return value with null for org/cardanofoundation/explorer/api/controller/StakeKeyReportController::getStakeKeyWithdrawalsByReportId → KILLED

274

1.1
Location : getWalletActivityByReportId
Killed by : org.cardanofoundation.explorer.api.controller.StakeKeyReportControllerTest.[engine:junit-jupiter]/[class:org.cardanofoundation.explorer.api.controller.StakeKeyReportControllerTest]/[method:shouldGetWalletActivity()]
replaced return value with null for org/cardanofoundation/explorer/api/controller/StakeKeyReportController::getWalletActivityByReportId → KILLED

284

1.1
Location : getReportLimit
Killed by : org.cardanofoundation.explorer.api.controller.StakeKeyReportControllerTest.[engine:junit-jupiter]/[class:org.cardanofoundation.explorer.api.controller.StakeKeyReportControllerTest]/[method:testGetReportLimit()]
replaced return value with null for org/cardanofoundation/explorer/api/controller/StakeKeyReportController::getReportLimit → KILLED

Active mutators

Tests examined


Report generated by PIT 1.14.2