Projekt

Obecné

Profil

« Předchozí | Další » 

Revize f37d2b59

Přidáno uživatelem Vojtěch Bartička před asi 2 roky(ů)

Added endpoint for user delete

Zobrazit rozdíly:

Backend/Backend/Controllers/UserController.cs
115 115
            }
116 116
            return Ok();
117 117
        }
118

  
119
        [HttpDelete("/user/{userId}")]
120
        [Authorize(Models.Enums.ERole.ADMINISTRATOR)]
121
        [ProducesResponseType((int)HttpStatusCode.OK)]
122
        [ProducesResponseType((int)HttpStatusCode.Forbidden)]
123
        public ActionResult DeleteUser(Guid userId)
124
        {
125
            try
126
            {
127
                userService.DeleteUser(userId);
128
            }
129
            catch (InvalidOperationException e)
130
            {
131
                throw new BadRequestException(e.Message);
132
            }
133

  
134
            return Ok();
135
        }
118 136
    }
119 137
}
Backend/Core/Services/UserService/IUserService.cs
20 20
        public User? ChangePassword(Guid userId, string newPassword);
21 21
        public User? CheckUsernamePassword(string username, string password);
22 22
        public UserList GetUsers();
23
        public void DeleteUser(Guid userId);
23 24
    }
24 25
}
Backend/Core/Services/UserService/UserServiceEF.cs
172 172
        {
173 173
            Users = _databaseContext.Users.Select(u => _mapper.Map<UserInfo>(u)).ToList()
174 174
        };
175

  
176
        public void DeleteUser(Guid userId)
177
        {
178
            try
179
            {
180
                var user = _databaseContext.Users.Where(u => u.Id == userId).First();
181
                _databaseContext.Users.Remove(user);
182
            }
183
            catch (Exception)
184
            {
185
                throw new InvalidOperationException("User not found");
186
            }
187
        }
175 188
    }
176 189
}
177 190

  

Také k dispozici: Unified diff