Projekt

Obecné

Profil

« Předchozí | Další » 

Revize be4deff8

Přidáno uživatelem Vojtěch Bartička před téměř 3 roky(ů)

Minor fixes, added annotation instance endpoint - untested

Zobrazit rozdíly:

Backend/Backend/Controllers/AnnotationController.cs
73 73
            }
74 74

  
75 75
        }
76

  
77
        [HttpPost("/annotation/{annotationId}")]
78
        [ProducesResponseType((int)HttpStatusCode.OK)]
79
        [ProducesResponseType((int)HttpStatusCode.Forbidden)]
80
        public ActionResult PostAnnotation([FromServices] ClientInfo clientInfo, [FromQuery] Guid annotationId, [FromBody] AnnotationInstanceAddRequest request)
81
        {
82
            if (clientInfo.LoggedUser == null)
83
            {
84
                logger.Warning("ClientInfo has null LoggerUser in [Authorized] controller /annotations");
85
                return Problem();
86
            }
87
            
88
            // Take care of - non-admin user requesting not-assigned annotation
89
            // non-existent annotation
90
            try
91
            {
92
                annotationService.AddAnnotationInstance(annotationId, clientInfo.LoggedUser.Id, clientInfo.LoggedUser.Role, request);
93
                return Ok();
94
            }
95
            catch (InvalidOperationException e)
96
            {
97
                throw new BadRequestException("Could not find specified annotation");
98
            }
99
            catch (UnauthorizedAccessException)
100
            {
101
                return Forbid();
102
            }
103

  
104
        }
76 105
    }
77 106
}
Backend/Backend/Migrations/20220417114429_V3.Designer.cs
1
// <auto-generated />
2
using System;
3
using Core.Contexts;
4
using Microsoft.EntityFrameworkCore;
5
using Microsoft.EntityFrameworkCore.Infrastructure;
6
using Microsoft.EntityFrameworkCore.Migrations;
7
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
8
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
9

  
10
#nullable disable
11

  
12
namespace RestAPI.Migrations
13
{
14
    [DbContext(typeof(DatabaseContext))]
15
    [Migration("20220417114429_V3")]
16
    partial class V3
17
    {
18
        protected override void BuildTargetModel(ModelBuilder modelBuilder)
19
        {
20
#pragma warning disable 612, 618
21
            modelBuilder
22
                .HasAnnotation("ProductVersion", "6.0.3")
23
                .HasAnnotation("Relational:MaxIdentifierLength", 63);
24

  
25
            NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
26

  
27
            modelBuilder.Entity("AnnotationClass", b =>
28
                {
29
                    b.Property<Guid>("AnnotationsId")
30
                        .HasColumnType("uuid");
31

  
32
                    b.Property<Guid>("ClassesId")
33
                        .HasColumnType("uuid");
34

  
35
                    b.HasKey("AnnotationsId", "ClassesId");
36

  
37
                    b.HasIndex("ClassesId");
38

  
39
                    b.ToTable("AnnotationClass");
40
                });
41

  
42
            modelBuilder.Entity("Core.Entities.Annotation", b =>
43
                {
44
                    b.Property<Guid>("Id")
45
                        .ValueGeneratedOnAdd()
46
                        .HasColumnType("uuid");
47

  
48
                    b.Property<DateTime>("DateAssigned")
49
                        .HasColumnType("timestamp with time zone");
50

  
51
                    b.Property<DateTime>("DateLastChanged")
52
                        .HasColumnType("timestamp with time zone");
53

  
54
                    b.Property<Guid>("DocumentId")
55
                        .HasColumnType("uuid");
56

  
57
                    b.Property<string>("Note")
58
                        .IsRequired()
59
                        .HasColumnType("text");
60

  
61
                    b.Property<int>("State")
62
                        .HasColumnType("integer");
63

  
64
                    b.Property<Guid>("UserAssignedId")
65
                        .HasColumnType("uuid");
66

  
67
                    b.Property<Guid>("UserId")
68
                        .HasColumnType("uuid");
69

  
70
                    b.HasKey("Id");
71

  
72
                    b.HasIndex("DocumentId");
73

  
74
                    b.HasIndex("UserAssignedId");
75

  
76
                    b.HasIndex("UserId");
77

  
78
                    b.ToTable("Annotations");
79
                });
80

  
81
            modelBuilder.Entity("Core.Entities.AnnotationTag", b =>
82
                {
83
                    b.Property<Guid>("Id")
84
                        .ValueGeneratedOnAdd()
85
                        .HasColumnType("uuid");
86

  
87
                    b.Property<Guid>("AnnotationId")
88
                        .HasColumnType("uuid");
89

  
90
                    b.Property<Guid>("Instance")
91
                        .HasColumnType("uuid");
92

  
93
                    b.Property<int>("Length")
94
                        .HasColumnType("integer");
95

  
96
                    b.Property<string>("Note")
97
                        .IsRequired()
98
                        .HasColumnType("text");
99

  
100
                    b.Property<int>("Position")
101
                        .HasColumnType("integer");
102

  
103
                    b.Property<Guid?>("SubTagId")
104
                        .HasColumnType("uuid");
105

  
106
                    b.Property<Guid>("TagId")
107
                        .HasColumnType("uuid");
108

  
109
                    b.HasKey("Id");
110

  
111
                    b.HasIndex("AnnotationId");
112

  
113
                    b.HasIndex("SubTagId");
114

  
115
                    b.HasIndex("TagId");
116

  
117
                    b.ToTable("AnnotationTags");
118
                });
119

  
120
            modelBuilder.Entity("Core.Entities.Class", b =>
121
                {
122
                    b.Property<Guid>("Id")
123
                        .ValueGeneratedOnAdd()
124
                        .HasColumnType("uuid");
125

  
126
                    b.Property<string>("Color")
127
                        .IsRequired()
128
                        .HasColumnType("text");
129

  
130
                    b.Property<string>("Description")
131
                        .IsRequired()
132
                        .HasColumnType("text");
133

  
134
                    b.Property<string>("Name")
135
                        .IsRequired()
136
                        .HasColumnType("text");
137

  
138
                    b.HasKey("Id");
139

  
140
                    b.ToTable("Classes");
141
                });
142

  
143
            modelBuilder.Entity("Core.Entities.Document", b =>
144
                {
145
                    b.Property<Guid>("Id")
146
                        .ValueGeneratedOnAdd()
147
                        .HasColumnType("uuid");
148

  
149
                    b.Property<Guid?>("ContentId")
150
                        .HasColumnType("uuid");
151

  
152
                    b.Property<DateTime>("DateAdded")
153
                        .HasColumnType("timestamp with time zone");
154

  
155
                    b.Property<int>("Length")
156
                        .HasColumnType("integer");
157

  
158
                    b.Property<string>("Name")
159
                        .HasColumnType("text");
160

  
161
                    b.Property<int>("RequiredAnnotations")
162
                        .HasColumnType("integer");
163

  
164
                    b.Property<Guid?>("UserAddedId")
165
                        .HasColumnType("uuid");
166

  
167
                    b.HasKey("Id");
168

  
169
                    b.HasIndex("ContentId");
170

  
171
                    b.HasIndex("UserAddedId");
172

  
173
                    b.ToTable("Documents");
174
                });
175

  
176
            modelBuilder.Entity("Core.Entities.DocumentContent", b =>
177
                {
178
                    b.Property<Guid>("Id")
179
                        .ValueGeneratedOnAdd()
180
                        .HasColumnType("uuid");
181

  
182
                    b.Property<string>("Content")
183
                        .IsRequired()
184
                        .HasColumnType("text");
185

  
186
                    b.HasKey("Id");
187

  
188
                    b.ToTable("DocumentContents");
189
                });
190

  
191
            modelBuilder.Entity("Core.Entities.SubTag", b =>
192
                {
193
                    b.Property<Guid>("Id")
194
                        .ValueGeneratedOnAdd()
195
                        .HasColumnType("uuid");
196

  
197
                    b.Property<string>("Description")
198
                        .IsRequired()
199
                        .HasColumnType("text");
200

  
201
                    b.Property<string>("Name")
202
                        .IsRequired()
203
                        .HasColumnType("text");
204

  
205
                    b.Property<Guid>("TagId")
206
                        .HasColumnType("uuid");
207

  
208
                    b.HasKey("Id");
209

  
210
                    b.HasIndex("TagId");
211

  
212
                    b.ToTable("SubTags");
213
                });
214

  
215
            modelBuilder.Entity("Core.Entities.Tag", b =>
216
                {
217
                    b.Property<Guid>("Id")
218
                        .ValueGeneratedOnAdd()
219
                        .HasColumnType("uuid");
220

  
221
                    b.Property<Guid>("CategoryId")
222
                        .HasColumnType("uuid");
223

  
224
                    b.Property<string>("Color")
225
                        .IsRequired()
226
                        .HasColumnType("text");
227

  
228
                    b.Property<string>("Description")
229
                        .IsRequired()
230
                        .HasColumnType("text");
231

  
232
                    b.Property<string>("Name")
233
                        .IsRequired()
234
                        .HasColumnType("text");
235

  
236
                    b.HasKey("Id");
237

  
238
                    b.HasIndex("CategoryId");
239

  
240
                    b.ToTable("Tags");
241
                });
242

  
243
            modelBuilder.Entity("Core.Entities.TagCategory", b =>
244
                {
245
                    b.Property<Guid>("Id")
246
                        .ValueGeneratedOnAdd()
247
                        .HasColumnType("uuid");
248

  
249
                    b.Property<string>("Color")
250
                        .HasColumnType("text");
251

  
252
                    b.Property<string>("Description")
253
                        .HasColumnType("text");
254

  
255
                    b.Property<string>("Name")
256
                        .HasColumnType("text");
257

  
258
                    b.HasKey("Id");
259

  
260
                    b.ToTable("TagCategories");
261
                });
262

  
263
            modelBuilder.Entity("Core.Entities.User", b =>
264
                {
265
                    b.Property<Guid>("Id")
266
                        .ValueGeneratedOnAdd()
267
                        .HasColumnType("uuid");
268

  
269
                    b.Property<string>("Name")
270
                        .HasColumnType("text");
271

  
272
                    b.Property<string>("Password")
273
                        .HasColumnType("text");
274

  
275
                    b.Property<int>("Role")
276
                        .HasColumnType("integer");
277

  
278
                    b.Property<string>("Surname")
279
                        .HasColumnType("text");
280

  
281
                    b.Property<string>("Username")
282
                        .HasColumnType("text");
283

  
284
                    b.HasKey("Id");
285

  
286
                    b.ToTable("Users");
287
                });
288

  
289
            modelBuilder.Entity("AnnotationClass", b =>
290
                {
291
                    b.HasOne("Core.Entities.Annotation", null)
292
                        .WithMany()
293
                        .HasForeignKey("AnnotationsId")
294
                        .OnDelete(DeleteBehavior.Cascade)
295
                        .IsRequired();
296

  
297
                    b.HasOne("Core.Entities.Class", null)
298
                        .WithMany()
299
                        .HasForeignKey("ClassesId")
300
                        .OnDelete(DeleteBehavior.Cascade)
301
                        .IsRequired();
302
                });
303

  
304
            modelBuilder.Entity("Core.Entities.Annotation", b =>
305
                {
306
                    b.HasOne("Core.Entities.Document", "Document")
307
                        .WithMany()
308
                        .HasForeignKey("DocumentId")
309
                        .OnDelete(DeleteBehavior.Cascade)
310
                        .IsRequired();
311

  
312
                    b.HasOne("Core.Entities.User", "UserAssigned")
313
                        .WithMany()
314
                        .HasForeignKey("UserAssignedId")
315
                        .OnDelete(DeleteBehavior.Cascade)
316
                        .IsRequired();
317

  
318
                    b.HasOne("Core.Entities.User", "User")
319
                        .WithMany()
320
                        .HasForeignKey("UserId")
321
                        .OnDelete(DeleteBehavior.Cascade)
322
                        .IsRequired();
323

  
324
                    b.Navigation("Document");
325

  
326
                    b.Navigation("User");
327

  
328
                    b.Navigation("UserAssigned");
329
                });
330

  
331
            modelBuilder.Entity("Core.Entities.AnnotationTag", b =>
332
                {
333
                    b.HasOne("Core.Entities.Annotation", "Annotation")
334
                        .WithMany()
335
                        .HasForeignKey("AnnotationId")
336
                        .OnDelete(DeleteBehavior.Cascade)
337
                        .IsRequired();
338

  
339
                    b.HasOne("Core.Entities.SubTag", "SubTag")
340
                        .WithMany()
341
                        .HasForeignKey("SubTagId");
342

  
343
                    b.HasOne("Core.Entities.Tag", "Tag")
344
                        .WithMany()
345
                        .HasForeignKey("TagId")
346
                        .OnDelete(DeleteBehavior.Cascade)
347
                        .IsRequired();
348

  
349
                    b.Navigation("Annotation");
350

  
351
                    b.Navigation("SubTag");
352

  
353
                    b.Navigation("Tag");
354
                });
355

  
356
            modelBuilder.Entity("Core.Entities.Document", b =>
357
                {
358
                    b.HasOne("Core.Entities.DocumentContent", "Content")
359
                        .WithMany()
360
                        .HasForeignKey("ContentId");
361

  
362
                    b.HasOne("Core.Entities.User", "UserAdded")
363
                        .WithMany()
364
                        .HasForeignKey("UserAddedId");
365

  
366
                    b.Navigation("Content");
367

  
368
                    b.Navigation("UserAdded");
369
                });
370

  
371
            modelBuilder.Entity("Core.Entities.SubTag", b =>
372
                {
373
                    b.HasOne("Core.Entities.Tag", "Tag")
374
                        .WithMany()
375
                        .HasForeignKey("TagId")
376
                        .OnDelete(DeleteBehavior.Cascade)
377
                        .IsRequired();
378

  
379
                    b.Navigation("Tag");
380
                });
381

  
382
            modelBuilder.Entity("Core.Entities.Tag", b =>
383
                {
384
                    b.HasOne("Core.Entities.TagCategory", "Category")
385
                        .WithMany()
386
                        .HasForeignKey("CategoryId")
387
                        .OnDelete(DeleteBehavior.Cascade)
388
                        .IsRequired();
389

  
390
                    b.Navigation("Category");
391
                });
392
#pragma warning restore 612, 618
393
        }
394
    }
395
}
Backend/Backend/Migrations/20220417114429_V3.cs
1
using System;
2
using Microsoft.EntityFrameworkCore.Migrations;
3

  
4
#nullable disable
5

  
6
namespace RestAPI.Migrations
7
{
8
    public partial class V3 : Migration
9
    {
10
        protected override void Up(MigrationBuilder migrationBuilder)
11
        {
12
            migrationBuilder.DropForeignKey(
13
                name: "FK_Documents_DocumentContents_ContentId",
14
                table: "Documents");
15

  
16
            migrationBuilder.DropForeignKey(
17
                name: "FK_Documents_Users_UserAddedId",
18
                table: "Documents");
19

  
20
            migrationBuilder.AlterColumn<string>(
21
                name: "Username",
22
                table: "Users",
23
                type: "text",
24
                nullable: true,
25
                oldClrType: typeof(string),
26
                oldType: "text");
27

  
28
            migrationBuilder.AlterColumn<string>(
29
                name: "Surname",
30
                table: "Users",
31
                type: "text",
32
                nullable: true,
33
                oldClrType: typeof(string),
34
                oldType: "text");
35

  
36
            migrationBuilder.AlterColumn<string>(
37
                name: "Password",
38
                table: "Users",
39
                type: "text",
40
                nullable: true,
41
                oldClrType: typeof(string),
42
                oldType: "text");
43

  
44
            migrationBuilder.AlterColumn<string>(
45
                name: "Name",
46
                table: "Users",
47
                type: "text",
48
                nullable: true,
49
                oldClrType: typeof(string),
50
                oldType: "text");
51

  
52
            migrationBuilder.AlterColumn<string>(
53
                name: "Name",
54
                table: "TagCategories",
55
                type: "text",
56
                nullable: true,
57
                oldClrType: typeof(string),
58
                oldType: "text");
59

  
60
            migrationBuilder.AlterColumn<string>(
61
                name: "Description",
62
                table: "TagCategories",
63
                type: "text",
64
                nullable: true,
65
                oldClrType: typeof(string),
66
                oldType: "text");
67

  
68
            migrationBuilder.AlterColumn<string>(
69
                name: "Color",
70
                table: "TagCategories",
71
                type: "text",
72
                nullable: true,
73
                oldClrType: typeof(string),
74
                oldType: "text");
75

  
76
            migrationBuilder.AlterColumn<Guid>(
77
                name: "UserAddedId",
78
                table: "Documents",
79
                type: "uuid",
80
                nullable: true,
81
                oldClrType: typeof(Guid),
82
                oldType: "uuid");
83

  
84
            migrationBuilder.AlterColumn<string>(
85
                name: "Name",
86
                table: "Documents",
87
                type: "text",
88
                nullable: true,
89
                oldClrType: typeof(string),
90
                oldType: "text");
91

  
92
            migrationBuilder.AlterColumn<Guid>(
93
                name: "ContentId",
94
                table: "Documents",
95
                type: "uuid",
96
                nullable: true,
97
                oldClrType: typeof(Guid),
98
                oldType: "uuid");
99

  
100
            migrationBuilder.AlterColumn<Guid>(
101
                name: "Instance",
102
                table: "AnnotationTags",
103
                type: "uuid",
104
                nullable: false,
105
                oldClrType: typeof(int),
106
                oldType: "integer");
107

  
108
            migrationBuilder.AddForeignKey(
109
                name: "FK_Documents_DocumentContents_ContentId",
110
                table: "Documents",
111
                column: "ContentId",
112
                principalTable: "DocumentContents",
113
                principalColumn: "Id");
114

  
115
            migrationBuilder.AddForeignKey(
116
                name: "FK_Documents_Users_UserAddedId",
117
                table: "Documents",
118
                column: "UserAddedId",
119
                principalTable: "Users",
120
                principalColumn: "Id");
121
        }
122

  
123
        protected override void Down(MigrationBuilder migrationBuilder)
124
        {
125
            migrationBuilder.DropForeignKey(
126
                name: "FK_Documents_DocumentContents_ContentId",
127
                table: "Documents");
128

  
129
            migrationBuilder.DropForeignKey(
130
                name: "FK_Documents_Users_UserAddedId",
131
                table: "Documents");
132

  
133
            migrationBuilder.AlterColumn<string>(
134
                name: "Username",
135
                table: "Users",
136
                type: "text",
137
                nullable: false,
138
                defaultValue: "",
139
                oldClrType: typeof(string),
140
                oldType: "text",
141
                oldNullable: true);
142

  
143
            migrationBuilder.AlterColumn<string>(
144
                name: "Surname",
145
                table: "Users",
146
                type: "text",
147
                nullable: false,
148
                defaultValue: "",
149
                oldClrType: typeof(string),
150
                oldType: "text",
151
                oldNullable: true);
152

  
153
            migrationBuilder.AlterColumn<string>(
154
                name: "Password",
155
                table: "Users",
156
                type: "text",
157
                nullable: false,
158
                defaultValue: "",
159
                oldClrType: typeof(string),
160
                oldType: "text",
161
                oldNullable: true);
162

  
163
            migrationBuilder.AlterColumn<string>(
164
                name: "Name",
165
                table: "Users",
166
                type: "text",
167
                nullable: false,
168
                defaultValue: "",
169
                oldClrType: typeof(string),
170
                oldType: "text",
171
                oldNullable: true);
172

  
173
            migrationBuilder.AlterColumn<string>(
174
                name: "Name",
175
                table: "TagCategories",
176
                type: "text",
177
                nullable: false,
178
                defaultValue: "",
179
                oldClrType: typeof(string),
180
                oldType: "text",
181
                oldNullable: true);
182

  
183
            migrationBuilder.AlterColumn<string>(
184
                name: "Description",
185
                table: "TagCategories",
186
                type: "text",
187
                nullable: false,
188
                defaultValue: "",
189
                oldClrType: typeof(string),
190
                oldType: "text",
191
                oldNullable: true);
192

  
193
            migrationBuilder.AlterColumn<string>(
194
                name: "Color",
195
                table: "TagCategories",
196
                type: "text",
197
                nullable: false,
198
                defaultValue: "",
199
                oldClrType: typeof(string),
200
                oldType: "text",
201
                oldNullable: true);
202

  
203
            migrationBuilder.AlterColumn<Guid>(
204
                name: "UserAddedId",
205
                table: "Documents",
206
                type: "uuid",
207
                nullable: false,
208
                defaultValue: new Guid("00000000-0000-0000-0000-000000000000"),
209
                oldClrType: typeof(Guid),
210
                oldType: "uuid",
211
                oldNullable: true);
212

  
213
            migrationBuilder.AlterColumn<string>(
214
                name: "Name",
215
                table: "Documents",
216
                type: "text",
217
                nullable: false,
218
                defaultValue: "",
219
                oldClrType: typeof(string),
220
                oldType: "text",
221
                oldNullable: true);
222

  
223
            migrationBuilder.AlterColumn<Guid>(
224
                name: "ContentId",
225
                table: "Documents",
226
                type: "uuid",
227
                nullable: false,
228
                defaultValue: new Guid("00000000-0000-0000-0000-000000000000"),
229
                oldClrType: typeof(Guid),
230
                oldType: "uuid",
231
                oldNullable: true);
232

  
233
            migrationBuilder.AlterColumn<int>(
234
                name: "Instance",
235
                table: "AnnotationTags",
236
                type: "integer",
237
                nullable: false,
238
                oldClrType: typeof(Guid),
239
                oldType: "uuid");
240

  
241
            migrationBuilder.AddForeignKey(
242
                name: "FK_Documents_DocumentContents_ContentId",
243
                table: "Documents",
244
                column: "ContentId",
245
                principalTable: "DocumentContents",
246
                principalColumn: "Id",
247
                onDelete: ReferentialAction.Cascade);
248

  
249
            migrationBuilder.AddForeignKey(
250
                name: "FK_Documents_Users_UserAddedId",
251
                table: "Documents",
252
                column: "UserAddedId",
253
                principalTable: "Users",
254
                principalColumn: "Id",
255
                onDelete: ReferentialAction.Cascade);
256
        }
257
    }
258
}
Backend/Backend/Migrations/DatabaseContextModelSnapshot.cs
85 85
                    b.Property<Guid>("AnnotationId")
