|
2 | 2 |
|
3 | 3 | import com.pecacm.backend.constants.Constants; |
4 | 4 | import com.pecacm.backend.entities.Transaction; |
5 | | -import com.pecacm.backend.entities.Event; |
6 | 5 | import com.pecacm.backend.entities.User; |
7 | 6 | import com.pecacm.backend.entities.VerificationToken; |
8 | 7 | import com.pecacm.backend.enums.EventRole; |
|
13 | 12 | import com.pecacm.backend.response.RegisterResponse; |
14 | 13 | import com.pecacm.backend.response.UserEventDetails; |
15 | 14 | import com.pecacm.backend.services.EmailService; |
16 | | -import com.pecacm.backend.services.VerificationService; |
17 | 15 | import com.pecacm.backend.services.JwtService; |
18 | 16 | import com.pecacm.backend.services.UserService; |
19 | | -import org.springframework.data.domain.Page; |
| 17 | +import com.pecacm.backend.services.VerificationService; |
20 | 18 | import org.springframework.http.HttpStatus; |
21 | 19 | import org.springframework.http.ResponseEntity; |
22 | 20 | import org.springframework.lang.NonNull; |
@@ -192,8 +190,25 @@ public ResponseEntity<List<UserEventDetails>> getEventsForUser(@RequestParam @Nu |
192 | 190 |
|
193 | 191 | } |
194 | 192 |
|
| 193 | + @GetMapping("/{email}/events") |
| 194 | + @PreAuthorize(Constants.HAS_ROLE_CORE_AND_ABOVE) |
| 195 | + public ResponseEntity<List<UserEventDetails>> getEventsForUserEmail(@PathVariable String email, @RequestParam @Nullable EventRole eventRole, @RequestParam @Nullable Integer pageSize, @RequestParam @Nullable Integer offset) { |
| 196 | + if (offset == null) offset = 0; |
| 197 | + if (pageSize == null) pageSize = 20; // returning first 20 users |
| 198 | + |
| 199 | + if (offset < 0) throw new AcmException("offset cannot be < 0", HttpStatus.BAD_REQUEST); |
| 200 | + if (pageSize <= 0) throw new AcmException("pageSize must be >= 0", HttpStatus.BAD_REQUEST); |
| 201 | + |
| 202 | + if (eventRole != null) { |
| 203 | + return ResponseEntity.ok(userService.getEventsForUserWithRole(email, eventRole, pageSize, offset)); |
| 204 | + } |
| 205 | + |
| 206 | + return ResponseEntity.ok(userService.getEventsForUser(email, pageSize, offset)); |
| 207 | + |
| 208 | + } |
| 209 | + |
195 | 210 | @GetMapping("/search") |
196 | | - public List<User> getFilteredUsers(@RequestParam String query, @RequestParam(required = false,defaultValue = "false") Boolean onlyVerified){ |
197 | | - return userService.getFilteredUserList(query,onlyVerified); |
| 211 | + public List<User> getFilteredUsers(@RequestParam String query, @RequestParam(required = false, defaultValue = "false") Boolean onlyVerified) { |
| 212 | + return userService.getFilteredUserList(query, onlyVerified); |
198 | 213 | } |
199 | 214 | } |
0 commit comments