Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
N
NotificationSVC
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
NotificationSVC
Commits
845ffe2e
Commit
845ffe2e
authored
Jul 17, 2024
by
Ali
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add notification controller
parent
bd5fdf7a
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
114 additions
and
2 deletions
+114
-2
NotificationController.java
...i/notificationsvc/controllers/NotificationController.java
+78
-0
CreateNotificationDto.java
...a/com/ali/notificationsvc/dtos/CreateNotificationDto.java
+6
-1
NotificationDto.java
...in/java/com/ali/notificationsvc/dtos/NotificationDto.java
+5
-1
Notification.java
...ain/java/com/ali/notificationsvc/models/Notification.java
+8
-0
INotificationRepository.java
...notificationsvc/repositories/INotificationRepository.java
+1
-0
NotificationService.java
...com/ali/notificationsvc/services/NotificationService.java
+16
-0
No files found.
src/main/java/com/ali/notificationsvc/controllers/NotificationController.java
0 → 100644
View file @
845ffe2e
package
com
.
ali
.
notificationsvc
.
controllers
;
import
com.ali.notificationsvc.dtos.CreateNotificationDto
;
import
com.ali.notificationsvc.dtos.NotificationDto
;
import
com.ali.notificationsvc.services.INotificationService
;
import
com.ali.notificationsvc.status.RequestStatus
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.web.bind.annotation.*
;
import
java.util.List
;
@RestController
@RequestMapping
(
"/api/notifications"
)
public
class
NotificationController
{
@Autowired
INotificationService
notificationService
;
public
NotificationController
(
INotificationService
iNotificationService
)
{
this
.
notificationService
=
iNotificationService
;
}
@GetMapping
(
"getById/{id}"
)
public
ResponseEntity
<
NotificationDto
>
getById
(
@PathVariable
(
"id"
)
int
id
)
{
NotificationDto
notificationDto
=
new
NotificationDto
();
notificationDto
=
notificationService
.
getById
(
id
);
return
ResponseEntity
.
ok
(
notificationDto
);
}
@GetMapping
(
"getAll"
)
public
ResponseEntity
<
List
<
NotificationDto
>>
getAllNotifications
()
{
List
<
NotificationDto
>
notificationDtos
=
notificationService
.
getAll
();
return
ResponseEntity
.
ok
(
notificationDtos
);
}
@GetMapping
(
"getAllByCompanyId/{id}"
)
public
ResponseEntity
<
List
<
NotificationDto
>>
getAllByCompanyId
(
@PathVariable
(
"id"
)
int
companyId
)
{
List
<
NotificationDto
>
notificationDtos
=
notificationService
.
getNotificationByCompanyId
(
companyId
);
return
ResponseEntity
.
ok
(
notificationDtos
);
}
@GetMapping
(
"getAllByJobseekerId/{id}"
)
public
ResponseEntity
<
List
<
NotificationDto
>>
getAllByJobseekerId
(
@PathVariable
(
"id"
)
int
jobseekerId
)
{
List
<
NotificationDto
>
notificationDtos
=
notificationService
.
getNotificationByJobseekerId
(
jobseekerId
);
return
ResponseEntity
.
ok
(
notificationDtos
);
}
@GetMapping
(
"isExist/{id}"
)
public
ResponseEntity
<
Boolean
>
isExist
(
@PathVariable
(
"id"
)
int
notificationId
)
{
boolean
isExist
=
notificationService
.
existById
(
notificationId
);
return
ResponseEntity
.
ok
(
isExist
);
}
@PostMapping
(
"create"
)
public
ResponseEntity
<
RequestStatus
>
createNotification
(
@RequestBody
CreateNotificationDto
createNotificationDto
)
{
RequestStatus
status
=
notificationService
.
create
(
createNotificationDto
);
if
(
status
.
isStatus
())
{
return
ResponseEntity
.
status
(
HttpStatus
.
CREATED
).
body
(
status
);
}
else
{
return
ResponseEntity
.
status
(
HttpStatus
.
BAD_REQUEST
).
body
(
status
);
}
}
@PutMapping
(
"update"
)
public
ResponseEntity
<
RequestStatus
>
updateNotification
(
@RequestBody
NotificationDto
notificationDto
)
{
RequestStatus
status
=
notificationService
.
update
(
notificationDto
);
if
(
status
.
isStatus
())
{
return
ResponseEntity
.
ok
(
status
);
}
else
{
return
ResponseEntity
.
status
(
HttpStatus
.
BAD_REQUEST
).
body
(
status
);
}
}
@DeleteMapping
(
"delete/{id}"
)
public
ResponseEntity
<
RequestStatus
>
deleteNotification
(
@PathVariable
(
"id"
)
int
id
)
{
RequestStatus
status
=
notificationService
.
delete
(
id
);
if
(
status
.
isStatus
())
{
return
ResponseEntity
.
ok
(
status
);
}
else
{
return
ResponseEntity
.
status
(
HttpStatus
.
BAD_REQUEST
).
body
(
status
);
}
}
}
src/main/java/com/ali/notificationsvc/dtos/CreateNotificationDto.java
View file @
845ffe2e
package
com
.
ali
.
notificationsvc
.
dtos
;
package
com
.
ali
.
notificationsvc
.
dtos
;
import
java.time.LocalDateTime
;
import
lombok.Builder
;
import
lombok.Data
;
import
java.time.LocalDateTime
;
@Data
@Builder
public
class
CreateNotificationDto
{
public
class
CreateNotificationDto
{
private
int
jobId
;
private
int
jobId
;
private
int
companyId
;
private
int
companyId
;
...
@@ -23,4 +27,5 @@ public class CreateNotificationDto {
...
@@ -23,4 +27,5 @@ public class CreateNotificationDto {
public
CreateNotificationDto
()
{
public
CreateNotificationDto
()
{
}
}
}
}
src/main/java/com/ali/notificationsvc/dtos/NotificationDto.java
View file @
845ffe2e
package
com
.
ali
.
notificationsvc
.
dtos
;
package
com
.
ali
.
notificationsvc
.
dtos
;
import
java.time.LocalDateTime
;
import
lombok.Builder
;
import
lombok.Data
;
import
java.time.LocalDateTime
;
@Data
@Builder
public
class
NotificationDto
{
public
class
NotificationDto
{
private
int
id
;
private
int
id
;
private
int
jobId
;
private
int
jobId
;
...
...
src/main/java/com/ali/notificationsvc/models/Notification.java
View file @
845ffe2e
package
com
.
ali
.
notificationsvc
.
models
;
package
com
.
ali
.
notificationsvc
.
models
;
import
jakarta.persistence.Entity
;
import
jakarta.persistence.Entity
;
import
jakarta.persistence.GeneratedValue
;
import
jakarta.persistence.GenerationType
;
import
jakarta.persistence.Id
;
import
jakarta.persistence.Id
;
import
lombok.Builder
;
import
lombok.Data
;
import
java.time.LocalDateTime
;
import
java.time.LocalDateTime
;
import
java.util.Date
;
import
java.util.Date
;
@Entity
@Entity
@Data
@Builder
public
class
Notification
{
public
class
Notification
{
@Id
@Id
@GeneratedValue
(
strategy
=
GenerationType
.
IDENTITY
)
private
int
id
;
private
int
id
;
private
int
jobId
;
private
int
jobId
;
private
int
companyId
;
private
int
companyId
;
...
...
src/main/java/com/ali/notificationsvc/repositories/INotificationRepository.java
View file @
845ffe2e
...
@@ -14,4 +14,5 @@ public interface INotificationRepository extends JpaRepository<Notification, Int
...
@@ -14,4 +14,5 @@ public interface INotificationRepository extends JpaRepository<Notification, Int
List
<
Notification
>
findNotificationsByCompanyId
(
@Param
(
"companyId"
)
int
companyId
);
List
<
Notification
>
findNotificationsByCompanyId
(
@Param
(
"companyId"
)
int
companyId
);
@Query
(
"SELECT i FROM Notification i WHERE i.jobseekerId = :jobseekerId"
)
@Query
(
"SELECT i FROM Notification i WHERE i.jobseekerId = :jobseekerId"
)
List
<
Notification
>
findNotificationsByJobseekerId
(
@Param
(
"jobseekerId"
)
int
jobseekerId
);
List
<
Notification
>
findNotificationsByJobseekerId
(
@Param
(
"jobseekerId"
)
int
jobseekerId
);
}
}
src/main/java/com/ali/notificationsvc/services/NotificationService.java
View file @
845ffe2e
...
@@ -5,6 +5,7 @@ import com.ali.notificationsvc.dtos.NotificationDto;
...
@@ -5,6 +5,7 @@ import com.ali.notificationsvc.dtos.NotificationDto;
import
com.ali.notificationsvc.models.Notification
;
import
com.ali.notificationsvc.models.Notification
;
import
com.ali.notificationsvc.repositories.INotificationRepository
;
import
com.ali.notificationsvc.repositories.INotificationRepository
;
import
com.ali.notificationsvc.status.RequestStatus
;
import
com.ali.notificationsvc.status.RequestStatus
;
import
org.modelmapper.Conditions
;
import
org.modelmapper.ModelMapper
;
import
org.modelmapper.ModelMapper
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
...
@@ -65,8 +66,11 @@ public class NotificationService implements INotificationService {
...
@@ -65,8 +66,11 @@ public class NotificationService implements INotificationService {
@Override
@Override
public
RequestStatus
create
(
CreateNotificationDto
cNotificationDto
)
{
public
RequestStatus
create
(
CreateNotificationDto
cNotificationDto
)
{
RequestStatus
status
=
new
RequestStatus
();
RequestStatus
status
=
new
RequestStatus
();
ignoreIdMapping
(
modelMapper
);
try
{
try
{
System
.
out
.
println
(
cNotificationDto
.
toString
());
Notification
notification
=
modelMapper
.
map
(
cNotificationDto
,
Notification
.
class
);
Notification
notification
=
modelMapper
.
map
(
cNotificationDto
,
Notification
.
class
);
System
.
out
.
println
(
notification
.
toString
());
iNotificationRepository
.
save
(
notification
);
iNotificationRepository
.
save
(
notification
);
status
.
setStatus
(
true
);
status
.
setStatus
(
true
);
status
.
setDescribtion
(
"created successfully"
);
status
.
setDescribtion
(
"created successfully"
);
...
@@ -115,4 +119,16 @@ public class NotificationService implements INotificationService {
...
@@ -115,4 +119,16 @@ public class NotificationService implements INotificationService {
public
boolean
existById
(
int
notificationId
)
{
public
boolean
existById
(
int
notificationId
)
{
return
iNotificationRepository
.
existsById
(
notificationId
);
return
iNotificationRepository
.
existsById
(
notificationId
);
}
}
private
void
ignoreIdMapping
(
ModelMapper
modelMapper
){
modelMapper
.
getConfiguration
()
.
setPropertyCondition
(
Conditions
.
isNotNull
())
.
setFieldMatchingEnabled
(
true
)
.
setFieldAccessLevel
(
org
.
modelmapper
.
config
.
Configuration
.
AccessLevel
.
PRIVATE
)
.
setSkipNullEnabled
(
true
)
.
setAmbiguityIgnored
(
true
);
modelMapper
.
typeMap
(
CreateNotificationDto
.
class
,
Notification
.
class
)
.
addMappings
(
mapper
->
{
mapper
.
skip
(
Notification:
:
setId
);
});
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment