-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
…tion [Feat]: Notification 모집알림 기능 v2 API 마이그레이션 작업
- Loading branch information
Showing
9 changed files
with
225 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
src/main/java/sopt/org/homepage/notification/NotificationController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package sopt.org.homepage.notification; | ||
|
||
import io.swagger.v3.oas.annotations.tags.Tag; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springdoc.core.annotations.ParameterObject; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.*; | ||
import sopt.org.homepage.notification.dto.GetNotificationListRequestDto; | ||
import sopt.org.homepage.notification.dto.GetNotificationListResponseDto; | ||
import sopt.org.homepage.notification.dto.RegisterNotificationRequestDto; | ||
import sopt.org.homepage.notification.dto.RegisterNotificationResponseDto; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("notification") | ||
@Tag(name = "Notification") | ||
public class NotificationController { | ||
private final NotificationService notificationService; | ||
|
||
@PostMapping("register") | ||
public ResponseEntity<RegisterNotificationResponseDto> registerNotification ( | ||
@ParameterObject @ModelAttribute RegisterNotificationRequestDto registerNotificationRequestDto | ||
) { | ||
RegisterNotificationResponseDto result = notificationService.registerNotification(registerNotificationRequestDto); | ||
return ResponseEntity.status(HttpStatus.CREATED).body(result); | ||
} | ||
@GetMapping("/list") | ||
public ResponseEntity<GetNotificationListResponseDto> getAllProject ( | ||
@ParameterObject @ModelAttribute GetNotificationListRequestDto getNotificationListRequestDto | ||
) { | ||
GetNotificationListResponseDto result = notificationService.getNotificationEmailList(getNotificationListRequestDto.getGeneration()); | ||
return ResponseEntity.status(HttpStatus.OK).body(result); | ||
} | ||
} | ||
|
||
|
6 changes: 5 additions & 1 deletion
6
...g/homepage/entity/NotificationEntity.java → ...page/notification/NotificationEntity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
src/main/java/sopt/org/homepage/notification/NotificationRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package sopt.org.homepage.notification; | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
import java.util.List; | ||
|
||
public interface NotificationRepository extends JpaRepository<NotificationEntity, Integer> { | ||
NotificationEntity findByEmailAndGeneration(String email, int generation); | ||
|
||
List<NotificationEntity> findByGeneration(int generation); | ||
} |
56 changes: 56 additions & 0 deletions
56
src/main/java/sopt/org/homepage/notification/NotificationService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package sopt.org.homepage.notification; | ||
|
||
import jakarta.transaction.Transactional; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.web.server.ResponseStatusException; | ||
import sopt.org.homepage.notification.dto.GetNotificationListResponseDto; | ||
import sopt.org.homepage.notification.dto.RegisterNotificationRequestDto; | ||
import sopt.org.homepage.notification.dto.RegisterNotificationResponseDto; | ||
|
||
import java.sql.Timestamp; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
@RequiredArgsConstructor | ||
@Service | ||
public class NotificationService { | ||
private final NotificationRepository notificationRepository; | ||
|
||
@Transactional | ||
public RegisterNotificationResponseDto registerNotification(RegisterNotificationRequestDto registerNotificationRequestDto) { | ||
NotificationEntity existingNotification = notificationRepository.findByEmailAndGeneration( | ||
registerNotificationRequestDto.getEmail(), registerNotificationRequestDto.getGeneration() | ||
); | ||
|
||
if (existingNotification != null) { | ||
throw new ResponseStatusException(HttpStatus.BAD_REQUEST, | ||
"Already Registered Email: " + registerNotificationRequestDto.getEmail()); | ||
} | ||
|
||
NotificationEntity notification = new NotificationEntity(); | ||
notification.setGeneration(registerNotificationRequestDto.getGeneration()); | ||
notification.setEmail(registerNotificationRequestDto.getEmail()); | ||
notification.setCreatedAt(new Timestamp(System.currentTimeMillis())); | ||
|
||
NotificationEntity savedNotification = notificationRepository.save(notification); | ||
|
||
return new RegisterNotificationResponseDto( | ||
savedNotification.getId(), | ||
savedNotification.getGeneration(), | ||
savedNotification.getEmail(), | ||
savedNotification.getCreatedAt() | ||
); | ||
} | ||
|
||
public GetNotificationListResponseDto getNotificationEmailList(int generation) { | ||
List<String> emailList = notificationRepository.findByGeneration(generation).stream() | ||
.map(NotificationEntity::getEmail) | ||
.collect(Collectors.toList()); | ||
|
||
return new GetNotificationListResponseDto(generation, emailList); | ||
} | ||
|
||
|
||
} |
19 changes: 19 additions & 0 deletions
19
src/main/java/sopt/org/homepage/notification/dto/GetNotificationListRequestDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package sopt.org.homepage.notification.dto; | ||
|
||
import io.swagger.v3.oas.annotations.Parameter; | ||
import lombok.Getter; | ||
import org.springframework.validation.annotation.Validated; | ||
|
||
@Validated | ||
@Getter | ||
public class GetNotificationListRequestDto { | ||
|
||
@Parameter(description = "기수") | ||
private final Integer generation; | ||
|
||
public GetNotificationListRequestDto(Integer generation) { | ||
this.generation = generation; | ||
|
||
} | ||
} | ||
|
23 changes: 23 additions & 0 deletions
23
src/main/java/sopt/org/homepage/notification/dto/GetNotificationListResponseDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package sopt.org.homepage.notification.dto; | ||
|
||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import lombok.Getter; | ||
import org.springframework.validation.annotation.Validated; | ||
|
||
import java.util.List; | ||
|
||
@Validated | ||
@Getter | ||
public class GetNotificationListResponseDto { | ||
|
||
@Schema(description = "기수", example = "34", requiredMode = Schema.RequiredMode.REQUIRED) | ||
private final Integer generation; | ||
|
||
@Schema(description = "모집알림 신청한 이메일 리스트", example = "[\"[email protected]\", \"[email protected]\", \"[email protected]\"]", required = true) | ||
private final List<String> emailList; | ||
|
||
public GetNotificationListResponseDto(Integer generation, List<String> emailList) { | ||
this.generation = generation; | ||
this.emailList = emailList; | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
src/main/java/sopt/org/homepage/notification/dto/RegisterNotificationRequestDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package sopt.org.homepage.notification.dto; | ||
|
||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import jakarta.validation.constraints.Email; | ||
import jakarta.validation.constraints.NotEmpty; | ||
import jakarta.validation.constraints.Positive; | ||
import lombok.Getter; | ||
import org.springframework.validation.annotation.Validated; | ||
|
||
@Validated | ||
@Getter | ||
public class RegisterNotificationRequestDto { | ||
|
||
@Schema(description = "활동 기수", requiredMode = Schema.RequiredMode.REQUIRED, example = "34") | ||
@NotEmpty(message = "Generation must not be empty") | ||
@Positive(message = "Generation must be a positive number") | ||
private final int generation; | ||
|
||
@Schema(description = "이메일", requiredMode = Schema.RequiredMode.REQUIRED, example = "[email protected]") | ||
@NotEmpty(message = "Email must not be empty") | ||
@Email(message = "Email should be valid") | ||
private final String email; | ||
|
||
public RegisterNotificationRequestDto(int generation, String email) { | ||
this.generation = generation; | ||
this.email = email; | ||
} | ||
} | ||
|
35 changes: 35 additions & 0 deletions
35
src/main/java/sopt/org/homepage/notification/dto/RegisterNotificationResponseDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package sopt.org.homepage.notification.dto; | ||
|
||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import jakarta.validation.constraints.Email; | ||
import jakarta.validation.constraints.NotEmpty; | ||
import jakarta.validation.constraints.Positive; | ||
import lombok.Getter; | ||
import org.springframework.validation.annotation.Validated; | ||
|
||
import java.util.Date; | ||
|
||
@Validated | ||
@Getter | ||
public class RegisterNotificationResponseDto { | ||
|
||
@Schema(description = "Notification ID", requiredMode = Schema.RequiredMode.REQUIRED) | ||
private final int id; | ||
|
||
@Schema(description = "기수 (Generation)", requiredMode = Schema.RequiredMode.REQUIRED) | ||
private final int generation; | ||
|
||
@Schema(description = "이메일 (Email)", requiredMode = Schema.RequiredMode.REQUIRED) | ||
private final String email; | ||
|
||
@Schema(description = "생성일자 (Creation Date)", requiredMode = Schema.RequiredMode.REQUIRED) | ||
private final Date createdAt; | ||
|
||
public RegisterNotificationResponseDto(int id, int generation, String email, Date createdAt) { | ||
this.id = id; | ||
this.generation = generation; | ||
this.email = email; | ||
this.createdAt = createdAt; | ||
} | ||
} | ||
|