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

Feature/84 artwork more info #98

Merged
merged 11 commits into from
Jan 18, 2023
Merged
Show file tree
Hide file tree
Changes from 6 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
17 changes: 16 additions & 1 deletion src/main/java/com/sptp/backend/art_work/repository/ArtWork.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class ArtWork extends BaseEntity {

private String material;

private String size;
private Integer productionYear;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

λ³€κ²½λœ ν•„λ“œλŠ” erd에 λ°˜μ˜ν•΄μ£Όμ„Έμš”!!


private Integer price;

Expand All @@ -43,4 +43,19 @@ public class ArtWork extends BaseEntity {
private String guaranteeImage;

private String mainImage;

private Integer width;

private Integer length;

private Integer height;

private Integer size;

private boolean frame;

private String genre;

private String description;

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.sptp.backend.art_work.repository.ArtWork;
import com.sptp.backend.art_work.repository.ArtWorkRepository;
import com.sptp.backend.art_work.web.dto.request.ArtWorkSaveRequestDto;
import com.sptp.backend.art_work.web.dto.response.ArtWorkInfoResponseDto;
import com.sptp.backend.art_work_image.repository.ArtWorkImage;
import com.sptp.backend.art_work_image.repository.ArtWorkImageRepository;
import com.sptp.backend.art_work_keyword.repository.ArtWorkKeyword;
Expand All @@ -21,7 +22,10 @@
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.List;
import java.util.Optional;
import java.util.UUID;
import java.util.stream.Collectors;

@Service
@RequiredArgsConstructor
Expand Down Expand Up @@ -52,12 +56,19 @@ public void saveArtWork(Long loginMemberId, ArtWorkSaveRequestDto dto) throws IO
.member(findMember)
.title(dto.getTitle())
.material(dto.getMaterial())
.size(dto.getSize())
.price(dto.getPrice())
.status(dto.getStatus())
.statusDescription(dto.getStatusDescription())
.guaranteeImage(GuaranteeImageUUID + "." + GuaranteeImageEXT)
.mainImage(mainImageUUID + "." + mainImageEXT)
.genre(dto.getGenre())
.size(dto.getSize())
.height(dto.getHeight())
.length(dto.getLength())
.width(dto.getWidth())
.frame(dto.isFrame())
.description(dto.getDescription())
.productionYear(dto.getProductionYear())
.build();

artWorkRepository.save(artWork);
Expand Down Expand Up @@ -104,4 +115,38 @@ public void checkExistsImage(ArtWorkSaveRequestDto dto) {
throw new CustomException(ErrorCode.SHOULD_EXIST_IMAGE);
}
}

public ArtWorkInfoResponseDto getArtWork(Long artWorkId) {

ArtWork findArtWork = artWorkRepository.findById(artWorkId)
.orElseThrow(() -> new CustomException(ErrorCode.NOT_FOUND_ARTWORK));

Member findArtist = memberRepository.findById(findArtWork.getMember().getId())
.orElseThrow(() -> new CustomException(ErrorCode.NOT_FOUND_ARTIST));

List<ArtWorkImage> artWorkImages = artWorkImageRepository.findByArtWorkId(artWorkId);
List<ArtWorkKeyword> artWorkKeywords = artWorkKeywordRepository.findByArtWorkId(artWorkId);

ArtWorkInfoResponseDto artWorkInfoResponseDto = ArtWorkInfoResponseDto.builder()
.title(findArtWork.getTitle())
.artistName(findArtist.getNickname())
.artistEducation(findArtist.getEducation())
.productionYear(findArtWork.getProductionYear())
.material(findArtWork.getMaterial())
.genre(findArtWork.getGenre())
.frame(findArtWork.isFrame())
.width(findArtWork.getWidth())
.height(findArtWork.getHeight())
.length(findArtWork.getLength())
.size(findArtWork.getSize())
.description(findArtWork.getDescription())
.guaranteeImage(findArtWork.getGuaranteeImage())
.mainImage(findArtWork.getMainImage())
.artistImage(findArtist.getImage())
.images(artWorkImages.stream().map(m -> m.getImage()).collect(Collectors.toList()))
.keywords(artWorkKeywords.stream().map(m->KeywordMap.getKeywordName(m.getKeywordId())).collect(Collectors.toList()))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

μœΌμ–΄ κΈ°λ„€μš”. ν˜Ήμ‹œ μ œκ°€ μž‘μ„±ν•œ ChatRoomDetailResponse λ‚΄λΆ€ 클래슀의 from()처럼 좔상화 ν•˜λŠ” 방법은 μ–΄λ–»κ²Œ μƒκ°ν•˜μ‹œλ‚˜μš”! μ˜κ²¬μ„ μ£Όκ³ λ°›κ³  μ‹ΆμŠ΅λ‹ˆλ‹Ή

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

μ•„ λ§μ”€ν•˜μ‹  λΆ€λΆ„ μ°Έκ³ ν•΄μ„œ μˆ˜μ •ν•΄λ³΄κ² μŠ΅λ‹ˆλ‹€!

.build();

return artWorkInfoResponseDto;
}
}
12 changes: 12 additions & 0 deletions src/main/java/com/sptp/backend/art_work/web/ArtWorkController.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@

