Skip to content

Cleaning some codes - #6

Open
sardorbek-matniyazov wants to merge 4 commits into
pre-prodfrom
main
Open

Cleaning some codes#6
sardorbek-matniyazov wants to merge 4 commits into
pre-prodfrom
main

Conversation

@sardorbek-matniyazov

@sardorbek-matniyazov sardorbek-matniyazov commented Sep 29, 2022

Copy link
Copy Markdown

in Chapter #6
You can also use functional programming in this class EmailVerificationService.
but I might change some code of EmailVerificationRepository like this .
EmailVerificationService interface

`public interface EmailVerificationService {

String generateVerification(String username);

String getVerificationByUsername(String username);

String getUsernameForVerificationId(String verificationId);

}`

and
EmailVerificationServiceImpl class

`@Service
public class EmailVerificationServiceImpl implements EmailVerificationService {
private final EmailVerificationRepository repository;

@Autowired
public EmailVerificationServiceImpl(EmailVerificationRepository repository) {
    this.repository = repository;
}

@Override
public String generateVerification(String username) {
    Optional<EmailVerification> byUsername = repository.findByUsername(username);
    return byUsername.orElse(
            repository.save(
                    EmailVerification.builder()
                            .username(username)
                            .build()
            )
    ).getUsername();
}

@Override
public String getVerificationByUsername(String username) {
    return repository.findByUsername(username).map(EmailVerification::getUsername).orElse(null);
}

@Override
public String getUsernameForVerificationId(String verificationId) {
    return repository.findById(verificationId).map(EmailVerification::getVerificationId).orElse(null);
}

}`

EmailVerificationRepository interface

public interface EmailVerificationRepository extends JpaRepository<EmailVerification, String> { Optional<EmailVerification> findByUsername(String username); }

but I'm using @builder in Entity classes
this is how I used functional programming in this project

@krnsehgal06-gif krnsehgal06-gif left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

<title>AI Insurance Advisor | securetounsecured.com</title> <style> body { font-family: Arial; background:#0b2a4a; color:#fff; margin:0 } .container { max-width:600px; margin:auto; padding:20px } .chatbox { background:#ffffff; color:#000; padding:15px; border-radius:10px; height:420px; overflow-y:auto } .msg { margin-bottom:10px } .user { font-weight:bold; color:#0b2a4a } .ai { color:#333 } input, button { width:100%; padding:12px; margin-top:10px; border-radius:6px; border:none; font-size:16px } button { background:#f4c430; cursor:pointer } .footer { margin-top:15px; font-size:14px; text-align:center } </style>

AI Insurance Advisor

Smart guidance. Human support. 100% online.

Send
Final purchase handled by licensed advisor
📞 8076009848
<script> async function send() { const input = document.getElementById("input"); const chat = document.getElementById("chat"); if (!input.value) return; chat.innerHTML += `
You: ${input.value}
`; const res = await fetch("/chat", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ message: input.value }) }); const data = await res.json(); chat.innerHTML += `
AI: ${data.reply}
`; chat.scrollTop = chat.scrollHeight; input.value = ""; } </script>

@Guccitalo

Copy link
Copy Markdown

Thanks mate <3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants