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

result post api 생성 close #59 #66

Merged
merged 1 commit into from
Feb 29, 2024
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,24 +1,29 @@
package com.endlesshorses.oot.custom.accessory.service;

import com.endlesshorses.oot.custom.accessory.dto.AccessoryListResponseDto;
import com.endlesshorses.oot.custom.accessory.enity.Accessory;
import com.endlesshorses.oot.custom.accessory.repository.AccessoryRepository;
import org.springframework.transaction.annotation.Transactional;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.stream.Collectors;

@Service
@RequiredArgsConstructor
public class AccessoryService {
private final AccessoryRepository accessoryRepository;
private final AccessoryRepository accessoryRepository;

// 액세서리 전체 목록 조회
@Transactional(readOnly = true)
public List<AccessoryListResponseDto> list() {
return accessoryRepository.findAll().stream()
.map(AccessoryListResponseDto::new)
.collect(Collectors.toList());
}

// 액세서리 전체 목록 조회
@Transactional(readOnly = true)
public List<AccessoryListResponseDto> list() {
return accessoryRepository.findAll().stream()
.map(AccessoryListResponseDto::new)
.collect(Collectors.toList());
}
public Accessory read(Long id) {
return accessoryRepository.findById(id).orElseThrow();
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.endlesshorses.oot.custom.color.service;

import com.endlesshorses.oot.custom.color.dto.ColorListResponseDto;
import com.endlesshorses.oot.custom.color.entity.Color;
import com.endlesshorses.oot.custom.color.repository.ColorRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
Expand All @@ -21,4 +22,7 @@ public List<ColorListResponseDto> list() {
.collect(Collectors.toList());
}

public Color read(Long id) {
return colorRepository.findById(id).orElseThrow();
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.endlesshorses.oot.custom.font.service;

import com.endlesshorses.oot.custom.font.dto.FontListResponseDto;
import com.endlesshorses.oot.custom.font.entity.Font;
import com.endlesshorses.oot.custom.font.repository.FontRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
Expand All @@ -20,4 +21,8 @@ public List<FontListResponseDto> list() {
.map(FontListResponseDto::new)
.collect(Collectors.toList());
}

public Font read(Long id) {
return fontRepository.findById(id).orElseThrow();
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package com.endlesshorses.oot.custom.pattern.service;

import com.endlesshorses.oot.custom.pattern.dto.PatternListResponseDto;
import com.endlesshorses.oot.custom.pattern.entity.Pattern;
import com.endlesshorses.oot.custom.pattern.repository.PatternRepository;
import lombok.NoArgsConstructor;
import lombok.RequiredArgsConstructor;
import lombok.Setter;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

Expand All @@ -24,5 +23,9 @@ public List<PatternListResponseDto> list() {
.collect(Collectors.toList());
}

public Pattern read(Long id) {
return patternRepository.findById(id).orElseThrow();

}
}

Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.endlesshorses.oot.custom.result.controller;

import com.endlesshorses.oot.custom.result.dto.ResultResponseDTO;
import com.endlesshorses.oot.custom.result.dto.ResultGetResponseDto;
import com.endlesshorses.oot.custom.result.dto.ResultPostResponseDto;
import com.endlesshorses.oot.custom.result.dto.ResultRequestDto;
import com.endlesshorses.oot.custom.result.service.ResultService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
Expand All @@ -10,23 +12,40 @@
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;

@RestController
@RequiredArgsConstructor
@Tag(name = "Result", description = "타이어 커스텀 결과물 관련 API")
@RequestMapping("/api/results")
public class ResultController {
private final ResultService resultService;

@Operation(summary = "타이어 커스텀 결과물 조회 메서드", description = "클라이언트가 요청한 타이어 결과물 정보를 조회하기 위한 메서드")
@GetMapping("/{id}")
@ResponseBody
@ApiResponses({
@ApiResponse(responseCode = "200", description = "결과물 조회 성공"),
@ApiResponse(responseCode = "400", description = "잘못된 요청, UUID 형식이 아닌 id가 입력된 경우"),
@ApiResponse(responseCode = "404", description = "결과물을 찾을 수 없음, 주어진 id에 해당하는 결과물이 없는 경우"),
@ApiResponse(responseCode = "500", description = "서버 내부 오류"),
})
public ResponseEntity<ResultResponseDTO> read(@PathVariable String id) {
return ResponseEntity.ok(resultService.read(id));
}
private final ResultService resultService;

@Operation(summary = "타이어 커스텀 결과물 조회 메서드", description = "클라이언트가 요청한 타이어 결과물 정보를 조회하기 위한 메서드")
@GetMapping("/{id}")
@ResponseBody
@ApiResponses({
@ApiResponse(responseCode = "200", description = "결과물 조회 성공"),
@ApiResponse(responseCode = "400", description = "잘못된 요청, UUID 형식이 아닌 id가 입력된 경우"),
@ApiResponse(responseCode = "404", description = "결과물을 찾을 수 없음, 주어진 id에 해당하는 결과물이 없는 경우"),
@ApiResponse(responseCode = "500", description = "서버 내부 오류"),
})

public ResponseEntity<ResultGetResponseDto> read(@PathVariable String id) {
return ResponseEntity.ok(resultService.read(id));
}

@PostMapping
@Operation(summary = "타이어 커스텀 결과물 저장", description = "타이어 커스텀 결과물을 저장합니다.")
@ApiResponses({
@ApiResponse(responseCode = "200(202)", description = "정보 등록 요청"),
}) //ResultResponseDto를 프론트에게 ResponseEntity를 통해서 전달하겠다!
public ResponseEntity<ResultPostResponseDto> create(@RequestBody ResultRequestDto resultRequestDto) throws
IOException {
return ResponseEntity.ok(
resultService.create(resultRequestDto)
);
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package com.endlesshorses.oot.custom.result.dto;

import com.endlesshorses.oot.custom.accessory.enity.Accessory;
import com.endlesshorses.oot.custom.color.entity.Color;
import com.endlesshorses.oot.custom.font.entity.Font;
import com.endlesshorses.oot.custom.pattern.entity.Pattern;
import com.endlesshorses.oot.custom.result.entity.Result;
import com.endlesshorses.oot.custom.wheel.entity.Wheel;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.time.LocalDateTime;

@Getter
@NoArgsConstructor
public class ResultGetResponseDto {
private String id;

private Pattern pattern;

private Wheel wheel;

private Font font;

private Color color;

private Accessory accessory;

private LocalDateTime createdAt;

@Builder
public ResultGetResponseDto(Result result) {
this.id = result.getId();
this.pattern = result.getPattern();
this.wheel = result.getWheel();
this.font = result.getFont();
this.color = result.getColor();
this.accessory = result.getAccessory();
this.createdAt = result.getCreatedAt();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.endlesshorses.oot.custom.result.dto;

import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

@Getter
@Setter
@NoArgsConstructor
public class ResultPostResponseDto { //주는 DTO
private String id;

public ResultPostResponseDto(String id) {
this.id = id;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.endlesshorses.oot.custom.result.dto;

import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

@Setter
@Getter
@NoArgsConstructor
public
class ResultRequestDto { //요청 DTO
private Long patternId;
private Long wheelId;
private Long fontId;
private Long colorId;
private Long accessoryId;

@Builder
public ResultRequestDto(Long patternId, Long wheelId, Long fontId, Long colorId, Long accessoryId) {
this.patternId = patternId;
this.wheelId = wheelId;
this.fontId = fontId;
this.colorId = colorId;
this.accessoryId = accessoryId;
}

}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -22,41 +22,43 @@
@EntityListeners(AuditingEntityListener.class)
public class Result {

@Id
private String id;

@ManyToOne
@JoinColumn(name = "PATTERN_ID", nullable = false)
private Pattern pattern;

@ManyToOne
@JoinColumn(name = "WHEEL_ID", nullable = false)
private Wheel wheel;

@ManyToOne
@JoinColumn(name = "FONT_ID", nullable = false)
private Font font;

@ManyToOne
@JoinColumn(name = "FONT_COLOR_ID", nullable = false)
private Color color;

@ManyToOne
@JoinColumn(name = "ACCESSORY_ID")
private Accessory accessory;

@Column(nullable = false)
@CreatedDate
private LocalDateTime createdAt;

@Builder
public Result(String id, Pattern pattern, Wheel wheel, Font font, Color color, Accessory accessory) {
this.id = id;
this.pattern = pattern;
this.wheel = wheel;
this.font = font;
this.color = color;
this.accessory = accessory;
this.createdAt = LocalDateTime.now();
}
@Id
private String id;

@ManyToOne
@JoinColumn(name = "PATTERN_ID", nullable = false)
private Pattern pattern;

@ManyToOne
@JoinColumn(name = "WHEEL_ID", nullable = false)
private Wheel wheel;

@ManyToOne
@JoinColumn(name = "FONT_ID", nullable = false)
private Font font;

@ManyToOne
@JoinColumn(name = "FONT_COLOR_ID", nullable = false)
private Color color;

@ManyToOne
@JoinColumn(name = "ACCESSORY_ID")
private Accessory accessory;

@Column(nullable = false)
@CreatedDate
private LocalDateTime createdAt;

@Builder
public Result(String id, Pattern pattern, Wheel wheel, Font font, Color color, Accessory accessory) {
this.id = id;
this.pattern = pattern;
this.wheel = wheel;
this.font = font;
this.color = color;
this.accessory = accessory;
this.createdAt = LocalDateTime.now();
}


}
Loading
Loading