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

✨ feat: 알림 읽음 로직 추가 & 공고 카테고리 추가 #171

Merged
merged 5 commits into from
Feb 12, 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
5 changes: 5 additions & 0 deletions out/production/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,8 @@ spring:
profiles:
active: local
include: secret

servlet:
multipart:
max-file-size: 20MB
max-request-size: 20MB
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package com.sponus.sponusbe.domain.announcement.entity.enums;

public enum AnnouncementCategory {
IDEA, MARKETING, DESIGN, DEVELOPMENT, OTHER
IDEA, MARKETING, DESIGN, MEDIA, DEVELOPMENT, OTHER
}
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,8 @@ public void setAnnouncement(Announcement announcement) {
public void setPropose(Propose propose) {
this.propose = propose;
}

public void setRead(boolean read) {
isRead = read;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,12 @@ public ApiResponse<Void> deleteNotification(
organizationService.deleteNotification(organization, notificationId);
return ApiResponse.onSuccess(null);
}

@PostMapping("/notifications/{notificationId}")
public ApiResponse<Void> readNotification(
@AuthOrganization Organization organization,
@PathVariable("notificationId") Long notificationId) {
organizationService.readNotification(organization, notificationId);
return ApiResponse.onSuccess(null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,14 @@ public void deactivateOrganization(Long organizationId) {

public String sendEmail(String to) throws Exception {
String code = createEmailCode();
MimeMessage message = createMessage(to, code);
MimeMessage message = createEmail(to, code);
emailSender.send(message);
return code;
}

private MimeMessage createMessage(String to, String code) throws Exception {
System.out.println("보내는 대상 : " + to);
System.out.println("인증 코드 : " + code);
private MimeMessage createEmail(String to, String code) throws Exception {
log.info("보내는 대상 : " + to);
log.info("인증 코드 : " + code);
MimeMessage message = emailSender.createMimeMessage();
message.addRecipients(MimeMessage.RecipientType.TO, to); // 보내는 대상
message.setSubject("Spon-us 인증 코드 발급입니다."); // 제목
Expand All @@ -87,22 +87,21 @@ private MimeMessage createMessage(String to, String code) throws Exception {
}

public static String createEmailCode() {
StringBuffer code = new StringBuffer();
StringBuilder code = new StringBuilder();
Random rnd = new Random();

for (int i = 0; i < 8; i++) { // 비밀번호 8자리
for (int i = 0; i < 6; i++) { // 인증 코드 6자리
int index = rnd.nextInt(3); // 0~2 까지 랜덤

switch (index) {
case 0:
code.append((char)((int)(rnd.nextInt(26)) + 97));
code.append((char)((rnd.nextInt(26)) + 97));
// a~z (ex. 1+97=98 => (char)98 = 'b')
break;
case 1:
code.append((char)((int)(rnd.nextInt(26)) + 65));
code.append((char)((rnd.nextInt(26)) + 65));
// A~Z
break;
case 2:
default:
code.append((rnd.nextInt(10)));
// 0~9
break;
Expand All @@ -126,4 +125,13 @@ public void deleteNotification(Organization organization, Long notificationId) {
}
notificationRepository.delete(notification);
}

public void readNotification(Organization organization, Long notificationId) {
Notification notification = notificationRepository.findById(notificationId)
.orElseThrow(() -> new NotificationException(NotificationErrorCode.NOTIFICATION_NOT_FOUND));
if (!notification.getOrganization().getId().equals(organization.getId())) {
throw new NotificationException(NotificationErrorCode.INVALID_ORGANIZATION);
}
notification.setRead(true);
}
}
1 change: 1 addition & 0 deletions src/main/java/com/sponus/sponusbe/domain/s3/S3Service.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public String uploadFile(MultipartFile file) {
UUID.randomUUID() + file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf("."));
ObjectMetadata metadata = new ObjectMetadata();
metadata.setContentLength(file.getSize());
log.info("[*] File Size : {}", file.getSize());
try {
amazonS3.putObject(
new PutObjectRequest(s3Config.getBucket(), s3Config.getFolder() + filePath, file.getInputStream(),
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ spring:
servlet:
multipart:
max-file-size: 20MB
max-request-size: 20MB
Loading