• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

torresj / community-api / 32

20 Jun 2025 01:35PM UTC coverage: 81.79% (-1.0%) from 82.813%
32

push

circleci

Jaime Torres Benavente
tests added and new endpoint /me added

1 of 5 new or added lines in 1 file covered. (20.0%)

265 of 324 relevant lines covered (81.79%)

0.82 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

69.23
/src/main/java/com/torresj/community/controllers/UserController.java
1
package com.torresj.community.controllers;
2

3
import com.torresj.community.dtos.UserDto;
4
import com.torresj.community.exceptions.CommunityNotFoundException;
5
import com.torresj.community.exceptions.UserNotFoundException;
6
import com.torresj.community.services.UserService;
7
import io.swagger.v3.oas.annotations.Operation;
8
import io.swagger.v3.oas.annotations.Parameter;
9
import io.swagger.v3.oas.annotations.media.ArraySchema;
10
import io.swagger.v3.oas.annotations.media.Content;
11
import io.swagger.v3.oas.annotations.media.Schema;
12
import io.swagger.v3.oas.annotations.responses.ApiResponse;
13
import io.swagger.v3.oas.annotations.responses.ApiResponses;
14
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
15
import lombok.RequiredArgsConstructor;
16
import lombok.extern.slf4j.Slf4j;
17
import org.springframework.http.ResponseEntity;
18
import org.springframework.security.access.prepost.PreAuthorize;
19
import org.springframework.web.bind.annotation.GetMapping;
20
import org.springframework.web.bind.annotation.PathVariable;
21
import org.springframework.web.bind.annotation.RequestMapping;
22
import org.springframework.web.bind.annotation.RestController;
23

24
import java.security.Principal;
25
import java.util.List;
26

27
@RestController
28
@RequestMapping("/v1/users")
29
@Slf4j
1✔
30
@RequiredArgsConstructor
31
public class UserController {
32

33
    private final UserService userService;
34

35
    @Operation(summary = "Get users")
36
    @ApiResponses(
37
            value = {
38
                    @ApiResponse(
39
                            responseCode = "200",
40
                            description = "Success",
41
                            content = {
42
                                    @Content(
43
                                            mediaType = "application/json",
44
                                            array = @ArraySchema(schema = @Schema(implementation = UserDto.class)))
45
                            }),
46
            })
47
    @GetMapping()
48
    @SecurityRequirement(name = "Bearer Authentication")
49
    @PreAuthorize("hasRole('SUPERADMIN')")
50
    public ResponseEntity<List<UserDto>> get(Principal principal) throws CommunityNotFoundException {
51
        log.info("Getting Users for user {}", principal.getName());
1✔
52
        List<UserDto> users = userService.get();
1✔
53
        log.info("Users found: {}", users.size());
1✔
54
        return ResponseEntity.ok(users);
1✔
55
    }
56

57
    @GetMapping("/{id}")
58
    @SecurityRequirement(name = "Bearer Authentication")
59
    @Operation(summary = "Get user by ID")
60
    @ApiResponses(
61
            value = {
62
                    @ApiResponse(
63
                            responseCode = "200",
64
                            description = "User found",
65
                            content = {
66
                                    @Content(
67
                                            mediaType = "application/json",
68
                                            schema = @Schema(implementation = UserDto.class))
69
                            }),
70
                    @ApiResponse(responseCode = "404", description = "Not found", content = @Content),
71
            })
72
    @PreAuthorize("hasRole('SUPERADMIN')")
73
    ResponseEntity<UserDto> getUserById(@Parameter(description = "User id") @PathVariable long id)
74
            throws UserNotFoundException, CommunityNotFoundException {
75
        log.info("Getting user by id {}", id);
1✔
76
        var user = userService.get(id);
1✔
77
        log.info("User found");
1✔
78
        return ResponseEntity.ok(user);
1✔
79
    }
80

81
    @GetMapping("/me")
82
    @SecurityRequirement(name = "Bearer Authentication")
83
    @Operation(summary = "Get user by ID")
84
    @ApiResponses(
85
            value = {
86
                    @ApiResponse(
87
                            responseCode = "200",
88
                            description = "User found",
89
                            content = {
90
                                    @Content(
91
                                            mediaType = "application/json",
92
                                            schema = @Schema(implementation = UserDto.class))
93
                            }),
94
                    @ApiResponse(responseCode = "404", description = "Not found", content = @Content),
95
            })
96
    @PreAuthorize("hasRole('SUPERADMIN')")
97
    ResponseEntity<UserDto> getUserLogged(Principal principal)
98
            throws UserNotFoundException, CommunityNotFoundException {
NEW
99
        log.info("Getting user by name {}", principal.getName());
×
NEW
100
        var user = userService.get(principal.getName());
×
NEW
101
        log.info("User found");
×
NEW
102
        return ResponseEntity.ok(user);
×
103
    }
104
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc