Skip to content

Commit

Permalink
Merge pull request #24 from 2024-ITEC0401/develop
Browse files Browse the repository at this point in the history
Develop : 코디 추천 API 까지 작성된 중간 완성본 Main에 Merge
  • Loading branch information
milk-stone authored Dec 4, 2024
2 parents 69f22e6 + 131dd6f commit 6cb5288
Show file tree
Hide file tree
Showing 47 changed files with 1,053 additions and 74 deletions.
4 changes: 3 additions & 1 deletion backend/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,6 @@ out/
.vscode/

### Ignore DB Password
src/main/resources/application-secret.yml
src/main/resources/application-secret.yml
dev.env
ec2.dev
13 changes: 13 additions & 0 deletions backend/src/main/java/com/itec0401/backend/config/AppConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.itec0401.backend.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.client.RestTemplate;

@Configuration
public class AppConfig {
@Bean
public RestTemplate restTemplate() {
return new RestTemplate();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,33 @@
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.security.web.SecurityFilterChain;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.CorsConfigurationSource;

import java.util.Collections;

@Configuration
@EnableWebSecurity
public class SecurityConfig {

// Security 단에서 Cors 설정하는 익명 클래스
CorsConfigurationSource corsConfigurationSource() {
return request -> {
CorsConfiguration config = new CorsConfiguration();
config.setAllowedHeaders(Collections.singletonList("*"));
config.setAllowedMethods(Collections.singletonList("*"));
config.setAllowedOriginPatterns(Collections.singletonList("http://localhost:5173")); // 허용할 origin
config.setAllowCredentials(true);
return config;
};
}

@Bean
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
http
//.cors((c) -> c.disable())
.cors(corsConfigurer -> corsConfigurer.configurationSource(corsConfigurationSource()))
.csrf((csrf) -> csrf.disable())
.cors((c) -> c.disable())
.headers((headers) -> headers.disable());
return http.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@


import com.itec0401.backend.domain.clothing.dto.ClothInfoDto;
import com.itec0401.backend.domain.clothing.dto.ClothRequestDto;
import com.itec0401.backend.domain.clothing.service.ClothingService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.Authentication;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

@RestController
@RequiredArgsConstructor
Expand All @@ -26,8 +28,44 @@ public class ClothingController {
}
)
@PostMapping("/upload")
public ResponseEntity<ClothInfoDto> createClothing(@RequestBody ClothInfoDto clothInfoDto, Authentication authentication){
return clothingService.createClothing(clothInfoDto, authentication);
public ResponseEntity<Void> createClothing(@RequestBody ClothRequestDto dto, Authentication authentication){
return clothingService.createClothing(dto, authentication);
}

@Operation(
summary = "특정 옷 조회",
description = "PathVariable 로 id 값을 받고, 그 id를 가진 옷 정보 반환"
)
@GetMapping("/{id}")
public ResponseEntity<ClothInfoDto> getClothingById(@PathVariable Long id, Authentication authentication){
return clothingService.getClothingById(id, authentication);
}

@Operation(
summary = "특정 옷 수정",
description = "PathVariable로 id 값을 받고, RequestBody로 업데이트 내용을 받으면 그 옷을 찾아서 내용 수정"
)
@PutMapping("/{id}")
public ResponseEntity<Void> updateClothing(@PathVariable Long id, @RequestBody ClothRequestDto dto, Authentication authentication){
return clothingService.updateClothing(id, dto, authentication);
}

@Operation(
summary = "유저의 모든 옷 열람",
description = "ClothInfoDto 내용 대로 모든 옷 정보 반환"
)
@GetMapping()
public ResponseEntity<List<ClothInfoDto>> getAllClothings(Authentication authentication){
return clothingService.getAllClothings(authentication);
}

@Operation(
summary = "특정 옷 삭제",
description = "PathVariable으로 id를 받고, 해당 id 값을 가진 옷 삭제"
)
@DeleteMapping("/{id}")
public ResponseEntity<Integer> deleteClothing(@PathVariable Long id, Authentication authentication){
return clothingService.deleteClothingById(id, authentication);
}

/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
@Builder
public class ClothInfoDto {
/* 용도 : 이미지를 Python 서버로 보냈을 때, 파이썬 서버가 보내준 정보를 담는 DTO */
/* Frontend -> Python -> Frontend -> Spring Boot */
private Long id;
private String imageUri;
private String name;
private String mainCategory;
Expand All @@ -22,16 +24,17 @@ public class ClothInfoDto {

public static ClothInfoDto toDto(Clothing clothing){
return ClothInfoDto.builder()
.id(clothing.getId())
.imageUri(clothing.getImageUri())
.name(clothing.getName())
.mainCategory(clothing.getSubCategory().getParentCategoryName())
.subCategory(clothing.getSubCategory().name())
.baseColor(clothing.getBaseColor().name())
.pointColor(clothing.getPointColor().name())
.textile(clothing.getTextile().name())
.pattern(clothing.getPattern().name())
.season(clothing.getSeason().name())
.style(clothing.getStyle().name())
.subCategory(clothing.getSubCategory().getTitle())
.baseColor(clothing.getBaseColor().getTitle())
.pointColor(clothing.getPointColor().getTitle())
.textile(clothing.getTextile().getTitle())
.pattern(clothing.getPattern().getTitle())
.season(clothing.getSeason().getTitle())
.style(clothing.getStyle().getTitle())
.description(clothing.getDescription())
.build();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.itec0401.backend.domain.clothing.dto;

import lombok.Builder;
import lombok.Getter;

@Getter
@Builder
public class ClothRequestDto {
// Create, Update 둘 다 이 형식
private String imageUri;
private String name;
private String mainCategory;
private String subCategory;
private String baseColor;
private String pointColor;
private String textile;
private String pattern;
private String season;
private String style;
private String description;
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.itec0401.backend.domain.clothing.entity;

import com.itec0401.backend.domain.clothing.dto.ClothRequestDto;
import com.itec0401.backend.domain.clothing.entity.type.*;
import com.itec0401.backend.domain.coordinationclothing.entity.CoordinationClothing;
import com.itec0401.backend.domain.user.entity.User;
Expand All @@ -8,6 +9,7 @@
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.util.ArrayList;
import java.util.List;

@Entity
Expand Down Expand Up @@ -49,12 +51,26 @@ public class Clothing {
private String description;

@OneToMany(mappedBy = "clothing")
private List<CoordinationClothing> coordinationClothingList;
private List<CoordinationClothing> coordinationClothingList = new ArrayList<>();

@ManyToOne
@JoinColumn(name = "user_id")
private User user;

public void update(ClothRequestDto dto){
this.imageUri = dto.getImageUri();
this.name = dto.getName();
this.mainCategory = Category.convertString(dto.getMainCategory());
this.subCategory = Category.convertString(dto.getSubCategory());
this.baseColor = ColorType.convertString(dto.getBaseColor());
this.pointColor = ColorType.convertString(dto.getPointColor());
this.textile = TextileType.convertString(dto.getTextile());
this.pattern = PatternType.convertString(dto.getPattern());
this.season = SeasonType.convertString(dto.getSeason());
this.style = StyleType.convertString(dto.getStyle());
this.description = dto.getDescription();
}

@Builder
public Clothing(String imageUri,
String name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,10 @@ public String getTitle() {
return title;
}

// 부모카테고리 Getter (Name 반환하도록 수정했음)
// 부모카테고리 Getter - 한글(title)을 반환해야함
public String getParentCategoryName() {
Optional<Category> category = Optional.ofNullable(parentCategory);
return category.map(Enum::name).orElse("INVALID");
return category.map(Category::getTitle).orElse("예외");
}

// 자식카테고리 Getter
Expand Down Expand Up @@ -161,9 +161,9 @@ private boolean contains(Category category) {
return Objects.nonNull(category.parentCategory) && this.contains(category.parentCategory);
}

public static Category convertString(String title) {
public static Category convertString(String korTitle) {
for (Category category : Category.values()) {
if(Objects.equals(category.name().toLowerCase(), title.toLowerCase())) return category;
if(Objects.equals(category.title, korTitle)) return category;
}
return INVALID;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,26 @@
import java.util.Objects;

public enum ColorType {
WHITE, CREAM, BEIGE, LIGHT_GRAY, DARK_GRAY,
BLACK, LIGHT_PINK, YELLOW, LIGHT_GREEN, MINT,
SKY_BLUE, LIGHT_PURPLE, PINK, CORAL, ORANGE,
GREEN, BLUE, PURPLE, RED, CAMEL,
BROWN, KHAKI, NAVY, WINE, GOLD,
SILVER, INVALID;
WHITE("흰색"), CREAM("크림"), BEIGE("베이지"), LIGHT_GRAY("연회색"), DARK_GRAY("진회색"),
BLACK("검정"), LIGHT_PINK("연분홍"), YELLOW("노랑"), LIGHT_GREEN("연두"), MINT("민트"),
SKY_BLUE("하늘색"), LIGHT_PURPLE("연보라"), PINK("분홍"), CORAL("코랄"), ORANGE("주황"),
GREEN("초록"), BLUE("파랑"), PURPLE("보라"), RED("빨강"), CAMEL("카멜"),
BROWN("갈색"), KHAKI("카키"), NAVY("네이비"), WINE("와인"), GOLD("골드"),
SILVER("실버"), INVALID("예외");

public static ColorType convertString(String color) {
private final String title;

ColorType(String title){
this.title = title;
}

public String getTitle(){
return title;
}

public static ColorType convertString(String korColor) {
for (ColorType colorType : ColorType.values()) {
if (Objects.equals(colorType.name().toLowerCase(), color.toLowerCase())) {
if (Objects.equals(colorType.getTitle(), korColor)) {
return colorType;
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,25 @@
package com.itec0401.backend.domain.clothing.entity.type;

import java.util.Objects;

public enum PatternType {
SOLID, CHECK, STRIPE, PRINT, DOT,
ANIMAL, FLORAL, TROPICAL, PAISLEY, ARGYLE,
MILITARY, COLOR_BLOCK, REPEAT, OTHER, INVALID;
SOLID("무지"), CHECK("체크"), STRIPE("스트라이프"), PRINT("프린트"), DOT("도트"),
ANIMAL("애니멀"), FLORAL("플로럴"), TROPICAL("트로피칼"), PAISLEY("페이즐리"), ARGYLE("아가일"),
MILITARY("밀리터리"), COLOR_BLOCK("컬러블럭"), REPEAT("반복"), OTHER("기타"), INVALID("예외");

private final String title;

PatternType(String title) {
this.title = title;
}

public String getTitle(){
return title;
}

public static PatternType convertString(String pattern) {
public static PatternType convertString(String korPattern) {
for (PatternType patternType : PatternType.values()) {
if (patternType.name().equalsIgnoreCase(pattern)) {
if (Objects.equals(patternType.getTitle(), korPattern)) {
return patternType;
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,23 @@
package com.itec0401.backend.domain.clothing.entity.type;

import java.util.Objects;

public enum SeasonType {
SPRING, SUMMER, AUTUMN, WINTER, INVALID;
SPRING("봄"), SUMMER("여름"), AUTUMN("가을"), WINTER("겨울"), INVALID("예외");

private final String title;

SeasonType(String title) {
this.title = title;
}

public String getTitle() {
return title;
}

public static SeasonType convertString(String seasonType) {
public static SeasonType convertString(String korSeasonType) {
for (SeasonType season : SeasonType.values()) {
if (season.name().equalsIgnoreCase(seasonType)) {
if (Objects.equals(season.getTitle(), korSeasonType)) {
return season;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,23 @@
import java.util.Objects;

public enum StyleType {
DAILY, WORK, DATE, CEREMONY, TRAVEL,
HOMEWEAR, PARTY, EXERCISE, SPECIAL_DAY, SCHOOL,
OTHER, INVALID;
DAILY("데일리"), WORK("직장"), DATE("데이트"), CEREMONY("경조사"), TRAVEL("여행"),
HOMEWEAR("홈웨어"), PARTY("파티"), EXERCISE("운동"), SPECIAL_DAY("특별한날"), SCHOOL("학교"),
OTHER("기타"), INVALID("예외");

public static StyleType convertString(String styleType) {
private final String title;

StyleType(String title) {
this.title = title;
}

public String getTitle() {
return title;
}

public static StyleType convertString(String korStyleType) {
for (StyleType style : StyleType.values()) {
if (Objects.equals(style.name().toLowerCase(), styleType.toLowerCase())) {
if (Objects.equals(style.getTitle(), korStyleType)) {
return style;
}
}
Expand Down
Loading

0 comments on commit 6cb5288

Please sign in to comment.