import com.sptp.backend.art_work.service.ArtWorkService;
import com.sptp.backend.art_work.web.dto.request.ArtWorkSaveRequestDto;
import com.sptp.backend.art_work.web.dto.response.ArtWorkInfoResponseDto;
import com.sptp.backend.jwt.service.dto.CustomUserDetails;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

Expand All @@ -27,4 +30,13 @@ public ResponseEntity<Void> saveArtWork(@AuthenticationPrincipal CustomUserDetai

return new ResponseEntity(HttpStatus.OK);
}

// μž‘ν’ˆ 상세 쑰회
@GetMapping("/art-work/{artWorkId}")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/art-worksκ°€ μ•„λ‹Œ /art-work둜 ν•˜μ‹  μ˜λ„κ°€ μžˆμœΌμ‹€κΉŒμš©

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

κΈ°μ‘΄ μž‘ν’ˆλ“±λ‘μ΄ /art-work λ‹€ λ³΄λ‹ˆ 상세 λ˜ν•œ μ΄λ ‡κ²Œ μž‘μ„± ν•œκ±΄λ°,
νšŒμ› κ΄€λ ¨ end point도 /membersλ‹€ λ³΄λ‹ˆκΉŒ /art-works둜 ν†΅μΌν•˜λŠ”κ²Œ λ§žλŠ”κ²ƒ κ°™μŠ΅λ‹ˆλ‹€

