Skip to content

Commit 72ea20f

Browse files
committed
update template
1 parent a3ff59b commit 72ea20f

File tree

78 files changed

+1990
-10667
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

78 files changed

+1990
-10667
lines changed

MyApp.ServiceModel/Admin.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using ServiceStack;
2+
3+
namespace MyApp.ServiceModel;
4+
5+
public class AdminData : IGet, IReturn<AdminDataResponse> {}
6+
7+
public class PageStats
8+
{
9+
public string Label { get; set; }
10+
public int Total { get; set; }
11+
}
12+
13+
public class AdminDataResponse
14+
{
15+
public List<PageStats> PageStats { get; set; }
16+
}

MyApp.ServiceModel/Bookings.cs

Lines changed: 95 additions & 111 deletions
Original file line numberDiff line numberDiff line change
@@ -1,184 +1,168 @@
1-
// Complete declarative AutoQuery services for Bookings CRUD example:
2-
// https://docs.servicestack.net/autoquery-crud-bookings
3-
41
using System;
2+
using System.IO;
3+
using System.Collections;
4+
using System.Collections.Generic;
5+
using System.Runtime.Serialization;
56
using ServiceStack;
67
using ServiceStack.DataAnnotations;
8+
using MyApp;
79

810
namespace MyApp.ServiceModel;
911

10-
[Icon(Svg = "<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'><path fill='currentColor' d='M16 10H8c-.55 0-1 .45-1 1s.45 1 1 1h8c.55 0 1-.45 1-1s-.45-1-1-1zm3-7h-1V2c0-.55-.45-1-1-1s-1 .45-1 1v1H8V2c0-.55-.45-1-1-1s-1 .45-1 1v1H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zm-1 16H6c-.55 0-1-.45-1-1V8h14v10c0 .55-.45 1-1 1zm-5-5H8c-.55 0-1 .45-1 1s.45 1 1 1h5c.55 0 1-.45 1-1s-.45-1-1-1z'/></svg>")]
11-
[Description("Booking Details")]
12-
[Notes("Captures a Persons Name & Room Booking information")]
13-
public class Booking : AuditBase
14-
{
15-
[AutoIncrement]
16-
public int Id { get; set; }
17-
public string Name { get; set; }
18-
public RoomType RoomType { get; set; }
19-
public int RoomNumber { get; set; }
20-
[IntlDateTime(DateStyle.Long)]
21-
public DateTime BookingStartDate { get; set; }
22-
[IntlRelativeTime]
23-
public DateTime? BookingEndDate { get; set; }
24-
[IntlNumber(Currency = NumberCurrency.USD)]
25-
public decimal Cost { get; set; }
26-
27-
[Ref(Model = nameof(Coupon), RefId = nameof(Coupon.Id), RefLabel = nameof(Coupon.Description))]
28-
[References(typeof(Coupon))]
29-
public string? CouponId { get; set; }
30-
31-
[Reference]
32-
public Coupon Discount { get; set; }
33-
public string? Notes { get; set; }
34-
public bool? Cancelled { get; set; }
35-
36-
[Reference(SelfId = nameof(CreatedBy), RefId = nameof(User.UserName), RefLabel = nameof(User.DisplayName))]
37-
public User Employee { get; set; }
38-
}
39-
40-
public enum RoomType
41-
{
42-
Single,
43-
Double,
44-
Queen,
45-
Twin,
46-
Suite,
47-
}
48-
49-
[Tag("bookings"), Description("Find Bookings")]
50-
[Notes("Find out how to quickly create a <a class='svg-external' target='_blank' href='https://youtu.be/nhc4MZufkcM'>C# Bookings App from Scratch</a>")]
51-
[Route("/bookings", "GET")]
52-
[Route("/bookings/{Id}", "GET")]
12+
[Tag("Bookings")]
13+
[Route("/bookings/{Id}","GET")]
14+
[Route("/bookings","GET")]
5315
[AutoApply(Behavior.AuditQuery)]
54-
public class QueryBookings : QueryDb<Booking>
16+
[ValidateHasRole("Employee")]
17+
public class QueryBookings : QueryDb<Booking>
5518
{
5619
public int? Id { get; set; }
20+
public List<int>? Ids { get; set; }
5721
}
5822

59-
// Uncomment below to enable DeletedBookings API to view deleted bookings:
60-
// [Route("/bookings/deleted")]
61-
// [AutoFilter(QueryTerm.Ensure, nameof(AuditBase.DeletedDate), Template = SqlTemplate.IsNotNull)]
62-
// public class DeletedBookings : QueryDb<Booking> {}
63-
64-
[Tag("bookings"), Description("Create a new Booking")]
65-
[LocodeCss(Field="col-span-12 sm:col-span-6", Fieldset = "grid grid-cols-8 gap-2", Form = "border overflow-hidden max-w-screen-lg")]
66-
[ExplorerCss(Field="col-span-12 sm:col-span-6", Fieldset = "grid grid-cols-6 gap-8", Form = "border border-indigo-500 overflow-hidden max-w-screen-lg")]
67-
[Route("/bookings", "POST")]
68-
[ValidateHasRole("Employee")]
23+
[Tag("Bookings")]
24+
[Route("/bookings","POST")]
6925
[AutoApply(Behavior.AuditCreate)]
26+
[Description("Create a new Booking")]
27+
[ValidateHasRole("Employee")]
7028
public class CreateBooking : ICreateDb<Booking>, IReturn<IdResponse>
7129
{
72-
[Description("Name this Booking is for"), ValidateNotEmpty]
30+
[ValidateNotEmpty]
7331
public string Name { get; set; }
7432
public RoomType RoomType { get; set; }
7533
[ValidateGreaterThan(0)]
7634
public int RoomNumber { get; set; }
77-
[ValidateGreaterThan(0)]
78-
public decimal Cost { get; set; }
79-
[Required]
8035
public DateTime BookingStartDate { get; set; }
8136
public DateTime? BookingEndDate { get; set; }
82-
[Input(Type = "textarea")]
83-
public string? Notes { get; set; }
37+
[ValidateGreaterThan(0)]
38+
public decimal Cost { get; set; }
8439
public string? CouponId { get; set; }
40+
[Input(Type="textarea")]
41+
public string? Notes { get; set; }
42+
public bool? Cancelled { get; set; }
8543
}
8644

87-
[Tag("bookings"), Description("Update an existing Booking")]
45+
[Tag("Bookings")]
8846
[Notes("Find out how to quickly create a <a class='svg-external' target='_blank' href='https://youtu.be/nhc4MZufkcM'>C# Bookings App from Scratch</a>")]
89-
[Route("/booking/{Id}", "PATCH")]
90-
[ValidateHasRole("Employee")]
47+
[Route("/booking/{Id}","PATCH")]
9148
[AutoApply(Behavior.AuditModify)]
49+
[Description("Update an existing Booking")]
50+
[ValidateHasRole("Employee")]
9251
public class UpdateBooking : IPatchDb<Booking>, IReturn<IdResponse>
9352
{
9453
public int Id { get; set; }
9554
public string? Name { get; set; }
9655
public RoomType? RoomType { get; set; }
9756
[ValidateGreaterThan(0)]
9857
public int? RoomNumber { get; set; }
99-
[ValidateGreaterThan(0)]
100-
public decimal? Cost { get; set; }
10158
public DateTime? BookingStartDate { get; set; }
10259
public DateTime? BookingEndDate { get; set; }
103-
[Input(Type = "textarea")]
104-
public string? Notes { get; set; }
60+
[ValidateGreaterThan(0)]
61+
public decimal? Cost { get; set; }
10562
public string? CouponId { get; set; }
63+
[Input(Type="textarea")]
64+
public string? Notes { get; set; }
10665
public bool? Cancelled { get; set; }
10766
}
10867

109-
[Tag("bookings"), Description("Delete a Booking")]
110-
[Route("/booking/{Id}", "DELETE")]
111-
[ValidateHasRole("Manager")]
68+
[Tag("Bookings")]
69+
[Route("/booking/{Id}","DELETE")]
11270
[AutoApply(Behavior.AuditSoftDelete)]
71+
[Description("Delete a Booking")]
72+
[ValidateHasRole("Employee")]
11373
public class DeleteBooking : IDeleteDb<Booking>, IReturnVoid
11474
{
115-
public int Id { get; set; }
116-
}
117-
118-
119-
[Description("Discount Coupons")]
120-
[Icon(Svg = "<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'><path fill='currentColor' d='M2 9.5V4a1 1 0 0 1 1-1h18a1 1 0 0 1 1 1v5.5a2.5 2.5 0 1 0 0 5V20a1 1 0 0 1-1 1H3a1 1 0 0 1-1-1v-5.5a2.5 2.5 0 1 0 0-5zm2-1.532a4.5 4.5 0 0 1 0 8.064V19h16v-2.968a4.5 4.5 0 0 1 0-8.064V5H4v2.968zM9 9h6v2H9V9zm0 4h6v2H9v-2z' /></svg>")]
121-
public class Coupon
122-
{
123-
public string Id { get; set; }
124-
public string Description { get; set; }
125-
public int Discount { get; set; }
126-
public DateTime ExpiryDate { get; set; }
75+
public int? Id { get; set; }
76+
public List<int>? Ids { get; set; }
12777
}
12878

