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
404837a9
Commit
404837a9
authored
Oct 20, 2024
by
Ishankha K.C
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
attach image to babyDto
parent
e3c40e4e
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
7 deletions
+26
-7
src/main/java/com/kaluwa/enterprises/babycarebackendservice/dto/BabyDto.java
...aluwa/enterprises/babycarebackendservice/dto/BabyDto.java
+2
-0
src/main/java/com/kaluwa/enterprises/babycarebackendservice/service/impl/BabyServiceImpl.java
.../babycarebackendservice/service/impl/BabyServiceImpl.java
+24
-7
No files found.
src/main/java/com/kaluwa/enterprises/babycarebackendservice/dto/BabyDto.java
View file @
404837a9
...
@@ -6,6 +6,7 @@ import lombok.AllArgsConstructor;
...
@@ -6,6 +6,7 @@ import lombok.AllArgsConstructor;
import
lombok.Data
;
import
lombok.Data
;
import
lombok.NoArgsConstructor
;
import
lombok.NoArgsConstructor
;
import
java.io.InputStream
;
import
java.time.LocalDate
;
import
java.time.LocalDate
;
import
static
com
.
kaluwa
.
enterprises
.
babycarebackendservice
.
constants
.
Status
.
STATUS_NEW
;
import
static
com
.
kaluwa
.
enterprises
.
babycarebackendservice
.
constants
.
Status
.
STATUS_NEW
;
...
@@ -54,6 +55,7 @@ public class BabyDto {
...
@@ -54,6 +55,7 @@ public class BabyDto {
private
String
notes
;
private
String
notes
;
private
String
uniqKey
;
private
String
uniqKey
;
private
UserDto
user
;
private
UserDto
user
;
private
byte
[]
imageData
;
@NotNull
(
message
=
"Logged user id is required"
)
@NotNull
(
message
=
"Logged user id is required"
)
@NotEmpty
(
message
=
"Logged user id is required"
)
@NotEmpty
(
message
=
"Logged user id is required"
)
...
...
src/main/java/com/kaluwa/enterprises/babycarebackendservice/service/impl/BabyServiceImpl.java
View file @
404837a9
...
@@ -9,14 +9,20 @@ import com.kaluwa.enterprises.babycarebackendservice.mappers.BabyMapper;
...
@@ -9,14 +9,20 @@ import com.kaluwa.enterprises.babycarebackendservice.mappers.BabyMapper;
import
com.kaluwa.enterprises.babycarebackendservice.model.Baby
;
import
com.kaluwa.enterprises.babycarebackendservice.model.Baby
;
import
com.kaluwa.enterprises.babycarebackendservice.model.Document
;
import
com.kaluwa.enterprises.babycarebackendservice.model.Document
;
import
com.kaluwa.enterprises.babycarebackendservice.service.BabyService
;
import
com.kaluwa.enterprises.babycarebackendservice.service.BabyService
;
import
com.kaluwa.enterprises.babycarebackendservice.service.DocumentService
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
import
org.slf4j.Logger
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
import
java.io.ByteArrayInputStream
;
import
java.io.InputStream
;
import
java.util.Arrays
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Optional
;
import
java.util.Optional
;
import
static
com
.
kaluwa
.
enterprises
.
babycarebackendservice
.
constants
.
DocumentTypes
.
IMAGE
;
import
static
com
.
kaluwa
.
enterprises
.
babycarebackendservice
.
constants
.
TableNames
.
BABY_TABLE
;
import
static
com
.
kaluwa
.
enterprises
.
babycarebackendservice
.
utils
.
Utils
.
uniqKeyGenerator
;
import
static
com
.
kaluwa
.
enterprises
.
babycarebackendservice
.
utils
.
Utils
.
uniqKeyGenerator
;
@Service
@Service
...
@@ -25,12 +31,13 @@ public class BabyServiceImpl implements BabyService {
...
@@ -25,12 +31,13 @@ public class BabyServiceImpl implements BabyService {
private
final
BabyDao
babyDao
;
private
final
BabyDao
babyDao
;
private
final
BabyMapper
babyMapper
;
private
final
BabyMapper
babyMapper
;
private
final
DocumentDao
documentDao
;
private
final
DocumentDao
documentDao
;
private
final
DocumentService
documentService
;
public
BabyServiceImpl
(
BabyDao
babyDao
,
BabyMapper
babyMapper
,
DocumentDao
documentDao
,
DocumentService
documentService
)
{
public
BabyServiceImpl
(
BabyDao
babyDao
,
BabyMapper
babyMapper
,
DocumentDao
documentDao
)
{
this
.
babyDao
=
babyDao
;
this
.
babyDao
=
babyDao
;
this
.
babyMapper
=
babyMapper
;
this
.
babyMapper
=
babyMapper
;
this
.
documentDao
=
documentDao
;
this
.
documentDao
=
documentDao
;
this
.
documentService
=
documentService
;
}
}
@Override
@Override
...
@@ -49,7 +56,19 @@ public class BabyServiceImpl implements BabyService {
...
@@ -49,7 +56,19 @@ public class BabyServiceImpl implements BabyService {
public
List
<
BabyDto
>
getAllBabies
()
{
public
List
<
BabyDto
>
getAllBabies
()
{
log
.
info
(
"Inside baby service getAllBabies method"
);
log
.
info
(
"Inside baby service getAllBabies method"
);
try
{
try
{
return
babyMapper
.
toDtoList
(
babyDao
.
findAll
());
List
<
BabyDto
>
babyList
=
babyMapper
.
toDtoList
(
babyDao
.
findAll
());
babyList
.
forEach
(
babyDto
->
{
Optional
<
Document
>
documentOp
=
documentDao
.
findByTableNameAndUniqKeyAndDocumentType
(
BABY_TABLE
,
babyDto
.
getUniqKey
(),
IMAGE
);
documentOp
.
ifPresent
(
document
->
{
byte
[]
imageData
=
documentService
.
getImage
(
BABY_TABLE
,
babyDto
.
getUniqKey
()).
getBody
();
if
(
imageData
!=
null
)
{
babyDto
.
setImageData
(
imageData
);
}
});
});
return
babyList
;
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
e
.
printStackTrace
();
throw
new
BadRequestAlertException
(
e
.
getMessage
(),
"baby"
,
"baby.error"
);
throw
new
BadRequestAlertException
(
e
.
getMessage
(),
"baby"
,
"baby.error"
);
...
@@ -100,10 +119,8 @@ public class BabyServiceImpl implements BabyService {
...
@@ -100,10 +119,8 @@ public class BabyServiceImpl implements BabyService {
if
(
babyOp
.
isEmpty
())
{
if
(
babyOp
.
isEmpty
())
{
throw
new
BadRequestAlertException
(
"Baby not found"
,
"baby"
,
"baby.error"
);
throw
new
BadRequestAlertException
(
"Baby not found"
,
"baby"
,
"baby.error"
);
}
else
{
}
else
{
Optional
<
Document
>
documentOp
=
documentDao
.
findById
(
babyOp
.
get
().
getDocumentId
());
Optional
<
Document
>
documentOp
=
documentDao
.
findByTableNameAndUniqKeyAndDocumentType
(
BABY_TABLE
,
babyOp
.
get
().
getUniqKey
(),
IMAGE
);
if
(
documentOp
.
isPresent
())
{
documentOp
.
ifPresent
(
document
->
documentDao
.
deleteById
(
document
.
getDocumentId
()));
documentDao
.
deleteById
(
babyOp
.
get
().
getDocumentId
());
}
babyDao
.
deleteById
(
babyId
);
babyDao
.
deleteById
(
babyId
);
ResponseDto
responseDto
=
new
ResponseDto
();
ResponseDto
responseDto
=
new
ResponseDto
();
responseDto
.
setId
(
babyId
);
responseDto
.
setId
(
babyId
);
...
...
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