86 86
                        .HasColumnType("uuid");
87 87

  
88
                    b.Property<int>("Instance")
89
                        .HasColumnType("integer");
88
                    b.Property<Guid>("Instance")
89
                        .HasColumnType("uuid");
90 90

  
91 91
                    b.Property<int>("Length")
92 92
                        .HasColumnType("integer");
......
144 144
                        .ValueGeneratedOnAdd()
145 145
                        .HasColumnType("uuid");
146 146

  
147
                    b.Property<Guid>("ContentId")
147
                    b.Property<Guid?>("ContentId")
148 148
                        .HasColumnType("uuid");
149 149

  
150 150
                    b.Property<DateTime>("DateAdded")
......
154 154
                        .HasColumnType("integer");
155 155

  
156 156
                    b.Property<string>("Name")
157
                        .IsRequired()
158 157
                        .HasColumnType("text");
159 158

  
160 159
                    b.Property<int>("RequiredAnnotations")
161 160
                        .HasColumnType("integer");
162 161

  
163
                    b.Property<Guid>("UserAddedId")
162
                    b.Property<Guid?>("UserAddedId")
164 163
                        .HasColumnType("uuid");
165 164

  
166 165
                    b.HasKey("Id");
......
246 245
                        .HasColumnType("uuid");
247 246

  
248 247
                    b.Property<string>("Color")
