Questions tagged [dto]

DTO is an acronym for Data Transfer Object, a design pattern used in data transfer.

DTO is an acronym for Data Transfer Object, a design pattern used in transferring data through internal or external interfaces. A DTO protects the application's internal data by acting as dummy storages, the whole logic is implemented only in actual Domain Objects (DO).

Pros:

  • Fewer remote calls (typically one, getDto() vs. individual getId(), getName(), etc.)
  • Improved data capsulation (Remote systems need only to know the details of the DTO, not DO internals)

Cons:

  • class explosion
  • conversions needed between DTOs and DOs
2100 questions
0
votes
1 answer

how we implement dto validation in nestjs TCP microservice

I need to implement dto validation in nestjs micro-service a complete implementation of dto in nestjs TCP micro-service**strong text** checkRemitter.dto.ts ```typescript import { IsNotEmpty, IsString } from 'class-validator'; export class…
RJ amal
  • 5
  • 2
0
votes
1 answer

How to nest same Data type with spatie/laravel-data?

I get JSON from API, and I need to convert it to a recursively nested object. One property of my object is an array with elements of the same type as the parent object. Here is my Data class: class Group extends Data { /** @var \App\Data\Group[]…
s3c
  • 1,481
  • 19
  • 28
0
votes
1 answer

class validation in nestjs with string property which validate number

nestJS class-validator: property is string: check the value is between 100 to 5000 i need to validate dto property that validate string number between 100 and 5000
RJ amal
  • 5
  • 2
0
votes
1 answer

Solution for overlapping part in response DTO design

We are currently designing response dto for user information. However, while designing, there are too many overlapping parts for fields, which is a concern. Assume that user data includes id, email, name, phone number, and manager id in charge…
0
votes
1 answer

DTO objects are not passed in the request

Here is my code on nestjs dto file export class RequestDTO { @IsString() name: string; book: { authorone: string; authortwo: string; }; @IsString() title: string = 'Test Book!'; } On post request, I'm passing all params but…
saravanan mp
  • 745
  • 3
  • 16
  • 34
0
votes
1 answer

Avoiding code duplication while using seperate DTOs for request and reponse

I'm using the DTO pattern for managing HTTP bodies in a Spring Boot REST application. I have seperate DTOs for requests and responses as the response contains additional data. I'm using inheritance for the response DTO as the additional data…
mac501
  • 37
  • 5
0
votes
1 answer

MapStruct - mapping method from iterable to non-iterable

I have been working with MapStruct some days now and haven't yet achieved what i need. As part of the exercises with Spring, I am writing a small app that will display information about the movies (title, description, director, etc.) and…
Marek
  • 3
  • 2
0
votes
1 answer

added data to the custom Dto class

also I have a user dto class class UserDto{ Long id; String name; String email; String password } when user login is success, I wants to show response like this { "user":{ "id":"1", …
0
votes
0 answers

Best practice for DTO classes that contain complex objects

If I have a Entity class as such where a user can have multiple addresses: @Entity public class User { private String name; private List
address; } @Entity public class Address { private String area; private String…
dataman
  • 123
  • 9
0
votes
1 answer

Set Required=True based on a condition in marshmallow

I was wondering whether there is a way in marshmallow to have a field to be required depending on another value. Eg: { 'name':'Tom' } { 'name':'Arthur', 'job':'teacher' } I'd like to know if there is a way to make the field job required if…
0
votes
1 answer

Linq adding items to list in the query

Good day, I have one problem. I have three Domain objects public class User { public Guid Id { get; set; } public string Username { get; set; } public string EmailAddress { get; set; } public string Password { get; set; } public…
0
votes
3 answers

MapStruct adding 1 suffix to object

I am using mapstruct to map my DTO to entity, My Entity @Entity @Data @Table(name = "break") public class Break { @Id @GeneratedValue(strategy = GenerationType.IDENTITY, generator = "native") private long id; private String…
0
votes
0 answers

Update Jpa Entity with Relationship using DTO

I have a entity that contains other entities. I'm getting data from ProductDTO, and i need get ids (each id can change or don't) and set it to entity. In my Service i get the actual product, get each entity by id and set in product entity. But …
devs4wl
  • 3
  • 2
0
votes
1 answer

is using DTOs in every case always a good practice?

Imagine i have an entity like this: @Entity @Getter @Setter @ToString @Table(name = "employeeSalary") public class EmployeeSalary{ @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private long id; @Column(name = "fullName", nullable =…
GiviXbo
  • 1
  • 1
0
votes
1 answer

Api-platform 2.7 - Can't use custom state provider to customize POST response

I'm using api-platform 2.7 to make an API. I like to control what the requests can accept and what the response send back so I use DTO. I try to customize what a POST request will return. I only want to show specific data from my User entity, so…
mat33260
  • 70
  • 1
  • 6