public ResponseEntity<ArtWorkInfoResponseDto> getArtWork(@PathVariable("artWorkId") Long artWorkId) {

ArtWorkInfoResponseDto artWorkInfoResponseDto = artWorkService.getArtWork(artWorkId);

return ResponseEntity.status(HttpStatus.OK).body(artWorkInfoResponseDto);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.sptp.backend.art_work.web.dto.request;

import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.*;
import org.springframework.web.multipart.MultipartFile;

Expand All @@ -14,10 +15,17 @@ public class ArtWorkSaveRequestDto {
private MultipartFile guaranteeImage;
private String title;
private String[] keywords;
private String productionYear;
private Integer productionYear;
private String material;
private String size;
private Integer price;
private String status;
private String statusDescription;
private Integer width;
private Integer length;
private Integer height;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

응집도 높은 ν•„λ“œλ“€μ€ 객체둜 λ¬Άκ³ , @Embeddedλ₯Ό ν™œμš©ν•˜λ©΄ 쒋을 것 κ°™μ•„μš”!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

λ„΅ ν†΅ν•©λœ 객체둜 κ΄€λ¦¬ν•˜λŠ”κ²Œ λ§žλŠ”κ²ƒ κ°™λ„€μš©

private Integer size;
private boolean frame;
private String genre;
private Integer price;
private String description;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.sptp.backend.art_work.web.dto.response;

import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.*;

import java.util.List;

@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class ArtWorkInfoResponseDto {

private String title;
private String artistEducation;
private String artistName;
private Integer productionYear;
private String material;
private String genre;
private boolean frame;
private Integer width;
private Integer length;
private Integer height;
private Integer size;
private String description;

private String guaranteeImage;
private String mainImage;
private String artistImage;
private List<String> keywords;
private List<String> images;

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

import org.springframework.data.jpa.repository.JpaRepository;

import java.util.List;

public interface ArtWorkImageRepository extends JpaRepository<ArtWorkImage, Long> {

List<ArtWorkImage> findByArtWorkId(Long artWorkId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

import org.springframework.data.jpa.repository.JpaRepository;

import java.util.List;

public interface ArtWorkKeywordRepository extends JpaRepository<ArtWorkKeyword, Long> {

List<ArtWorkKeyword> findByArtWorkId(Long artWorkId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ public interface MemberRepository extends JpaRepository<Member, Long> {
boolean existsByUserId(String userId);

boolean existsByNickname(String nickname);

}
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
package com.sptp.backend.member.web;
import com.sptp.backend.common.BaseControllerTest;
import com.sptp.backend.member.repository.Member;
import com.sptp.backend.member.service.MemberService;
import com.sptp.backend.member.web.dto.request.MemberLoginRequestDto;
import com.sptp.backend.member.web.dto.request.MemberSaveRequestDto;
import com.sptp.backend.member.web.dto.response.MemberLoginResponseDto;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.security.test.context.support.WithUserDetails;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.ResultActions;
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
import org.springframework.test.web.servlet.result.MockMvcResultHandlers;
import org.springframework.test.web.servlet.result.MockMvcResultMatchers;


import javax.annotation.PostConstruct;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.List;
Expand All @@ -40,7 +38,7 @@ class MemberControllerTest extends BaseControllerTest {
MemberService memberService;

// 인증 ν•„μš”ν•œ api ν…ŒμŠ€νŠΈ μ‹œ ν•΄λ‹Ή μœ μ € 정보 μ‚¬μš©
@PostConstruct
@BeforeEach
void settingAuthenticatedUser() {

MemberSaveRequestDto dto = MemberSaveRequestDto.builder()
Expand Down Expand Up @@ -126,12 +124,16 @@ void memberLoginTest() throws Exception {

@Test
@DisplayName("νšŒμ› 정보 쑰회 ν…ŒμŠ€νŠΈ")
@WithUserDetails(value = "test2")
public void getUserInfo() throws Exception {

//given
MemberLoginRequestDto dto = MemberLoginRequestDto.builder().userId("test2").password("test1234").build();
MemberLoginResponseDto token = memberService.login(dto);

//when
ResultActions resultActions = mockMvc.perform(
MockMvcRequestBuilders.get("/members/me")
.header("Authorization", token.getAccessToken())
.contentType(MediaType.APPLICATION_JSON)
.characterEncoding(StandardCharsets.UTF_8)
.accept(MediaType.APPLICATION_JSON)
Expand All @@ -152,5 +154,4 @@ public void getUserInfo() throws Exception {
.andExpect(MockMvcResultMatchers.jsonPath("$.keywords[4]").value("μ„Έλ ¨λœ"));
}


}
6 changes: 6 additions & 0 deletions src/test/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ spring:
host: localhost
port: ${application.spring.redis.port}

datasource:
url: ${application.spring.datasource.url}
username: ${application.spring.datasource.username}
password: ${application.spring.datasource.password}
driver-class-name: com.mysql.cj.jdbc.Driver
Copy link
Contributor

@JunYoung-C JunYoung-C Jan 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

datasourceλ₯Ό μƒλž΅ν•˜λ©΄ h2 inmemory λͺ¨λ“œλ‘œ μžλ™μœΌλ‘œ λ™μž‘ν•˜λŠ” κ²ƒμœΌλ‘œ μ•Œκ³ μžˆμŠ΅λ‹ˆλ‹€. ν˜Ήμ‹œ μ €λ ‡κ²Œ μΆ”κ°€ν•˜λ©΄ mysql둜 λ™μž‘ν•˜κ³ , 둜컬 mysql db와 데이터 좩돌이 λ°œμƒν•  수 μžˆμ§€ μ•Šλ‚˜μš©??

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

μ•„μ•„ λ„΅. 이 뢀뢄은 μ œκ°€ μˆ™μ§€λ₯Ό λͺ»ν•΄μ„œ μˆ˜μ •ν•΄μ„œ μ˜¬λ¦¬κ² μŠ΅λ‹ˆλ‹€!


jpa:
hibernate:
ddl-auto: create
Expand Down