249
                        .IsRequired()
250 248
                        .HasColumnType("text");
251 249

  
252 250
                    b.Property<string>("Description")
253
                        .IsRequired()
254 251
                        .HasColumnType("text");
255 252

  
256 253
                    b.Property<string>("Name")
257
                        .IsRequired()
258 254
                        .HasColumnType("text");
259 255

  
260 256
                    b.HasKey("Id");
......
269 265
                        .HasColumnType("uuid");
270 266

  
271 267
                    b.Property<string>("Name")
272
                        .IsRequired()
273 268
                        .HasColumnType("text");
274 269

  
275 270
                    b.Property<string>("Password")
276
                        .IsRequired()
277 271
                        .HasColumnType("text");
278 272

  
279 273
                    b.Property<int>("Role")
280 274
                        .HasColumnType("integer");
281 275

  
282 276
                    b.Property<string>("Surname")
283
                        .IsRequired()
284 277
                        .HasColumnType("text");
285 278

  
286 279
                    b.Property<string>("Username")
287
                        .IsRequired()
288 280
                        .HasColumnType("text");
289 281

  
290 282
                    b.HasKey("Id");
......
363 355
                {
364 356
                    b.HasOne("Core.Entities.DocumentContent", "Content")
365 357
                        .WithMany()
366
                        .HasForeignKey("ContentId")
367
                        .OnDelete(DeleteBehavior.Cascade)
368
                        .IsRequired();
358
                        .HasForeignKey("ContentId");
369 359

  
370 360
                    b.HasOne("Core.Entities.User", "UserAdded")
371 361
                        .WithMany()
372
                        .HasForeignKey("UserAddedId")
373
                        .OnDelete(DeleteBehavior.Cascade)
374
                        .IsRequired();
362
                        .HasForeignKey("UserAddedId");
375 363

  
376 364
                    b.Navigation("Content");
377 365

  
Backend/Backend/Program.cs
113 113
    // In development we seed dummy data
114 114
    if (app.Environment.IsDevelopment())
115 115
    {
116
        //context.Database.EnsureDeleted();
117
        //context.Database.EnsureCreated();
116 118
        context.Database.Migrate();
117 119
        Seeder.SeedDevelopment(context);
118 120
    }
Backend/Core/Entities/AnnotationTag.cs
17 17
        /** Nullable for optional */
18 18
        public SubTag? SubTag { get; set; }
19 19

  
20
        public int Instance { get; set; }
20
        public Guid Instance { get; set; }
21 21
        public string Note { get; set; }
22 22
        public int Position { get; set; }
23 23
        public int Length { get; set; }
Backend/Core/Seeding/Seeder.cs
36 36
            AnnotationTag at = new AnnotationTag()
37 37
            {
38 38
                Annotation = annotation,
39
                Instance = 1,
39
                Instance = Guid.NewGuid(),
40 40
                Length = 10,
41 41
                Position = 0,
42 42
                SubTag = subtag,
Backend/Core/Services/AnnotationService/AnnotationServiceEF.cs
184 184
            HtmlSanitizer sanitizer = new HtmlSanitizer();
185 185
            sanitizer.AllowedAttributes.Clear();
186 186
            sanitizer.AllowedAttributes.Add(idAttributeName);
187
            if (sanitizer.AllowedTags.Contains("script"))
188
            {
189
                sanitizer.AllowedTags.Remove("script");
190
            }
187 191

  
188 192
            docToRender = sanitizer.Sanitize(docToRender);
189 193

  
......
195 199
        {
196 200
            return text.Contains("<!DOCTYPE html>");
197 201
        }
202

  
203
        public void AddAnnotationInstance(Guid annotationId, Guid userId, ERole userRole, AnnotationInstanceAddRequest request)
204
        {
205
            var annotation = context.Annotations
206
               .Where(a => a.Id == annotationId)
207
               .Include(a => a.User)
208
               .Include(a => a.Document).ThenInclude(d => d.Content)
209
               .First();
210

  
211
            if (userRole < ERole.ADMINISTRATOR)
212
            {
213
                if (annotation.User.Id != userId)
214
                {
215
                    throw new UnauthorizedAccessException($"User {userId} does not have assigned annotation {annotationId}");
216
                }
217
            }
218

  
219
            AnnotationTag annotationTag = new()
220
            {
221
                Annotation = annotation,
222
                Instance = request.InstanceId == null ? Guid.NewGuid() : request.InstanceId.Value,
223
                Length = request.Length,
224
                Position = request.Position,
225
                Note = ""
226
            };
227

  
228
            if (request.Type == ETagType.TAG)
229
            {
230
                annotationTag.Tag = context.Tags.Where(t => t.Id == request.Id).Single();
231
                annotationTag.SubTag = null;
232
            }
233
            else if (request.Type == ETagType.SUBTAG)
234
            {
235
                var subTag = context.SubTags.Where(st => st.Id == request.Id).Include(st => st.Tag).Single();
236
                annotationTag.SubTag = subTag;
237
                annotationTag.Tag = subTag.Tag;
238
            }
239
            else
240
            {
241
                throw new ArgumentException($"Unknown tag type {request.Type}");
242
            }
243

  
244
            context.SaveChanges();
245
        }
198 246
    }
199 247
}
Backend/Core/Services/AnnotationService/IAnnotationService.cs
13 13
        public void CreateDocumentAnnotations(AnnotationsAddRequest request, Guid userId);
