Projekt

Obecné

Profil

« Předchozí | Další » 

Revize f7aa763d

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

Added endpoint for user creation

Zobrazit rozdíly:

Backend/Backend/Controllers/UserController.cs
76 76

  
77 77
        [HttpPut("/user/{userId}")]
78 78
        [Authorize(Models.Enums.ERole.ADMINISTRATOR)]
79
        [ProducesResponseType((int)HttpStatusCode.OK, Type = typeof(AnnotationListResponse))]
79
        [ProducesResponseType((int)HttpStatusCode.OK)]
80 80
        [ProducesResponseType((int)HttpStatusCode.Forbidden)]
81
        public ActionResult<AnnotationListResponse> ChangeUserInfo(Guid userId, [FromBody] ChangeUserInfoRequest request)
81
        public ActionResult ChangeUserInfo(Guid userId, [FromBody] ChangeUserInfoRequest request)
82 82
        {
83 83
            try
84 84
            {
......
102 102

  
103 103
            return Ok();
104 104
        }
105

  
106
        [HttpPost("/users")]
107
        [Authorize(Models.Enums.ERole.ADMINISTRATOR)]
108
        [ProducesResponseType((int)HttpStatusCode.OK)]
109
        [ProducesResponseType((int)HttpStatusCode.Forbidden)]
110
        public ActionResult CreateUser([FromBody] CreateUserRequest request)
111
        {
112
            if (userService.CreateUser(request.Username, request.Name, request.Surname, request.Password, request.Role) == null)
113
            {
114
                throw new BadRequestException("Username already used");
115
            }
116
            return Ok();
117
        }
105 118
    }
106 119
}
Backend/Models/Users/CreateUserRequest.cs
1
using Models.Enums;
2
using System;
3
using System.Collections.Generic;
4
using System.Linq;
5
using System.Text;
6
using System.Threading.Tasks;
7

  
8
namespace Models.Users
9
{
10
    public class CreateUserRequest
11
    {
12
        public string Username { get; set; }
13
        public string Password { get; set; }
14
        public string Name { get; set; }
15
        public string Surname { get; set; }
16
        public ERole Role { get; set; }
17
    }
18
}

Také k dispozici: Unified diff