Skip to content

Commit

Permalink
[fix] conflict 해결
Browse files Browse the repository at this point in the history
  • Loading branch information
gardening-y committed Jul 15, 2024
2 parents 30c6d45 + d80b989 commit 859592f
Show file tree
Hide file tree
Showing 10 changed files with 337 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.ConfigurationPropertiesScan;

@SpringBootApplication
public class DateroadApplication {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
package org.dateroad.advertisement.api;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.ExampleObject;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.dateroad.advertisement.dto.response.AdvGetAllRes;
import org.dateroad.advertisement.dto.response.AdvGetDetailRes;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PathVariable;

@Tag(name = "광고 관련 API")
@SecurityRequirement(name = "Authorization")
public interface AdvertisementApi {
@Operation(
summary = "광고 전체 조회 API",
responses = {
@ApiResponse(
responseCode = "200",
content = @Content(
schema = @Schema(implementation = AdvGetAllRes.class),
examples = @ExampleObject(value = """
{
"advertismentDtoResList": [
{
"advertismentId": 1,
"thumbnail": "http://example.com/thumbnail1.jpg",
"title": "광고 제목 1",
},
{
"advertismentId": 2,
"thumbnail": "http://example.com/thumbnail2.jpg",
"title": "광고 제목 2",
},
{
"advertismentId": 3,
"thumbnail": "http://example.com/thumbnail2.jpg",
"title": "광고 제목 3",
},
{
"advertismentId": 4,
"thumbnail": "http://example.com/thumbnail2.jpg",
"title": "광고 제목 4",
}
]
}
""")
),
description = "요청이 성공했습니다."
),
@ApiResponse(
responseCode = "400",
description = "잘못된 요청입니다.",
content = @Content),
@ApiResponse(
responseCode = "401",
description = "액세스 토큰의 형식이 올바르지 않습니다. Bearer 타입을 확인해 주세요.",
content = @Content),
@ApiResponse(
responseCode = "401",
description = "액세스 토큰의 값이 올바르지 않습니다.",
content = @Content),
@ApiResponse(
responseCode = "401",
description = "액세스 토큰이 만료되었습니다. 재발급 받아주세요.",
content = @Content),
@ApiResponse(
responseCode = "405",
description = "잘못된 HTTP method 요청입니다.",
content = @Content),
@ApiResponse(
responseCode = "500",
description = "서버 내부 오류입니다.",
content = @Content)})
ResponseEntity<AdvGetAllRes> getAllAdvertisements();

@Operation(
summary = "광고 상세 조회 API",
responses = {
@ApiResponse(
responseCode = "200",
content = @Content(
schema = @Schema(implementation = AdvGetDetailRes.class),
examples = @ExampleObject(value = """
{
"images": [
{
"imagesUrl": "http://example.com/image1.jpg",
"sequence": 1
},
{
"imagesUrl": "http://example.com/image2.jpg",
"sequence": 2
}
],
"title": "광고 제목",
"createAt": "2023.07.14",
"description": "광고 설명"
}
""")
),
description = "요청이 성공했습니다."
),
@ApiResponse(
responseCode = "400",
description = "잘못된 요청입니다.",
content = @Content),
@ApiResponse(
responseCode = "400",
description = "유효하지 않은 요청 파라미터 값입니다.",
content = @Content),
@ApiResponse(
responseCode = "401",
description = "액세스 토큰의 형식이 올바르지 않습니다. Bearer 타입을 확인해 주세요.",
content = @Content),
@ApiResponse(
responseCode = "401",
description = "액세스 토큰의 값이 올바르지 않습니다.",
content = @Content),
@ApiResponse(
responseCode = "401",
description = "액세스 토큰이 만료되었습니다. 재발급 받아주세요.",
content = @Content),

@ApiResponse(
responseCode = "404",
description = "존재하지 않는 광고입니다.",
content = @Content),
@ApiResponse(
responseCode = "405",
description = "잘못된 HTTP method 요청입니다.",
content = @Content),
@ApiResponse(
responseCode = "500",
description = "서버 내부 오류입니다.",
content = @Content)})
ResponseEntity<AdvGetDetailRes> getAdvertisementsDetail(
@Parameter(required = true) final @PathVariable Long advId
);
}
88 changes: 88 additions & 0 deletions dateroad-api/src/main/java/org/dateroad/point/api/PointApi.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
package org.dateroad.point.api;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.ExampleObject;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.dateroad.auth.argumentresolve.UserId;
import org.dateroad.point.dto.response.PointGetAllRes;
import org.springframework.http.ResponseEntity;

@Tag(name = "포인트 관련 API")
@SecurityRequirement(name = "Authorization")
public interface PointApi {
@Operation(
summary = "포인트 내역 조회 API",
responses = {
@ApiResponse(
responseCode = "200",
content = @Content(
schema = @Schema(implementation = PointGetAllRes.class),
examples = @ExampleObject(value = """
{
"gained": {
"points": [
{
"point": 100,
"description": "첫 구매 적립",
"createdAt": "2023.07.14"
},
{
"point": 200,
"description": "리뷰 작성 적립",
"createdAt": "2023.07.15"
}
]
},
"used": {
"points": [
{
"point": 50,
"description": "구매 사용",
"createdAt": "2023.07.16"
},
{
"point": 80,
"description": "이벤트 참여 사용",
"createdAt": "2023.07.17"
}
]
}
}
""")
),
description = "요청이 성공했습니다."
),
@ApiResponse(
responseCode = "400",
description = "잘못된 요청입니다.",
content = @Content),
@ApiResponse(
responseCode = "401",
description = "액세스 토큰의 형식이 올바르지 않습니다. Bearer 타입을 확인해 주세요.",
content = @Content),
@ApiResponse(
responseCode = "401",
description = "액세스 토큰의 값이 올바르지 않습니다.",
content = @Content),
@ApiResponse(
responseCode = "401",
description = "액세스 토큰이 만료되었습니다. 재발급 받아주세요.",
content = @Content),
@ApiResponse(
responseCode = "405",
description = "잘못된 HTTP method 요청입니다.",
content = @Content),
@ApiResponse(
responseCode = "500",
description = "서버 내부 오류입니다.",
content = @Content)})
public ResponseEntity<PointGetAllRes> getAllPoints(
@Parameter(required = true)
@UserId Long userId
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import java.io.IOException;
import java.util.List;
import java.util.concurrent.ExecutionException;

import static org.dateroad.common.Constants.AUTHORIZATION;

Expand Down Expand Up @@ -80,4 +81,15 @@ public ResponseEntity<UserInfoGetMyPageRes> getUserInfoMyPage(@UserId final Long
UserInfoGetMyPageRes userInfoGetMyPageRes = userService.getUserInfoMyPage(userId);
return ResponseEntity.ok(userInfoGetMyPageRes);
}

@PatchMapping
public ResponseEntity<Void> patchUserProfile(@UserId final Long userId,
@RequestPart("name") final String name,
@RequestPart("tags") final List<DateTagType> tags,
@RequestPart("image") final MultipartFile image ) throws IOException, ExecutionException, InterruptedException {
userService.editUserProfile(userId, name, tags, image);
return ResponseEntity
.ok()
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,87 @@

import lombok.RequiredArgsConstructor;
import org.dateroad.code.FailureCode;
import org.dateroad.exception.BadRequestException;
import org.dateroad.exception.EntityNotFoundException;
import org.dateroad.s3.S3Service;
import org.dateroad.tag.domain.DateTagType;
import org.dateroad.tag.domain.UserTag;
import org.dateroad.tag.repository.UserTagRepository;
import org.dateroad.user.domain.User;
import org.dateroad.user.dto.response.UserInfoGetMyPageRes;
import org.dateroad.user.dto.response.UserInfoMainRes;
import org.dateroad.user.repository.UserRepository;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.List;

import java.util.concurrent.ExecutionException;

@Service
@Transactional(readOnly = true)
@RequiredArgsConstructor
public class UserService {

@Value("${aws-property.s3-bucket-name}")
private String path;

@Value("${cloudfront.domain}")
private String cachePath;
private final UserRepository userRepository;
private final UserTagRepository userTagRepository;
private final S3Service s3Service;

public UserInfoGetMyPageRes getUserInfoMyPage(final Long userId) {
User foundUser = findUserById(userId);
List<UserTag> userTags= userTagRepository.findAllByUserId(userId);
List<DateTagType> dateTagTypes =
userTags
.stream()
.map(UserTag::getDateTagType)
.toList();
.stream()
.map(UserTag::getDateTagType)
.toList();

return UserInfoGetMyPageRes.of(foundUser.getName(), dateTagTypes, foundUser.getTotalPoint(), foundUser.getImageUrl());
}

@Transactional
public void editUserProfile(final Long userId,
final String name,
final List<DateTagType> tags,
final MultipartFile newImage) throws IOException, ExecutionException, InterruptedException {
User foundUser = findUserById(userId);

//이름 변경
foundUser.setName(name);

//tag 변경
userTagRepository.deleteAllByUserId(foundUser.getId());
saveUserTag(foundUser, tags);

//이미지 변경
String userImage = foundUser.getImageUrl();

// 1. 원래 이미지가 있다가 null로 변경
if (userImage != null && newImage == null) {
deleteImage(userImage);
foundUser.setImageUrl(null);

// 2. 원래 이미지가 있다가 새로운 이미지로 변경
} else if (userImage != null && newImage != null) {
deleteImage(userImage);
String newImageUrl = uploadImage(newImage);
foundUser.setImageUrl(newImageUrl);

// 3. 원래 이미지가 없다가 새로운 이미지로 변경
} else if (userImage == null && newImage != null) {
String newImageUrl = uploadImage(newImage);
foundUser.setImageUrl(newImageUrl);
}
userRepository.save(foundUser);
}

public UserInfoMainRes getUserInfoMain(final Long userId) {
User foundUser = findUserById(userId);
return UserInfoMainRes.of(foundUser.getName(), foundUser.getTotalPoint(), foundUser.getImageUrl());
Expand All @@ -44,4 +92,28 @@ private User findUserById(final Long userId) {
return userRepository.findById(userId)
.orElseThrow(() -> new EntityNotFoundException(FailureCode.USER_NOT_FOUND));
}

//유저 태그 수정
public void saveUserTag(final User savedUser, final List<DateTagType> userTags) {
List<UserTag> list = userTags.stream()
.map(dateTagType -> UserTag.create(savedUser, dateTagType))
.toList();
userTagRepository.saveAll(list);
}

private void deleteImage(final String imageUrl) {
try {
s3Service.deleteImage(imageUrl);
} catch (IOException e) {
throw new BadRequestException(FailureCode.WRONG_IMAGE_URL);
}
}

private String uploadImage(final MultipartFile newImage) {
try {
return cachePath + s3Service.uploadImage(path, newImage).get();
} catch (IOException | InterruptedException | ExecutionException e) {
throw new BadRequestException(FailureCode.WRONG_IMAGE_URL);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ public enum FailureCode {
*/
BAD_REQUEST(HttpStatus.BAD_REQUEST, "e4000", "잘못된 요청입니다."),
INVALID_PLATFORM_TYPE(HttpStatus.BAD_REQUEST, "e4001", "잘못된 플랫폼 타입입니다."),
WRONG_USER_TAG_SIZE(HttpStatus.BAD_REQUEST, "e4002", "유저 태그 개수가 0이거나 3보다 많습니다."),
WRONG_USER_TAG_SIZE(HttpStatus.BAD_REQUEST, "e4002", "유저 태그 개수가 0이거나 3보다 많습니다.."),
INVALID_IMAGE_TYPE(HttpStatus.BAD_REQUEST, "e4003", "지원하지 않는 이미지 확장자 입니다."),
INVALID_IMAGE_SIZE(HttpStatus.BAD_REQUEST, "e4004", "지원하지 않는 이미지 크기 입니다."),

WRONG_IMAGE_URL(HttpStatus.BAD_REQUEST, "e4005", "잘못된 이미지 URL 입니다."),

/**
* 401 Unauthorized
Expand Down
Loading

0 comments on commit 859592f

Please sign in to comment.