Skip to content

Commit f1d9e57

Browse files
Add getSubscriptions optinal parameters.
1 parent 5d64a86 commit f1d9e57

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

src/main/java/com/kodluyoruz/subscription/controllers/SubscriptionController.java

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,23 @@
44
import org.springframework.web.bind.annotation.*;
55

66
import java.net.URI;
7+
import java.util.Objects;
78

89
@RestController
910
@RequestMapping("/subscriptions")
1011
public class SubscriptionController {
1112

1213
@GetMapping
13-
public ResponseEntity getSubscriptions(){
14-
return ResponseEntity.ok().build();
14+
public ResponseEntity getSubscriptions(@RequestParam(required = false) String userId, @RequestParam(required = false) String paymentId) {
15+
if (Objects.nonNull(userId) && Objects.nonNull(paymentId)) {
16+
return ResponseEntity.ok(String.format("user id -> %s -- payment id -> %s", userId, paymentId));
17+
} else if (Objects.nonNull(userId)) {
18+
return ResponseEntity.ok(String.format("user id -> %s", userId));
19+
} else if (Objects.nonNull(paymentId)) {
20+
return ResponseEntity.ok(String.format("payment id -> %s", paymentId));
21+
} else {
22+
return ResponseEntity.ok("All Subscription");
23+
}
1524
}
1625

1726
@PostMapping
@@ -21,7 +30,7 @@ public ResponseEntity createSubscription() {
2130
}
2231

2332
@PatchMapping
24-
public ResponseEntity changeSunscription() {
33+
public ResponseEntity changeSubscription() {
2534
return ResponseEntity.noContent().build();
2635
}
2736

@@ -36,7 +45,4 @@ public ResponseEntity deleteSubscription(@PathVariable String id) {
3645
}
3746

3847

39-
40-
41-
4248
}

0 commit comments

Comments
 (0)