Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…into dev
  • Loading branch information
SUMMERLOVE7 committed Feb 22, 2023
2 parents 71004b6 + f8c517f commit 57e603a
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,15 @@ public class AuthorizationAop {
@Before("within(@com.amatta.amatta_server.aop.ClassRequiresAuth *)")
public void authorizeClass() throws NotAuthenticatedException, NullPointerException {
logger.info("AuthorizationAop.authorize");
//TODO: 테스트 후 복구!!!
/*HttpServletRequest request = ((ServletRequestAttributes) Objects.requireNonNull(RequestContextHolder.getRequestAttributes())).getRequest();
HttpServletRequest request = ((ServletRequestAttributes) Objects.requireNonNull(RequestContextHolder.getRequestAttributes())).getRequest();
HttpSession session = request.getSession(false);
if(session == null) {
throw new NotAuthenticatedException();
}
Users user = (Users) session.getAttribute("User");
if(user == null) {
throw new NotAuthenticatedException();
}*/
}
}

@Before("@annotation(com.amatta.amatta_server.aop.MethodRequiresAuth)")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public ResponseEntity<?> gifticonList(@RequestParam(name = "keyword", required =

@GetMapping("/used")
public ResponseEntity<?> usedGifticonList() {
return new ResponseEntity<>(gifticonService.usedTest(), HttpStatus.OK);
return new ResponseEntity<>(gifticonService.usedGifticonList(), HttpStatus.OK);
}

@PutMapping("/used")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,11 @@ public Gifticon mapTextToGifticon(GifticonTextDto dto) throws GifticonParseExcep

@Transactional
public void addGifticon(GifticonDto dto, MultipartFile image, MultipartFile thumbnail) throws DuplicateGifticonException, IOException {
long uid = 2;
Users user = getUserBySessionId();
if(user == null) {
throw new NotAuthenticatedException();
}
long uid = user.getId();
String brandName = dto.getBrandName();
String itemName = dto.getItemName();
String barcode = dto.getBarcode();
Expand All @@ -84,32 +88,13 @@ public void addGifticon(GifticonDto dto, MultipartFile image, MultipartFile thum
if(gifticonRepository.findByBarcode(barcode).isPresent()) {
throw new DuplicateGifticonException();
}
String originalName = String.valueOf(System.currentTimeMillis()); // 파일 이름
long size = image.getSize(); // 파일 크기
ObjectMetadata objectMetaData = new ObjectMetadata();
objectMetaData.setContentType(image.getContentType());
objectMetaData.setContentLength(size);
amazonS3Client.putObject(
new PutObjectRequest(S3Bucket, originalName, image.getInputStream(), objectMetaData)
.withCannedAcl(CannedAccessControlList.PublicRead)
);
String imagePath = amazonS3Client.getUrl(S3Bucket, originalName).toString();

String originalName2 = String.valueOf(System.currentTimeMillis()); // 파일 이름
long size2 = thumbnail.getSize(); // 파일 크기
ObjectMetadata objectMetaData2 = new ObjectMetadata();
objectMetaData2.setContentType(thumbnail.getContentType());
objectMetaData2.setContentLength(size2);
amazonS3Client.putObject(
new PutObjectRequest(S3Bucket, originalName2, thumbnail.getInputStream(), objectMetaData2)
.withCannedAcl(CannedAccessControlList.PublicRead)
);
String imagePath2 = amazonS3Client.getUrl(S3Bucket, originalName2).toString();
String imagePath = sendToS3(image, String.valueOf(System.currentTimeMillis()));
String thumbnailPath = sendToS3(thumbnail, String.valueOf(System.currentTimeMillis()));

gifticonRepository.addGifticon(
uid,
imagePath,
imagePath2,
thumbnailPath,
brandName,
itemName,
barcode,
Expand Down Expand Up @@ -156,6 +141,18 @@ private Users getUserBySessionId() {
return (Users) session.getAttribute("User");
}

private String sendToS3(MultipartFile image, String name) throws IOException {
long size = image.getSize();
ObjectMetadata objectMetaData = new ObjectMetadata();
objectMetaData.setContentType(image.getContentType());
objectMetaData.setContentLength(size);
amazonS3Client.putObject(
new PutObjectRequest(S3Bucket, name, image.getInputStream(), objectMetaData)
.withCannedAcl(CannedAccessControlList.PublicRead)
);
return amazonS3Client.getUrl(S3Bucket, name).toString();
}

public List<Gifticon> test(String keyword) {
return gifticonRepository.test(keyword);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.MethodArgumentNotValidException;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
Expand Down Expand Up @@ -85,12 +83,11 @@ public ResponseEntity<?> findPasswordByEmail(@RequestBody UserFindPasswordByEmai
}

@GetMapping("/mypage")
public ResponseEntity<?> mypage(/*@SessionAttribute(value = "User", required = false) Users user*/) {
// if (Objects.isNull(user)) {
// return new ResponseEntity<>(new UserMypageRes(false), HttpStatus.UNAUTHORIZED);
// }
return new ResponseEntity<>(new UserMypageRes(true, "[email protected]", "testPassword", "test", "010-0000-0000"), HttpStatus.OK);
// return new ResponseEntity<>(new UserMypageRes(true, user.getEmail(), user.getPassword(), user.getName(), user.getPhoneNumber()), HttpStatus.OK);
public ResponseEntity<?> mypage(@SessionAttribute(value = "User", required = false) Users user) {
if (Objects.isNull(user)) {
return new ResponseEntity<>(new UserMypageRes(false), HttpStatus.UNAUTHORIZED);
}
return new ResponseEntity<>(new UserMypageRes(true, user.getEmail(), user.getPassword(), user.getName(), user.getPhoneNumber()), HttpStatus.OK);
}

@PutMapping("/password")
Expand Down

0 comments on commit 57e603a

Please sign in to comment.