mirror of
https://github.com/usatiuk/y.git
synced 2025-10-28 10:37:47 +01:00
rename personsignupto
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
package com.usatiuk.tjv.y.server.controller;
|
||||
|
||||
import com.usatiuk.tjv.y.server.dto.PersonSignupTo;
|
||||
import com.usatiuk.tjv.y.server.dto.PersonCreateTo;
|
||||
import com.usatiuk.tjv.y.server.dto.PersonTo;
|
||||
import com.usatiuk.tjv.y.server.dto.converters.PersonMapper;
|
||||
import com.usatiuk.tjv.y.server.entity.Chat;
|
||||
@@ -38,7 +38,7 @@ public class PersonController {
|
||||
}
|
||||
|
||||
@PostMapping
|
||||
public PersonTo signup(@RequestBody PersonSignupTo signupRequest) throws UserAlreadyExistsException {
|
||||
public PersonTo signup(@RequestBody PersonCreateTo signupRequest) throws UserAlreadyExistsException {
|
||||
Person toCreate = new Person();
|
||||
toCreate.setUsername(signupRequest.username())
|
||||
.setPassword(signupRequest.password())
|
||||
@@ -78,11 +78,11 @@ public class PersonController {
|
||||
}
|
||||
|
||||
@PatchMapping(path = "/self")
|
||||
public PersonTo update(Authentication authentication, @RequestBody PersonSignupTo personSignupTo) {
|
||||
public PersonTo update(Authentication authentication, @RequestBody PersonCreateTo personCreateTo) {
|
||||
var person = personService.readById(authentication.getName()).orElseThrow(() -> new ResponseStatusException(HttpStatus.NOT_FOUND));
|
||||
person.setUsername(personSignupTo.username())
|
||||
.setFullName(personSignupTo.fullName());
|
||||
if (!personSignupTo.password().isEmpty()) person.setPassword(passwordEncoder.encode(personSignupTo.password()));
|
||||
person.setUsername(personCreateTo.username())
|
||||
.setFullName(personCreateTo.fullName());
|
||||
if (!personCreateTo.password().isEmpty()) person.setPassword(passwordEncoder.encode(personCreateTo.password()));
|
||||
personService.update(person);
|
||||
return personMapper.makeDto(person);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
package com.usatiuk.tjv.y.server.dto;
|
||||
|
||||
public record PersonCreateTo(String username, String fullName, String password) {
|
||||
}
|
||||
@@ -1,4 +0,0 @@
|
||||
package com.usatiuk.tjv.y.server.dto;
|
||||
|
||||
public record PersonSignupTo(String username, String fullName, String password) {
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.usatiuk.tjv.y.server.controller;
|
||||
|
||||
import com.usatiuk.tjv.y.server.dto.PersonSignupTo;
|
||||
import com.usatiuk.tjv.y.server.dto.PersonCreateTo;
|
||||
import com.usatiuk.tjv.y.server.dto.PersonTo;
|
||||
import com.usatiuk.tjv.y.server.dto.converters.PersonMapper;
|
||||
import com.usatiuk.tjv.y.server.repository.PersonRepository;
|
||||
@@ -24,7 +24,7 @@ public class PersonControllerTest extends DemoDataDbTest {
|
||||
@Test
|
||||
void shouldSignUp() {
|
||||
var response = restTemplate.exchange(addr + "/person", HttpMethod.POST,
|
||||
new HttpEntity<>(new PersonSignupTo("usernew", "full name", "pass")),
|
||||
new HttpEntity<>(new PersonCreateTo("usernew", "full name", "pass")),
|
||||
PersonTo.class);
|
||||
|
||||
Assertions.assertNotNull(response);
|
||||
|
||||
Reference in New Issue
Block a user