teleren/devto huggingface dataset:
Spring Boot REST Basics : How to validate your request body
Tags: springboot, beginners, webdev, restapi
Published: 2023-09-23 23:57:14

## Overview
In software development, it is important to do some validation for security purposes and also lessen the unexpected errors, but it takes a lot of hours just to implement specific validation methods. In this post, I will share the easiest way on how to validate your request body in Spring Boot. 

## Let's get started
### Add dependency
Add the spring boot starter validation to your project. You can do this by adding the code below to your `pom.xml`.
```
<dependency>			 
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-validation</artifactId>
</dependency>
```

### Update your controller
Let's say you have a login API that authenticates the user. All you need to do is add the `@Valid` annotation to your request body. For this example I added the `@Valid` annotation to my `userLoginRequestModel`. This signals Spring Boot to do some validation of the model.

```
@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    IUserService userService;

    @PostMapping("/login")
    public UserLoginResponseModel login(@Valid @RequestBody UserLoginRequestModel userLoginRequestModel) {
        return userService.login(userLoginRequestModel);
    }
}
```

### Update your model
In your model, all you need to add is the specific validation annotation that we want to implement. For this example, I used the `@NotEmpty` annotation to make sure the username and password is required. I also added the message parameter.

```
public class UserLoginRequestModel {
    @NotEmpty(message = "Username is required.")
    private String username;

    @NotEmpty(message = "Password is required.")
    private String password;

    //...
}

```

There are a lot of validations you can use, such as `@Min` and `@Max`, make sure to check the documentation.

### Update your exception handler
To display the validation results, It is better to handle the error in your exception handler method. 

```
@ResponseStatus(HttpStatus.BAD_REQUEST)
@ExceptionHandler(MethodArgumentNotValidException.class)
public Map<String, String> handleValidationExceptions(
  MethodArgumentNotValidException ex) {
    Map<String, String> errors = new HashMap<>();
    ex.getBindingResult().getAllErrors().forEach((error) -> {
        String fieldName = ((FieldError) error).getField();
        String errorMessage = error.getDefaultMessage();
        errors.put(fieldName, errorMessage);
    });
    return errors;
}
```

### Test
Now, try to test the validation in your API. The result should return something like this.

```
{
  "Username is required.",
  "Password is required."
}
```


## Conclusion
Spring Boot makes it way easier to do validation just by using the `@Valid `annotation. No need to implement validation methods that sometimes may not work. So make sure to try this out.
BDR.ai - Always on prospecting
Published: 2023-09-23 23:41:01

BDR.ai Reachout is a sales engagement technology designed to help businesses streamline their sales process and improve conversion rates. With BDR.ai, sales teams save time and effort by automating repetitive tasks such as lead generation, email outreach, and appointment scheduling. The platform also provides real-time analytics and insights to help sales reps track their progress and optimize their sales strategies.

BDR.ai integrates with popular CRM systems such as Salesforce, HubSpot, and Microsoft Dynamics, making it easy for businesses to incorporate the tool into their existing workflows. Overall, BDR.ai is a powerful sales automation solution that can help businesses improve their sales performance and drive revenue growth.

[https://www.bdr.ai](https://www.bdr.ai)
🤯Navigating the Complexities of Debugging: Challenges and Strategies for Software Developers, Every Programmers May Encounter💯
Published: 2023-09-23 23:15:27


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/re24zjxe28up440t5rsh.png)

Debugging is an essential skill for programmers, but it comes with its fair share of challenges. Non-reproducible bugs, complex interactions, Heisenbugs, third-party dependencies, and time constraints can all make debugging a daunting task. However, by employing best practices, using appropriate debugging tools, and maintaining a methodical approach, programmers can overcome these challenges and become more effective at identifying and fixing bugs. Remember that debugging is not just about fixing issues but also about improving the overall quality of your code and software




---------
#programming #programmer #coding #coder #code #web #website #design #designer #development #developer #webdesign #webdesigner #webdevelopment #webdeveloper #frontend #backend #frontenddeveloper #backenddeveloper #html5 #html #css3 #css #javascript #js #reactjs #engineering #engineer #software #developer #joke #bugs #bug #debugging
Adding markdown support
Published: 2023-09-23 23:00:11

