ShopPlatform.Web
1.0.0.0
농산물, 소프트웨어 라이선스와 개발 용역을 직접 판매하는 CodeMaru 직영 쇼핑몰입니다.
Toggle main menu visibility
로딩중...
검색중...
일치하는것 없음
ShopCustomerProfileStore.cs
이 파일의 문서화 페이지로 가기
1
using
System.Text.Json;
2
using
ShopPlatform.Models
;
3
4
namespace
ShopPlatform.Services
;
5
14
public
sealed
class
ShopCustomerProfileStore
15
{
24
private
readonly
string
_root
;
33
private
static
readonly JsonSerializerOptions
JsonOptions
=
new
() { WriteIndented =
true
};
34
51
public
ShopCustomerProfileStore
(
ShopOptions
options)
52
{
53
_root
= options.
ResolvedDataPath
;
54
}
55
88
public
async Task<ShopCustomerProfile?>
GetAsync
(
string
slug,
string
userId)
89
{
90
var profiles = await
LoadAsync
(slug).ConfigureAwait(
false
);
91
return
profiles.FirstOrDefault(x =>
string
.Equals(x.UserId, userId, StringComparison.Ordinal));
92
}
93
126
public
async Task
SaveAsync
(
string
slug,
ShopCustomerProfile
profile)
127
{
128
var profiles = await
LoadAsync
(slug).ConfigureAwait(
false
);
129
var index = profiles.FindIndex(x =>
string
.Equals(x.UserId, profile.
UserId
, StringComparison.Ordinal));
130
profile.UpdatedAt = DateTime.UtcNow;
131
132
if
(index >= 0)
133
{
134
profiles[index] = profile;
135
}
136
else
137
{
138
profiles.Add(profile);
139
}
140
141
Directory.CreateDirectory(
ShopDir
(slug));
142
await File.WriteAllTextAsync(
ProfilePath
(slug), JsonSerializer.Serialize(profiles,
JsonOptions
)).ConfigureAwait(
false
);
143
}
144
169
private
async Task<List<ShopCustomerProfile>>
LoadAsync
(
string
slug)
170
{
171
var path =
ProfilePath
(slug);
172
if
(!File.Exists(path))
173
{
174
return
[];
175
}
176
177
await
using
var stream = File.OpenRead(path);
178
return
await JsonSerializer.DeserializeAsync<List<ShopCustomerProfile>>(stream,
JsonOptions
).ConfigureAwait(
false
) ?? [];
179
}
180
205
private
string
ShopDir
(
string
slug) => Path.Combine(
_root
, slug);
230
private
string
ProfilePath
(
string
slug) => Path.Combine(
ShopDir
(slug),
"customers.json"
);
231
}
ShopPlatform.Models
Definition
CartItem.cs:1
ShopPlatform.Services
Definition
CartService.cs:3
ShopPlatform.Models.ShopCustomerProfile
Definition
ShopCustomerProfile.cs:12
ShopPlatform.Models.ShopCustomerProfile.UserId
string UserId
Definition
ShopCustomerProfile.cs:21
ShopPlatform.Models.ShopOptions
Definition
ShopOptions.cs:12
ShopPlatform.Models.ShopOptions.ResolvedDataPath
string ResolvedDataPath
Definition
ShopOptions.cs:61
ShopPlatform.Services.ShopCustomerProfileStore.SaveAsync
async Task SaveAsync(string slug, ShopCustomerProfile profile)
Definition
ShopCustomerProfileStore.cs:126
ShopPlatform.Services.ShopCustomerProfileStore.ShopDir
string ShopDir(string slug)
Definition
ShopCustomerProfileStore.cs:205
ShopPlatform.Services.ShopCustomerProfileStore.ShopCustomerProfileStore
ShopCustomerProfileStore(ShopOptions options)
Definition
ShopCustomerProfileStore.cs:51
ShopPlatform.Services.ShopCustomerProfileStore.LoadAsync
async Task< List< ShopCustomerProfile > > LoadAsync(string slug)
Definition
ShopCustomerProfileStore.cs:169
ShopPlatform.Services.ShopCustomerProfileStore.ProfilePath
string ProfilePath(string slug)
Definition
ShopCustomerProfileStore.cs:230
ShopPlatform.Services.ShopCustomerProfileStore._root
readonly string _root
Definition
ShopCustomerProfileStore.cs:24
ShopPlatform.Services.ShopCustomerProfileStore.GetAsync
async Task< ShopCustomerProfile?> GetAsync(string slug, string userId)
Definition
ShopCustomerProfileStore.cs:88
ShopPlatform.Services.ShopCustomerProfileStore.JsonOptions
static readonly JsonSerializerOptions JsonOptions
Definition
ShopCustomerProfileStore.cs:33
Services
ShopCustomerProfileStore.cs
다음에 의해 생성됨 :
1.17.0