easytests.core.mappers.UsersMapper
last analyzed

Complexity

Total Complexity 0

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
c 1
b 0
f 0
loc 35
wmc 0
1
package easytests.core.mappers;
2
3
import easytests.core.entities.UserEntity;
4
import java.util.List;
5
import org.apache.ibatis.annotations.*;
6
7
8
/**
9
 * @author malinink
10
 */
11
@Mapper
12
@SuppressWarnings("checkstyle:linelength")
13
public interface UsersMapper {
14
    @Results(
15
        id = "User",
16
        value = {
17
            @Result(property = "id", column = "id"),
18
            @Result(property = "firstName", column = "first_name"),
19
            @Result(property = "lastName", column = "last_name"),
20
            @Result(property = "surname", column = "surname"),
21
            @Result(property = "email", column = "email"),
22
            @Result(property = "password", column = "password"),
23
            @Result(property = "isAdmin", column = "is_admin"),
24
            @Result(property = "state", column = "state")
25
        })
26
    @Select("SELECT * FROM users")
27
    List<UserEntity> findAll();
28
29
    @Select("SELECT * FROM users where id=#{id}")
30
    @ResultMap("User")
31
    UserEntity find(Integer id);
32
33
    @Select("SELECT * FROM users where email=#{email}")
34
    @ResultMap("User")
35
    UserEntity findByEmail(String email);
36
37
    @Insert("INSERT INTO users (first_name, last_name, surname, email, password, is_admin, state) VALUES(#{firstName}, #{lastName}, #{surname}, #{email}, #{password}, #{isAdmin}, #{state})")
38
    @Options(useGeneratedKeys = true, keyColumn = "id")
39
    void insert(UserEntity user);
40
41
    @Update("UPDATE users SET first_name=#{firstName}, last_name=#{lastName}, surname=#{surname}, email=#{email}, password=#{password}, is_admin=#{isAdmin}, state=#{state} WHERE id=#{id}")
0 ignored issues
show
Security introduced by
Hard-coding user names and passwords is a very insecure and inefficient practice. Consider reading the credentials from an outside file or other source, which you may not want to put in your source code repository.
Loading history...
42
    void update(UserEntity user);
43
44
    @Delete("DELETE FROM users WHERE id=#{id}")
45
    void delete(UserEntity user);
46
}
47