129-
[Tag("bookings"), Description("Find Coupons")]
130-
[Route("/coupons", "GET")]
79+
[Tag("Bookings")]
80+
[AutoApply(Behavior.AuditQuery)]
13181
public class QueryCoupons : QueryDb<Coupon>
13282
{
133-
public string Id { get; set; }
83+
public string? Id { get; set; }
84+
public List<string>? Ids { get; set; }
13485
}
13586

136-
[Tag("bookings")]
137-
[Route("/coupons", "POST")]
138-
[ValidateHasRole("Employee")]
87+
[Tag("Bookings")]
88+
[AutoApply(Behavior.AuditCreate)]
89+
[ValidateIsAuthenticated]
13990
public class CreateCoupon : ICreateDb<Coupon>, IReturn<IdResponse>
14091
{
14192
[ValidateNotEmpty]
14293
public string Id { get; set; }
14394
[ValidateNotEmpty]
14495
public string Description { get; set; }
145-
[ValidateGreaterThan(0)]
146-
public int Discount { get; set; }
147-
[ValidateNotNull]
96+
public decimal Discount { get; set; }
14897
public DateTime ExpiryDate { get; set; }
14998
}
15099

151-
[Tag("bookings")]
152-
[Route("/coupons/{Id}", "PATCH")]
153-
[ValidateHasRole("Employee")]
100+
[Tag("Bookings")]
101+
[AutoApply(Behavior.AuditModify)]
102+
[ValidateIsAuthenticated]
154103
public class UpdateCoupon : IPatchDb<Coupon>, IReturn<IdResponse>
155104
{
156105
public string Id { get; set; }
157-
[ValidateNotEmpty]
158106
public string? Description { get; set; }
159-
[ValidateNotNull, ValidateGreaterThan(0)]
160-
public int? Discount { get; set; }
161-
[ValidateNotNull]
107+
public decimal? Discount { get; set; }
162108
public DateTime? ExpiryDate { get; set; }
163109
}
164110

165-
[Tag("bookings"), Description("Delete a Coupon")]
166-
[Route("/coupons/{Id}", "DELETE")]
167-
[ValidateHasRole("Manager")]
111+
[Tag("Bookings")]
112+
[AutoApply(Behavior.AuditSoftDelete)]
113+
[ValidateIsAuthenticated]
168114
public class DeleteCoupon : IDeleteDb<Coupon>, IReturnVoid
169115
{
170-
public string Id { get; set; }
116+
public string? Id { get; set; }
117+
public List<string>? Ids { get; set; }
171118
}
172119

173-
public class AdminData : IGet, IReturn<AdminDataResponse> {}
174120

175-
public class PageStats
121+
[Icon(Svg="<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'><path fill='currentColor' d='M16 10H8c-.55 0-1 .45-1 1s.45 1 1 1h8c.55 0 1-.45 1-1s-.45-1-1-1zm3-7h-1V2c0-.55-.45-1-1-1s-1 .45-1 1v1H8V2c0-.55-.45-1-1-1s-1 .45-1 1v1H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zm-1 16H6c-.55 0-1-.45-1-1V8h14v10c0 .55-.45 1-1 1zm-5-5H8c-.55 0-1 .45-1 1s.45 1 1 1h5c.55 0 1-.45 1-1s-.45-1-1-1z'/></svg>")]
122+
[Notes("Captures a Persons Name & Room Booking information")]
123+
[Description("Booking Details")]
124+
public class Booking : AuditBase
125+
{
126+
[AutoIncrement]
127+
public int Id { get; set; }
128+
public string Name { get; set; }
129+
public RoomType RoomType { get; set; }
130+
public int RoomNumber { get; set; }
131+
[IntlDateTime(DateStyle.Long)]
132+
public DateTime BookingStartDate { get; set; }
133+
[IntlRelativeTime]
134+
public DateTime? BookingEndDate { get; set; }
135+
[IntlNumber(Currency="USD")]
136+
public decimal Cost { get; set; }
137+
[Ref(Model=nameof(Coupon),RefId=nameof(Coupon.Id),RefLabel=nameof(Coupon.Description))]
138+
[References(typeof(Coupon))]
139+
public string? CouponId { get; set; }
140+
[Format(FormatMethods.Hidden)]
141+
[Reference]
142+
public Coupon? Discount { get; set; }
143+
public string? Notes { get; set; }
144+
public bool? Cancelled { get; set; }
145+
[Format(FormatMethods.Hidden)]
146+
[Reference(SelfId=nameof(CreatedBy),RefId=nameof(User.UserName),RefLabel=nameof(User.DisplayName))]
147+
public User Employee { get; set; }
148+
}
149+
150+
[Icon(Svg="<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'><path fill='currentColor' d='M2 9.5V4a1 1 0 0 1 1-1h18a1 1 0 0 1 1 1v5.5a2.5 2.5 0 1 0 0 5V20a1 1 0 0 1-1 1H3a1 1 0 0 1-1-1v-5.5a2.5 2.5 0 1 0 0-5zm2-1.532a4.5 4.5 0 0 1 0 8.064V19h16v-2.968a4.5 4.5 0 0 1 0-8.064V5H4v2.968zM9 9h6v2H9V9zm0 4h6v2H9v-2z' /></svg>")]
151+
public class Coupon : AuditBase
176152
{
177-
public string Label { get; set; }
178-
public int Total { get; set; }
153+
public string Id { get; set; }
154+
public string Description { get; set; }
155+
public decimal Discount { get; set; }
156+
public DateTime ExpiryDate { get; set; }
179157
}
180158

181-
public class AdminDataResponse
159+
160+
public enum RoomType
182161
{
183-
public List<PageStats> PageStats { get; set; }
162+
Single,
163+
Double,
164+
Queen,
165+
Twin,
166+
Suite,
184167
}
168+

MyApp.ServiceModel/Bookings.d.ts

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/// <reference path="./api.d.ts" />
2+
export type Config = {
3+
prompt: "New Booking"
4+
api: "~/MyApp.ServiceModel/Bookings.cs"
5+
migration: "~/MyApp/Migrations/Migration1001.cs"
6+
uiMjs: "~/MyApp/wwwroot/admin/sections/Bookings.mjs"
7+
}
8+
9+
export enum RoomType {
10+
Single,
11+
Double,
12+
Queen,
13+
Twin,
14+
Suite,
15+
}
16+
17+
@Read.route("/bookings","GET")
18+
@Read.route("/bookings/{Id}","GET")
19+
@Create.route("/bookings","POST")
20+
@Create.description("Create a new Booking")
21+
@Update.notes("Find out how to quickly create a <a class='svg-external' target='_blank' href='https://youtu.be/nhc4MZufkcM'>C# Bookings App from Scratch</a>")
22+
@Update.route("/booking/{Id}","PATCH")
23+
@Update.description("Update an existing Booking")
24+
@Delete.route("/booking/{Id}","DELETE")
25+
@Delete.description("Delete a Booking")
26+
@tag("Bookings")
27+
@icon({svg:"<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'><path fill='currentColor' d='M16 10H8c-.55 0-1 .45-1 1s.45 1 1 1h8c.55 0 1-.45 1-1s-.45-1-1-1zm3-7h-1V2c0-.55-.45-1-1-1s-1 .45-1 1v1H8V2c0-.55-.45-1-1-1s-1 .45-1 1v1H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zm-1 16H6c-.55 0-1-.45-1-1V8h14v10c0 .55-.45 1-1 1zm-5-5H8c-.55 0-1 .45-1 1s.45 1 1 1h5c.55 0 1-.45 1-1s-.45-1-1-1z'/></svg>"})
28+
@notes("Captures a Persons Name & Room Booking information")
29+
@description("Booking Details")
30+
@validateHasRole("Employee")
31+
export class Booking extends AuditBase {
32+
@autoIncrement()
33+
id: number
34+
@Create.description("Name this Booking is for")
35+
@validateNotEmpty()
36+
name: string
37+
roomType: RoomType
38+
@validateGreaterThan(0)
39+
roomNumber: number
40+
@intlDateTime(DateStyle.Long)
41+
bookingStartDate: Date
42+
@intlRelativeTime()
43+
bookingEndDate?: Date
44+
@intlNumber({currency:"USD"})
45+
@validateGreaterThan(0)
46+
cost: decimal
47+
@ref({model:"nameof(Coupon)",refId:"nameof(Coupon.Id)",refLabel:"nameof(Coupon.Description)"})
48+
@references("typeof(Coupon)")
49+
couponId?: string
50+
@reference()
51+
discount?: Coupon
52+
@input({type:"textarea"})
53+
notes?: string
54+
cancelled?: boolean
55+
@reference({selfId:"nameof(CreatedBy)",refId:"nameof(User.UserName)",refLabel:"nameof(User.DisplayName)"})
56+
employee: User
57+
}
58+
59+
@tag("Bookings")
60+
@icon({svg:"<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'><path fill='currentColor' d='M2 9.5V4a1 1 0 0 1 1-1h18a1 1 0 0 1 1 1v5.5a2.5 2.5 0 1 0 0 5V20a1 1 0 0 1-1 1H3a1 1 0 0 1-1-1v-5.5a2.5 2.5 0 1 0 0-5zm2-1.532a4.5 4.5 0 0 1 0 8.064V19h16v-2.968a4.5 4.5 0 0 1 0-8.064V5H4v2.968zM9 9h6v2H9V9zm0 4h6v2H9v-2z' /></svg>"})
61+
export class Coupon extends AuditBase {
62+
id: string
63+
description: string
64+
discount: number
65+
expiryDate: Date
66+
}

0 commit comments

Comments
 (0)