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