rename personsignupto

This commit is contained in:
Stepan Usatiuk
2023-12-29 14:58:09 +01:00
parent b79c1dd1ad
commit 32a7d2bd32
4 changed files with 12 additions and 12 deletions

View File

@@ -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);
}

View File

@@ -0,0 +1,4 @@
package com.usatiuk.tjv.y.server.dto;
public record PersonCreateTo(String username, String fullName, String password) {
}

View File

@@ -1,4 +0,0 @@
package com.usatiuk.tjv.y.server.dto;
public record PersonSignupTo(String username, String fullName, String password) {
}

View File

@@ -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);