Skip to content

Commit 7539c61

Browse files
authored
Merge pull request #26 from KYJKY/master
DB 개선, FCM 토큰 추가
2 parents d4b2f07 + 5f523fe commit 7539c61

33 files changed

+984
-1406
lines changed

EveryPinApi.Entites/Code/CodePlatform.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ namespace Entites.Code;
88

99
public enum CodePlatform
1010
{
11-
NONE = -1,
12-
KAKAO = 1,
13-
GOOGLE = 2
11+
NONE = 1,
12+
KAKAO = 2,
13+
GOOGLE = 3
1414
}

EveryPinApi.Entites/Models/CodeOAuthPlatform.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ namespace Entites.Models;
1010

1111
public class CodeOAuthPlatform
1212
{
13-
[Column("PlatformCodeId")]
14-
public int Id { get; set; }
15-
[Required]
16-
public string? PlatformName { get; set; }
17-
public ICollection<User>? User { get; set; } = new List<User>();
13+
[Key]
14+
public int PlatformCode { get; set; }
15+
public required string PlatformName { get; set; }
16+
17+
public virtual ICollection<User> Users { get; set; } = new List<User>();
1818
}

EveryPinApi.Entites/Models/Comment.cs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.ComponentModel.DataAnnotations;
34
using System.ComponentModel.DataAnnotations.Schema;
45
using System.Linq;
56
using System.Text;
@@ -9,16 +10,16 @@ namespace Entites.Models;
910

1011
public class Comment
1112
{
12-
[Column("CommentId")]
13-
public int CommentId { get; set; }
14-
15-
public int? PostId { get; set; }
16-
public Post? Post { get; set; }
17-
18-
[ForeignKey(nameof(User))]
13+
[Key]
14+
public int CommentSeq { get; set; }
15+
public required int PostSeq { get; set; }
1916
public required string UserId { get; set; }
20-
public User? User { get; set; }
21-
2217
public string? CommentMessage { get; set; }
23-
public DateTime? CreatedDate { get; set; } = DateTime.Now;
18+
public DateTime? UpdateDate { get; set; }
19+
public DateTime CreatedDate { get; set; }
20+
21+
[ForeignKey("PostSeq")]
22+
public virtual required Post Post { get; set; }
23+
[ForeignKey("UserId")]
24+
public virtual required User User { get; set; }
2425
}

EveryPinApi.Entites/Models/Follow.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.ComponentModel.DataAnnotations;
4+
using System.ComponentModel.DataAnnotations.Schema;
5+
using System.Linq;
6+
using System.Text;
7+
using System.Threading.Tasks;
8+
9+
namespace Entites.Models;
10+
public class Follow
11+
{
12+
[Key]
13+
public int FollowSeq { get; set; }
14+
public required string FollowerId { get; set; }
15+
public required string FollowingId { get; set; }
16+
public DateTime CreatedDate { get; set; }
17+
18+
[ForeignKey("FollowerId")]
19+
public virtual required User Follower { get; set; }
20+
[ForeignKey("FollowingId")]
21+
public virtual required User Following { get; set; }
22+
}

EveryPinApi.Entites/Models/Like.cs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
 using System;
22
using System.Collections.Generic;
3+
using System.ComponentModel.DataAnnotations;
34
using System.ComponentModel.DataAnnotations.Schema;
45
using System.Linq;
56
using System.Text;
@@ -9,15 +10,15 @@ namespace Entites.Models;
910

1011
public class Like
1112
{
12-
[Column("LikeId")]
13-
public int LikeId { get; set; }
14-
15-
public int? PostId { get; set; }
16-
public Post? Post { get; set; }
17-
18-
[ForeignKey(nameof(User))]
13+
[Key]
14+
public int LikeSeq { get; set; }
15+
public int PostSeq { get; set; }
1916
public required string UserId { get; set; }
20-
public User? User { get; set; }
17+
public DateTime CreatedDate { get; set; }
18+
19+
[ForeignKey("PostSeq")]
20+
public virtual Post? Post { get; set; }
21+
[ForeignKey("UserId")]
22+
public virtual User? User { get; set; }
2123

22-
public DateTime? CreatedDate { get; set; } = DateTime.Now;
2324
}

EveryPinApi.Entites/Models/Post.cs

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.ComponentModel.DataAnnotations;
34
using System.ComponentModel.DataAnnotations.Schema;
45
using System.Linq;
56
using System.Text;
@@ -9,17 +10,19 @@ namespace Entites.Models;
910

1011
public class Post
1112
{
12-
[Column("PostId")]
13-
public int PostId { get; set; }
14-
[ForeignKey(nameof(User))]
13+
[Key]
14+
public int PostSeq { get; set; }
1515
public required string UserId { get; set; }
1616
public string? PostContent { get; set; }
1717
public string? Address { get; set; }
18-
public double? x { get; set; }
19-
public double? y { get; set; }
20-
public ICollection<PostPhoto> PostPhotos { get; set; } = new List<PostPhoto>();
21-
public ICollection<Like> Likes { get; } = new List<Like>();
22-
public ICollection<Comment> Comments { get; } = new List<Comment>();
23-
public DateTime? UpdateDate { get; set; } = null;
24-
public DateTime? CreatedDate { get; set; } = DateTime.Now;
18+
public float? X { get; set; }
19+
public float? Y { get; set; }
20+
public DateTime? UpdateDate { get; set; }
21+
public DateTime CreatedDate { get; set; }
22+
23+
[ForeignKey("UserId")]
24+
public virtual required User User { get; set; }
25+
public virtual ICollection<PostPhoto> PostPhotos { get; set; } = new List<PostPhoto>();
26+
public virtual ICollection<Like> Likes { get; } = new List<Like>();
27+
public virtual ICollection<Comment> Comments { get; } = new List<Comment>();
2528
}

EveryPinApi.Entites/Models/PostPhoto.cs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,16 @@ namespace Entites.Models;
1010

1111
public class PostPhoto
1212
{
13-
[Column("PostPhotoId")]
14-
public int PostPhotoId { get; set; }
13+
[Key]
14+
public int PostPhotoSeq { get; set; }
15+
16+
[ForeignKey(nameof(Post))]
17+
public int PostSeq { get; set; }
18+
19+
public string? PhotoUrl { get; set; }
20+
public DateTime? UpdateDate { get; set; }
21+
public DateTime CreatedDate { get; set; }
1522

16-
public int? PostId { get; set; }
1723
public Post? Post { get; set; }
18-
19-
public string? photoUrl { get; set; }
2024
}
25+

EveryPinApi.Entites/Models/Profile.cs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.ComponentModel.DataAnnotations;
34
using System.ComponentModel.DataAnnotations.Schema;
45
using System.Linq;
56
using System.Text;
@@ -9,18 +10,16 @@ namespace Entites.Models;
910

1011
public class Profile
1112
{
12-
[Column("ProfileId")]
13-
public int Id { get; set; }
14-
15-
[ForeignKey(nameof(User))]
13+
[Key]
14+
public int ProfileSeq { get; set; }
1615
public required string UserId { get; set; }
17-
public User? User { get; set; }
18-
19-
public string? TagId { get; set; } = null!;
20-
public string? Name { get; set; }
16+
public required string ProfileTag { get; set; }
17+
public required string ProfileName { get; set; }
2118
public string? SelfIntroduction { get; set; }
2219
public string? PhotoUrl { get; set; }
23-
public DateTime? UpdatedDate { get; set; } = null;
24-
public DateTime? CreatedDate { get; set; } = DateTime.Now;
20+
public DateTime? UpdatedDate { get; set; }
21+
public required DateTime CreatedDate { get; set; }
2522

23+
[ForeignKey("UserId")]
24+
public virtual required User User { get; set; }
2625
}

EveryPinApi.Entites/Models/User.cs

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
using Microsoft.AspNetCore.Identity;
2+
using Microsoft.EntityFrameworkCore;
23
using System;
34
using System.Collections.Generic;
5+
using System.ComponentModel.DataAnnotations;
46
using System.ComponentModel.DataAnnotations.Schema;
57
using System.Linq;
68
using System.Text;
@@ -10,18 +12,21 @@ namespace Entites.Models;
1012

1113
public class User : IdentityUser
1214
{
13-
//[Column("UserId")]
14-
//public int Id { get; set; }
15-
[ForeignKey(nameof(CodeOAuthPlatform))]
16-
public int PlatformCodeId { get; set; }
17-
public Profile? Profile { get; set; }
18-
public string? Name { get; set; }
19-
//public string? Email { get; set; }
15+
public override required string Id { get; set; }
16+
public int? PlatformCode { get; set; }
17+
public string? FcmToken { get; set; }
2018
public string? RefreshToken { get; set; }
2119
public DateTime RefreshTokenExpiryTime { get; set; }
2220
public DateTime CreatedDate { get; set; }
2321
public DateTime LastLoginDate { get; set; }
2422
public bool DeleteCheck { get; set; }
25-
public ICollection<Like> Like { get; set; } = new List<Like>();
26-
public ICollection<Post> Post { get; set; } = new List<Post>();
23+
24+
[ForeignKey("PlatformCode")]
25+
public virtual required CodeOAuthPlatform CodeOAuthPlatform { get; set; }
26+
public virtual Profile? Profile { get; set; }
27+
public virtual ICollection<Like> Like { get; set; } = new List<Like>();
28+
public virtual ICollection<Comment> Comments { get; set; } = new List<Comment>();
29+
public virtual ICollection<Post> Post { get; set; } = new List<Post>();
30+
public virtual ICollection<Follow> FollowingList { get; set; } = new List<Follow>();
31+
public virtual ICollection<Follow> FollowerList { get; set; } = new List<Follow>();
2732
}

