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

torresj / community-api / 2

23 May 2025 01:56PM UTC coverage: 22.105%. First build
2

push

circleci

Jaime Torres Benavente
Project ready to be deployed

42 of 173 new or added lines in 18 files covered. (24.28%)

42 of 190 relevant lines covered (22.11%)

0.22 hits per line

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

60.0
/src/main/java/com/torresj/community/services/impl/UserServiceImpl.java
1
package com.torresj.community.services.impl;
2

3
import com.torresj.community.dtos.CommunityDto;
4
import com.torresj.community.dtos.UserDto;
5
import com.torresj.community.entities.UserEntity;
6
import com.torresj.community.enums.UserRole;
7
import com.torresj.community.exceptions.CommunityNotFoundException;
8
import com.torresj.community.exceptions.UserNotFoundException;
9
import com.torresj.community.mappers.UserMapper;
10
import com.torresj.community.repositories.UserRepository;
11
import com.torresj.community.services.CommunityService;
12
import com.torresj.community.services.UserService;
13
import lombok.RequiredArgsConstructor;
14
import lombok.extern.slf4j.Slf4j;
15
import org.springframework.stereotype.Service;
16

17
import java.util.ArrayList;
18
import java.util.List;
19

20
@Service
21
@RequiredArgsConstructor
22
@Slf4j
1✔
23
public class UserServiceImpl implements UserService {
24
    private final UserRepository repository;
25
    private final UserMapper userMapper;
26
    private final CommunityService communityService;
27

28
    @Override
29
    public UserDto create(Long communityId, String name, String password, UserRole role)
30
            throws CommunityNotFoundException {
31
        CommunityDto communityDto = null;
1✔
32
        if (communityId != null) {
1✔
33
            communityDto = communityService.get(communityId);
1✔
34
        }
35

36
        return userMapper.toUserDto(
1✔
37
                repository.save(
1✔
38
                        UserEntity.builder()
1✔
39
                                .communityId(communityId)
1✔
40
                                .role(role)
1✔
41
                                .name(name)
1✔
42
                                .password(password)
1✔
43
                                .build()),
1✔
44
                communityDto);
45
    }
46

47
    @Override
48
    public UserDto get(long userId) throws UserNotFoundException, CommunityNotFoundException {
49
        UserEntity userEntity =
1✔
50
                repository.findById(userId).orElseThrow(() -> new UserNotFoundException(userId));
1✔
51
        CommunityDto communityDto = communityService.get(userEntity.getCommunityId());
1✔
52
        return userMapper.toUserDto(userEntity, communityDto);
1✔
53
    }
54

55
    @Override
56
    public List<UserDto> get() throws CommunityNotFoundException {
57
        List<UserEntity> entities = repository.findAll();
1✔
58
        List<UserDto> users = new ArrayList<>();
1✔
59
        for (UserEntity entity : entities) {
1✔
60
            users.add(userMapper.toUserDto(entity, communityService.get(entity.getCommunityId())));
1✔
61
        }
1✔
62
        return users;
1✔
63
    }
64

65
    @Override
66
    public UserDto get(String name) throws UserNotFoundException, CommunityNotFoundException {
67
        UserEntity userEntity =
1✔
68
                repository.findByName(name).orElseThrow(() -> new UserNotFoundException(name));
1✔
69
        CommunityDto communityDto = communityService.get(userEntity.getCommunityId());
1✔
70
        return userMapper.toUserDto(userEntity, communityDto);
1✔
71
    }
72

73
    @Override
74
    public void update(long userId, String newPassword) throws UserNotFoundException {
75
        UserEntity userEntity =
1✔
76
                repository.findById(userId).orElseThrow(() -> new UserNotFoundException(userId));
1✔
NEW
77
        repository.save(
×
78
                userEntity
NEW
79
                        .toBuilder()
×
NEW
80
                        .id(userId)
×
NEW
81
                        .name(userEntity.getName())
×
NEW
82
                        .role(userEntity.getRole())
×
NEW
83
                        .communityId(userEntity.getCommunityId())
×
NEW
84
                        .password(newPassword)
×
NEW
85
                        .build()
×
86
        );
NEW
87
    }
×
88

89
    @Override
90
    public void update(long userId, UserRole newRole) throws UserNotFoundException {
91
        UserEntity userEntity =
1✔
92
                repository.findById(userId).orElseThrow(() -> new UserNotFoundException(userId));
1✔
NEW
93
        repository.save(
×
94
                userEntity
NEW
95
                        .toBuilder()
×
NEW
96
                        .id(userId)
×
NEW
97
                        .name(userEntity.getName())
×
NEW
98
                        .role(newRole)
×
NEW
99
                        .communityId(userEntity.getCommunityId())
×
NEW
100
                        .password(userEntity.getPassword())
×
NEW
101
                        .build()
×
102
        );
NEW
103
    }
×
104

105
    @Override
106
    public void delete(long userId) {
NEW
107
        repository.deleteById(userId);
×
NEW
108
    }
×
109
}
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