Hello everyone,

I am excited to announce that i have successfully completed the lab 2: [txtToHtml](https://github.com/sshah135/Converter-txtToHtml)

In the initials phase i do faced some issues in the function creation with proper indentation. I tried more to focus with user friendly code which seems I was able to overcome like converting .md file to HTML with same command on terminal with little variation.

firstly i looked at my collaborator code and understand what can be best way to implement the additional feature like converting .md file into HTML format and adding bold feature without appending more libraries. 

By implementing above feature with try and error method i finally completed the lab requirement and pushed the code on the forked repository and with the collaborator permission i pulled request for the main branch.

Thank you...
HI! I am writing my thesis and need your help answering this survey about development with AI vs without AI.
Tags: webdev, ai, programming, javascript
Published: 2023-09-23 21:42:02

Any help would be appreciated and provide valuable insights to my research and my grades!

[Form Link](https://forms.gle/HE4xkan1m1RjvwYx8)

I have been amazed at the capability of AI in my web development experience! For my thesis, I have created a frontend website with and without AI and compared them. Both were created using React and Material UI. I used ChatGPT with plugins + advanced data analysis, GitHub Copilot, Codeium AI, and Codium AI.

The most important question to answer is the example scenario, as my professor would like other people's estimation on how long it would take them to create a similar website with and without AI.

Please let me know if you have any questions or comments, I'm happy to answer them. Thanks!
Exception Handling
Tags: java, beginners, exception, programming
Published: 2023-09-23 20:45:35

Hi Guys,

In programming, lots of time we face errors. As a programmer we need to know how to handle those unexpected scenario in a best way so that's why we are going to see about **Exception Handling**

## Exception:

**Exception** is an unwanted or unexpected situation which causes the program to ***terminate abnormally***.

## Default Exception Handler:

  When executing the program if an exception occurs then the method in which the exception created is responsible to create the **Exception Object**.The Exception Object Contains 3 information

- Name of the Exception
- Description of the Exception
- Stack trace(provide the information from which method and which line exactly the error occurs) and handover this object to the JVM(Java Virtual Machine).

Then JVM gives the object to ***Default Exception Handler*** and terminates the program abnormally without executing rest of the lines.

### Example with no Exception:

```
public class ExcepExample{
    public static void main(String args[]){

        int num=10/2;
        System.out.println("Print the A Value  "+num);
        System.out.println("End of the Program! ");

    }
}
```
**Output**

![Without Exception](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ihq0u8l8gu0razt2fb6h.png)

### Example with Exception

```
public class ExcepExample{
    public static void main(String args[]){

        int num=10/0;
        System.out.println("Print the A Value  "+num);
        System.out.println("End of the Program! ");

    }
}
```
**Output**

![With Exception](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bh6pzdbciuzqhsf1j8jw.png)

In Example Without Exception the program runs successfully and we got the output but in the Example with Exception the program terminates abruptly without executing the rest of the lines and prints the details of the Exception **ArithmeticException**.
In above exception exception example
_ArithmeticException_ => Name of the Exception
_/ by zero_ => Description of the Exception
_at ExcepExample.main(ExcepExample.java:4)_ => Is the stack trace.

So as programmer we need to handle this scenario and make program to terminate in normal way.

For that will use try...catch

## Try...Catch

### Syntax

`try{
    //code Which cause the Exception
}Catch(Exception ex){
   // Customize the how to display the exception
}
`
### Example

```
public class ExcepExample{
    public static void main(String args[]){

        try{
                int num=10/0;
                System.out.println("Print the A Value  "+num);
        }catch(ArithmeticException ex){
            ex.printStackTrace();
       }
        
        System.out.println("End of the Program! ");

    }
}
```
**Output**


![try...catch](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/i19su9jjiulzxn86hved.png)
Debugging C/C++ on M1 Macs
Published: 2023-09-23 20:24:48

## Background
Recently I had to debug a project written in C but this time round I was using my new M1 Mac and turns out the old familiar `GDB Debugger` is not available on it. I had to dig deep to find a solution and I'm writing this article so you don't have to do the same.

## Solution
You can either use some fancy ways to make GDB working on M1 or a simpler and recommended solution is to use `lldb` instead of `gdb`. `lldb` is similar than `gdb` and supported on M1 Macs. It's commands are also similar to `gdb` so you wont have much issues. 

Here's the documentation for it:
[Documentation](https://lldb.llvm.org)
Best way to avoid multiple if statements in python
Tags: python, bestpractic
Published: 2023-09-23 19:48:48

In general scenario, if you want to check multiple conditions of a simple operation like:

```python
def getFoodPrice(itemName: str) -> float:
  if itemName == "Idli":
      return 10
  if itemName == "Rice":
      return 100
  else:
      raise Exception("Item not found")
```

In these kinds of scenario we can use Dict object to perform fast and it is very scalable

```python
itemPrice: Dict[str, float] = {
   "idli": 10,
   "rice": 100
}

def getFoodPrice(itemName: str) -> float:
    try:
       return itemPrice[itemName.lower()]
    except KeyError:
       raise Exception("Item not found")
```

This will reduce the lines of code and improve the scalability. If any new items needs to be added, we can update the dict object not the code.
Synchronizing Users From LDAP With Keycloak Using AD Filters
Tags: keycloak, authentication, ldap
Published: 2023-09-23 20:09:24

---
title: Synchronizing Users From LDAP With Keycloak Using AD Filters
published: true
date: 2023-09-23 19:32:41 UTC
tags: keycloak, authentication, LDAP
canonical_url: https://akrisanov.com/custom-user-ldap-filter-in-keycloak/
---

 ![Synchronizing Users From LDAP With Keycloak Using AD Filters](https://akrisanov.com/content/images/2023/09/liljeforsgeese.webp)

One of the ways to synchronize users via a third-party provider with Keycloak is a mechanism called User Federation. It allows, using Kerberos or LDAP protocol, to pull user entries from your corporate authentication storage. However, if your organization is big enough to have a complex structure and there are a lot of users in the user directory, it could be challenging to get only a subset of the accounts that belong to different organization units.

For example, Active Directory models a tree-based structure using the following entities:

- CN = Common Name
- OU = Organizational Unit
- DC = Domain Component

All the distinguished names can be found in [the official documentation](https://docs.microsoft.com/en-us/previous-versions/windows/desktop/ldap/distinguished-names?ref=akrisanov.com) provided by Microsoft.

To configure a new User Federation in Keycloak, it's required to specify a User DN. This distinguished name is the base object in the directory information tree where the search begins forming candidates for pulling authentication entries. Therefore, we need to know how to construct the User DN.

The base option that an Active Directory administrator could use to create user accounts is to organize them under organizational units:

```
OU=Main,DC=Orgname,DC=ru
```

Even if your organizational unit has a complex structure, it's still relatively easy for Keycloak to find user entries inside it – just activate the `Search Scope: Subtree` setting when configuring the user federation. In large organizations, the Active Directory structure can get quite messy. Instead of using clear distinguished names, administrators do something surprising even to them. How about putting entries under CN in different organizational units?

This is what I encountered while working on corporate user authentication for a media platform's CMS. User entries of the editors were grouped via the Common Name. So, there is no way to define User DN in the way I've mentioned in the example above. Fortunately, the LDAP connection allows providing a filter for Active Directory. In my case, writing the filter to select all of the members of the `CMS_EDITOR` group was enough to solve a problem:

```
(&(objectCategory=Person)(sAMAccountName=*)(|(memberOf=CN=CMS_EDITOR,OU=Security,OU=Groups,OU=Central,OU=Main,DC=Orgname,DC=ru)))
```

Moreover, the `Custom User LDAP Filter` setting in Keycloak supports logical operators like _or_ with `|`, and I could use it for finding not only the members of the editor staff but also CMS admins, guests, etc.
Top 10 Essential VS Code Extensions for Developers
Tags: developers, vscode, webdev, programming
Published: 2023-09-23 18:36:31

Visual Studio Code (VS Code) has rapidly become one of the most popular code editors in the software development world. Its power lies not just in its core features but also in its extensibility. With a thriving marketplace of extensions, developers can tailor VS Code to suit their specific needs, making it an indispensable tool for efficient coding. In this article, we’ll explore the top 10 essential VS Code extensions that every developer should consider adding to their toolbox.


Supercharge Your Coding Workflow: Essential Visual Studio Code Extensions

Explore a curated list of must-have Visual Studio Code extensions that can boost your productivity and simplify your coding tasks. Discover powerful tools for code formatting, debugging, and more [here](https://codesolutionshub.com/2023/09/22/top-10-essential-vs-code-extensions-for-developers/?utm_source=dev_to&utm_campagin=csh_vs_code)
Introducing convertcase.dev: a simple tool for converting between cases
Published: 2023-09-23 18:33:26

Hey fellow devs! 🖐️

If you've ever found yourself needing to convert between different naming conventions, I've got good news. I recently worked on a project called [convertcase.dev](https://convertcase.dev) that makes this process a breeze. No more manual renaming or using multiple online tools!

Why [convertcase.dev](https://convertcase.dev)?
While working on different projects, I often encountered scenarios where I needed to switch between camelCase, PascalCase, kebab-case, snake_case, and SNAKE_CASE_UPPER. It's a task that sounds simple, but can get tedious and repetitive pretty fast. So, I thought: "Why not make a tool to do this quickly?"

## Features
🐫 camelCase Conversion: Perfect for your JavaScript variables.

👾 PascalCase Conversion: Got a class or a constructor? Convert to PascalCase in a second!

🍢 kebab-case Conversion: Ideal for CSS classes or URLs.

🐍 snake_case Conversion: Pythonistas, this one's for you!

⬆️ SNAKE_CASE_UPPER Conversion: Making constants or environment variables? Get them in uppercase!

## How to Use
Head over to [convertcase.dev](https://convertcase.dev)
Input your text in the provided field.
Select the desired case from the dropdown.
Voila! Your text is converted. Just copy and use it in your project.

## A Real-world Example
Imagine you're creating a new component in your favorite front-end framework. You've decided to name the file as `my-button`. Following the best practices:

The component's name should be `MyButton`.
If you're defining a CSS class, you'd probably go with my-button or `myButton` if you use CSS modules.

Doing these conversions manually can be repetitive, especially if you're dealing with multiple names or if you're refactoring. With convertcase.dev, just type in one format, and get all the others instantly!

I hope [convertcase.dev](https://convertcase.dev) proves to be a useful tool for your development workflow. I'd love to hear your feedback and suggestions. If you encounter any issues or want to see additional features, feel free to drop a comment or reach out to me directly!

Happy coding! 💻🚀
The Best PHP Frameworks for Web Development in 2023
Tags: laravel, learning, programming, tutorial
Published: 2023-09-23 18:28:58


in this post i'll give you The Best PHP Frameworks for Web Development in 2023 :
click here => [**The Best PHP Frameworks for Web Development in 2023**](https://thebestcoding.com/the-power-of-laravel-the-best-php-framework-2023/)
visit our Website => [**The Best Coding**](https://thebestcoding.com/)
Why is this so hard for me?
Tags: softwareengineering, cpp, productivity, programming
Published: 2023-09-23 16:29:08

During a "Study with Me" livestream today, a comment from one of the participants sparked an extended discussion. The participant said, "C is hard," referring to the programming language known for its complexity, especially for beginners. While I agree that C can be difficult, I take issue with framing challenges in this way, and here's why.

The brain is naturally wired to seek comfort and avoid difficulty. When we label something as "hard," our brains, which govern our actions, begin to prepare for retreat even before the journey has commenced. And if we do muster the courage to start, our brains constantly nudge us towards the exit, offering the path of least resistance—quitting.

The issue isn't the difficulty of the task but the mindset with which we approach it. A mindset that anticipates failure will most likely lead to it. Conversely, adopting a mindset that foresees triumph can significantly improve your chances of overcoming challenges.

What I propose is a shift in perspective. Instead of seeing challenges as insurmountable obstacles, view them as opportunities for growth. Yes, C programming might be tough, but you're tougher. The situation you're facing might be daunting, but you're more than capable of conquering it. Many have triumphed over similar challenges, and there's no reason to believe you can't do the same.

The key lies in training your brain to see possibilities where others see barriers, urging you forward even when the path is steep. Adopting this mindset won't just help you overcome challenges; it'll make you unstoppable.
Getting Saucy: I Joined OpenSauced!
Tags: career, opensource
Published: 2023-09-23 18:17:40

It's fall and the leaves are starting to change here in Montreal, which allows me to use that analogy to say that I've started a new role!

I've always been a fan of open source and have had the privilege to be paid to work in open source since January 2020 ([I used to work at DEV!](https://dev.to/nickytonline/a-new-year-a-new-start-i-m-joining-the-dev-team-3ap0)). I've been a fan of all the stuff Brian Douglas (@bdougieyo) did at GitHub and what he and the team have been doing at OpenSauced.

With that, I'm super pumped to say that [I’ve joined OpenSauced](https://www.linkedin.com/posts/nickytonline_today-is-my-first-day-opensauced-im-looking-activity-7109549689242312704-g4_c)!

I completed my first week, hitting the ground running. I've already had some work merged and even wrote my first blog post for them!

{%embed https://dev.to/opensauced/supercharge-your-repository-with-code-owners-4clg %}

I love all that we're doing at OpenSauced, and I'm super excited about all the work we're shipping. I'm also a fan of our highlights feature. Here's one of mine.

[![An OpenSauced highlight of mine](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/af8k2ex8rl326bhumdat.png)](https://insights.opensauced.pizza/feed/432)

If you're interested, you can [give me a follow on OpenSauced](https://insights.opensauced.pizza/user/nickytonline?tab=highlights).

Looking to learn more about open source? Come [join our community](https://discord.com/invite/U2peSNf23P) and [give us a follow on DEV](https://dev.to/opensauced)!

![Someone riding a piece of pizza like a bull](https://media.giphy.com/media/10kxE34bJPaUO4/giphy.gif)

Stay saucy friends! 🍕

Photo by <a href="https://unsplash.com/@v_uk_europe?utm_source=unsplash&utm_medium=referral&utm_content=creditCopyText">Vit Ch</a> on <a href="https://unsplash.com/photos/Oxb84ENcFfU?utm_source=unsplash&utm_medium=referral&utm_content=creditCopyText">Unsplash</a>
DevOps AI: Transforming Software Delivery with Real-World Examples
Tags: devops, developers, ai, webdev
Published: 2023-09-23 17:56:05

In the ever-evolving landscape of software development and IT operations, DevOps has brought transformative changes to how teams collaborate and deliver software. Now, imagine taking DevOps to the next level by infusing it with the power of artificial intelligence. Welcome to the world of DevOps AI, where data-driven insights and automation converge to reshape software delivery

Checkout the the Power of DevOps AI: Real-World Scenarios [here](https://codesolutionshub.com/2023/09/18/devops-ai-transforming-software-delivery-with-real-world-examples/?utm_source=dev_to&utm_campaign=csh_devops_ai)
[Debate] Reliable, long-run DOCS System - What options do we have ?!
Tags: documentation, docusaurus, opensource
Published: 2023-09-23 17:46:24

---
title: [Debate] Reliable, long-run DOCS System - What options do we have ?!
published: true
description: A reliable, long-run DOCS system - what options do we have
tags: docs, docusaurus, opensource
cover_image: https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4udisyiqk6ub3f9micsl.jpg
---
Hello Coders! 

**DOCS** are a very important part of any software product. Some projects use only a `README`, while others use PAID services like `GitBook`, `ArcheBee`, or opensource solutions (**Docusaurus**, `MkDocs`, `Vuedoc` ... etc)

For all [my projects](https://rosoftware.ro/), after a long run from `MkDocs`, `GitBook`, and other engines, I finally chose [Docusaurus](https://docusaurus.io/) and I simply love it. 


[![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/uv2s98ka87650hvduodq.png)](https://docs.appseed.us/) 

--- 

For those who have the time to debate this topic, I would appreciate hearing some other options regarding the DOCS engine. 

> **Thank You!** 🚀