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

ASP.NET Core Web API - Put action with DTO didn't update the existing object

I've been trying to write Put (update) action without the id property, by using DTO. But every time I'm trying I'm getting the existing object and not the updated one, and I can't figure out why and how to change it so it will work. My…
0
votes
1 answer

How to use the same NestJS DTO for different user roles

I have this UpdateAccountDto export class UpdateAccountDto { @ApiPropertyOptional() @IsOptional() roles: string[]; @ApiPropertyOptional() @IsOptional() managers: string[]; @ApiPropertyOptional() @IsOptional() @IsBoolean() …
Catopus
  • 81
  • 1
  • 8
0
votes
0 answers

Nest JS transform Iso8601String to Date in DTO with Error in Time

I'm trying parse ISo8601String to Date in Nest JS through DTO. I send a json with the date's string like: {lunMIni: 1001-01-01 00:00:00.000} In Nest js, I receive the data and it's transform by: @ApiProperty() @Type(() => Date) @IsDate() …
Jose David
  • 39
  • 9
0
votes
1 answer

Nest.JS validate object where keys are enum and values ​have the same shape

I need to validate an object where each key is an enum and each value have the same shape. Right now I was able to validate the object by explicitly setting each key and validate each nested object, but I would like something more usable so when I…
fasenderos
  • 388
  • 3
  • 18
0
votes
1 answer

I can't add the @IsNotEmpty() validator in nestjs Dtos

I can't add the @IsNotEmpty() validator in nestjs Dtos
0
votes
1 answer

What type of Exception is this?

I am sending a DTO from client with a failed validation for one field. I tried to handle it in the Controller Advice, but it turns out it is not the instance of the ValidationException.class as that handler does not work. I checked it using the…
0
votes
1 answer

Proper way to create and return a DTO from a controller?

First of all, the question may sound broad, but let me be specific. Through past questions, I understood the role and usage of the DTO in my own way. But after seeing a lot of code that I wrote my way, I still have my doubts. First, I'll show you…
바보린
  • 159
  • 1
  • 13
0
votes
0 answers

Alternative for using @Nullable for double in Java Spring Boot?

I've made a class for request body, now it has a double field which might come in request body sometimes and sometimes it won't, how should I handle it? Sample code: @Nullable private String phoneNumber; [what should be here?] private double…
0
votes
1 answer

spring entity to DTO with compute getter

Trying to understand the best practice here, i have an entity and i add some login to the getPrice property: public class Order{ private Integer price; private Integer addOn; public Integer setAddOn(Integer addOn){ …
TomerMiz
  • 377
  • 1
  • 3
  • 13
0
votes
0 answers

Nestjs Dto as a array

i can not get rules. rules are empty. Data transfer array of objects . function ruleCreateMany return empty { } . where i am doing wrong . Am i pass argument array right way . here is my input array var rules= [ { "name": "After every…
ali
  • 3
  • 3
0
votes
1 answer

How to create dto of an complex object in NestJs

I'm a beginner at NestJs and I want to create a dto of the following struct: I want to create an API that can return this object using DTOs. export let Week = [ { DayName : "TuesDay", TimeZone: [ { …
DarkSide77
  • 719
  • 1
  • 4
  • 21
0
votes
1 answer

ASP.NET C# DTO initialization by constructor with parameters or paramless constructor with curly braces in-line?

Hi im just wondering how should I initialize my DTO objects in my ASPNET project, seems like everyone uses second approach but I dont know why and I can't really find clear answer. My argument for the first method with constructor with parameters is…
aaaaSton2
  • 7
  • 1
  • 3
0
votes
1 answer

How to deal with a OneToOne relationship when implementing the DTO pattern for a REST API?

Given two entities Employee and EmployeeAddress, I am trying to implement the DTO pattern - mainly because my IDE shows a warning when using an entity as parameter in my REST controller. In this context, I have a question regarding how to deal with…
Luk
  • 1,009
  • 2
  • 15
  • 33
0
votes
1 answer

Unable to locate appropriate constructor Expected arguments are: java.lang.String

I have been completely unable to get Hibernate with DTOs. Not even very simple object with a single string, it always complains about "Unable to locate appropriate constructor" :( I started with real code but tried to narrow it down and it doesn't…
0
votes
0 answers

How to filter (or alter) a request result with RestTemplate.getForObject (Best Practice for mapping not-consistent data)?

I have very weird API and code, partly legacy (the reason of RestTemplate is provided). I'm getting the result from source with JSON and mapping it to array of inner objects. Unfortunately, the data is not consistent. It's supposed to be: [{ "a":…
Jarvis
  • 384
  • 2
  • 6
  • 18