Skip to content

Commit

Permalink
feat: adding validations in local creation method
Browse files Browse the repository at this point in the history
  • Loading branch information
PedroVidalDev committed Apr 22, 2024
1 parent 8cd2710 commit 7e2a7dc
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/main/java/com/pedro/sphynx/domain/LocalService.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.pedro.sphynx.application.dtos.local.LocalDataEditInput;
import com.pedro.sphynx.application.dtos.local.LocalDataInput;
import com.pedro.sphynx.infrastructure.entities.Local;
import com.pedro.sphynx.infrastructure.exceptions.Validation;
import com.pedro.sphynx.infrastructure.repository.LocalRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
Expand All @@ -30,14 +31,21 @@ else if(language.equals("en-US")){
public LocalDataComplete createVerify(LocalDataInput data, String language){
defineMessagesLanguage(language);

if(!repository.existsByName(data.name()) || !repository.existsByMac(data.mac())){
if(repository.existsByName(data.name())){
throw new Validation(messages.getString("error.localAlreadyExists"));
}

if(repository.existsByMac(data.mac())){
throw new Validation(messages.getString("error.macAlreadyExists"));
}

else{
Local local = new Local(data);

repository.save(local);

return new LocalDataComplete(local);
}
return null;
}

public LocalDataComplete updateVerify(LocalDataEditInput data, String name, String language) {
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/messagesEn.properties
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ error.raDontExistsInPerson=Informed RA dont exists in the persons database.
error.tagDontExists=Informed TAG dont exists in database.

error.localDontExists=Informed local dont exists in database.
error.localAlreadyExists=Informed local name already exists in database.
error.macAlreadyExists=Informed MAC Address already exists in database.

success.201=Created.
success.200=Operation realized.
2 changes: 2 additions & 0 deletions src/main/resources/messagesPt.properties
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ error.raDontExistsInPerson=RA informado nao existe na tabela de doscentes.
error.tagDontExists=TAG informada nao existe no banco.

error.localDontExists=Local informado nao existe no banco.
error.localAlreadyExists=Nome do local informado ja existe no banco de dados.
error.macAlreadyExists=MAC informado ja existe no banco de dados de locais.

success.201=Criado.
success.200=Operacao realizada.

0 comments on commit 7e2a7dc

Please sign in to comment.