14 14
        public AnnotationListResponse GetUserAnnotations(Guid userId);
15 15
        public AnnotationInfo GetAnnotation(Guid annotationId, Guid userId, ERole userRole);
16
        public void AddAnnotationInstance(Guid annotationId, Guid userId, ERole userRole, AnnotationInstanceAddRequest request);
17

  
16 18
    }
17 19
}
Backend/Models/Annotations/AnnotationInstanceAddRequest.cs
1
using Models.Enums;
2
using System;
3
using System.Collections.Generic;
4
using System.Linq;
5
using System.Text;
6
using System.Threading.Tasks;
7

  
8
namespace Models.Annotations
9
{
10
    public class AnnotationInstanceAddRequest
11
    {
12
        public int Position { get; set; }
13
        public int Length { get; set; }
14
        public ETagType Type { get; set; }
15
        public Guid Id { get; set; }
16
        
17
        // If se to null, the instance is a new one 
18
        public Guid? InstanceId { get; set; }
19
    }
20
}
Backend/Models/Enums/ETagType.cs
1
using System;
2
using System.Collections.Generic;
3
using System.Linq;
4
using System.Text;
5
using System.Threading.Tasks;
6

  
7
namespace Models.Enums
8
{
9
    public enum ETagType
10
    {
11
        TAG,
12
        SUBTAG
13
    }
14
}
Backend/Models/Tags/TagInstanceInfo.cs
15 15
        public string? SubTagName { get; set; }
16 16
        public Guid? SubTagId { get; set; }
17 17

  
18
        public int Instance { get; set; }
18
        public Guid Instance { get; set; }
19 19
        public int Position { get; set; }
20 20
        public int Length { get; set; }
21 21

  

Také k dispozici: Unified diff