Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BE] Feat/jsonarray #26

Merged
merged 6 commits into from
Apr 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package develop.baminchan.controller;

import develop.baminchan.dto.BanchanDto;
import develop.baminchan.entity.Banchan;
import develop.baminchan.repository.BanchanRepository;
import develop.baminchan.service.BanchanService;
Expand All @@ -17,9 +18,9 @@ public BanchanController(BanchanService banchanService) {
}

@GetMapping("/main/{detail_hash}")
public Banchan readOneMain(@PathVariable String detail_hash) {
Banchan banchan = banchanService.findBanchanByDetailHash(detail_hash);
return banchan;
public BanchanDto findOneMain(@PathVariable String detail_hash) {
BanchanDto banchanDto = banchanService.findBanchanByDetailHash(detail_hash);
return banchanDto;
}

// @GetMapping("/soup/{detail_hash}")
Expand Down
77 changes: 77 additions & 0 deletions backend/src/main/java/develop/baminchan/dto/BanchanDto.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package develop.baminchan.dto;

import develop.baminchan.entity.Banchan;

public class BanchanDto {
private String detail_hash;
private String image;
private String alt;
private String[] delivery_type;
private String title;
private String description;
private String n_price;
private String s_price;
private String[] badge;

protected BanchanDto() {

}

private BanchanDto(Banchan banchan) {
this.detail_hash = banchan.getDetail_hash();
this.image = banchan.getImage();
this.alt = banchan.getAlt();
this.delivery_type = convertStringToArray(banchan.getDelivery_type());
this.title = banchan.getTitle();
this.description = banchan.getDescription();
this.n_price = banchan.getN_price();
this.s_price = banchan.getS_price();
this.badge = convertStringToArray(banchan.getBadge());
}

private String[] convertStringToArray(String str) {
String[] arr = str.split(",");
return arr;
}

// Entity -> DTO
public static BanchanDto of(Banchan banchan) {
return new BanchanDto(banchan);
}

public String getDetail_hash() {
return detail_hash;
}

public String getImage() {
return image;
}

public String getAlt() {
return alt;
}

public String[] getDelivery_type() {
return delivery_type;
}

public String getTitle() {
return title;
}

public String getDescription() {
return description;
}

public String getN_price() {
return n_price;
}

public String getS_price() {
return s_price;
}

public String[] getBadge() {
return badge;
}
}
12 changes: 5 additions & 7 deletions backend/src/main/java/develop/baminchan/entity/Banchan.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package develop.baminchan.entity;

import develop.baminchan.entity.banchan.Badge;
import develop.baminchan.entity.banchan.DeliveryType;
import org.springframework.data.annotation.Id;

import java.util.Set;
Expand All @@ -13,14 +11,14 @@ public class Banchan {
private String detail_hash;
private String image;
private String alt;
private Set<DeliveryType> delivery_type;
private String delivery_type;
private String title;
private String description;
private String n_price;
private String s_price;
private Set<Badge> badge;
private String badge;

public Banchan(Long id, String detail_hash, String image, String alt, Set<DeliveryType> delivery_type, String title, String description, String n_price, String s_price, Set<Badge> badge) {
public Banchan(Long id, String detail_hash, String image, String alt, String delivery_type, String title, String description, String n_price, String s_price, String badge) {
this.id = id;
this.detail_hash = detail_hash;
this.image = image;
Expand Down Expand Up @@ -49,7 +47,7 @@ public String getAlt() {
return alt;
}

public Set<DeliveryType> getDelivery_type() {
public String getDelivery_type() {
return delivery_type;
}

Expand All @@ -69,7 +67,7 @@ public String getS_price() {
return s_price;
}

public Set<Badge> getBadge() {
public String getBadge() {
return badge;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package develop.baminchan.entity;

public class BanchanDetail {
}

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package develop.baminchan.service;

import develop.baminchan.dto.BanchanDto;
import develop.baminchan.entity.Banchan;
import develop.baminchan.repository.BanchanRepository;
import org.springframework.stereotype.Service;
Expand All @@ -16,9 +17,10 @@ public BanchanService(BanchanRepository banchanRepository) {
this.banchanRepository = banchanRepository;
}

public Banchan findBanchanByDetailHash(String detail_hash) {
public BanchanDto findBanchanByDetailHash(String detail_hash) {
Banchan banchan = banchanRepository.findBanchanByDetail_hash(detail_hash);
return banchan;
BanchanDto banchanDto = BanchanDto.of(banchan);
return banchanDto;
}

@Transactional
Expand Down
2 changes: 1 addition & 1 deletion backend/src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ logging.level.sql=DEBUG

spring.datasource.url=jdbc:mysql://localhost:3306/sidedish?autoReconnect=true&useUnicode=true&characterEncoding=UTF8
spring.datasource.username=root
spring.datasource.password=
spring.datasource.password=1234
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver