Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
G
Group17ProfileMicroservice
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Asif, Adiv (UG - Comp Sci & Elec Eng)
Group17ProfileMicroservice
Commits
ebc0dc2e
Commit
ebc0dc2e
authored
2 years ago
by
MikelLiza
Committed by
Adiv
2 years ago
Browse files
Options
Downloads
Patches
Plain Diff
add
parent
01255df6
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
Services/ProfileService.cs
+25
-12
25 additions, 12 deletions
Services/ProfileService.cs
with
25 additions
and
12 deletions
Services/ProfileService.cs
+
25
−
12
View file @
ebc0dc2e
...
@@ -12,9 +12,9 @@ namespace Group17profile.Services;
...
@@ -12,9 +12,9 @@ namespace Group17profile.Services;
public
interface
IProfileService
public
interface
IProfileService
{
{
Task
<
ProfileDTO
>
CreateOrUpdateProfile
(
ProfileDTO
profile
,
int
userId
);
Task
<
ProfileDTO
>
CreateOrUpdateProfile
(
ProfileDTO
profile
,
int
userId
);
Task
<
UserProfileDTO
>
GetProfileForUser
(
int
userId
);
Task
<
UserProfileDTO
>
GetProfileForUser
(
ProfileDTO
profile
,
int
userId
);
Task
<
string
>
UploadBannerPicture
(
int
userId
,
IFormFile
bannerPicture
);
Task
<
string
>
UploadBannerPicture
(
ProfileDTO
profile
,
int
userId
,
IFormFile
bannerPicture
);
Task
<
string
>
EditBannerPicture
(
int
userId
,
IFormFile
?
bannerPicture
=
null
);
Task
<
string
>
EditBannerPicture
(
ProfileDTO
profile
,
int
userId
,
IFormFile
?
bannerPicture
=
null
);
}
}
public
class
ProfileService
:
IProfileService
public
class
ProfileService
:
IProfileService
...
@@ -29,14 +29,13 @@ public class ProfileService : IProfileService
...
@@ -29,14 +29,13 @@ public class ProfileService : IProfileService
_mapper
=
mapper
;
_mapper
=
mapper
;
_profileRepository
=
profileRepository
;
_profileRepository
=
profileRepository
;
_userRepository
=
userRepository
;
_userRepository
=
userRepository
;
}
}
public
async
Task
<
ProfileDTO
>
CreateOrUpdateProfile
(
ProfileDTO
profile
,
int
userId
)
public
async
Task
<
ProfileDTO
>
CreateOrUpdateProfile
(
ProfileDTO
profile
,
int
userId
)
{
{
var
user
=
_userRepository
.
GetByIdThrowIfNull
(
userId
);
var
user
=
_userRepository
.
GetByIdThrowIfNull
(
userId
);
var
age
=
DateTimeOffset
.
Now
.
Year
-
profile
.
DoB
.
GetValueOrDefault
().
Year
;
var
age
=
DateTimeOffset
.
Now
.
Year
-
profile
.
DoB
.
GetValueOrDefault
().
Year
;
if
(
age
is
<=
16
or
>=
100
)
if
(
age
is
<=
16
or
>=
100
)
{
{
throw
new
ProfileException
(
"Please enter valid age"
);
throw
new
ProfileException
(
"Please enter valid age"
);
...
@@ -53,7 +52,7 @@ public class ProfileService : IProfileService
...
@@ -53,7 +52,7 @@ public class ProfileService : IProfileService
record
.
FavouriteShows
=
builder
.
ToString
();
record
.
FavouriteShows
=
builder
.
ToString
();
}
}
if
(
user
.
ProfileId
==
null
)
if
(
user
.
ProfileId
==
null
)
{
{
var
newProfile
=
await
_profileRepository
.
CreateAndSaveAsync
(
record
);
var
newProfile
=
await
_profileRepository
.
CreateAndSaveAsync
(
record
);
...
@@ -69,20 +68,34 @@ public class ProfileService : IProfileService
...
@@ -69,20 +68,34 @@ public class ProfileService : IProfileService
var
user
=
_userRepository
.
GetByIdThrowIfNull
(
userId
);
var
user
=
_userRepository
.
GetByIdThrowIfNull
(
userId
);
if
(
user
.
ProfileId
==
null
)
if
(
user
.
ProfileId
==
null
)
throw
new
ProfileException
(
"Failed to retrieve profile for user"
);
throw
new
ProfileException
(
"Failed to retrieve profile for user"
);
var
record
=
_mapper
.
Map
<
Profile
>(
profile
);
if
(!
string
.
IsNullOrWhiteSpace
(
record
.
FavouriteShows
))
{
var
s
=
record
.
FavouriteShows
.
Split
(
','
);
var
list
=
s
.
ToList
();
profile
.
FavouriteShows
=
list
;
}
var
profile
=
_mapper
.
Map
<
ProfileDTO
>(
_profileRepository
.
GetAll
().
AsNoTracking
()
var
profile
=
_mapper
.
Map
<
ProfileDTO
>(
_profileRepository
.
GetAll
().
AsNoTracking
()
.
FirstOrDefault
(
p
=>
p
.
Id
==
user
.
ProfileId
));
.
FirstOrDefault
(
p
=>
p
.
Id
==
user
.
ProfileId
));
return
new
UserProfileDTO
()
{
User
=
_mapper
.
Map
<
UserDTO
>(
user
),
Profile
=
profile
};
return
new
UserProfileDTO
()
{
User
=
_mapper
.
Map
<
UserDTO
>(
user
),
Profile
=
profile
};
}
}
public
Task
<
string
>
UploadBannerPicture
(
int
userId
,
IFormFile
bannerPicture
)
public
Task
<
string
>
UploadBannerPicture
(
ProfileDTO
profile
,
int
userId
,
IFormFile
bannerPicture
)
{
{
var
user
=
_userRepository
.
GetByIdThrowIfNull
(
userId
);
if
(
profile
.
BannerUrl
==
null
)
{
}
throw
new
NotImplementedException
();
throw
new
NotImplementedException
();
}
}
public
Task
<
string
>
EditBannerPicture
(
int
userId
,
IFormFile
?
bannerPicture
=
null
)
public
Task
<
string
>
EditBannerPicture
(
ProfileDTO
profile
,
int
userId
,
IFormFile
?
bannerPicture
=
null
)
{
{
var
user
=
_userRepository
.
GetByIdThrowIfNull
(
userId
);
throw
new
NotImplementedException
();
throw
new
NotImplementedException
();
}
}
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment