data-transfer-objects

What is the purpose of a Data Transfer Object in NestJS?

久未见 提交于 2021-01-02 18:06:12
问题 Im struggling with a problem. Im following the documentation of NestJS. The back-end framework for NodeJS. The documentation mentions a DTO (Data Transfer Object). I created a DTO for creating a user: export class CreateUserDto { readonly email: string; readonly password: string; } In combination with this: @Post('create') createUser(@Body() userData: CreateUserDto): User { return this.usersService.createUser(userData); } For some reason, I am able to make a post request to this route with

What is the purpose of a Data Transfer Object in NestJS?

让人想犯罪 __ 提交于 2021-01-02 18:05:14
问题 Im struggling with a problem. Im following the documentation of NestJS. The back-end framework for NodeJS. The documentation mentions a DTO (Data Transfer Object). I created a DTO for creating a user: export class CreateUserDto { readonly email: string; readonly password: string; } In combination with this: @Post('create') createUser(@Body() userData: CreateUserDto): User { return this.usersService.createUser(userData); } For some reason, I am able to make a post request to this route with

Map a dto to an entity retrieved from database if Dto has Id using MapStruct

安稳与你 提交于 2020-05-23 04:54:17
问题 I'm using MapStruct to make dto <-> entity mapping. The same mappers are used to create and update entities from dtos. A verification of the dto's id is done to know whether a new entity must be created (id == null) or it should be retrieved from database (id != null) . I'm actually using MapperDecorator as a workaround. Example : Mapper @Mapper @DecoratedWith(UserAccountDecorator.class) public interface UserAccountMapper { UserAccountDto map(User user); User map(UserAccountDto dto); User map

How do I write a JPA query to populate a data transfer object (different than my @Entity object)?

我怕爱的太早我们不能终老 提交于 2019-12-23 01:53:14
问题 We’re using Java 6, JPA 2.1, and Hibernate 4.3.6.Final. I have the below code that finds our Organization objects … final CriteriaBuilder builder = entityManager.getCriteriaBuilder(); final CriteriaQuery<Organization> criteria = builder.createQuery(Organization.class); final Root<Organization> root = criteria.from(Organization.class); final CriteriaQuery query = buildCriteriaQuery(builder, criteria, root, country, state, organizationTypes, parentOrg, zipCode); final TypedQuery<Organization>

Symfony2.1 - The option “em” does not exist when using DataTransformer

杀马特。学长 韩版系。学妹 提交于 2019-12-22 08:26:50
问题 I am using this cookbook recipe to add a data transformer in Symfon 2.1, but I am getting the following error, The option "em" does not exist. Known options are: "attr", "block_name",.... Is this still a valid way to send the entity manager over to the form type? $taskForm = $this->createForm(new TaskType(), $task, array( 'em' => $this->getDoctrine()->getEntityManager(), )); 回答1: While I can't comment if that's the best way or not, I've always passed them to my task constructor as a hard

Should a WCF service return an EntityObject or a POCO/DTO class?

◇◆丶佛笑我妖孽 提交于 2019-12-21 12:36:11
问题 I've been looking at a lot of WCF examples using EntityFramework and most of them seem to return some kind of POCO or DTO class to the client. I was wondering why this was since the default EntityObject includes the [DataContract] attributes and implements INotifyPropertyChanged . Is returning a DTO or POCO class better than an EntityObject (or vise versa)? And is there specific instances where it is better to use one return value over another? 回答1: As a best practice, you should definitely

DTOs in WCF RIA Services Master-Detail

落花浮王杯 提交于 2019-12-11 07:43:39
问题 I have to make a Master-Detail scenario where in the master I can show many types of items, that they all implement IDto : interface IDto { int Id { get; set; } string Title { get; set; } EntityType { get; set; } enum EntityType { Contact, Person, Company, Customer Employee, Vendor, Job } Note: I am using Entity Framework EDM (generated ObjectContext and EntityObject s). The class hierarchy is that Contact is the subclass for Person and Company , Person is the baseclass of Employee , Company

Complex DTO structure

六月ゝ 毕业季﹏ 提交于 2019-12-10 19:44:21
问题 I've read a lot about DTO's here on SO, in books and articles, but I'm not sure if I get it right. We're using DTO's in our project so that they're almost just properties of Domain Objects. For that reason, we need to have a complex DTO structure. There're some classes extending one another, compositions, aggregate, etc. . Question is more general. Is it right to inherit a dto from another one or to have a reference on a dto in another dto? 回答1: Is it right to inherit a DTO from another one

What is a DTO and BO? What is the difference?

久未见 提交于 2019-12-10 01:14:35
问题 I know DTO is a data transfer object and a BO is a business object. But, what does it actually mean? When should I choose one over the other? From, what I understand DTO is just used to transfer data and doesn't have business logic. Does this mean that a DTO doesn't have any method only properties(getter and setter)? But, it still has properties of a BO. Can someone please explain? Thanks. 回答1: DTO is used to transfer data between layers/tiers. For such purpose it doesn't need any methos and

Using DTOs and BOs

耗尽温柔 提交于 2019-12-07 07:32:51
问题 One area of question for me about DTOs/BOs is about when to pass/return the DTOs and when to pass/return the BOs. My gut reaction tells me to always map NHibernate to the DTOs, not BOs, and always pass/return the DTOs. Then whenever I needed to perform business logic, I would convert my DTO into a BO. The way I would do this is that my BO would have a have a constructor that takes a parameter that is the type of my interface (that defines the required fields/properties) that both my DTO and