I'm creating this business app card using Java for my project and now I'm stuck at creating the Service to upload a file in Java. So far I did my research on the internet but mainly they only show how to do it through Controller and I'm afraid if I build the Controller first it will ruin the architecture. Do you guys have experience of how to do it or maybe can refer to a project or any resources to learn about it?
#How to create an upload file (any types of file) service in Java?
51 messages · Page 1 of 1 (latest)
<@&987246841693360200> please have a look, thanks.
Here is an AI assisted attempt to answer your question 🤖. Maybe it helps! In any case, a human is on the way 👍. To continue talking to the AI, you can use </chatgpt:1108714622413963314>.
what do you mean by "ruin the architecture" - what architecture do you have?
I was asking the ai about this process and it says that if I create the controller first it will ruin the architecture
don't ask the AI anything. you stop that
genuinely it will sabotage the mechanisms by which you learn and retain info
I did that because I don't have any mentor to ask that's why I am using it. Thank you for reminding me about this
a business card application. I want the project to be able to upload the file and read it however I get confuse on how to create the logic of uploading the file
most of the example I get from the internet is only discussing about the Controller class
who are you doing this program for
For my personal project. I am shifting a career toward softwate engineering
describe in detail what you know as of right now
I have created the dto and the entity also injected the dependecies required. I have created the mapper as well to translates the data so it can be saved into the database and processed within the service. So far these things what I did
that is what you did
that is not what you know
if you dont know why you are doing the things you have done we need to take a step back
Can you explain more about what do I know?
like, what that means?
I still don't understand. Mind to elaborate or give an example?
okay there is a difference between knowledge and understanding
if you "know" to do something you don't need to understand why you do it, just to do it
if you understand why you do something you would know when you wouldn't do it
and it sounds to me like you followed a tutorial that just said "write this file. do this. this is the pattern"
and while that can be useful in small doses, it sabotages your ability to truly learn
So what should I do for handling this?
package org.example.bizcardapp.Entity;
import org.example.bizcardapp.dto.CardDto;
import org.springframework.stereotype.Component;
@Component
public class CardMapper {
public Card toEntity (CardDto dto, User owner){
if (dto != null){
return Card.builder()
.fullName(dto.name())
.title(dto.title())
.company(dto.company())
.address(dto.address())
.email(dto.email())
.phone(dto.phone())
.website(dto.website())
.tagline(dto.tagline())
.logoDesc(dto.logoDesc())
.ocrRawText(dto.ocrRawText())
.user(owner)
.build();
} else {
return null;
}
}
public CardDto toDto(Card card){
if (card == null){
return null;
}
return new CardDto(
card.getFullName(),
card.getTitle(),
card.getCompany(),
card.getEmail(),
card.getAddress(),
card.getPhone(),
card.getWebsite(),
card.getTagline(),
card.getLogoDesc(),
card.getOcrRawText()
);
}
}
this is the mapper
package org.example.bizcardapp.Entity;
import jakarta.persistence.;
import lombok.;
import java.time.LocalDate;
import java.time.LocalDateTime;
@Entity
@Table
@Builder
@AllArgsConstructor(access = AccessLevel.PRIVATE)
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@Getter
@Setter
public class Card {
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE)
private Long id;
private String fullName;
private String email;
private String title;
private String phone;
private String company;
private String website;
private String address;
private String tagline;
private String logoDesc;
private String ocrRawText;
private LocalDate dateCreated;
private LocalDateTime timeStamp;
@ManyToOne
@JoinColumn(name = "user_id")
private User user;
}
this is the entity
package org.example.bizcardapp.dto;
public record CardDto (
String name,
String title,
String company,
String email,
String phone,
String website,
String address,
String tagline,
String logoDesc,
String ocrRawText
) {
}
this is the dto
This is the whole code
and when you were learning java, did you jump straight into spring?
how long have you been at this?
okay
can you make a new project, make it a maven project and call it BizCardAppDetour
or
well okay i want to bring you through a longer tutorial but i dont really have the time do give it
so for now just do file uploads in the controller
whatever thing you saw online explaining that is "right" in how to do it
Please let me know if you have time tomorrow I will listen and learn a lot from you I believe
For now I will do the controller
If you can reach out to this message again tomorrow I'd be happy to hear from you