#Java Spring Boot dto

1 messages · Page 1 of 1 (latest)

chilly mirage
#

I did a dto class in Java Spring Boot but I am unsure whether I should use an int or a String to use as a phoneNumber field in the database, just want some advice on whether I should change my database schema

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@AllArgsConstructor
@NoArgsConstructor    
public class UserDataTransferObejct {
    
    private int userId;
    private String emailString;
    private String userNameString;
    private String passwordString;
    private int phoneNumber; // change to String?
    
}
faint spearBOT
#

<@&1004656351647117403> please have a look, thanks.

hot flame
#

the phone number you should use a String, as it can be parsed and regex to remove the chars you don't need. But some will look like

#

you can guide your users to use the format yu want, but in reality, users are not the smartest at times

chilly mirage
#

right now I have int8

verbal canyon
marsh harbor
#

Use String. You'll have more unnecessary issues with number format

verbal canyon
#

don't bother

#

seriously

#

a lot of database features (in sql databases) are from a time when you couldn't buy a gigabyte of hard disk space without the budget of a government

#

and for phone numbers - yeah a regex is useful, but its best to send them a text to confirm it as well

#

and lean towards a more permissive rather than restrictive regex

past hill
#

A phone number class might work for country code and number

verbal canyon
#

also also

#

for DTOs

#
record UserDataTransferObejct(
    int userId,
    String emailString,
    String userNameString,
    String passwordString,
    int phoneNumber
) { 
}
chilly mirage
#

ok should I change from classto record?

past hill
#

If you dont plan on changing the data later on then yes it should be a record

#

Its a DTO so double yes

chilly mirage
#

ooh but then I woldn't be able to use my other annotations xd

past hill
#

Oh don't use the other annotations

#

record is effectively data + finals without the implicit setters

chilly mirage
#

oh sure! So I don't need to worry about the Lombok and other constructors @AllArgsConstructorright?

past hill
#

Yep

chilly mirage
#

Thanks!