Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
B
baby-monitoring-spring-backend
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
R24-145
baby-monitoring-spring-backend
Commits
948ec935
Commit
948ec935
authored
May 17, 2024
by
Chamod Ishankha
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
accept live video from web cam -> backend -> python model to process and return prediction
parent
8e3182b4
Changes
25
Show whitespace changes
Inline
Side-by-side
Showing
25 changed files
with
664 additions
and
8 deletions
+664
-8
pom.xml
pom.xml
+22
-0
src/main/java/com/kaluwa/enterprises/babycarebackendservice/config/AppConfig.java
.../enterprises/babycarebackendservice/config/AppConfig.java
+15
-0
src/main/java/com/kaluwa/enterprises/babycarebackendservice/config/SecurityConfig.java
...rprises/babycarebackendservice/config/SecurityConfig.java
+2
-1
src/main/java/com/kaluwa/enterprises/babycarebackendservice/config/WebSocketClient.java
...prises/babycarebackendservice/config/WebSocketClient.java
+54
-0
src/main/java/com/kaluwa/enterprises/babycarebackendservice/config/WebSocketConfig.java
...prises/babycarebackendservice/config/WebSocketConfig.java
+58
-0
src/main/java/com/kaluwa/enterprises/babycarebackendservice/constants/TableNames.java
...erprises/babycarebackendservice/constants/TableNames.java
+1
-0
src/main/java/com/kaluwa/enterprises/babycarebackendservice/dao/BabyDao.java
...aluwa/enterprises/babycarebackendservice/dao/BabyDao.java
+9
-0
src/main/java/com/kaluwa/enterprises/babycarebackendservice/dto/BabyDto.java
...aluwa/enterprises/babycarebackendservice/dto/BabyDto.java
+27
-0
src/main/java/com/kaluwa/enterprises/babycarebackendservice/dto/EmotionDetectionResponse.java
.../babycarebackendservice/dto/EmotionDetectionResponse.java
+13
-0
src/main/java/com/kaluwa/enterprises/babycarebackendservice/dto/ResponseDto.java
...a/enterprises/babycarebackendservice/dto/ResponseDto.java
+13
-0
src/main/java/com/kaluwa/enterprises/babycarebackendservice/dto/UserDto.java
...aluwa/enterprises/babycarebackendservice/dto/UserDto.java
+3
-0
src/main/java/com/kaluwa/enterprises/babycarebackendservice/mappers/BabyMapper.java
...nterprises/babycarebackendservice/mappers/BabyMapper.java
+28
-0
src/main/java/com/kaluwa/enterprises/babycarebackendservice/model/Baby.java
...kaluwa/enterprises/babycarebackendservice/model/Baby.java
+28
-0
src/main/java/com/kaluwa/enterprises/babycarebackendservice/rest/AuthenticationController.java
...babycarebackendservice/rest/AuthenticationController.java
+0
-2
src/main/java/com/kaluwa/enterprises/babycarebackendservice/rest/BabyController.java
...terprises/babycarebackendservice/rest/BabyController.java
+53
-0
src/main/java/com/kaluwa/enterprises/babycarebackendservice/rest/EmotionalDetectionController.java
...carebackendservice/rest/EmotionalDetectionController.java
+22
-0
src/main/java/com/kaluwa/enterprises/babycarebackendservice/rest/UserController.java
...terprises/babycarebackendservice/rest/UserController.java
+50
-0
src/main/java/com/kaluwa/enterprises/babycarebackendservice/service/BabyService.java
...terprises/babycarebackendservice/service/BabyService.java
+18
-0
src/main/java/com/kaluwa/enterprises/babycarebackendservice/service/UserService.java
...terprises/babycarebackendservice/service/UserService.java
+11
-4
src/main/java/com/kaluwa/enterprises/babycarebackendservice/service/impl/BabyServiceImpl.java
.../babycarebackendservice/service/impl/BabyServiceImpl.java
+106
-0
src/main/java/com/kaluwa/enterprises/babycarebackendservice/service/impl/UserServiceImpl.java
.../babycarebackendservice/service/impl/UserServiceImpl.java
+82
-0
src/main/java/com/kaluwa/enterprises/babycarebackendservice/socketHandlers/BoundingBox.java
...es/babycarebackendservice/socketHandlers/BoundingBox.java
+15
-0
src/main/java/com/kaluwa/enterprises/babycarebackendservice/socketHandlers/EmotionPrediction.java
...ycarebackendservice/socketHandlers/EmotionPrediction.java
+13
-0
src/main/java/com/kaluwa/enterprises/babycarebackendservice/socketHandlers/SocketConnectionHandlers.java
...ckendservice/socketHandlers/SocketConnectionHandlers.java
+20
-0
src/main/resources/application.yaml
src/main/resources/application.yaml
+1
-1
No files found.
pom.xml
View file @
948ec935
...
@@ -126,6 +126,28 @@
...
@@ -126,6 +126,28 @@
<artifactId>
mapstruct
</artifactId>
<artifactId>
mapstruct
</artifactId>
<version>
${org.mapstruct.version}
</version>
<version>
${org.mapstruct.version}
</version>
</dependency>
</dependency>
<!--handle live feeds-->
<dependency>
<groupId>
javax.websocket
</groupId>
<artifactId>
javax.websocket-api
</artifactId>
<version>
1.1
</version>
</dependency>
<dependency>
<groupId>
org.glassfish.tyrus.bundles
</groupId>
<artifactId>
tyrus-standalone-client
</artifactId>
<version>
1.17
</version>
</dependency>
<dependency>
<groupId>
org.bytedeco
</groupId>
<artifactId>
opencv
</artifactId>
<version>
4.9.0-1.5.10
</version>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-websocket
</artifactId>
</dependency>
</dependencies>
</dependencies>
<build>
<build>
...
...
src/main/java/com/kaluwa/enterprises/babycarebackendservice/config/AppConfig.java
View file @
948ec935
...
@@ -2,8 +2,12 @@ package com.kaluwa.enterprises.babycarebackendservice.config;
...
@@ -2,8 +2,12 @@ package com.kaluwa.enterprises.babycarebackendservice.config;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
com.fasterxml.jackson.datatype.jsr310.JavaTimeModule
;
import
com.fasterxml.jackson.datatype.jsr310.JavaTimeModule
;
import
org.springframework.boot.web.client.RestTemplateBuilder
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.web.client.RestTemplate
;
import
org.springframework.web.socket.client.WebSocketClient
;
import
org.springframework.web.socket.client.standard.StandardWebSocketClient
;
@Configuration
@Configuration
public
class
AppConfig
{
public
class
AppConfig
{
...
@@ -14,4 +18,15 @@ public class AppConfig {
...
@@ -14,4 +18,15 @@ public class AppConfig {
objectMapper
.
registerModule
(
new
JavaTimeModule
());
objectMapper
.
registerModule
(
new
JavaTimeModule
());
return
objectMapper
;
return
objectMapper
;
}
}
@Bean
public
WebSocketClient
webSocketClient
()
{
return
new
StandardWebSocketClient
();
}
@Bean
public
RestTemplate
restTemplate
(
RestTemplateBuilder
builder
)
{
return
builder
.
build
();
}
}
}
src/main/java/com/kaluwa/enterprises/babycarebackendservice/config/SecurityConfig.java
View file @
948ec935
...
@@ -45,7 +45,8 @@ public class SecurityConfig {
...
@@ -45,7 +45,8 @@ public class SecurityConfig {
"/configuration/security"
,
"/configuration/security"
,
"/swagger-ui/**"
,
"/swagger-ui/**"
,
"/webjars/**"
,
"/webjars/**"
,
"/swagger-ui.html"
"/swagger-ui.html"
,
"/emotional/video-process"
};
};
@Bean
@Bean
...
...
src/main/java/com/kaluwa/enterprises/babycarebackendservice/config/WebSocketClient.java
0 → 100644
View file @
948ec935
package
com.kaluwa.enterprises.babycarebackendservice.config
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
com.kaluwa.enterprises.babycarebackendservice.socketHandlers.EmotionPrediction
;
import
org.springframework.web.socket.BinaryMessage
;
import
org.springframework.web.socket.TextMessage
;
import
org.springframework.web.socket.WebSocketSession
;
import
org.springframework.web.socket.client.standard.StandardWebSocketClient
;
import
org.springframework.web.socket.handler.TextWebSocketHandler
;
import
java.sql.Blob
;
class
WebSocketClient
{
private
WebSocketSession
session
;
public
WebSocketClient
()
{
try
{
this
.
session
=
new
StandardWebSocketClient
()
.
doHandshake
(
new
MyWebSocketHandler
(),
"ws://localhost:8000/ws/emotion"
)
.
get
();
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
}
public
void
sendBytesToWebSocket
(
byte
[]
bytes
)
{
try
{
session
.
sendMessage
(
new
BinaryMessage
(
bytes
));
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
}
static
ObjectMapper
objectMapper
=
new
ObjectMapper
();
static
class
MyWebSocketHandler
extends
TextWebSocketHandler
{
@Override
protected
void
handleTextMessage
(
WebSocketSession
session
,
TextMessage
message
)
throws
Exception
{
// This method will be called when the server sends a text message
// Deserialize JSON array of objects into an array of Java objects
EmotionPrediction
[]
predictions
=
objectMapper
.
readValue
(
message
.
getPayload
(),
EmotionPrediction
[].
class
);
// Print each element of the array
for
(
EmotionPrediction
prediction
:
predictions
)
{
System
.
out
.
println
(
"Emotion: "
+
prediction
.
getEmotion
());
System
.
out
.
println
(
"Bounding Box:"
);
System
.
out
.
println
(
" X: "
+
prediction
.
getBounding_box
().
getX
());
System
.
out
.
println
(
" Y: "
+
prediction
.
getBounding_box
().
getY
());
System
.
out
.
println
(
" Width: "
+
prediction
.
getBounding_box
().
getWidth
());
System
.
out
.
println
(
" Height: "
+
prediction
.
getBounding_box
().
getHeight
());
}
}
}
}
\ No newline at end of file
src/main/java/com/kaluwa/enterprises/babycarebackendservice/config/WebSocketConfig.java
0 → 100644
View file @
948ec935
package
com.kaluwa.enterprises.babycarebackendservice.config
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.stereotype.Component
;
import
org.springframework.web.socket.BinaryMessage
;
import
org.springframework.web.socket.TextMessage
;
import
org.springframework.web.socket.WebSocketSession
;
import
org.springframework.web.socket.config.annotation.EnableWebSocket
;
import
org.springframework.web.socket.config.annotation.WebSocketConfigurer
;
import
org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry
;
import
org.springframework.web.socket.handler.BinaryWebSocketHandler
;
import
org.springframework.web.socket.server.standard.ServletServerContainerFactoryBean
;
import
javax.sql.rowset.serial.SerialBlob
;
import
java.sql.Blob
;
import
java.util.Map
;
@Configuration
@EnableWebSocket
@Slf4j
public
class
WebSocketConfig
implements
WebSocketConfigurer
{
WebSocketClient
webSocketClient
=
new
WebSocketClient
();
@Bean
public
ServletServerContainerFactoryBean
createWebSocketContainer
()
{
ServletServerContainerFactoryBean
container
=
new
ServletServerContainerFactoryBean
();
container
.
setMaxTextMessageBufferSize
(
500000
);
container
.
setMaxBinaryMessageBufferSize
(
500000
);
return
container
;
}
@Override
public
void
registerWebSocketHandlers
(
WebSocketHandlerRegistry
registry
)
{
registry
.
addHandler
(
new
VideoFrameHandler
(),
"/emotional/video-process"
)
.
setAllowedOrigins
(
"*"
);
}
@Component
class
VideoFrameHandler
extends
BinaryWebSocketHandler
{
@Override
protected
void
handleBinaryMessage
(
WebSocketSession
session
,
BinaryMessage
message
)
throws
Exception
{
byte
[]
binaryData
=
message
.
getPayload
().
array
();
// Process the binary data representing the video frame
// log.info("Received binary data from client: {}", binaryData);
// Here you can process the binary data as needed, such as saving it to a file, performing image processing, etc.
webSocketClient
.
sendBytesToWebSocket
(
binaryData
);
}
@Override
protected
void
handleTextMessage
(
WebSocketSession
session
,
TextMessage
message
)
{
super
.
handleTextMessage
(
session
,
message
);
}
}
}
\ No newline at end of file
src/main/java/com/kaluwa/enterprises/babycarebackendservice/constants/TableNames.java
View file @
948ec935
...
@@ -3,5 +3,6 @@ package com.kaluwa.enterprises.babycarebackendservice.constants;
...
@@ -3,5 +3,6 @@ package com.kaluwa.enterprises.babycarebackendservice.constants;
public
class
TableNames
{
public
class
TableNames
{
public
final
static
String
USER_TABLE
=
"users"
;
public
final
static
String
USER_TABLE
=
"users"
;
public
final
static
String
BABY_TABLE
=
"babies"
;
}
}
src/main/java/com/kaluwa/enterprises/babycarebackendservice/dao/BabyDao.java
0 → 100644
View file @
948ec935
package
com.kaluwa.enterprises.babycarebackendservice.dao
;
import
com.kaluwa.enterprises.babycarebackendservice.model.Baby
;
import
org.springframework.data.jpa.repository.JpaRepository
;
import
org.springframework.stereotype.Repository
;
@Repository
public
interface
BabyDao
extends
JpaRepository
<
Baby
,
Long
>
{
}
src/main/java/com/kaluwa/enterprises/babycarebackendservice/dto/BabyDto.java
0 → 100644
View file @
948ec935
package
com.kaluwa.enterprises.babycarebackendservice.dto
;
import
jakarta.validation.constraints.NotEmpty
;
import
jakarta.validation.constraints.NotNull
;
import
lombok.AllArgsConstructor
;
import
lombok.Data
;
import
lombok.NoArgsConstructor
;
import
java.time.LocalDate
;
@Data
@AllArgsConstructor
@NoArgsConstructor
public
class
BabyDto
{
private
Long
babyId
;
@NotNull
(
message
=
"Baby name is required"
)
@NotEmpty
(
message
=
"Baby name is required"
)
private
String
babyName
;
private
String
babyGender
;
private
LocalDate
babyDob
;
private
String
babyWeight
;
private
UserDto
user
;
@NotNull
(
message
=
"Logged user id is required"
)
@NotEmpty
(
message
=
"Logged user id is required"
)
private
Long
userId
;
}
src/main/java/com/kaluwa/enterprises/babycarebackendservice/dto/EmotionDetectionResponse.java
0 → 100644
View file @
948ec935
package
com.kaluwa.enterprises.babycarebackendservice.dto
;
import
lombok.AllArgsConstructor
;
import
lombok.Data
;
import
lombok.NoArgsConstructor
;
@Data
@AllArgsConstructor
@NoArgsConstructor
public
class
EmotionDetectionResponse
{
private
String
emotion
;
private
String
feeds
;
}
src/main/java/com/kaluwa/enterprises/babycarebackendservice/dto/ResponseDto.java
0 → 100644
View file @
948ec935
package
com.kaluwa.enterprises.babycarebackendservice.dto
;
import
lombok.AllArgsConstructor
;
import
lombok.Data
;
import
lombok.NoArgsConstructor
;
@Data
@AllArgsConstructor
@NoArgsConstructor
public
class
ResponseDto
{
private
Long
id
;
private
String
message
;
}
src/main/java/com/kaluwa/enterprises/babycarebackendservice/dto/UserDto.java
View file @
948ec935
package
com.kaluwa.enterprises.babycarebackendservice.dto
;
package
com.kaluwa.enterprises.babycarebackendservice.dto
;
import
com.fasterxml.jackson.annotation.JsonIgnore
;
import
lombok.AllArgsConstructor
;
import
lombok.AllArgsConstructor
;
import
lombok.Data
;
import
lombok.Data
;
import
lombok.NoArgsConstructor
;
import
lombok.NoArgsConstructor
;
...
@@ -13,6 +14,8 @@ public class UserDto {
...
@@ -13,6 +14,8 @@ public class UserDto {
private
String
lastName
;
private
String
lastName
;
private
String
email
;
private
String
email
;
private
String
phone
;
private
String
phone
;
@JsonIgnore
private
String
role
;
private
String
role
;
@JsonIgnore
private
String
status
;
private
String
status
;
}
}
src/main/java/com/kaluwa/enterprises/babycarebackendservice/mappers/BabyMapper.java
0 → 100644
View file @
948ec935
package
com.kaluwa.enterprises.babycarebackendservice.mappers
;
import
com.kaluwa.enterprises.babycarebackendservice.dto.BabyDto
;
import
com.kaluwa.enterprises.babycarebackendservice.model.Baby
;
import
org.mapstruct.Mapper
;
import
org.mapstruct.Mapping
;
import
org.mapstruct.Mappings
;
import
java.util.List
;
@Mapper
(
componentModel
=
"spring"
)
public
interface
BabyMapper
{
@Mappings
({
@Mapping
(
source
=
"user.userId"
,
target
=
"userId"
)
})
BabyDto
toDto
(
Baby
baby
);
@Mappings
({
@Mapping
(
target
=
"user.userId"
,
source
=
"userId"
)
})
Baby
toEntity
(
BabyDto
babyDto
);
@Mappings
({
@Mapping
(
source
=
"user.userId"
,
target
=
"userId"
)
})
List
<
BabyDto
>
toDtoList
(
List
<
Baby
>
babyList
);
}
src/main/java/com/kaluwa/enterprises/babycarebackendservice/model/Baby.java
0 → 100644
View file @
948ec935
package
com.kaluwa.enterprises.babycarebackendservice.model
;
import
jakarta.persistence.*
;
import
lombok.AllArgsConstructor
;
import
lombok.Data
;
import
lombok.NoArgsConstructor
;
import
java.time.LocalDate
;
import
static
com
.
kaluwa
.
enterprises
.
babycarebackendservice
.
constants
.
TableNames
.
BABY_TABLE
;
@Data
@AllArgsConstructor
@NoArgsConstructor
@Entity
@Table
(
name
=
BABY_TABLE
)
public
class
Baby
{
@Id
@GeneratedValue
(
strategy
=
GenerationType
.
AUTO
)
private
Long
babyId
;
private
String
babyName
;
private
String
babyGender
;
private
LocalDate
babyDob
;
private
String
babyWeight
;
@ManyToOne
(
fetch
=
FetchType
.
LAZY
)
@JoinColumn
(
name
=
"userId"
,
referencedColumnName
=
"userId"
,
nullable
=
false
)
private
User
user
;
}
src/main/java/com/kaluwa/enterprises/babycarebackendservice/rest/AuthenticationController.java
View file @
948ec935
...
@@ -44,7 +44,5 @@ public class AuthenticationController {
...
@@ -44,7 +44,5 @@ public class AuthenticationController {
// change password
// change password
// logout
}
}
src/main/java/com/kaluwa/enterprises/babycarebackendservice/rest/BabyController.java
0 → 100644
View file @
948ec935
package
com.kaluwa.enterprises.babycarebackendservice.rest
;
import
com.kaluwa.enterprises.babycarebackendservice.dto.BabyDto
;
import
com.kaluwa.enterprises.babycarebackendservice.dto.ResponseDto
;
import
com.kaluwa.enterprises.babycarebackendservice.service.BabyService
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.web.bind.annotation.*
;
import
java.util.List
;
@RestController
@RequestMapping
(
"/baby"
)
@Slf4j
public
class
BabyController
{
private
final
BabyService
babyService
;
public
BabyController
(
BabyService
babyService
)
{
this
.
babyService
=
babyService
;
}
@PostMapping
()
public
ResponseEntity
<
BabyDto
>
createBaby
(
@RequestBody
BabyDto
babyDto
)
{
log
.
info
(
"Inside baby controller createBaby method"
);
return
new
ResponseEntity
<>(
babyService
.
createBaby
(
babyDto
),
HttpStatus
.
CREATED
);
}
@GetMapping
()
public
ResponseEntity
<
List
<
BabyDto
>>
getAllbabies
()
{
log
.
info
(
"Inside baby controller getAllbabies method"
);
return
ResponseEntity
.
ok
(
babyService
.
getAllBabies
());
}
@GetMapping
(
"/{id}"
)
public
ResponseEntity
<
BabyDto
>
getBabyById
(
@PathVariable
Long
babyId
)
{
log
.
info
(
"Inside baby controller getBabyById method"
);
return
ResponseEntity
.
ok
(
babyService
.
getBabyById
(
babyId
));
}
@PutMapping
(
"/{id}"
)
public
ResponseEntity
<
BabyDto
>
updateBaby
(
@PathVariable
Long
babyId
,
@RequestBody
BabyDto
babyDto
)
{
log
.
info
(
"Inside baby controller updateBaby method"
);
return
ResponseEntity
.
ok
(
babyService
.
updateBaby
(
babyId
,
babyDto
));
}
@DeleteMapping
(
"/{id}"
)
public
ResponseEntity
<
ResponseDto
>
deleteBaby
(
@PathVariable
Long
babyId
)
{
log
.
info
(
"Inside baby controller deleteBaby method"
);
return
ResponseEntity
.
ok
(
babyService
.
deleteBaby
(
babyId
));
}
}
src/main/java/com/kaluwa/enterprises/babycarebackendservice/rest/EmotionalDetectionController.java
0 → 100644
View file @
948ec935
//package com.kaluwa.enterprises.babycarebackendservice.rest;
//
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.web.bind.annotation.*;
//
//import java.util.Map;
//
//@RestController
//@RequestMapping("/emotional")
//@CrossOrigin(origins = "*")
//@Slf4j
//public class EmotionalDetectionController {
//
// @PostMapping("/process-video")
// public Map<String, String> processVideo(@RequestBody String imageData) {
// // Send the image data to the Python FastAPI server for processing
// // Implement WebSocket or HTTP client to send data to FastAPI server
// log.info("Received video frame for processing");
// return Map.of("status", "Received video frame for processing");
// }
//
//}
src/main/java/com/kaluwa/enterprises/babycarebackendservice/rest/UserController.java
0 → 100644
View file @
948ec935
package
com.kaluwa.enterprises.babycarebackendservice.rest
;
import
com.kaluwa.enterprises.babycarebackendservice.dto.ResponseDto
;
import
com.kaluwa.enterprises.babycarebackendservice.dto.UserDto
;
import
com.kaluwa.enterprises.babycarebackendservice.service.UserService
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.web.bind.annotation.*
;
import
java.util.List
;
@RestController
@RequestMapping
(
"/user"
)
@Slf4j
public
class
UserController
{
private
final
UserService
userService
;
public
UserController
(
UserService
userService
)
{
this
.
userService
=
userService
;
}
// get user by id
@GetMapping
(
"/{userId}"
)
public
ResponseEntity
<
UserDto
>
getUserById
(
@PathVariable
Long
userId
)
{
log
.
info
(
"Inside user controller get user by id method"
);
return
new
ResponseEntity
<>(
userService
.
getUserById
(
userId
),
HttpStatus
.
OK
);
}
// get all users
@GetMapping
(
"/all"
)
public
ResponseEntity
<
List
<
UserDto
>>
getAllUsers
()
{
log
.
info
(
"Inside user controller get all users method"
);
return
new
ResponseEntity
<>(
userService
.
getAllUsers
(),
HttpStatus
.
OK
);
}
// update user
@PutMapping
(
"/{userId}"
)
public
ResponseEntity
<
UserDto
>
updateUser
(
@PathVariable
Long
userId
,
@RequestBody
UserDto
userDto
)
{
log
.
info
(
"Inside user controller update user method"
);
return
new
ResponseEntity
<>(
userService
.
updateUser
(
userId
,
userDto
),
HttpStatus
.
OK
);
}
// delete user
@DeleteMapping
(
"/{userId}"
)
public
ResponseEntity
<
ResponseDto
>
deleteUser
(
@PathVariable
Long
userId
)
{
log
.
info
(
"Inside user controller delete user method"
);
return
new
ResponseEntity
<>(
userService
.
deleteUser
(
userId
),
HttpStatus
.
OK
);
}
}
src/main/java/com/kaluwa/enterprises/babycarebackendservice/service/BabyService.java
0 → 100644
View file @
948ec935
package
com.kaluwa.enterprises.babycarebackendservice.service
;
import
com.kaluwa.enterprises.babycarebackendservice.dto.BabyDto
;
import
com.kaluwa.enterprises.babycarebackendservice.dto.ResponseDto
;
import
java.util.List
;
public
interface
BabyService
{
BabyDto
createBaby
(
BabyDto
babyDto
);
List
<
BabyDto
>
getAllBabies
();
BabyDto
getBabyById
(
Long
babyId
);
BabyDto
updateBaby
(
Long
babyId
,
BabyDto
babyDto
);
ResponseDto
deleteBaby
(
Long
babyId
);
}
src/main/java/com/kaluwa/enterprises/babycarebackendservice/service/UserService.java
View file @
948ec935
package
com.kaluwa.enterprises.babycarebackendservice.service
;
package
com.kaluwa.enterprises.babycarebackendservice.service
;
import
com.kaluwa.enterprises.babycarebackendservice.dto.AuthenticationDto
;
import
com.kaluwa.enterprises.babycarebackendservice.dto.*
;
import
com.kaluwa.enterprises.babycarebackendservice.dto.LoginRequest
;
import
com.kaluwa.enterprises.babycarebackendservice.dto.RegisterRequest
;
import
java.util.List
;
import
com.kaluwa.enterprises.babycarebackendservice.dto.UserDto
;
public
interface
UserService
{
public
interface
UserService
{
AuthenticationDto
login
(
LoginRequest
loginRequest
);
AuthenticationDto
login
(
LoginRequest
loginRequest
);
UserDto
register
(
RegisterRequest
registerRequest
);
UserDto
register
(
RegisterRequest
registerRequest
);
UserDto
getUserById
(
Long
userId
);
List
<
UserDto
>
getAllUsers
();
UserDto
updateUser
(
Long
userId
,
UserDto
userDto
);
ResponseDto
deleteUser
(
Long
userId
);
}
}
src/main/java/com/kaluwa/enterprises/babycarebackendservice/service/impl/BabyServiceImpl.java
0 → 100644
View file @
948ec935
package
com.kaluwa.enterprises.babycarebackendservice.service.impl
;
import
com.kaluwa.enterprises.babycarebackendservice.dao.BabyDao
;
import
com.kaluwa.enterprises.babycarebackendservice.dto.BabyDto
;
import
com.kaluwa.enterprises.babycarebackendservice.dto.ResponseDto
;
import
com.kaluwa.enterprises.babycarebackendservice.error.BadRequestAlertException
;
import
com.kaluwa.enterprises.babycarebackendservice.mappers.BabyMapper
;
import
com.kaluwa.enterprises.babycarebackendservice.model.Baby
;
import
com.kaluwa.enterprises.babycarebackendservice.service.BabyService
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.stereotype.Service
;
import
java.util.List
;
import
java.util.Optional
;
@Service
public
class
BabyServiceImpl
implements
BabyService
{
private
static
final
Logger
log
=
LoggerFactory
.
getLogger
(
BabyServiceImpl
.
class
);
private
final
BabyDao
babyDao
;
private
final
BabyMapper
babyMapper
;
public
BabyServiceImpl
(
BabyDao
babyDao
,
BabyMapper
babyMapper
)
{
this
.
babyDao
=
babyDao
;
this
.
babyMapper
=
babyMapper
;
}
@Override
public
BabyDto
createBaby
(
BabyDto
babyDto
)
{
log
.
info
(
"Inside baby service createBaby method"
);
try
{
return
babyMapper
.
toDto
(
babyDao
.
save
(
babyMapper
.
toEntity
(
babyDto
)));
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
throw
new
BadRequestAlertException
(
e
.
getMessage
(),
"baby"
,
"baby.error"
);
}
}
@Override
public
List
<
BabyDto
>
getAllBabies
()
{
log
.
info
(
"Inside baby service getAllBabies method"
);
try
{
return
babyMapper
.
toDtoList
(
babyDao
.
findAll
());
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
throw
new
BadRequestAlertException
(
e
.
getMessage
(),
"baby"
,
"baby.error"
);
}
}
@Override
public
BabyDto
getBabyById
(
Long
babyId
)
{
log
.
info
(
"Inside baby service getBabyById method"
);
try
{
Optional
<
Baby
>
babyOp
=
babyDao
.
findById
(
babyId
);
if
(
babyOp
.
isEmpty
())
{
throw
new
BadRequestAlertException
(
"Baby not found"
,
"baby"
,
"baby.error"
);
}
else
{
return
babyMapper
.
toDto
(
babyOp
.
get
());
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
throw
new
BadRequestAlertException
(
e
.
getMessage
(),
"baby"
,
"baby.error"
);
}
}
@Override
public
BabyDto
updateBaby
(
Long
babyId
,
BabyDto
babyDto
)
{
log
.
info
(
"Inside baby service updateBaby method"
);
try
{
Optional
<
Baby
>
babyOp
=
babyDao
.
findById
(
babyId
);
if
(
babyDto
.
getBabyId
()
==
null
)
{
throw
new
BadRequestAlertException
(
"Baby id is required"
,
"baby"
,
"baby.error"
);
}
else
if
(!
babyId
.
equals
(
babyDto
.
getBabyId
()))
{
throw
new
BadRequestAlertException
(
"Baby id mismatch"
,
"baby"
,
"baby.error"
);
}
else
if
(
babyOp
.
isEmpty
())
{
throw
new
BadRequestAlertException
(
"Baby not found"
,
"baby"
,
"baby.error"
);
}
else
{
return
babyMapper
.
toDto
(
babyDao
.
save
(
babyMapper
.
toEntity
(
babyDto
)));
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
throw
new
BadRequestAlertException
(
e
.
getMessage
(),
"baby"
,
"baby.error"
);
}
}
@Override
public
ResponseDto
deleteBaby
(
Long
babyId
)
{
log
.
info
(
"Inside baby service deleteBaby method"
);
try
{
Optional
<
Baby
>
babyOp
=
babyDao
.
findById
(
babyId
);
if
(
babyOp
.
isEmpty
())
{
throw
new
BadRequestAlertException
(
"Baby not found"
,
"baby"
,
"baby.error"
);
}
else
{
babyDao
.
deleteById
(
babyId
);
ResponseDto
responseDto
=
new
ResponseDto
();
responseDto
.
setId
(
babyId
);
responseDto
.
setMessage
(
"Baby deleted successfully"
);
return
responseDto
;
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
throw
new
BadRequestAlertException
(
e
.
getMessage
(),
"baby"
,
"baby.error"
);
}
}
}
src/main/java/com/kaluwa/enterprises/babycarebackendservice/service/impl/UserServiceImpl.java
View file @
948ec935
...
@@ -14,6 +14,8 @@ import org.springframework.security.crypto.password.PasswordEncoder;
...
@@ -14,6 +14,8 @@ import org.springframework.security.crypto.password.PasswordEncoder;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
import
java.util.HashMap
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Optional
;
import
static
com
.
kaluwa
.
enterprises
.
babycarebackendservice
.
constants
.
Common
.
TOKEN_TYPE
;
import
static
com
.
kaluwa
.
enterprises
.
babycarebackendservice
.
constants
.
Common
.
TOKEN_TYPE
;
import
static
com
.
kaluwa
.
enterprises
.
babycarebackendservice
.
constants
.
Status
.
STATUS_NEW
;
import
static
com
.
kaluwa
.
enterprises
.
babycarebackendservice
.
constants
.
Status
.
STATUS_NEW
;
...
@@ -69,6 +71,7 @@ public class UserServiceImpl implements UserService {
...
@@ -69,6 +71,7 @@ public class UserServiceImpl implements UserService {
return
authenticationDto
;
return
authenticationDto
;
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
throw
new
BadRequestAlertException
(
e
.
getMessage
(),
"User"
,
"User login failed"
);
throw
new
BadRequestAlertException
(
e
.
getMessage
(),
"User"
,
"User login failed"
);
}
}
}
}
...
@@ -96,6 +99,85 @@ public class UserServiceImpl implements UserService {
...
@@ -96,6 +99,85 @@ public class UserServiceImpl implements UserService {
userDto
=
userMapper
.
toDto
(
userDao
.
save
(
user
));
userDto
=
userMapper
.
toDto
(
userDao
.
save
(
user
));
return
userDto
;
return
userDto
;
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
throw
new
BadRequestAlertException
(
e
.
getMessage
(),
"User"
,
"User registration failed"
);
}
}
@Override
public
UserDto
getUserById
(
Long
userId
)
{
log
.
info
(
"Inside user service get user by id method"
);
try
{
Optional
<
User
>
userOp
=
userDao
.
findById
(
userId
);
if
(
userOp
.
isEmpty
())
{
throw
new
BadRequestAlertException
(
"User not found"
,
"User"
,
"User not found"
);
}
else
{
return
userMapper
.
toDto
(
userOp
.
get
());
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
throw
new
BadRequestAlertException
(
e
.
getMessage
(),
"User"
,
"User registration failed"
);
}
}
@Override
public
List
<
UserDto
>
getAllUsers
()
{
log
.
info
(
"Inside user service get all users method"
);
try
{
List
<
User
>
users
=
userDao
.
findAll
();
return
userMapper
.
listToDto
(
users
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
throw
new
BadRequestAlertException
(
e
.
getMessage
(),
"User"
,
"User registration failed"
);
}
}
@Override
public
UserDto
updateUser
(
Long
userId
,
UserDto
userDto
)
{
log
.
info
(
"Inside user service update user method"
);
try
{
Optional
<
User
>
userOp
=
userDao
.
findById
(
userId
);
if
(
userDto
.
getUserId
()
==
null
)
{
throw
new
BadRequestAlertException
(
"User id is required"
,
"User"
,
"User update failed"
);
}
else
if
(!
userId
.
equals
(
userDto
.
getUserId
()))
{
throw
new
BadRequestAlertException
(
"User id mismatch"
,
"User"
,
"User update failed"
);
}
else
if
(
userOp
.
isEmpty
())
{
throw
new
BadRequestAlertException
(
"User not found"
,
"User"
,
"User not found"
);
}
else
if
(
userDto
.
getPhone
()
==
null
||
userDto
.
getPhone
().
isEmpty
())
{
throw
new
BadRequestAlertException
(
"Phone number is required"
,
"User"
,
"User update failed"
);
}
else
if
(
userDto
.
getFirstName
()
==
null
||
userDto
.
getFirstName
().
isEmpty
())
{
throw
new
BadRequestAlertException
(
"First name is required"
,
"User"
,
"User update failed"
);
}
else
if
(
userDto
.
getLastName
()
==
null
||
userDto
.
getLastName
().
isEmpty
())
{
throw
new
BadRequestAlertException
(
"Last name is required"
,
"User"
,
"User update failed"
);
}
else
{
User
user
=
userOp
.
get
();
user
.
setFirstName
(
userDto
.
getFirstName
());
user
.
setLastName
(
userDto
.
getLastName
());
user
.
setPhone
(
userDto
.
getPhone
());
return
userMapper
.
toDto
(
userDao
.
save
(
user
));
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
throw
new
BadRequestAlertException
(
e
.
getMessage
(),
"User"
,
"User registration failed"
);
}
}
@Override
public
ResponseDto
deleteUser
(
Long
userId
)
{
log
.
info
(
"Inside user service delete user method"
);
try
{
Optional
<
User
>
userOp
=
userDao
.
findById
(
userId
);
if
(
userOp
.
isEmpty
())
{
throw
new
BadRequestAlertException
(
"User not found"
,
"User"
,
"User not found"
);
}
else
{
userDao
.
deleteById
(
userId
);
ResponseDto
responseDto
=
new
ResponseDto
();
responseDto
.
setId
(
userId
);
responseDto
.
setMessage
(
"User deleted successfully"
);
return
responseDto
;
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
throw
new
BadRequestAlertException
(
e
.
getMessage
(),
"User"
,
"User registration failed"
);
throw
new
BadRequestAlertException
(
e
.
getMessage
(),
"User"
,
"User registration failed"
);
}
}
}
}
...
...
src/main/java/com/kaluwa/enterprises/babycarebackendservice/socketHandlers/BoundingBox.java
0 → 100644
View file @
948ec935
package
com.kaluwa.enterprises.babycarebackendservice.socketHandlers
;
import
lombok.AllArgsConstructor
;
import
lombok.Data
;
import
lombok.NoArgsConstructor
;
@Data
@AllArgsConstructor
@NoArgsConstructor
public
class
BoundingBox
{
private
int
x
;
private
int
y
;
private
int
width
;
private
int
height
;
}
src/main/java/com/kaluwa/enterprises/babycarebackendservice/socketHandlers/EmotionPrediction.java
0 → 100644
View file @
948ec935
package
com.kaluwa.enterprises.babycarebackendservice.socketHandlers
;
import
lombok.AllArgsConstructor
;
import
lombok.Data
;
import
lombok.NoArgsConstructor
;
@Data
@AllArgsConstructor
@NoArgsConstructor
public
class
EmotionPrediction
{
private
String
emotion
;
private
BoundingBox
bounding_box
;
}
\ No newline at end of file
src/main/java/com/kaluwa/enterprises/babycarebackendservice/socketHandlers/SocketConnectionHandlers.java
0 → 100644
View file @
948ec935
//package com.kaluwa.enterprises.babycarebackendservice.socketHandlers;
//
//// Program to eastablish the socket connection
//
//import java.util.ArrayList;
//import java.util.Collections;
//import java.util.List;
//
//import com.kaluwa.enterprises.babycarebackendservice.config.WebSocketClient;
//import org.springframework.web.socket.*;
//import org.springframework.web.socket.handler.BinaryWebSocketHandler;
//import org.springframework.web.socket.handler.TextWebSocketHandler;
//
//// Socket-Connection Configuration class
//public class SocketConnectionHandlers {
//
//
//
//}
//
src/main/resources/application.yaml
View file @
948ec935
...
@@ -13,7 +13,7 @@ spring:
...
@@ -13,7 +13,7 @@ spring:
jpa
:
jpa
:
hibernate
:
hibernate
:
ddl-auto
:
update
ddl-auto
:
update
show-sql
:
tru
e
show-sql
:
fals
e
properties
:
properties
:
hibernate
:
hibernate
:
format_sql
:
true
format_sql
:
true
...
...
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