-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
29 changed files
with
1,049 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
README.md | ||
.gradle | ||
build/ | ||
!gradle/wrapper/gradle-wrapper.jar | ||
!**/src/main/**/build/ | ||
!**/src/test/**/build/ | ||
|
||
### STS ### | ||
.apt_generated | ||
.classpath | ||
.factorypath | ||
.project | ||
.settings | ||
.springBeans | ||
.sts4-cache | ||
bin/ | ||
!**/src/main/**/bin/ | ||
!**/src/test/**/bin/ | ||
|
||
### IntelliJ IDEA ### | ||
.idea | ||
*.iws | ||
*.iml | ||
*.ipr | ||
out/ | ||
!**/src/main/**/out/ | ||
!**/src/test/**/out/ | ||
|
||
### NetBeans ### | ||
/nbproject/private/ | ||
/nbbuild/ | ||
/dist/ | ||
/nbdist/ | ||
/.nb-gradle/ | ||
|
||
### VS Code ### | ||
.vscode/ |
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,13 @@ | ||
bootJar { | ||
enabled = true | ||
} | ||
|
||
dependencies { | ||
implementation 'org.springframework.boot:spring-boot-starter-data-jpa' | ||
runtimeOnly 'com.h2database:h2' | ||
runtimeOnly 'com.mysql:mysql-connector-j' | ||
|
||
implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.2.0' | ||
|
||
implementation 'org.springframework.kafka:spring-kafka' | ||
} |
13 changes: 13 additions & 0 deletions
13
src/backend/alarm-server/alarm-api/src/main/java/com/lalala/alarm/AlarmApplication.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,13 @@ | ||
package com.lalala.alarm; | ||
|
||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
|
||
@SpringBootApplication | ||
public class AlarmApplication { | ||
|
||
public static void main(String[] args) { | ||
SpringApplication.run(AlarmApplication.class, args); | ||
} | ||
|
||
} |
9 changes: 9 additions & 0 deletions
9
...larm-server/alarm-api/src/main/java/com/lalala/alarm/config/JpaAuditingConfiguration.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,9 @@ | ||
package com.lalala.alarm.config; | ||
|
||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.data.jpa.repository.config.EnableJpaAuditing; | ||
|
||
@Configuration | ||
@EnableJpaAuditing | ||
public class JpaAuditingConfiguration { | ||
} |
19 changes: 19 additions & 0 deletions
19
...nd/alarm-server/alarm-api/src/main/java/com/lalala/alarm/config/SwaggerConfiguration.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 com.lalala.alarm.config; | ||
|
||
import io.swagger.v3.oas.models.OpenAPI; | ||
import io.swagger.v3.oas.models.info.Info; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
@Configuration | ||
public class SwaggerConfiguration { | ||
@Bean | ||
public OpenAPI openAPI() { | ||
return new OpenAPI() | ||
.info(new Info() | ||
.title("알람 API") | ||
.description("알람 API를 제공합니다.") | ||
.version("0.0.1") | ||
); | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
...ackend/alarm-server/alarm-api/src/main/java/com/lalala/alarm/config/WebConfiguration.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,17 @@ | ||
package com.lalala.alarm.config; | ||
|
||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.web.servlet.config.annotation.CorsRegistry; | ||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; | ||
|
||
@Configuration | ||
public class WebConfiguration implements WebMvcConfigurer { | ||
private static final Long MAX_AGE = 3000L; | ||
|
||
@Override | ||
public void addCorsMappings(final CorsRegistry registry) { | ||
registry.addMapping("/**") | ||
.allowedOrigins("*") | ||
.maxAge(MAX_AGE); | ||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
...rm-server/alarm-api/src/main/java/com/lalala/alarm/controller/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,56 @@ | ||
package com.lalala.alarm.controller; | ||
|
||
import com.lalala.alarm.dto.CreateNotificationRequestDTO; | ||
import com.lalala.alarm.dto.NotificationDTO; | ||
import com.lalala.alarm.dto.UpdateNotificationRequestDTO; | ||
import com.lalala.alarm.service.NotificationService; | ||
import java.util.List; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.DeleteMapping; | ||
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.PutMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("/api/v1/notifications") | ||
public class NotificationController { | ||
private final NotificationService service; | ||
|
||
@PostMapping | ||
public ResponseEntity<NotificationDTO> createNotification(@RequestBody CreateNotificationRequestDTO request) { | ||
NotificationDTO notification = service.createNotification(request); | ||
return ResponseEntity.ok(notification); | ||
} | ||
|
||
@GetMapping("/{id}") | ||
public ResponseEntity<List<NotificationDTO>> readNotifications( | ||
@PathVariable("id") Long id, | ||
@RequestParam(required = false, defaultValue = "0", name = "page") int page, | ||
@RequestParam(required = false, defaultValue = "50", name = "size") int pageSize | ||
) { | ||
List<NotificationDTO> notifications = service.getNotifications(id, page, pageSize); | ||
return ResponseEntity.ok(notifications); | ||
} | ||
|
||
@PutMapping("/{id}") | ||
public ResponseEntity<NotificationDTO> updateNotification( | ||
@PathVariable("id") Long id, | ||
@RequestBody UpdateNotificationRequestDTO request | ||
) { | ||
NotificationDTO notification = service.updateNotification(id, request); | ||
return ResponseEntity.ok(notification); | ||
} | ||
|
||
@DeleteMapping("/{id}") | ||
public ResponseEntity<NotificationDTO> deleteNotification(@PathVariable("id") Long id) { | ||
NotificationDTO notification = service.deleteNotification(id); | ||
return ResponseEntity.ok(notification); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
...arm-server/alarm-api/src/main/java/com/lalala/alarm/dto/CreateNotificationRequestDTO.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,21 @@ | ||
package com.lalala.alarm.dto; | ||
|
||
import com.lalala.alarm.entity.NotificationType; | ||
import java.time.LocalDateTime; | ||
import lombok.AccessLevel; | ||
import lombok.Getter; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@Getter | ||
@RequiredArgsConstructor(access = AccessLevel.PRIVATE) | ||
public class CreateNotificationRequestDTO { | ||
private String message; | ||
|
||
private UserDTO sender; | ||
private UserDTO receiver; | ||
|
||
private boolean isViewed; | ||
private LocalDateTime viewedAt; | ||
|
||
private NotificationType type; | ||
} |
42 changes: 42 additions & 0 deletions
42
src/backend/alarm-server/alarm-api/src/main/java/com/lalala/alarm/dto/NotificationDTO.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,42 @@ | ||
package com.lalala.alarm.dto; | ||
|
||
import com.lalala.alarm.entity.NotificationEntity; | ||
import com.lalala.alarm.entity.NotificationType; | ||
import java.time.LocalDateTime; | ||
import lombok.AccessLevel; | ||
import lombok.Getter; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@Getter | ||
@RequiredArgsConstructor(access = AccessLevel.PRIVATE) | ||
public class NotificationDTO { | ||
private final Long id; | ||
private final String message; | ||
|
||
private final UserDTO sender; | ||
private final UserDTO receiver; | ||
|
||
private final boolean isViewed; | ||
private final LocalDateTime viewedAt; | ||
|
||
private final NotificationType type; | ||
|
||
private final LocalDateTime createdAt; | ||
private final LocalDateTime updatedAt; | ||
|
||
public static NotificationDTO from( | ||
NotificationEntity notification | ||
) { | ||
return new NotificationDTO( | ||
notification.getId(), | ||
notification.getMessage(), | ||
UserDTO.from(notification.getSender()), | ||
UserDTO.from(notification.getReceiver()), | ||
notification.getIsViewed(), | ||
notification.getViewedAt(), | ||
notification.getType(), | ||
notification.getCreatedAt(), | ||
notification.getUpdatedAt() | ||
); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
...arm-server/alarm-api/src/main/java/com/lalala/alarm/dto/UpdateNotificationRequestDTO.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,21 @@ | ||
package com.lalala.alarm.dto; | ||
|
||
import com.lalala.alarm.entity.NotificationType; | ||
import java.time.LocalDateTime; | ||
import lombok.AccessLevel; | ||
import lombok.Getter; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@Getter | ||
@RequiredArgsConstructor(access = AccessLevel.PRIVATE) | ||
public class UpdateNotificationRequestDTO { | ||
private String message; | ||
|
||
private UserDTO sender; | ||
private UserDTO receiver; | ||
|
||
private boolean isViewed; | ||
private LocalDateTime viewedAt; | ||
|
||
private NotificationType type; | ||
} |
24 changes: 24 additions & 0 deletions
24
src/backend/alarm-server/alarm-api/src/main/java/com/lalala/alarm/dto/UserDTO.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,24 @@ | ||
package com.lalala.alarm.dto; | ||
|
||
import com.lalala.alarm.entity.User; | ||
import lombok.AccessLevel; | ||
import lombok.Getter; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@Getter | ||
@RequiredArgsConstructor(access = AccessLevel.PRIVATE) | ||
public class UserDTO { | ||
private final Long id; | ||
private final String nickname; | ||
private final String profile; | ||
|
||
public static UserDTO from( | ||
User user | ||
) { | ||
return new UserDTO( | ||
user.getId(), | ||
user.getNickname(), | ||
user.getProfile() | ||
); | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
src/backend/alarm-server/alarm-api/src/main/java/com/lalala/alarm/entity/BaseTimeEntity.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 com.lalala.alarm.entity; | ||
|
||
import jakarta.persistence.Column; | ||
import jakarta.persistence.EntityListeners; | ||
import jakarta.persistence.MappedSuperclass; | ||
import java.time.LocalDateTime; | ||
import lombok.Getter; | ||
import org.springframework.data.annotation.CreatedDate; | ||
import org.springframework.data.annotation.LastModifiedDate; | ||
import org.springframework.data.jpa.domain.support.AuditingEntityListener; | ||
|
||
@EntityListeners(AuditingEntityListener.class) | ||
@MappedSuperclass | ||
@Getter | ||
public abstract class BaseTimeEntity { | ||
@CreatedDate | ||
@Column(name = "created_at", insertable = false, updatable = false) | ||
private LocalDateTime createdAt; | ||
|
||
@LastModifiedDate | ||
@Column(name = "updated_at", insertable = false, updatable = false) | ||
private LocalDateTime updatedAt; | ||
} |
85 changes: 85 additions & 0 deletions
85
...kend/alarm-server/alarm-api/src/main/java/com/lalala/alarm/entity/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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
package com.lalala.alarm.entity; | ||
|
||
import jakarta.persistence.AttributeOverride; | ||
import jakarta.persistence.AttributeOverrides; | ||
import jakarta.persistence.Column; | ||
import jakarta.persistence.Embedded; | ||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.EnumType; | ||
import jakarta.persistence.Enumerated; | ||
import jakarta.persistence.GeneratedValue; | ||
import jakarta.persistence.GenerationType; | ||
import jakarta.persistence.Id; | ||
import jakarta.persistence.Table; | ||
import java.time.LocalDateTime; | ||
import lombok.AccessLevel; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Entity | ||
@Table(name = "notifications") | ||
@Getter | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
public class NotificationEntity extends BaseTimeEntity { | ||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
private Long id; | ||
|
||
@Column(nullable = false) | ||
private String message; | ||
|
||
@Embedded | ||
@AttributeOverrides({ | ||
@AttributeOverride(name = "id", column = @Column(name = "sender_id")), | ||
@AttributeOverride(name = "nickname", column = @Column(name = "sender_nickname")), | ||
@AttributeOverride(name = "profile", column = @Column(name = "sender_profile")) | ||
}) | ||
private User sender; | ||
|
||
@Embedded | ||
@AttributeOverrides({ | ||
@AttributeOverride(name = "id", column = @Column(name = "receiver_id")), | ||
@AttributeOverride(name = "nickname", column = @Column(name = "receiver_nickname")), | ||
@AttributeOverride(name = "profile", column = @Column(name = "receiver_profile")) | ||
}) | ||
private User receiver; | ||
|
||
@Column(name = "is_viewed", nullable = false, columnDefinition = "TINYINT") | ||
private Boolean isViewed = false; | ||
|
||
@Column(name = "viewed_at") | ||
private LocalDateTime viewedAt; | ||
|
||
@Column(nullable = false, columnDefinition = "VARCHAR(10)") | ||
@Enumerated(EnumType.STRING) | ||
private NotificationType type = NotificationType.NORMAL; | ||
|
||
public NotificationEntity( | ||
String message, | ||
User sender, | ||
User receiver, | ||
NotificationType type | ||
) { | ||
this.message = message; | ||
this.sender = sender; | ||
this.receiver = receiver; | ||
this.type = type; | ||
} | ||
|
||
public void update( | ||
String message, | ||
User sender, | ||
User receiver, | ||
NotificationType type | ||
) { | ||
this.message = message; | ||
this.sender = sender; | ||
this.receiver = receiver; | ||
this.type = type; | ||
} | ||
|
||
public void read() { | ||
this.isViewed = true; | ||
this.viewedAt = LocalDateTime.now(); | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
...ackend/alarm-server/alarm-api/src/main/java/com/lalala/alarm/entity/NotificationType.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,5 @@ | ||
package com.lalala.alarm.entity; | ||
|
||
public enum NotificationType { | ||
NORMAL | ||
} |
Oops, something went wrong.