Skip to content

Commit

Permalink
JPA - implémentation annotation api
Browse files Browse the repository at this point in the history
  • Loading branch information
gideruette committed Sep 27, 2023
1 parent fefc62e commit 320992a
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions TopModel.Generator.Jpa/SpringServerApiGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ protected override void HandleFile(string filePath, string fileName, string tag,

foreach (var endpoint in endpoints)
{
WriteEndpoint(fw, endpoint);
WriteEndpoint(fw, endpoint, tag);
}

fw.WriteLine("}");
Expand Down Expand Up @@ -97,7 +97,7 @@ private IEnumerable<string> GetTypeImports(IEnumerable<Endpoint> endpoints, stri
.SelectMany(c => c.GetKindImports(Config, tag)));
}

private void WriteEndPointMethod(JavaWriter fw, Endpoint endpoint)
private void WriteEndPointMethod(JavaWriter fw, Endpoint endpoint, string tag)
{
fw.WriteDocStart(1, endpoint.Description);

Expand Down Expand Up @@ -145,18 +145,22 @@ private void WriteEndPointMethod(JavaWriter fw, Endpoint endpoint)
var methodParams = new List<string>();
foreach (var param in endpoint.GetRouteParams())
{
var ann = string.Empty;
ann += @$"@PathVariable(""{param.GetParamName()}"") ";
var pathParamAnnotation = @$"@PathVariable(""{param.GetParamName()}"")";

fw.AddImport("org.springframework.web.bind.annotation.PathVariable");
methodParams.Add($"{ann}{Config.GetType(param)} {param.GetParamName()}");
fw.AddImports(Config.GetDomainImports(param, tag));
var decoratorAnnotations = string.Join(' ', Config.GetDomainAnnotations(param, tag).Select(a => a.StartsWith("@") ? a : "@" + a));
methodParams.Add($"{pathParamAnnotation}{(decoratorAnnotations.Length > 0 ? $" {decoratorAnnotations}" : string.Empty)} {Config.GetType(param)} {param.GetParamName()}");
}

foreach (var param in endpoint.GetQueryParams())
{
var ann = string.Empty;
ann += @$"@RequestParam(value = ""{param.GetParamName()}"", required = {(param is not IFieldProperty fp || fp.Required).ToString().ToFirstLower()}) ";
fw.AddImport("org.springframework.web.bind.annotation.RequestParam");
methodParams.Add($"{ann}{Config.GetType(param)} {param.GetParamName()}");
fw.AddImports(Config.GetDomainImports(param, tag));
var decoratorAnnotations = string.Join(' ', Config.GetDomainAnnotations(param, tag).Select(a => a.StartsWith("@") ? a : "@" + a));
methodParams.Add($"{ann}{(decoratorAnnotations.Length > 0 ? $" {decoratorAnnotations}" : string.Empty)}{Config.GetType(param)} {param.GetParamName()}");
}

var bodyParam = endpoint.GetBodyParam();
Expand Down Expand Up @@ -189,10 +193,10 @@ private void WriteEndPointMethod(JavaWriter fw, Endpoint endpoint)
}
}

private void WriteEndpoint(JavaWriter fw, Endpoint endpoint)
private void WriteEndpoint(JavaWriter fw, Endpoint endpoint, string tag)
{
fw.WriteLine();
WriteEndPointMethod(fw, endpoint);
WriteEndPointMethod(fw, endpoint, tag);
}

private void WriteImports(IEnumerable<Endpoint> endpoints, JavaWriter fw, string tag)
Expand Down

0 comments on commit 320992a

Please sign in to comment.