EveryPinApi.Presentation/Controllers/AuthController.cs

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
using Entites.Code;
2+
using Entites.Models;
3+
using Microsoft.AspNetCore.Authentication;
4+
using Microsoft.AspNetCore.Authentication.Cookies;
5+
using Microsoft.AspNetCore.Http;
26
using Microsoft.AspNetCore.Identity;
37
using Microsoft.AspNetCore.Mvc;
48
using Microsoft.Extensions.Logging;
59
using Service.Contracts;
610
using Shared.DataTransferObject;
711
using Shared.DataTransferObject.Auth;
812
using Shared.DataTransferObject.InputDto.Auth;
13+
using System.Security.Claims;
914

1015
namespace EveryPinApi.Presentation.Controllers;
1116

@@ -15,11 +20,13 @@ public class AuthController : ControllerBase
1520
{
1621
private readonly ILogger _logger;
1722
private readonly IServiceManager _service;
23+
private readonly IHttpContextAccessor _httpContextAccessor;
1824

19-
public AuthController(ILogger<AuthController> logger, IServiceManager service)
25+
public AuthController(ILogger<AuthController> logger, IServiceManager service, IHttpContextAccessor httpContextAccessor)
2026
{
2127
_logger = logger;
2228
_service = service;
29+
_httpContextAccessor = httpContextAccessor;
2330
}
2431

2532
[HttpPost("login")]
@@ -37,11 +44,11 @@ public async Task<IActionResult> Login(LoginInputDto loginInputDto)
3744
{
3845
case nameof(CodePlatform.KAKAO):
3946
userPlatform = CodePlatform.KAKAO;
40-
userInfo = await _service.SingleSignOnService.GetKakaoUserInfo(loginInputDto.accessToken);
47+
userInfo = await _service.SingleSignOnService.GetKakaoUserInfo(loginInputDto.ssoAccessToken);
4148
break;
4249
case nameof(CodePlatform.GOOGLE):
4350
userPlatform = CodePlatform.GOOGLE;
44-
userInfo = await _service.SingleSignOnService.GetGoogleUserInfoToIdToken(loginInputDto.accessToken);
51+
userInfo = await _service.SingleSignOnService.GetGoogleUserInfoToIdToken(loginInputDto.ssoAccessToken);
4552
break;
4653
default:
4754
throw new Exception("유효한 platformCode 값이 아닙니다.");
@@ -52,7 +59,7 @@ public async Task<IActionResult> Login(LoginInputDto loginInputDto)
5259

5360
if (user)
5461
{
55-
var tokenDto = await _service.AuthenticationService.CreateToken(populateExp: true);
62+
var tokenDto = await _service.AuthenticationService.CreateTokenWithUpdateFcmToken(loginInputDto.fcmToken, populateExp: true);
5663

5764
return Ok(tokenDto);
5865
}
@@ -64,7 +71,8 @@ public async Task<IActionResult> Login(LoginInputDto loginInputDto)
6471
UserName = userInfo.UserNickName,
6572
Email = userInfo.UserEmail,
6673
Password = "0",
67-
PlatformCodeId = (int)userPlatform,
74+
PlatformCode = (int)userPlatform,
75+
FcmToken = loginInputDto.fcmToken,
6876
Roles = new List<string>() { "NormalUser" }
6977
};
7078

@@ -77,9 +85,12 @@ public async Task<IActionResult> Login(LoginInputDto loginInputDto)
7785
var profile = new Entites.Models.Profile()
7886
{
7987
UserId = userAccountInfo.Id,
80-
Name = null,
88+
ProfileName = userInfo.UserNickName,
8189
SelfIntroduction = null,
82-
PhotoUrl = null
90+
PhotoUrl = null,
91+
ProfileTag = userInfo.UserNickName,
92+
User = userAccountInfo,
93+
CreatedDate = DateTime.Now
8394
};
8495

8596
var createdProfile = await _service.ProfileService.CreateProfile(profile);
@@ -98,7 +109,7 @@ public async Task<IActionResult> Login(LoginInputDto loginInputDto)
98109
}
99110
else
100111
{
101-
_logger.LogError($"로그인 - 유저 생성 유효성 검사, platformCode: {loginInputDto.platformCode}, accessToken: {loginInputDto.accessToken}, userInfo.UserEmail: {userInfo.UserEmail}");
112+
_logger.LogError($"로그인 - 유저 생성 유효성 검사, platformCode: {loginInputDto.platformCode}, ssoAccessToken: {loginInputDto.ssoAccessToken}, userInfo.UserEmail: {userInfo.UserEmail}");
102113

103114
foreach (var error in registedUser.Errors)
104115
{
@@ -108,11 +119,10 @@ public async Task<IActionResult> Login(LoginInputDto loginInputDto)
108119
return Unauthorized();
109120
}
110121
}
111-
112122
}
113123
catch (Exception ex)
114124
{
115-
_logger.LogError($"로그인 catch, platformCode: {loginInputDto.platformCode}, accessToken: {loginInputDto.accessToken}, [{ex.Message}], [{ex.StackTrace}]");
125+
_logger.LogError($"로그인 catch, platformCode: {loginInputDto.platformCode}, ssoAccessToken: {loginInputDto.ssoAccessToken}, [{ex.Message}], [{ex.StackTrace}]");
116126
return Unauthorized();
117127
}
118128
}

0 commit comments

Comments
 (0)